Slicer  4.13
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
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"
32 #include "vtkMRMLAbstractWidget.h"
33 #include "vtkWidgetCallbackMapper.h"
34 
35 #include "vtkMRMLMarkupsNode.h"
36 
41 class vtkIdList;
42 class vtkPolyData;
44 
45 class VTK_SLICER_MARKUPS_MODULE_VTKWIDGETS_EXPORT vtkSlicerMarkupsWidget : public vtkMRMLAbstractWidget
46 {
47 public:
50  void PrintSelf(ostream& os, vtkIndent indent) override;
51 
53  virtual void CreateDefaultRepresentation(vtkMRMLMarkupsDisplayNode* markupsDisplayNode, vtkMRMLAbstractViewNode* viewNode, vtkRenderer* renderer) = 0;
54 
56  enum
57  {
58  WidgetStateDefine = WidgetStateUser, // click in empty area will place a new point
59  WidgetStateTranslateControlPoint, // translating the active point by mouse move
60  WidgetStateOnTranslationHandle, // hovering over a translation interaction handle
61  WidgetStateOnRotationHandle, // hovering over a rotation interaction handle
62  };
63 
65  enum
66  {
67  WidgetEventControlPointPlace = WidgetEventUser,
75  WidgetEventControlPointSnapToSlice
76  };
77 
78  // Returns true if one of the markup points are just being previewed and not placed yet.
79  bool IsPointPreviewed();
80 
82  void UpdatePreviewPoint(vtkMRMLInteractionEventData* eventData, const char* associatedNodeID, int positionStatus);
83 
86  bool RemovePreviewPoint();
87 
88  // Places a new markup point.
89  // Reuses current preview point, if possible.
90  // Returns true if the event is processed.
91  bool PlacePoint(vtkMRMLInteractionEventData* eventData);
92 
94  virtual int AddPointFromWorldCoordinate(const double worldCoordinates[3]);
95 
98  virtual int AddNodeOnWidget(const int displayPos[2]);
99 
101  bool CanProcessInteractionEvent(vtkMRMLInteractionEventData* eventData, double &distance2) override;
102 
104  bool ProcessInteractionEvent(vtkMRMLInteractionEventData* eventData) override;
105 
107  void Leave(vtkMRMLInteractionEventData* eventData) override;
108 
109  // Allows the widget to request interactive mode (faster updates)
110  bool GetInteractive() override;
111  // Allows the widget to request a cursor shape
112  int GetMouseCursor() override;
113 
114  vtkMRMLMarkupsNode* GetMarkupsNode();
115  vtkMRMLMarkupsDisplayNode* GetMarkupsDisplayNode();
116  int GetActiveControlPoint();
117 
118  vtkSlicerMarkupsWidgetRepresentation* GetMarkupsRepresentation();
119 
120  int GetActiveComponentType();
121  int GetActiveComponentIndex();
122 
123 protected:
125  ~vtkSlicerMarkupsWidget() override;
126 
127  void StartWidgetInteraction(vtkMRMLInteractionEventData* eventData);
128  void EndWidgetInteraction();
129 
130  virtual void TranslatePoint(double eventPos[2], bool snapToSlice = false);
131  virtual void TranslateWidget(double eventPos[2]);
132  virtual void ScaleWidget(double eventPos[2]);
133  virtual void RotateWidget(double eventPos[2]);
134 
135  bool IsAnyControlPointLocked();
136 
137  // Get accurate world position.
138  // World position that comes in the event data may be inaccurate, this method computes a more reliable position.
139  // Returns true on success.
140  // refWorldPos is an optional reference position: if point distance from camera cannot be determined then
141  // depth of this reference position is used.
142  bool ConvertDisplayPositionToWorld(const int displayPos[2], double worldPos[3], double worldOrientationMatrix[9],
143  double* refWorldPos = nullptr);
144 
148 
149  // Callback interface to capture events when
150  // placing the widget.
151  // Return true if the event is processed.
152  virtual bool ProcessMouseMove(vtkMRMLInteractionEventData* eventData);
153  virtual bool ProcessWidgetMenu(vtkMRMLInteractionEventData* eventData);
154  virtual bool ProcessWidgetAction(vtkMRMLInteractionEventData* eventData);
155  virtual bool ProcessControlPointSnapToSlice(vtkMRMLInteractionEventData* eventData);
156  virtual bool ProcessControlPointDelete(vtkMRMLInteractionEventData* eventData);
157  virtual bool ProcessControlPointInsert(vtkMRMLInteractionEventData* eventData);
158  virtual bool ProcessControlPointMoveStart(vtkMRMLInteractionEventData* eventData);
159  virtual bool ProcessWidgetTranslateStart(vtkMRMLInteractionEventData* eventData);
160  virtual bool ProcessWidgetRotateStart(vtkMRMLInteractionEventData* eventData);
161  virtual bool ProcessWidgetScaleStart(vtkMRMLInteractionEventData* eventData);
162  virtual bool ProcessEndMouseDrag(vtkMRMLInteractionEventData* eventData);
163  virtual bool ProcessWidgetReset(vtkMRMLInteractionEventData* eventData);
164  virtual bool ProcessWidgetJumpCursor(vtkMRMLInteractionEventData* eventData);
165 
166  // Get the closest point on the line defined by the interaction handle axis.
167  // Input coordinates are in display coordinates, while output are in world coordinates.
168  virtual bool GetClosestPointOnInteractionAxis(int type, int index, const double inputDisplay[2], double outputIntersectionWorld[3]);
169 
170  // Get the closest point on the plane defined using the interaction handle axis as the plane normal.
171  // Input coordinates are in display coordinates, while output are in world coordinates
172  virtual bool GetIntersectionOnAxisPlane(int type, int index, const double inputDisplay[2], double outputIntersectionWorld[3]);
173 
174  // Variables for translate/rotate/scale
175  double LastEventPosition[2];
176  double StartEventOffsetPosition[2];
177 
178  // True if mouse button pressed since a point was placed.
179  // This is used to filter out "click" events that started before the point was placed.
181 
182 private:
184  void operator=(const vtkSlicerMarkupsWidget&) = delete;
185 };
186 
187 #endif
virtual bool CanProcessInteractionEvent(vtkMRMLInteractionEventData *eventData, double &distance2)
virtual bool GetInteractive()
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 markup widget nodes.
virtual bool ProcessInteractionEvent(vtkMRMLInteractionEventData *eventData)
virtual void Leave(vtkMRMLInteractionEventData *eventData)
Called when the the widget loses the focus.
void PrintSelf(ostream &os, vtkIndent indent) override
virtual int GetMouseCursor()
Process interaction events to update state of MRML widget nodes.