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