Slicer  5.0
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkSlicerMarkupsWidgetRepresentation2D.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 
30 #ifndef vtkSlicerMarkupsWidgetRepresentation2D_h
31 #define vtkSlicerMarkupsWidgetRepresentation2D_h
32 
33 #include "vtkSlicerMarkupsModuleVTKWidgetsExport.h"
35 
36 #include "vtkMRMLSliceNode.h"
37 
38 class vtkActor2D;
39 class vtkDiscretizableColorTransferFunction;
40 class vtkGlyph2D;
41 class vtkLabelPlacementMapper;
43 class vtkPlane;
44 class vtkPolyDataMapper2D;
45 class vtkProperty2D;
46 
48 
49 class VTK_SLICER_MARKUPS_MODULE_VTKWIDGETS_EXPORT vtkSlicerMarkupsWidgetRepresentation2D : public vtkSlicerMarkupsWidgetRepresentation
50 {
51 public:
54  void PrintSelf(ostream& os, vtkIndent indent) override;
55 
57  void CanInteract(vtkMRMLInteractionEventData* interactionEventData,
58  int &foundComponentType, int &foundComponentIndex, double &closestDistance2) override;
59 
61  virtual void CanInteractWithHandles(vtkMRMLInteractionEventData* interactionEventData,
62  int& foundComponentType, int& foundComponentIndex, double& closestDistance2);
63 
66  void CanInteractWithLine(vtkMRMLInteractionEventData* interactionEventData,
67  int &foundComponentType, int &foundComponentIndex, double &closestDistance2);
68 
72  void UpdateFromMRML(vtkMRMLNode* caller, unsigned long event, void *callData=nullptr) override;
73 
75  void GetActors(vtkPropCollection *) override;
76  void ReleaseGraphicsResources(vtkWindow *) override;
77  int RenderOverlay(vtkViewport *viewport) override;
78  int RenderOpaqueGeometry(vtkViewport *viewport) override;
79  int RenderTranslucentPolygonalGeometry(vtkViewport *viewport) override;
80  vtkTypeBool HasTranslucentPolygonalGeometry() override;
81 
85  int GetNthControlPointDisplayPosition(int n, double pos[2]) override;
86 
90  virtual bool GetNthControlPointViewVisibility(int n);
91 
93  virtual void SetNthControlPointSliceVisibility(int n, bool visibility);
94 
96  virtual void SetCenterSliceVisibility(bool visibility);
97 
98  void GetSliceToWorldCoordinates(const double[2], double[3]);
99  void GetWorldToSliceCoordinates(const double worldPos[3], double slicePos[2]);
100 
101  void UpdateInteractionPipeline() override;
102 
103 protected:
106 
108  void SetupInteractionPipeline() override;
109 
111  vtkMRMLSliceNode *GetSliceNode();
112 
113  void UpdatePlaneFromSliceNode();
114 
115  void UpdateViewScaleFactor() override;
116  void UpdateControlPointSize() override;
117 
118  // Return squared distance of maximum distance for picking a control point,
119  // in pixels.
120  double GetMaximumControlPointPickingDistance2();
121  // Return squared distance of maximum distance for picking an interaction handle,
122  // in pixels.
123  double GetMaximumInteractionHandlePickingDistance2();
124 
125  bool GetAllControlPointsVisible() override;
126 
128  virtual bool IsControlPointDisplayableOnSlice(vtkMRMLMarkupsNode* node, int pointIndex = 0);
129 
130  // Update colormap based on provided base color (modulated with settings stored in the display node)
131  virtual void UpdateDistanceColorMap(vtkDiscretizableColorTransferFunction* colormap, double color[3]);
132 
134  virtual bool IsPointBehindSlice(vtkMRMLMarkupsNode* node, int pointIndex = 0);
135 
137  virtual bool IsPointInFrontSlice(vtkMRMLMarkupsNode* node, int pointIndex = 0);
138 
140  virtual bool IsCenterDisplayableOnSlice(vtkMRMLMarkupsNode* node);
141 
143  void GetWorldToDisplayCoordinates(double r, double a, double s, double * displayCoordinates);
144  void GetWorldToDisplayCoordinates(double * worldCoordinates, double * displayCoordinates);
145 
147  bool IsRepresentationIntersectingSlice(vtkPolyData* representation, const char* arrayName);
148 
149  class ControlPointsPipeline2D : public ControlPointsPipeline
150  {
151  public:
153  ~ControlPointsPipeline2D() override;
154 
155  vtkSmartPointer<vtkActor2D> Actor;
156  vtkSmartPointer<vtkPolyDataMapper2D> Mapper;
157  vtkSmartPointer<vtkGlyph2D> Glypher;
158  vtkSmartPointer<vtkActor2D> LabelsActor;
159  vtkSmartPointer<vtkLabelPlacementMapper> LabelsMapper;
160  // Properties used to control the appearance of selected objects and
161  // the manipulator in general.
162  vtkSmartPointer<vtkProperty2D> Property;
163  };
164 
165  ControlPointsPipeline2D* GetControlPointsPipeline(int controlPointType);
166 
167  vtkSmartPointer<vtkIntArray> PointsVisibilityOnSlice;
168  bool CenterVisibilityOnSlice = { false };
169  bool AnyPointVisibilityOnSlice = { false }; // at least one point is visible
170 
171  vtkSmartPointer<vtkTransform> WorldToSliceTransform;
172  vtkSmartPointer<vtkPlane> SlicePlane;
173 
174  virtual void UpdateAllPointsAndLabelsFromMRML(double labelsOffset);
175 
176  double GetWidgetOpacity(int controlPointType);
177 
178  class MarkupsInteractionPipeline2D : public MarkupsInteractionPipeline
179  {
180  public:
182  ~MarkupsInteractionPipeline2D() override = default;;
183 
184  void GetViewPlaneNormal(double viewPlaneNormal[3]) override;
185 
186  vtkSmartPointer<vtkTransformPolyDataFilter> WorldToSliceTransformFilter;
187  };
188 
189 private:
191  void operator=(const vtkSlicerMarkupsWidgetRepresentation2D&) = delete;
192 };
193 
194 #endif
virtual void CanInteract(vtkMRMLInteractionEventData *interactionEventData, int &foundComponentType, int &foundComponentIndex, double &closestDistance2)
virtual bool GetAllControlPointsVisible()
Convenience method.
virtual void UpdateInteractionPipeline()
Update the interaction pipeline.
void UpdateFromMRML(vtkMRMLNode *caller, unsigned long event, void *callData=nullptr) override
Update the representation from markups node.
MRML node for storing a slice through RAS space.
int RenderOverlay(vtkViewport *viewport) override
vtkTypeBool HasTranslucentPolygonalGeometry() override
int RenderOpaqueGeometry(vtkViewport *viewport) override
int RenderTranslucentPolygonalGeometry(vtkViewport *viewport) override
void ReleaseGraphicsResources(vtkWindow *) override
void PrintSelf(ostream &os, vtkIndent indent) override
void GetActors(vtkPropCollection *) override
Methods to make this class behave as a vtkProp.
Default representation for the slicer markups widget.
virtual int GetNthControlPointDisplayPosition(int n, double pos[2])
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167