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  WidgetStateOnScaleHandle, // hovering over a scale interaction handle
63  };
64 
66  enum
67  {
68  WidgetEventControlPointPlace = WidgetEventUser,
76  WidgetEventControlPointSnapToSlice
77  };
78 
79  // Returns true if one of the markup points are just being previewed and not placed yet.
80  bool IsPointPreviewed();
81 
83  void UpdatePreviewPoint(vtkMRMLInteractionEventData* eventData, const char* associatedNodeID, int positionStatus);
84 
87  bool RemovePreviewPoint();
88 
89  // Places a new markup point.
90  // Reuses current preview point, if possible.
91  // Returns true if the event is processed.
92  bool PlacePoint(vtkMRMLInteractionEventData* eventData);
93 
95  virtual int AddPointFromWorldCoordinate(const double worldCoordinates[3]);
96 
99  virtual int AddNodeOnWidget(const int displayPos[2]);
100 
102  bool CanProcessInteractionEvent(vtkMRMLInteractionEventData* eventData, double &distance2) override;
103 
105  bool ProcessInteractionEvent(vtkMRMLInteractionEventData* eventData) override;
106 
108  void Leave(vtkMRMLInteractionEventData* eventData) override;
109 
110  // Allows the widget to request interactive mode (faster updates)
111  bool GetInteractive() override;
112  // Allows the widget to request a cursor shape
113  int GetMouseCursor() override;
114 
115  vtkMRMLMarkupsNode* GetMarkupsNode();
116  vtkMRMLMarkupsDisplayNode* GetMarkupsDisplayNode();
117  int GetActiveControlPoint();
118 
119  vtkSlicerMarkupsWidgetRepresentation* GetMarkupsRepresentation();
120 
121  int GetActiveComponentType();
122  int GetActiveComponentIndex();
123 
124 protected:
126  ~vtkSlicerMarkupsWidget() override;
127 
128  void StartWidgetInteraction(vtkMRMLInteractionEventData* eventData);
129  void EndWidgetInteraction();
130 
131  virtual void TranslatePoint(double eventPos[2], bool snapToSlice = false);
132  virtual void TranslateWidget(double eventPos[2]);
133  virtual void ScaleWidget(double eventPos[2]);
134  virtual void RotateWidget(double eventPos[2]);
135 
136  bool IsAnyControlPointLocked();
137 
138  // Get accurate world position.
139  // World position that comes in the event data may be inaccurate, this method computes a more reliable position.
140  // Returns true on success.
141  // refWorldPos is an optional reference position: if point distance from camera cannot be determined then
142  // depth of this reference position is used.
143  bool ConvertDisplayPositionToWorld(const int displayPos[2], double worldPos[3], double worldOrientationMatrix[9],
144  double* refWorldPos = nullptr);
145 
149 
150  // Callback interface to capture events when
151  // placing the widget.
152  // Return true if the event is processed.
153  virtual bool ProcessMouseMove(vtkMRMLInteractionEventData* eventData);
154  virtual bool ProcessWidgetMenu(vtkMRMLInteractionEventData* eventData);
155  virtual bool ProcessWidgetAction(vtkMRMLInteractionEventData* eventData);
156  virtual bool ProcessControlPointSnapToSlice(vtkMRMLInteractionEventData* eventData);
157  virtual bool ProcessControlPointDelete(vtkMRMLInteractionEventData* eventData);
158  virtual bool ProcessControlPointInsert(vtkMRMLInteractionEventData* eventData);
159  virtual bool ProcessControlPointMoveStart(vtkMRMLInteractionEventData* eventData);
160  virtual bool ProcessWidgetTranslateStart(vtkMRMLInteractionEventData* eventData);
161  virtual bool ProcessWidgetRotateStart(vtkMRMLInteractionEventData* eventData);
162  virtual bool ProcessWidgetScaleStart(vtkMRMLInteractionEventData* eventData);
163  virtual bool ProcessEndMouseDrag(vtkMRMLInteractionEventData* eventData);
164  virtual bool ProcessWidgetReset(vtkMRMLInteractionEventData* eventData);
165  virtual bool ProcessWidgetJumpCursor(vtkMRMLInteractionEventData* eventData);
166 
167  // Get the closest point on the line defined by the interaction handle axis.
168  // Input coordinates are in display coordinates, while output are in world coordinates.
169  virtual bool GetClosestPointOnInteractionAxis(int type, int index, const double inputDisplay[2], double outputIntersectionWorld[3]);
170 
171  // Get the closest point on the plane defined using the interaction handle axis as the plane normal.
172  // Input coordinates are in display coordinates, while output are in world coordinates
173  virtual bool GetIntersectionOnAxisPlane(int type, int index, const double inputDisplay[2], double outputIntersectionWorld[3]);
174 
175  // Variables for translate/rotate/scale
176  double LastEventPosition[2];
177  double StartEventOffsetPosition[2];
178 
179  // True if mouse button pressed since a point was placed.
180  // This is used to filter out "click" events that started before the point was placed.
182 
183 private:
185  void operator=(const vtkSlicerMarkupsWidget&) = delete;
186 };
187 
188 #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.