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 int GetSelectedMeasureIndex() { return m_LastSelection; }
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 int GetCurreasureIdx() const { return m_CurrMeasure; }
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(int dist/*Default = 4*/);
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 FindAndHighlight(double *pointCoord) {};
232
234 virtual void UpdateEditActors(double * point1, double * point2 = NULL) {};
235 virtual void UpdatePointActor(double * point) {};
236 virtual void UpdateTextActor(int index, double * point);
237
238 virtual void ShowEditLineActors() {};
239 virtual void HideEditActors() {};
240
241// /** Set Measure Action (None, Add, Edit, Move) and Update mouse Cursor */
242// void SetAction(MEASURE_ACTIONS action);
243
244 void SetColor(vtkActor2D *actor, Color *color);
245
247 MEASURE_ACTIONS GetAction() { return m_Action; }
248
249 void iSetColor(int color, double r, double g, double b, double a);
250
252 bool IsInBound(double *pos);
253 void ScreenToWorld(double screen[2], double world[3]);
254 void WorldToScreen(double world[3], double screen[2]);
255
256 //vtkPointSource produces a random-distributed pointCloud, use this method to obtain a fixed position single point output
257 vtkPointSource *GetNewPointSource();
258
259 double DistanceBetweenPoints(double *point1, double *point2);
260 double DistancePointToLine(double * point, double * lineP1, double * lineP2);
261 void GetMidPoint(double(&midPoint)[3], double *point1, double *point2);
262 bool FindPointOnLine(double(&point)[3], double *linePoint1, double *linePoint2, double distance);
263 double GetAngle(double* point1, double* point2, double* origin);
264 void RotatePoint(double *point, double *origin, double angle);
265 int PointUpDownLine(double *point, double *lp1, double *lp2);
266 void GetParallelLine(double(&point1)[3], double(&point2)[3], double *linePoint1, double *linePoint2, double distance);
267
269 vtkRenderer *m_Renderer;
270 vtkRenderer *m_CurrentRenderer;
271 std::vector<vtkRenderer *> m_AllRenderersVector;
273 vtkCoordinate *m_Coordinate;
274
276
277 // Text Actor Vector
278 std::vector<vtkALBATextActorMeter *> m_TextActorVector;
279
281
284
285 Color m_Colors[5];
286
289
290 double m_OldLineP1[3];
291 double m_OldLineP2[3];
292
293 double *m_Bounds;
296
297 double m_StartMousePosition[3];
298
301 double m_ViewPlaneNormal[3];
304
307
311
317
320
324
325 int POINT_UPDATE_DISTANCE = 4;
326 int POINT_UPDATE_DISTANCE_2 = (POINT_UPDATE_DISTANCE * POINT_UPDATE_DISTANCE);
327
328private:
329
330 MEASURE_ACTIONS m_Action; // Measure Action
331
332 albaInteractor2DMeasure(const albaInteractor2DMeasure&); // Not implemented.
333 void operator=(const albaInteractor2DMeasure&); // Not implemented.
334 friend class albaInteractor2DMeasureTest;
335};
336
337#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)
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 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)
void SetUpdateDistance(int dist)
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.
int GetCurreasureIdx() const
Returns current measure index.
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.
int GetSelectedMeasureIndex()
Returns the Current Measure Selected index.
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