Slicer  4.13
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkSlicerMarkupsWidgetRepresentation.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 
41 #ifndef vtkSlicerMarkupsRepresentation_h
42 #define vtkSlicerMarkupsRepresentation_h
43 
44 #include "vtkSlicerMarkupsModuleVTKWidgetsExport.h"
46 
48 #include "vtkMRMLMarkupsNode.h"
49 
50 #include "vtkSmartPointer.h"
51 
52 class vtkActor2D;
53 class vtkAppendPolyData;
54 class vtkArcSource;
55 class vtkArrayCalculator;
56 class vtkArrowSource;
57 class vtkConeSource;
58 class vtkGlyph3D;
61 class vtkPointPlacer;
62 class vtkPointSetToLabelHierarchy;
63 class vtkPolyDataMapper2D;
64 class vtkProperty2D;
65 class vtkRegularPolygonSource;
66 class vtkSphereSource;
67 class vtkTextActor;
68 class vtkTextProperty;
69 class vtkTensorGlyph;
70 class vtkTubeFilter;
71 
72 class VTK_SLICER_MARKUPS_MODULE_VTKWIDGETS_EXPORT vtkSlicerMarkupsWidgetRepresentation : public vtkMRMLAbstractWidgetRepresentation
73 {
74 public:
75  enum
76  {
82  NumberOfControlPointTypes
83  };
84 
87  void PrintSelf(ostream& os, vtkIndent indent) override;
88 
90  void UpdateFromMRML(vtkMRMLNode* caller, unsigned long event, void *callData = nullptr) override;
91 
93  void GetActors(vtkPropCollection*) override;
94  void ReleaseGraphicsResources(vtkWindow*) override;
95  int RenderOverlay(vtkViewport* viewport) override;
96  int RenderOpaqueGeometry(vtkViewport* viewport) override;
97  int RenderTranslucentPolygonalGeometry(vtkViewport* viewport) override;
98  vtkTypeBool HasTranslucentPolygonalGeometry() override;
99 
101  virtual int GetNumberOfControlPoints();
102 
106  virtual int GetNthControlPointDisplayPosition(int n, double pos[2]);
107 
109  virtual vtkMRMLMarkupsNode::ControlPoint *GetNthControlPoint(int n);
110 
112  virtual void SetMarkupsDisplayNode(vtkMRMLMarkupsDisplayNode *markupsDisplayNode);
113  virtual vtkMRMLMarkupsDisplayNode* GetMarkupsDisplayNode();
114  virtual vtkMRMLMarkupsNode* GetMarkupsNode();
115 
119  virtual void UpdateCenter();
120 
122  virtual bool GetTransformationReferencePoint(double referencePointWorld[3]);
123 
127  virtual void CanInteract(vtkMRMLInteractionEventData* interactionEventData,
128  int &foundComponentType, int &foundComponentIndex, double &closestDistance2);
129 
130  virtual int FindClosestPointOnWidget(const int displayPos[2], double worldPos[3], int *idx);
131 
132  virtual vtkPointPlacer* GetPointPlacer();
133 
136  virtual vtkPolyData* GetControlPointsPolyData(int controlPointType);
139  virtual vtkPolyData* GetLabelControlPointsPolyData(int pipeline);
142  virtual vtkStringArray* GetLabels(int pipeline);
143 
145 
149  bool IsDisplayable();
151 
153  virtual void GetInteractionHandleAxisWorld(int type, int index, double axis[3]);
155  virtual void GetInteractionHandleOriginWorld(double origin[3]);
156 
157 protected:
160 
161  // Convert glyph types from display node enums to 2D glyph source enums
162  static int GetGlyphTypeSourceFromDisplay(int glyphTypeDisplay);
163 
165  {
166  public:
168  virtual ~ControlPointsPipeline();
169 
174  //vtkSmartPointer<vtkPolyData> PointMarkerShape;
175  vtkSmartPointer<vtkMarkupsGlyphSource2D> GlyphSource2D;
176  vtkSmartPointer<vtkSphereSource> GlyphSourceSphere;
177 
178  vtkSmartPointer<vtkPolyData> ControlPointsPolyData;
179  vtkSmartPointer<vtkPoints> ControlPoints;
180  vtkSmartPointer<vtkPolyData> LabelControlPointsPolyData;
181  vtkSmartPointer<vtkPoints> LabelControlPoints;
182  vtkSmartPointer<vtkPointSetToLabelHierarchy> PointSetToLabelHierarchyFilter;
183  vtkSmartPointer<vtkStringArray> Labels;
184  vtkSmartPointer<vtkStringArray> LabelsPriority;
185  vtkSmartPointer<vtkTextProperty> TextProperty;
186  };
187 
189  {
190  public:
192  virtual ~MarkupsInteractionPipeline();
193 
194  vtkWeakPointer<vtkMRMLAbstractWidgetRepresentation> Representation;
195 
196  vtkSmartPointer<vtkSphereSource> AxisRotationHandleSource;
197  vtkSmartPointer<vtkArcSource> AxisRotationArcSource;
198  vtkSmartPointer<vtkTubeFilter> AxisRotationTubeFilter;
199  vtkSmartPointer<vtkAppendPolyData> AxisRotationGlyphSource;
200  vtkSmartPointer<vtkPolyData> RotationHandlePoints;
201  vtkSmartPointer<vtkTransformPolyDataFilter> RotationScaleTransform;
202  vtkSmartPointer<vtkTensorGlyph> AxisRotationGlypher;
203 
204  vtkSmartPointer<vtkArrowSource> AxisTranslationGlyphSource;
205  vtkSmartPointer<vtkTransformPolyDataFilter> AxisTranslationGlyphTransformer;
206  vtkSmartPointer<vtkPolyData> TranslationHandlePoints;
207  vtkSmartPointer<vtkTransformPolyDataFilter> TranslationScaleTransform;
208  vtkSmartPointer<vtkGlyph3D> AxisTranslationGlypher;
209 
210  vtkSmartPointer<vtkSphereSource> AxisScaleHandleSource;
211  vtkSmartPointer<vtkPolyData> ScaleHandlePoints;
212  vtkSmartPointer<vtkTransformPolyDataFilter> ScaleScaleTransform;
213  vtkSmartPointer<vtkGlyph3D> AxisScaleGlypher;
214 
215  vtkSmartPointer<vtkAppendPolyData> Append;
216  vtkSmartPointer<vtkTransformPolyDataFilter> HandleToWorldTransformFilter;
217  vtkSmartPointer<vtkTransform> HandleToWorldTransform;
218  vtkSmartPointer<vtkLookupTable> ColorTable;
219  vtkSmartPointer<vtkPolyDataMapper2D> Mapper;
220  vtkSmartPointer<vtkActor2D> Actor;
221  vtkSmartPointer<vtkProperty2D> Property;
222 
223  double StartFadeAngle{30};
224  double EndFadeAngle{20};
225  double InteractionHandleScaleFactor{7.0};
226 
227  virtual void InitializePipeline();
228  virtual void CreateRotationHandles();
229  virtual void CreateTranslationHandles();
230  virtual void CreateScaleHandles();
231  virtual void UpdateHandleColors();
232 
234  virtual void SetWidgetScale(double scale);
237  virtual void GetHandleColor(int type, int index, double color[4]);
239  virtual double GetHandleOpacity(int type, int index);
240 
242  virtual void GetViewPlaneNormal(double normal[3]);
243 
246  virtual void GetInteractionHandlePositionWorld(int type, int index, double position[3]);
249  virtual void GetInteractionHandleAxis(int type, int index, double axis[3]);
251  virtual void GetInteractionHandleAxisWorld(int type, int index, double axis[3]);
253  virtual void GetInteractionHandleOriginWorld(double origin[3]);
254 
255  struct HandleInfo
256  {
257  HandleInfo(int index, int componentType, double positionWorld[3], double positionLocal[3], double color[4])
258  : Index(index)
259  , ComponentType(componentType)
260  {
261  for (int i = 0; i < 3; ++i)
262  {
263  this->PositionWorld[i] = positionWorld[i];
264  }
265  this->PositionWorld[3] = 1.0;
266  for (int i = 0; i < 3; ++i)
267  {
268  this->PositionLocal[i] = positionLocal[i];
269  }
270  this->PositionLocal[3] = 1.0;
271  for (int i = 0; i < 4; ++i)
272  {
273  this->Color[i] = color[i];
274  }
275  }
276  int Index;
278  double PositionLocal[4];
279  double PositionWorld[4];
280  double Color[4];
281  bool IsVisible()
282  {
283  double epsilon = 0.001;
284  return this->Color[3] > epsilon;
285  }
286  };
287 
289  virtual std::vector<HandleInfo> GetHandleInfoList();
290  };
291  typedef std::vector<MarkupsInteractionPipeline::HandleInfo> HandleInfoList;
292 
293  // Calculate view size and scale factor
294  virtual void UpdateViewScaleFactor() = 0;
295 
296  virtual void UpdateControlPointSize() = 0;
297 
299  double ScreenSizePixel; // diagonal size of the screen
300 
301  // Control point size, specified in renderer world coordinate system.
302  // For slice views, renderer world coordinate system is the display coordinate system, so it is measured in pixels.
303  // For 3D views, renderer world coordinate system is the Slicer world coordinate system, so it is measured in the
304  // scene length unit (typically millimeters).
306 
307  virtual void SetMarkupsNode(vtkMRMLMarkupsNode *markupsNode);
308 
309  vtkWeakPointer<vtkMRMLMarkupsDisplayNode> MarkupsDisplayNode;
310  vtkWeakPointer<vtkMRMLMarkupsNode> MarkupsNode;
311 
312  vtkSmartPointer<vtkPointPlacer> PointPlacer;
313 
314  vtkSmartPointer<vtkTextActor> TextActor;
315 
316  vtkTypeBool CurveClosed;
317 
319  virtual bool GetAllControlPointsVisible();
320 
322  bool GetAllControlPointsSelected();
323 
324  // Utility function to build straight lines between control points.
325  // If displayPosition is true then positions will be computed in display coordinate system,
326  // otherwise in world coordinate system.
327  // displayPosition is normally set to true in 2D, and to false in 3D representations.
328  void BuildLine(vtkPolyData* linePolyData, bool displayPosition);
329 
331 
332  double* GetWidgetColor(int controlPointType);
333 
334  ControlPointsPipeline* ControlPoints[NumberOfControlPointTypes]; // Unselected, Selected, Active, Project, ProjectBehind
335 
336  virtual void SetupInteractionPipeline();
338 
340  virtual void UpdateInteractionPipeline();
341 
342 private:
344  void operator=(const vtkSlicerMarkupsWidgetRepresentation&) = delete;
345 };
346 
347 #endif
HandleInfo(int index, int componentType, double positionWorld[3], double positionLocal[3], double color[4])
vtkWeakPointer< vtkMRMLMarkupsDisplayNode > MarkupsDisplayNode
int RenderOpaqueGeometry(vtkViewport *vtkNotUsed(viewport)) override
void PrintSelf(ostream &os, vtkIndent indent) override
int RenderOverlay(vtkViewport *vtkNotUsed(viewport)) override
std::vector< MarkupsInteractionPipeline::HandleInfo > HandleInfoList
vtkSmartPointer< vtkPointSetToLabelHierarchy > PointSetToLabelHierarchyFilter
virtual void UpdateFromMRML(vtkMRMLNode *caller, unsigned long event, void *callData=nullptr)
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167
int RenderTranslucentPolygonalGeometry(vtkViewport *vtkNotUsed(viewport)) override