ALBA
albaInteractor2DMeasure.h
Go to the documentation of this file.
1/*=========================================================================
2Program: ALBA (Agile Library for Biomedical Applications)
3Module: albaInteractor2DMeasure.h
4Language: C++
5Date: $Date: 2021-01-01 12:00:00 $
6Version: $Revision: 1.0.0.0 $
7Authors: Nicola Vanella
8==========================================================================
9Copyright (c) BIC-IOR 2021 (https://github.com/IOR-BIC)
10
11This software is distributed WITHOUT ANY WARRANTY; without even
12the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13PURPOSE. See the above copyright notice for more information.
14=========================================================================*/
15
16#ifndef __albaInteractor2DMeasure_h
17#define __albaInteractor2DMeasure_h
18
19//----------------------------------------------------------------------------
20// Include :
21//----------------------------------------------------------------------------
22/*#include "appGeometry.h"*/
23
24#include "albaEvent.h"
25#include "albaInteractorPER.h"
27#include "albaGeometryUtils.h"
28#include "albaServiceClient.h"
29
30//----------------------------------------------------------------------------
31// Forward references :
32//----------------------------------------------------------------------------
34class albaRWI;
35class albaRWIBase;
36
37class vtkALBATextActorMeter;
38class vtkActor2D;
39class vtkCoordinate;
40class vtkLineSource;
41class vtkPointSource;
42class vtkPolyDataMapper2D;
43class vtkRenderWindow;
44class vtkRenderer;
45class vtkRendererCollection;
46class vtkTextActor;
47
48#define TEXT_W_SHIFT 10
49#define TEXT_H_SHIFT 5
50// #define POINT_UPDATE_DISTANCE 4
51// #define POINT_UPDATE_DISTANCE_2 (POINT_UPDATE_DISTANCE * POINT_UPDATE_DISTANCE)
52
53// Class Name: albaInteractor2DMeasure
54class ALBA_EXPORT albaInteractor2DMeasure : public albaInteractorPER, public albaServiceClient
55{
56public:
57
59
61 {
62 ID_MEASURE_STARTED = MINID,
69 };
70
72 {
73 ACTION_NONE = 0,
79 };
80
82 {
83 NO_POINT = 0,
88 };
89
90 virtual void OnEvent(albaEventBase *event);
91
93
94 virtual void AddMeasure(double *point1, double *point2 = NULL);
96 virtual void RemoveMeasure(int index);
98 virtual void RemoveAllMeasures();
100 virtual void SelectMeasure(int index);
102 virtual void ActivateMeasure(int index = -1 /*-1=All*/, bool activate = true);
103
105 virtual void Enable(bool enable = true) { m_IsEnabled = enable; SelectMeasure(-1); };
106
108 void EnableAddMeasure(bool move = true) { m_AddMeasureEnable = move; };
110 void EnableEditMeasure(bool edit = true) { m_EditMeasureEnable = edit; };
112 void EnableMoveMeasure(bool move = true) { m_MoveMeasureEnable = move; };
113
115 virtual void Update(int index = -1 /*Update All*/) {};
116
118 virtual bool Load(albaVME *input, wxString tag) { return true; };
119 virtual bool Save(albaVME *input, wxString tag) { return true; };
120
122
123 double GetMeasureValue(int index);
129 albaString GetMeasureType() { return m_MeasureTypeText; };
130
132 int GetMaxMeasures(){ return m_MaxMeasures; };
134 int GetMeasureCount() { return m_Measure2DVector.size(); };
136 int GetLastEditedMeasureIndex() { return m_LastEditing; }
138 inline int GetSelectedMeasure() { return m_CurrMeasure; }
140 bool IsEnabled() { return m_IsEnabled; };
141
142 double GetPointSize() { return m_PointSize; };
143 double GetLineWidth() { return m_LineWidth; };
144
146
147 void SetMaxMeasures(int maxMeasures) { m_MaxMeasures = maxMeasures; };
149 void SetMeasureLabel(int index, albaString text);
150
152 void SetColorDefault(double r, double g, double b, double a = 1.0) { iSetColor(COLOR_DEFAULT, r, g, b, a); };
154 void SetColorSelection(double r, double g, double b, double a = 1.0) { iSetColor(COLOR_SELECTION, r, g, b, a); };
156 void SetColorEdit(double r, double g, double b, double a = 1.0) { iSetColor(COLOR_EDIT, r, g, b, a); };
158 void SetColorDisable(double r, double g, double b, double a = 1.0) { iSetColor(COLOR_DISABLE, r, g, b, a); };
160 void SetColorText(double r, double g, double b, double a = 1.0) { iSetColor(COLOR_TEXT, r, g, b, a); };
161
162 virtual void SetPointSize(double size) {};
163 virtual void SetLineWidth(double width) {};
164
165 virtual void Show(bool show) {};
166
168 void ShowText(bool show);
169 void ShowText(int measure, bool show);
170
173
174 /* Call Rendering and Camera Update */
175 void Render();
176
178 albaRWIBase* GetCurrentRwi() { return m_CurrentRwi; }
179 albaRWIBase* GetCurrentRwi(int m) { return m_Measure2DVector[m].Rwi; }
180
181 int GetCurrPlane() { return m_CurrPlane; }
182 void SetCurrPlane(int plane) { m_CurrPlane = plane; }
183
184 // Update and Draw All Measure
185 virtual void ReDrawAll() {};
186
187 void SetUpdateDistance(double dist);
188
191
192protected:
193
195 {
196 bool Active;
200 vtkRenderer *Renderer = NULL;
202 double Value = 0.0;
203 //std::vector<double[3]> Points;
204 };
205
206 // Measure Vector
207 std::vector<Measure2D> m_Measure2DVector;
209
210 enum AXIS { X, Y, Z, };
211 enum Colors { COLOR_DEFAULT, COLOR_EDIT, COLOR_SELECTION, COLOR_DISABLE, COLOR_TEXT };
212
215
217
222 virtual void OnMove(albaEventInteraction *e);
223
225 virtual void DrawNewMeasure(double * wp) {};
227 virtual void MoveMeasure(int index, double *pointCoord) {};
229 virtual void EditMeasure(int index, double *point) {};
231 virtual void RotateMeasure(int index, double *point) {};
232
234 virtual void FindAndHighlight(double *pointCoord) {};
235
237 virtual void UpdateEditActors(double * point1, double * point2 = NULL) {};
238 virtual void UpdatePointActor(double * point) {};
239 virtual void UpdateTextActor(int index, double * point);
240
241 virtual void ShowEditLineActors() {};
242 virtual void HideEditActors() {};
243
244// /** Set Measure Action (None, Add, Edit, Move) and Update mouse Cursor */
245// void SetAction(MEASURE_ACTIONS action);
246
247 void SetColor(vtkActor2D *actor, Color *color);
248
250 MEASURE_ACTIONS GetAction() { return m_Action; }
251
252 void iSetColor(int color, double r, double g, double b, double a);
253
255 bool IsInBound(double *pos);
256 void ScreenToWorld(double screen[2], double world[3]);
258 void WorldToScreen(double world[3], double screen[2]);
259
260 //vtkPointSource produces a random-distributed pointCloud, use this method to obtain a fixed position single point output
261 vtkPointSource *GetNewPointSource();
262
263 double DistanceBetweenPoints(double *point1, double *point2);
264 double DistancePointToLine(double * point, double * lineP1, double * lineP2);
265 void GetMidPoint(double(&midPoint)[3], double *point1, double *point2);
266 bool FindPointOnLine(double(&point)[3], double *linePoint1, double *linePoint2, double distance);
267 double GetAngle(double* point1, double* point2, double* origin);
268 void RotatePoint(double *point, double *origin, double angle);
269 int PointUpDownLine(double *point, double *lp1, double *lp2);
270 void GetParallelLine(double(&point1)[3], double(&point2)[3], double *linePoint1, double *linePoint2, double distance);
271
273 vtkRenderer *m_Renderer;
274 vtkRenderer *m_CurrentRenderer;
275 std::vector<vtkRenderer *> m_AllRenderersVector;
277 vtkCoordinate *m_Coordinate;
278
280
281 // Text Actor Vector
282 std::vector<vtkALBATextActorMeter *> m_TextActorVector;
283
285
288
289 Color m_Colors[5];
290
292
293 double m_OldLineP1[3];
294 double m_OldLineP2[3];
295
296 double *m_Bounds;
299
300 double m_StartMousePosition[3];
301
304 double m_ViewPlaneNormal[3];
307
309
312
315
321
324
328
331
332private:
333
334
335 MEASURE_ACTIONS m_Action; // Measure Action
336
337 albaInteractor2DMeasure(const albaInteractor2DMeasure&); // Not implemented.
338 void operator=(const albaInteractor2DMeasure&); // Not implemented.
339 friend class albaInteractor2DMeasureTest;
340};
341
342#endif
MINID
Definition: albaDecl.h:420
Implementation of the message object for the Subject/Observer design pattern.
Definition: albaEventBase.h:49
Event class to transport a triggering button and a position from pointing devices.
albaRWIBase * GetCurrentRwi(int m)
int GetSelectedMeasure()
Returns the Current Measure Selected index.
albaDeviceButtonsPadMouse * m_Mouse
virtual bool Save(albaVME *input, wxString tag)
void SetMaxMeasures(int maxMeasures)
SET.
std::vector< vtkRenderer * > m_AllRenderersVector
virtual void UpdateEditActors(double *point1, double *point2=NULL)
Update.
void EnableEditMeasure(bool edit=true)
Enable/Disable Editing Mode.
virtual void SetLineWidth(double width)
bool IsInBound(double *pos)
Utilities.
virtual void AddMeasure(double *point1, double *point2=NULL)
MEASURE.
int GetLastEditedMeasureIndex()
Returns the last Edited Measure index.
virtual void Enable(bool enable=true)
Enable/Disable Measure Interactor.
void ScreenToWorld(double screen[2], double world[3])
albaString GetMeasureType()
Get a string type of measure.
void SetColorDisable(double r, double g, double b, double a=1.0)
Set Color For Disable Measure.
void EnableMoveMeasure(bool move=true)
Enable/Disable Moving Mode.
virtual ~albaInteractor2DMeasure()
virtual void Show(bool show)
void SetColorText(double r, double g, double b, double a=1.0)
Set Color For Disable Measure.
virtual void EditMeasure(int index, double *point)
Edit Measure.
void iSetColor(int color, double r, double g, double b, double a)
void SetColorDefault(double r, double g, double b, double a=1.0)
Set Color Default.
void SetColorSelection(double r, double g, double b, double a=1.0)
Set Color Selection.
virtual void OnRightButtonUp(albaEventInteraction *e)
void SetUpdateDistance(double dist)
void WorldToScreen(double world[3], double screen[2])
int GetMaxMeasures()
Get Max Measures.
void EnableAddMeasure(bool move=true)
Enable/Disable Add Mode.
albaString GetMeasureText(int index)
Get Measure Text Value.
virtual void OnMove(albaEventInteraction *e)
virtual void OnEvent(albaEventBase *event)
Process events coming from input device.
void GetMidPoint(double(&midPoint)[3], double *point1, double *point2)
virtual void Update(int index=-1)
Update All Actors.
void RotatePoint(double *point, double *origin, double angle)
albaTypeMacro(albaInteractor2DMeasure, albaInteractorPER)
void InitRenderer(albaEventInteraction *e)
double GetMeasureValue(int index)
GET.
albaString GetMeasureLabel(int index)
Get Measure Extra Label.
virtual void SetPointSize(double size)
void GetParallelLine(double(&point1)[3], double(&point2)[3], double *linePoint1, double *linePoint2, double distance)
vtkPointSource * GetNewPointSource()
virtual void UpdateTextActor(int index, double *point)
int GetMeasureCount()
Get Number of Measures.
virtual void SelectMeasure(int index)
Select a Measure.
albaRWIBase * GetCurrentRwi()
return the current rwi
virtual void RemoveAllMeasures()
Delete all Measures.
double GetAngle(double *point1, double *point2, double *origin)
virtual void RemoveMeasure(int index)
Delete the Measure.
bool FindPointOnLine(double(&point)[3], double *linePoint1, double *linePoint2, double distance)
bool IsEnabled()
Measure Interactor Is Enabled.
void SetAction(MEASURE_ACTIONS action)
Set Measure Action (None, Add, Edit, Move) and Update mouse Cursor.
std::vector< Measure2D > m_Measure2DVector
void ShowText(int measure, bool show)
virtual void MoveMeasure(int index, double *pointCoord)
Move Measure.
virtual void UpdatePointActor(double *point)
void ShowText(bool show)
Show/Hide Text Labels.
void SetColorEdit(double r, double g, double b, double a=1.0)
Set Color Edit.
virtual void OnLeftButtonUp(albaEventInteraction *e)
int PointUpDownLine(double *point, double *lp1, double *lp2)
void SetColor(vtkActor2D *actor, Color *color)
virtual void FindAndHighlight(double *pointCoord)
Find Measure Point and Set Action.
virtual void OnLeftButtonDown(albaEventInteraction *e)
Mouse Events.
virtual void ActivateMeasure(int index=-1, bool activate=true)
Disable Measure.
virtual void DrawNewMeasure(double *wp)
Draw New Measure.
virtual bool Load(albaVME *input, wxString tag)
LOAD/SAVE.
double DistancePointToLine(double *point, double *lineP1, double *lineP2)
void SetRendererByView(albaView *view)
Set Renderer by View needed.
void SetMeasureLabel(int index, albaString text)
Set Measure Extra Label.
MEASURE_ACTIONS GetAction()
Get current Measure.
double DistanceBetweenPoints(double *point1, double *point2)
std::vector< vtkALBATextActorMeter * > m_TextActorVector
virtual void RotateMeasure(int index, double *point)
Rotate Measure.
Class implementing routing of events based on picking.
albaRWIBase is a vtkRenderWindowInteractor placed on a wxWindow
Definition: albaRWIBase.h:61
albaString - performs common string operations on c-strings.
Definition: albaString.h:43
albaVME -
Definition: albaVME.h:150
albaView is the base class for Views in alba.
Definition: albaView.h:79