Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
27
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
64 };
65
67 enum
68 {
78 WidgetEventReserved, // this events is only to prevent other widgets from processing an event
80 };
81
82 // Returns true if one of the markup points are just being previewed and not placed yet.
84
87
89 void UpdatePreviewPoint(vtkMRMLInteractionEventData* eventData, const char* associatedNodeID, int positionStatus);
90
94
95 // Places a new markup point.
96 // Reuses current preview point, if possible.
97 // Returns true if the event is processed.
98 virtual bool PlacePoint(vtkMRMLInteractionEventData* eventData);
99
101 virtual int AddPointFromWorldCoordinate(const double worldCoordinates[3]);
102
105 virtual int AddNodeOnWidget(const int displayPos[2]);
106
108 bool CanProcessInteractionEvent(vtkMRMLInteractionEventData* eventData, double &distance2) override;
109
112
114 void Leave(vtkMRMLInteractionEventData* eventData) override;
115
116 // Allows the widget to request interactive mode (faster updates)
117 bool GetInteractive() override;
118 // Allows the widget to request a cursor shape
119 int GetMouseCursor() override;
120
124
126
129
131
132protected:
135
138
139 virtual void TranslatePoint(double eventPos[2], bool snapToSlice = false);
140 virtual void TranslateWidget(double eventPos[2]);
141
143
144 // Get accurate world position.
145 // World position that comes in the event data may be inaccurate, this method computes a more reliable position.
146 // Returns true on success.
147 // refWorldPos is an optional reference position: if point distance from camera cannot be determined then
148 // depth of this reference position is used.
149 bool ConvertDisplayPositionToWorld(const int displayPos[2], double worldPos[3], double worldOrientationMatrix[9],
150 double* refWorldPos = nullptr);
151
155
156 // Callback interface to capture events when
157 // placing the widget.
158 // Return true if the event is processed.
171
172 // Variables for translate
175
176private:
178 void operator=(const vtkSlicerMarkupsWidget&) = delete;
179};
180
181//----------------------------------------------------------------------
182// CREATE INSTANCE MACRO
183
184#ifdef VTK_HAS_INITIALIZE_OBJECT_BASE
185#define vtkSlicerMarkupsWidgetCreateInstanceMacro(type) \
186vtkSlicerMarkupsWidget* CreateInstance() const override\
187{ \
188 vtkObject* ret = vtkObjectFactory::CreateInstance(#type); \
189 if(ret) \
190 { \
191 return static_cast<type *>(ret); \
192 } \
193 type* result = new type; \
194 result->InitializeObjectBase(); \
195 return result; \
196}
197#else
198#define vtkSlicerMarkupsWidgetCreateInstanceMacro(type) \
199vtkSlicerMarkupsWidget* CreateInstance() const override\
200{ \
201 vtkObject* ret = vtkObjectFactory::CreateInstance(#type); \
202 if(ret) \
203 { \
204 return static_cast<type *>(ret); \
205 } \
206 return new type; \
207}
208#endif
209
210#endif
Abstract MRML node to represent a view. The class holds the properties common to any view type (3D,...
@ WidgetStateUser
this is a starting index that can be used for widget-specific states
@ WidgetEventUser
this is a starting index that can be used for widget-specific events
MRML node for storing information about the active nodes in the scene.
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.
vtkSlicerMarkupsWidgetRepresentation * GetMarkupsRepresentation()
virtual bool ProcessWidgetStopPlace(vtkMRMLInteractionEventData *eventData)
virtual bool ProcessControlPointDelete(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)
~vtkSlicerMarkupsWidget() override
virtual bool ProcessWidgetMenu(vtkMRMLInteractionEventData *eventData)
void PrintSelf(ostream &os, vtkIndent indent) override
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 ProcessWidgetJumpCursor(vtkMRMLInteractionEventData *eventData)
vtkMRMLMarkupsNode * GetMarkupsNode()
int GetMouseCursor() override
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)