Slicer 5.4
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
vtkSlicerMarkupsWidget.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Copyright (c) ProxSim ltd., Kwun Tong, Hong Kong. All Rights Reserved.
4
5 See COPYRIGHT.txt
6 or http://www.slicer.org/copyright/copyright.txt for details.
7
8 Unless required by applicable law or agreed to in writing, software
9 distributed under the License is distributed on an "AS IS" BASIS,
10 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 See the License for the specific language governing permissions and
12 limitations under the License.
13
14 This file was originally developed by Davide Punzo, punzodavide@hotmail.it,
15 and development was supported by ProxSim ltd.
16
17=========================================================================*/
18
28#ifndef vtkSlicerMarkupsWidget_h
29#define vtkSlicerMarkupsWidget_h
30
31#include "vtkSlicerMarkupsModuleVTKWidgetsExport.h"
33#include "vtkWidgetCallbackMapper.h"
34
35#include "vtkMRMLMarkupsNode.h"
36
41class vtkIdList;
42class vtkPolyData;
44
45class VTK_SLICER_MARKUPS_MODULE_VTKWIDGETS_EXPORT vtkSlicerMarkupsWidget : public vtkMRMLAbstractWidget
46{
47public:
50 void PrintSelf(ostream& os, vtkIndent indent) override;
51
53 virtual void CreateDefaultRepresentation(vtkMRMLMarkupsDisplayNode* markupsDisplayNode, vtkMRMLAbstractViewNode* viewNode, vtkRenderer* renderer) = 0;
54
57
59 enum
60 {
61 WidgetStateDefine = WidgetStateUser, // click in empty area will place a new point
62 WidgetStateTranslateControlPoint, // translating the active point by mouse move
63 WidgetStateOnTranslationHandle, // hovering over a translation interaction handle
64 WidgetStateOnRotationHandle, // hovering over a rotation interaction handle
65 WidgetStateOnScaleHandle, // hovering over a scale interaction handle
66 WidgetStateMarkups_Last
67 };
68
70 enum
71 {
72 WidgetEventControlPointPlace = WidgetEventUser,
81 WidgetEventReserved, // this events is only to prevent other widgets from processing an event
82 WidgetEventMarkups_Last
83 };
84
85 // Returns true if one of the markup points are just being previewed and not placed yet.
87
90
92 void UpdatePreviewPoint(vtkMRMLInteractionEventData* eventData, const char* associatedNodeID, int positionStatus);
93
97
98 // Places a new markup point.
99 // Reuses current preview point, if possible.
100 // Returns true if the event is processed.
101 virtual bool PlacePoint(vtkMRMLInteractionEventData* eventData);
102
104 virtual int AddPointFromWorldCoordinate(const double worldCoordinates[3]);
105
108 virtual int AddNodeOnWidget(const int displayPos[2]);
109
111 bool CanProcessInteractionEvent(vtkMRMLInteractionEventData* eventData, double &distance2) override;
112
115
117 void Leave(vtkMRMLInteractionEventData* eventData) override;
118
119 // Allows the widget to request interactive mode (faster updates)
120 bool GetInteractive() override;
121 // Allows the widget to request a cursor shape
122 int GetMouseCursor() override;
123
127
129
132
134
135protected:
138
141
142 virtual void TranslatePoint(double eventPos[2], bool snapToSlice = false);
143 virtual void TranslateWidget(double eventPos[2]);
144 virtual void ScaleWidget(double eventPos[2]);
145 virtual void RotateWidget(double eventPos[2]);
146
148
149 // Get accurate world position.
150 // World position that comes in the event data may be inaccurate, this method computes a more reliable position.
151 // Returns true on success.
152 // refWorldPos is an optional reference position: if point distance from camera cannot be determined then
153 // depth of this reference position is used.
154 bool ConvertDisplayPositionToWorld(const int displayPos[2], double worldPos[3], double worldOrientationMatrix[9],
155 double* refWorldPos = nullptr);
156
160
161 // Callback interface to capture events when
162 // placing the widget.
163 // Return true if the event is processed.
178
179 // Get the closest point on the line defined by the interaction handle axis.
180 // Input coordinates are in display coordinates, while output are in world coordinates.
181 virtual bool GetClosestPointOnInteractionAxis(int type, int index, const double inputDisplay[2], double outputIntersectionWorld[3]);
182
183 // Get the closest point on the plane defined using the interaction handle axis as the plane normal.
184 // Input coordinates are in display coordinates, while output are in world coordinates
185 virtual bool GetIntersectionOnAxisPlane(int type, int index, const double inputDisplay[2], double outputIntersectionWorld[3]);
186
187 // Variables for translate/rotate/scale
188 double LastEventPosition[2];
189 double StartEventOffsetPosition[2];
190
191private:
193 void operator=(const vtkSlicerMarkupsWidget&) = delete;
194};
195
196//----------------------------------------------------------------------
197// CREATE INSTANCE MACRO
198
199#ifdef VTK_HAS_INITIALIZE_OBJECT_BASE
200#define vtkSlicerMarkupsWidgetCreateInstanceMacro(type) \
201vtkSlicerMarkupsWidget* CreateInstance() const override\
202{ \
203 vtkObject* ret = vtkObjectFactory::CreateInstance(#type); \
204 if(ret) \
205 { \
206 return static_cast<type *>(ret); \
207 } \
208 type* result = new type; \
209 result->InitializeObjectBase(); \
210 return result; \
211}
212#else
213#define vtkSlicerMarkupsWidgetCreateInstanceMacro(type) \
214vtkSlicerMarkupsWidget* CreateInstance() const override\
215{ \
216 vtkObject* ret = vtkObjectFactory::CreateInstance(#type); \
217 if(ret) \
218 { \
219 return static_cast<type *>(ret); \
220 } \
221 return new type; \
222}
223#endif
224
225#endif
Abstract MRML node to represent a view. The class holds the properties common to any view type (3D,...
Process interaction events to update state of MRML widget nodes.
MRML node for storing information about the active nodes in the scene.
Process interaction events to update state of markup widget nodes.
virtual void TranslatePoint(double eventPos[2], bool snapToSlice=false)
virtual bool ProcessControlPointSnapToSlice(vtkMRMLInteractionEventData *eventData)
bool GetInteractive() override
vtkMRMLMarkupsDisplayNode * GetMarkupsDisplayNode()
void UpdatePreviewPoint(vtkMRMLInteractionEventData *eventData, const char *associatedNodeID, int positionStatus)
Add/update a point preview to the current active Markup at the specified position.
virtual int AddNodeOnWidget(const int displayPos[2])
virtual bool ProcessWidgetReset(vtkMRMLInteractionEventData *eventData)
virtual void CreateDefaultRepresentation(vtkMRMLMarkupsDisplayNode *markupsDisplayNode, vtkMRMLAbstractViewNode *viewNode, vtkRenderer *renderer)=0
Create the default widget representation and initializes the widget and representation.
virtual vtkSlicerMarkupsWidget * CreateInstance() const =0
Create instance of the markups widget.
virtual void ScaleWidget(double eventPos[2])
vtkSlicerMarkupsWidgetRepresentation * GetMarkupsRepresentation()
virtual bool ProcessWidgetStopPlace(vtkMRMLInteractionEventData *eventData)
virtual bool ProcessControlPointDelete(vtkMRMLInteractionEventData *eventData)
virtual bool ProcessWidgetRotateStart(vtkMRMLInteractionEventData *eventData)
virtual bool ProcessWidgetAction(vtkMRMLInteractionEventData *eventData)
bool CanProcessInteractionEvent(vtkMRMLInteractionEventData *eventData, double &distance2) override
Return true if the widget can process the event.
void UpdatePreviewPointIndex(vtkMRMLInteractionEventData *eventData)
Update a the current index of the point preview being previewed.
void StartWidgetInteraction(vtkMRMLInteractionEventData *eventData)
bool ConvertDisplayPositionToWorld(const int displayPos[2], double worldPos[3], double worldOrientationMatrix[9], double *refWorldPos=nullptr)
virtual bool ProcessWidgetTranslateStart(vtkMRMLInteractionEventData *eventData)
virtual void RotateWidget(double eventPos[2])
~vtkSlicerMarkupsWidget() override
virtual bool ProcessWidgetMenu(vtkMRMLInteractionEventData *eventData)
void PrintSelf(ostream &os, vtkIndent indent) override
virtual bool GetClosestPointOnInteractionAxis(int type, int index, const double inputDisplay[2], double outputIntersectionWorld[3])
virtual bool ProcessControlPointInsert(vtkMRMLInteractionEventData *eventData)
virtual int AddPointFromWorldCoordinate(const double worldCoordinates[3])
Add a point to the current active Markup at input World coordinates.
bool ProcessInteractionEvent(vtkMRMLInteractionEventData *eventData) override
Process interaction event.
virtual bool GetIntersectionOnAxisPlane(int type, int index, const double inputDisplay[2], double outputIntersectionWorld[3])
virtual bool ProcessWidgetJumpCursor(vtkMRMLInteractionEventData *eventData)
vtkMRMLMarkupsNode * GetMarkupsNode()
int GetMouseCursor() override
virtual bool ProcessWidgetScaleStart(vtkMRMLInteractionEventData *eventData)
void Leave(vtkMRMLInteractionEventData *eventData) override
Called when the the widget loses the focus.
virtual bool ProcessEndMouseDrag(vtkMRMLInteractionEventData *eventData)
vtkMRMLSelectionNode * selectionNode()
virtual bool PlacePoint(vtkMRMLInteractionEventData *eventData)
virtual bool ProcessMouseMove(vtkMRMLInteractionEventData *eventData)
virtual void TranslateWidget(double eventPos[2])
virtual bool ProcessControlPointMoveStart(vtkMRMLInteractionEventData *eventData)