Slicer  4.13
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 
122  bool GetAllControlPointsVisible() override;
123 
125  virtual bool IsControlPointDisplayableOnSlice(vtkMRMLMarkupsNode* node, int pointIndex = 0);
126 
127  // Update colormap based on provided base color (modulated with settings stored in the display node)
128  virtual void UpdateDistanceColorMap(vtkDiscretizableColorTransferFunction* colormap, double color[3]);
129 
131  virtual bool IsPointBehindSlice(vtkMRMLMarkupsNode* node, int pointIndex = 0);
132 
134  virtual bool IsPointInFrontSlice(vtkMRMLMarkupsNode* node, int pointIndex = 0);
135 
137  virtual bool IsCenterDisplayableOnSlice(vtkMRMLMarkupsNode* node);
138 
140  void GetWorldToDisplayCoordinates(double r, double a, double s, double * displayCoordinates);
141  void GetWorldToDisplayCoordinates(double * worldCoordinates, double * displayCoordinates);
142 
143  class ControlPointsPipeline2D : public ControlPointsPipeline
144  {
145  public:
147  ~ControlPointsPipeline2D() override;
148 
149  vtkSmartPointer<vtkActor2D> Actor;
150  vtkSmartPointer<vtkPolyDataMapper2D> Mapper;
151  vtkSmartPointer<vtkGlyph2D> Glypher;
152  vtkSmartPointer<vtkActor2D> LabelsActor;
153  vtkSmartPointer<vtkLabelPlacementMapper> LabelsMapper;
154  // Properties used to control the appearance of selected objects and
155  // the manipulator in general.
156  vtkSmartPointer<vtkProperty2D> Property;
157  };
158 
159  ControlPointsPipeline2D* GetControlPointsPipeline(int controlPointType);
160 
161  vtkSmartPointer<vtkIntArray> PointsVisibilityOnSlice;
162  bool CenterVisibilityOnSlice = { false };
163  bool AnyPointVisibilityOnSlice = { false }; // at least one point is visible
164 
165  vtkSmartPointer<vtkTransform> WorldToSliceTransform;
166  vtkSmartPointer<vtkPlane> SlicePlane;
167 
168  virtual void UpdateAllPointsAndLabelsFromMRML(double labelsOffset);
169 
170  double GetWidgetOpacity(int controlPointType);
171 
172  class MarkupsInteractionPipeline2D : public MarkupsInteractionPipeline
173  {
174  public:
176  ~MarkupsInteractionPipeline2D() override = default;;
177 
178  void GetViewPlaneNormal(double viewPlaneNormal[3]) override;
179 
180  vtkSmartPointer<vtkTransformPolyDataFilter> WorldToSliceTransformFilter;
181  };
182 
183 private:
185  void operator=(const vtkSlicerMarkupsWidgetRepresentation2D&) = delete;
186 };
187 
188 #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