Slicer 5.9
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
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], double* refWorldPos = nullptr);
150
154
155 // Callback interface to capture events when
156 // placing the widget.
157 // Return true if the event is processed.
170
171 // Variables for translate
174
175private:
177 void operator=(const vtkSlicerMarkupsWidget&) = delete;
178};
179
180//----------------------------------------------------------------------
181// CREATE INSTANCE MACRO
182
183#ifdef VTK_HAS_INITIALIZE_OBJECT_BASE
184# define vtkSlicerMarkupsWidgetCreateInstanceMacro(type) \
185 vtkSlicerMarkupsWidget* CreateInstance() const override \
186 { \
187 vtkObject* ret = vtkObjectFactory::CreateInstance(#type); \
188 if (ret) \
189 { \
190 return static_cast<type*>(ret); \
191 } \
192 type* result = new type; \
193 result->InitializeObjectBase(); \
194 return result; \
195 }
196#else
197# define vtkSlicerMarkupsWidgetCreateInstanceMacro(type) \
198 vtkSlicerMarkupsWidget* CreateInstance() const override \
199 { \
200 vtkObject* ret = vtkObjectFactory::CreateInstance(#type); \
201 if (ret) \
202 { \
203 return static_cast<type*>(ret); \
204 } \
205 return new type; \
206 }
207#endif
208
209#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)