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
29//----------------------------------------------------------------------------
30// Forward references :
31//----------------------------------------------------------------------------
33class albaRWI;
34class albaRWIBase;
35
36class vtkALBATextActorMeter;
37class vtkActor2D;
38class vtkCoordinate;
39class vtkLineSource;
40class vtkPointSource;
41class vtkPolyDataMapper2D;
42class vtkRenderWindow;
43class vtkRenderer;
44class vtkRendererCollection;
45class vtkTextActor;
46
47#define TEXT_W_SHIFT 10
48#define TEXT_H_SHIFT 5
49// #define POINT_UPDATE_DISTANCE 4
50// #define POINT_UPDATE_DISTANCE_2 (POINT_UPDATE_DISTANCE * POINT_UPDATE_DISTANCE)
51
52// Class Name: albaInteractor2DMeasure
54{
55public:
56
58
60 {
61 ID_MEASURE_STARTED = MINID,
68 };
69
71 {
72 ACTION_NONE = 0,
76 };
77
79 {
80 NO_POINT = 0,
85 };
86
87 virtual void OnEvent(albaEventBase *event);
88
90
91 virtual void AddMeasure(double *point1, double *point2 = NULL);
93 virtual void RemoveMeasure(int index);
95 virtual void RemoveAllMeasures();
97 virtual void SelectMeasure(int index);
99 virtual void ActivateMeasure(int index = -1 /*-1=All*/, bool activate = true);
100
102 void Enable(bool enable = true) { m_IsEnabled = enable; SelectMeasure(-1); };
103
105 void EnableAddMeasure(bool move = true) { m_AddMeasureEnable = move; };
107 void EnableEditMeasure(bool edit = true) { m_EditMeasureEnable = edit; };
109 void EnableMoveMeasure(bool move = true) { m_MoveMeasureEnable = move; };
110
112 virtual void Update(int index = -1 /*Update All*/) {};
113
115 virtual bool Load(albaVME *input, wxString tag) { return true; };
116 virtual bool Save(albaVME *input, wxString tag) { return true; };
117
119
120 double GetMeasureValue(int index);
126 albaString GetMeasureType() { return m_MeasureTypeText; };
127
129 int GetMaxMeasures(){ return m_MaxMeasures; };
131 int GetMeasureCount() { return m_Measure2DVector.size(); };
133 int GetLastEditedMeasureIndex() { return m_LastEditing; }
135 inline int GetSelectedMeasure() { return m_CurrMeasure; }
137 bool IsEnabled() { return m_IsEnabled; };
138
139 double GetPointSize() { return m_PointSize; };
140 double GetLineWidth() { return m_LineWidth; };
141
143
144 void SetMaxMeasures(int maxMeasures) { m_MaxMeasures = maxMeasures; };
146 void SetMeasureLabel(int index, albaString text);
147
149 void SetColorDefault(double r, double g, double b, double a = 1.0) { iSetColor(COLOR_DEFAULT, r, g, b, a); };
151 void SetColorSelection(double r, double g, double b, double a = 1.0) { iSetColor(COLOR_SELECTION, r, g, b, a); };
153 void SetColorEdit(double r, double g, double b, double a = 1.0) { iSetColor(COLOR_EDIT, r, g, b, a); };
155 void SetColorDisable(double r, double g, double b, double a = 1.0) { iSetColor(COLOR_DISABLE, r, g, b, a); };
157 void SetColorText(double r, double g, double b, double a = 1.0) { iSetColor(COLOR_TEXT, r, g, b, a); };
158
159 virtual void SetPointSize(double size) {};
160 virtual void SetLineWidth(double width) {};
161
162 virtual void Show(bool show) {};
163
165 void ShowText(bool show);
166 void ShowText(int measure, bool show);
167
170
171 /* Call Rendering and Camera Update */
172 void Render();
173
175 albaRWIBase* GetCurrentRwi() { return m_CurrentRwi; }
176 albaRWIBase* GetCurrentRwi(int m) { return m_Measure2DVector[m].Rwi; }
177
178 int GetCurrPlane() { return m_CurrPlane; }
179 void SetCurrPlane(int plane) { m_CurrPlane = plane; }
180
181 // Update and Draw All Measure
182 virtual void ReDrawAll() {};
183
184 void SetUpdateDistance(double dist);
185
188
189protected:
190
192 {
193 bool Active;
197 vtkRenderer *Renderer = NULL;
199 double Value = 0.0;
200 //std::vector<double[3]> Points;
201 };
202
203 // Measure Vector
204 std::vector<Measure2D> m_Measure2DVector;
206
207 enum AXIS { X, Y, Z, };
208 enum Colors { COLOR_DEFAULT, COLOR_EDIT, COLOR_SELECTION, COLOR_DISABLE, COLOR_TEXT };
209
212
214
219 virtual void OnMove(albaEventInteraction *e);
220
222 virtual void DrawNewMeasure(double * wp) {};
224 virtual void MoveMeasure(int index, double *pointCoord) {};
226 virtual void EditMeasure(int index, double *point) {};
228 virtual void FindAndHighlight(double *pointCoord) {};
229
231 virtual void UpdateEditActors(double * point1, double * point2 = NULL) {};
232 virtual void UpdatePointActor(double * point) {};
233 virtual void UpdateTextActor(int index, double * point);
234
235 virtual void ShowEditLineActors() {};
236 virtual void HideEditActors() {};
237
238// /** Set Measure Action (None, Add, Edit, Move) and Update mouse Cursor */
239// void SetAction(MEASURE_ACTIONS action);
240
241 void SetColor(vtkActor2D *actor, Color *color);
242
244 MEASURE_ACTIONS GetAction() { return m_Action; }
245
246 void iSetColor(int color, double r, double g, double b, double a);
247
249 bool IsInBound(double *pos);
250 void ScreenToWorld(double screen[2], double world[3]);
252 void WorldToScreen(double world[3], double screen[2]);
253
254 //vtkPointSource produces a random-distributed pointCloud, use this method to obtain a fixed position single point output
255 vtkPointSource *GetNewPointSource();
256
257 double DistanceBetweenPoints(double *point1, double *point2);
258 double DistancePointToLine(double * point, double * lineP1, double * lineP2);
259 void GetMidPoint(double(&midPoint)[3], double *point1, double *point2);
260 bool FindPointOnLine(double(&point)[3], double *linePoint1, double *linePoint2, double distance);
261 double GetAngle(double* point1, double* point2, double* origin);
262 void RotatePoint(double *point, double *origin, double angle);
263 int PointUpDownLine(double *point, double *lp1, double *lp2);
264 void GetParallelLine(double(&point1)[3], double(&point2)[3], double *linePoint1, double *linePoint2, double distance);
265
267 vtkRenderer *m_Renderer;
268 vtkRenderer *m_CurrentRenderer;
269 std::vector<vtkRenderer *> m_AllRenderersVector;
271 vtkCoordinate *m_Coordinate;
272
274
275 // Text Actor Vector
276 std::vector<vtkALBATextActorMeter *> m_TextActorVector;
277
279
282
283 Color m_Colors[5];
284
286
287 double m_OldLineP1[3];
288 double m_OldLineP2[3];
289
290 double *m_Bounds;
293
294 double m_StartMousePosition[3];
295
298 double m_ViewPlaneNormal[3];
301
303
306
309
315
318
322
325
326private:
327
328
329 MEASURE_ACTIONS m_Action; // Measure Action
330
331 albaInteractor2DMeasure(const albaInteractor2DMeasure&); // Not implemented.
332 void operator=(const albaInteractor2DMeasure&); // Not implemented.
333 friend class albaInteractor2DMeasureTest;
334};
335
336#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.
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.
void Enable(bool enable=true)
Enable/Disable Measure Interactor.
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
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