Slicer 5.4
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
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 vtkSlicerMarkupsWidgetRepresentation_h
42#define vtkSlicerMarkupsWidgetRepresentation_h
43
44#include "vtkSlicerMarkupsModuleVTKWidgetsExport.h"
45
48#include "vtkMRMLMarkupsNode.h"
49
50#include "vtkActor2D.h"
51#include "vtkAppendPolyData.h"
52#include "vtkArcSource.h"
53#include "vtkArrowSource.h"
54#include "vtkGlyph3D.h"
55#include "vtkLookupTable.h"
57#include "vtkPointPlacer.h"
58#include "vtkPointSetToLabelHierarchy.h"
59#include "vtkPolyDataMapper2D.h"
60#include "vtkProperty2D.h"
61#include "vtkSmartPointer.h"
62#include "vtkSphereSource.h"
63#include "vtkTextActor.h"
64#include "vtkTextProperty.h"
65#include "vtkTensorGlyph.h"
66#include "vtkTransform.h"
67#include "vtkTransformPolyDataFilter.h"
68#include "vtkTubeFilter.h"
69
71
72class VTK_SLICER_MARKUPS_MODULE_VTKWIDGETS_EXPORT vtkSlicerMarkupsWidgetRepresentation : public vtkMRMLAbstractWidgetRepresentation
73{
74public:
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 virtual void UpdateFromMRMLInternal(vtkMRMLNode* caller, unsigned long event, void *callData = nullptr);
92
94 void GetActors(vtkPropCollection*) override;
95 void ReleaseGraphicsResources(vtkWindow*) override;
96 int RenderOverlay(vtkViewport* viewport) override;
97 int RenderOpaqueGeometry(vtkViewport* viewport) override;
98 int RenderTranslucentPolygonalGeometry(vtkViewport* viewport) override;
99 vtkTypeBool HasTranslucentPolygonalGeometry() override;
100
103
107 virtual int GetNthControlPointDisplayPosition(int n, double pos[2]);
108
111
113 virtual void SetMarkupsDisplayNode(vtkMRMLMarkupsDisplayNode *markupsDisplayNode);
116
119
121 virtual bool GetTransformationReferencePoint(double referencePointWorld[3]);
122
126 virtual void CanInteract(vtkMRMLInteractionEventData* interactionEventData,
127 int &foundComponentType, int &foundComponentIndex, double &closestDistance2);
128
129 virtual int FindClosestPointOnWidget(const int displayPos[2], double worldPos[3], int *idx);
130
131 virtual vtkPointPlacer* GetPointPlacer();
132
135 virtual vtkPolyData* GetControlPointsPolyData(int controlPointType);
138 virtual vtkPolyData* GetLabelControlPointsPolyData(int pipeline);
141 virtual vtkStringArray* GetLabels(int pipeline);
142
144
150
152 virtual void GetInteractionHandleAxisWorld(int type, int index, double axis[3]);
154 virtual void GetInteractionHandleOriginWorld(double origin[3]);
156 virtual void GetInteractionHandlePositionWorld(int type, int index, double position[3]);
157
158protected:
161
162 // Convert glyph types from display node enums to 2D glyph source enums
163 static int GetGlyphTypeSourceFromDisplay(int glyphTypeDisplay);
164
166 {
167 public:
170
175 //vtkSmartPointer<vtkPolyData> PointMarkerShape;
176 vtkSmartPointer<vtkMarkupsGlyphSource2D> GlyphSource2D;
177 vtkSmartPointer<vtkSphereSource> GlyphSourceSphere;
178
179 vtkSmartPointer<vtkPolyData> ControlPointsPolyData;
180 vtkSmartPointer<vtkPoints> ControlPoints;
181 vtkSmartPointer<vtkPolyData> LabelControlPointsPolyData;
182 vtkSmartPointer<vtkPoints> LabelControlPoints;
183 vtkSmartPointer<vtkPointSetToLabelHierarchy> PointSetToLabelHierarchyFilter;
184 vtkSmartPointer<vtkStringArray> Labels;
185 vtkSmartPointer<vtkStringArray> LabelsPriority;
186 vtkSmartPointer<vtkTextProperty> TextProperty;
187 };
188
189 class VTK_SLICER_MARKUPS_MODULE_VTKWIDGETS_EXPORT MarkupsInteractionPipeline
190 {
191 public:
194
195 vtkWeakPointer<vtkMRMLAbstractWidgetRepresentation> Representation;
196
197 vtkSmartPointer<vtkSphereSource> AxisRotationHandleSource;
198 vtkSmartPointer<vtkArcSource> AxisRotationArcSource;
199 vtkSmartPointer<vtkTubeFilter> AxisRotationTubeFilter;
200 vtkSmartPointer<vtkPolyData> AxisRotationInteriorAnglePolyData;
201 vtkSmartPointer<vtkTubeFilter> AxisRotationInterorAngleTubeFilter;
202 vtkSmartPointer<vtkPolyData> RotationHandlePoints;
203 vtkSmartPointer<vtkTransformPolyDataFilter> RotationScaleTransform;
204 vtkSmartPointer<vtkAppendPolyData> AxisRotationGlyphSource;
205 vtkSmartPointer<vtkTensorGlyph> AxisRotationGlypher;
206
207 vtkSmartPointer<vtkArrowSource> AxisTranslationGlyphSource;
208 vtkSmartPointer<vtkTransformPolyDataFilter> AxisTranslationGlyphTransformer;
209 vtkSmartPointer<vtkPolyData> TranslationHandlePoints;
210 vtkSmartPointer<vtkTransformPolyDataFilter> TranslationScaleTransform;
211 vtkSmartPointer<vtkGlyph3D> AxisTranslationGlypher;
212
213 vtkSmartPointer<vtkSphereSource> AxisScaleHandleSource;
214 vtkSmartPointer<vtkPolyData> ScaleHandlePoints;
215 vtkSmartPointer<vtkTransformPolyDataFilter> ScaleScaleTransform;
216 vtkSmartPointer<vtkGlyph3D> AxisScaleGlypher;
217
218 vtkSmartPointer<vtkAppendPolyData> Append;
219 vtkSmartPointer<vtkTransformPolyDataFilter> HandleToWorldTransformFilter;
220 vtkSmartPointer<vtkTransform> HandleToWorldTransform;
221 vtkSmartPointer<vtkLookupTable> ColorTable;
222 vtkSmartPointer<vtkPolyDataMapper2D> Mapper;
223 vtkSmartPointer<vtkActor2D> Actor;
224 vtkSmartPointer<vtkProperty2D> Property;
225
226 double StartFadeAngle{30};
227 double EndFadeAngle{20};
228 double InteractionHandleSize{1.0};
229
230 virtual void InitializePipeline();
231 virtual void CreateRotationHandles();
233 virtual void CreateScaleHandles();
235 virtual void UpdateHandleColors();
236
238 virtual void SetWidgetScale(double scale);
241 virtual void GetHandleColor(int type, int index, double color[4]);
243 virtual double GetHandleOpacity(int type, int index);
244
246 virtual void GetViewPlaneNormal(double normal[3]);
247
250 virtual void GetInteractionHandlePositionWorld(int type, int index, double position[3]);
253 virtual void GetInteractionHandleAxis(int type, int index, double axis[3]);
255 virtual void GetInteractionHandleAxisWorld(int type, int index, double axis[3]);
257 virtual void GetInteractionHandleOriginWorld(double origin[3]);
258
260 {
261 HandleInfo(int index, int componentType, double positionWorld[3], double positionLocal[3], double color[4])
262 : Index(index)
263 , ComponentType(componentType)
264 {
265 for (int i = 0; i < 3; ++i)
266 {
267 this->PositionWorld[i] = positionWorld[i];
268 }
269 this->PositionWorld[3] = 1.0;
270 for (int i = 0; i < 3; ++i)
271 {
272 this->PositionLocal[i] = positionLocal[i];
273 }
274 this->PositionLocal[3] = 1.0;
275 for (int i = 0; i < 4; ++i)
276 {
277 this->Color[i] = color[i];
278 }
279 }
280 int Index;
282 double PositionLocal[4];
283 double PositionWorld[4];
284 double Color[4];
286 {
287 double epsilon = 0.001;
288 return this->Color[3] > epsilon;
289 }
290 };
291
293 virtual std::vector<HandleInfo> GetHandleInfoList();
294 };
295 typedef std::vector<MarkupsInteractionPipeline::HandleInfo> HandleInfoList;
296
297 // Calculate view size and scale factor
298 virtual void UpdateViewScaleFactor() = 0;
299
300 virtual void UpdateControlPointSize() = 0;
301
302 // Update the size of the interaction handle based on screen size + vtkMRMLMarkupsDisplayNode::InteractionHandleScale parameter.
304
306 double ScreenSizePixel; // diagonal size of the screen
307
308 // Control point size, specified in renderer world coordinate system.
309 // For slice views, renderer world coordinate system is the display coordinate system, so it is measured in pixels.
310 // For 3D views, renderer world coordinate system is the Slicer world coordinate system, so it is measured in the
311 // scene length unit (typically millimeters).
313
314 virtual void SetMarkupsNode(vtkMRMLMarkupsNode *markupsNode);
315
316 vtkWeakPointer<vtkMRMLMarkupsDisplayNode> MarkupsDisplayNode;
317 vtkWeakPointer<vtkMRMLMarkupsNode> MarkupsNode;
318
319 vtkSmartPointer<vtkPointPlacer> PointPlacer;
320
321 vtkSmartPointer<vtkTextActor> TextActor;
322
323 vtkTypeBool CurveClosed;
324
327
330
331 // Utility function to build straight lines between control points.
332 // If displayPosition is true then positions will be computed in display coordinate system,
333 // otherwise in world coordinate system.
334 // displayPosition is normally set to true in 2D, and to false in 3D representations.
335 void BuildLine(vtkPolyData* linePolyData, bool displayPosition);
336
338
339 double* GetWidgetColor(int controlPointType) VTK_SIZEHINT(3);
340
341 ControlPointsPipeline* ControlPoints[NumberOfControlPointTypes]; // Unselected, Selected, Active, Project, ProjectBehind
342
345
348
349private:
351 void operator=(const vtkSlicerMarkupsWidgetRepresentation&) = delete;
352};
353
354#endif
Abstract Superclass for all specific types of MRML nodes.
virtual std::vector< HandleInfo > GetHandleInfoList()
Get the list of info for all interaction handles.
virtual void GetInteractionHandlePositionWorld(int type, int index, double position[3])
virtual void GetViewPlaneNormal(double normal[3])
Get the view plane normal for the widget in world coordinates.
virtual void SetWidgetScale(double scale)
Set the scale of the interaction handles in world coordinates.
virtual void GetInteractionHandleOriginWorld(double origin[3])
Get the interaction handle origin.
virtual void GetInteractionHandleAxis(int type, int index, double axis[3])
virtual void GetHandleColor(int type, int index, double color[4])
virtual double GetHandleOpacity(int type, int index)
Get the opacity of the specified handle.
virtual void GetInteractionHandleAxisWorld(int type, int index, double axis[3])
Get the direction vector of the interaction handle from the interaction origin in world coordinates.
MarkupsInteractionPipeline(vtkMRMLAbstractWidgetRepresentation *representation)
virtual void GetInteractionHandleOriginWorld(double origin[3])
Get the origin of the interaction handle widget.
void GetActors(vtkPropCollection *) override
Methods to make this class behave as a vtkProp.
int RenderTranslucentPolygonalGeometry(vtkViewport *viewport) override
vtkTypeBool HasTranslucentPolygonalGeometry() override
std::vector< MarkupsInteractionPipeline::HandleInfo > HandleInfoList
virtual void UpdateFromMRMLInternal(vtkMRMLNode *caller, unsigned long event, void *callData=nullptr)
int RenderOverlay(vtkViewport *viewport) override
virtual int FindClosestPointOnWidget(const int displayPos[2], double worldPos[3], int *idx)
void BuildLine(vtkPolyData *linePolyData, bool displayPosition)
virtual void SetMarkupsDisplayNode(vtkMRMLMarkupsDisplayNode *markupsDisplayNode)
Set/Get the vtkMRMLMarkupsNode connected with this representation.
virtual vtkMRMLMarkupsNode::ControlPoint * GetNthControlPoint(int n)
Get the nth control point.
vtkWeakPointer< vtkMRMLMarkupsDisplayNode > MarkupsDisplayNode
void UpdateFromMRML(vtkMRMLNode *caller, unsigned long event, void *callData=nullptr) override
Update the representation from markups node.
virtual int GetNthControlPointDisplayPosition(int n, double pos[2])
double * GetWidgetColor(int controlPointType) VTK_SIZEHINT(3)
virtual vtkPointPlacer * GetPointPlacer()
void PrintSelf(ostream &os, vtkIndent indent) override
virtual vtkPolyData * GetLabelControlPointsPolyData(int pipeline)
int RenderOpaqueGeometry(vtkViewport *viewport) override
virtual void UpdateInteractionPipeline()
Update the interaction pipeline.
virtual vtkStringArray * GetLabels(int pipeline)
bool GetAllControlPointsSelected()
Convenience method.
virtual bool GetTransformationReferencePoint(double referencePointWorld[3])
Translation, rotation, scaling will happen around this position.
static int GetGlyphTypeSourceFromDisplay(int glyphTypeDisplay)
virtual vtkPolyData * GetControlPointsPolyData(int controlPointType)
virtual void UpdateCenterOfRotation()
Compute the center of rotation and update it in the Markups node.
virtual vtkMRMLMarkupsNode * GetMarkupsNode()
virtual vtkMRMLMarkupsDisplayNode * GetMarkupsDisplayNode()
virtual void GetInteractionHandlePositionWorld(int type, int index, double position[3])
Get the position of an interaction handle in world coordinates.
void ReleaseGraphicsResources(vtkWindow *) override
virtual void SetMarkupsNode(vtkMRMLMarkupsNode *markupsNode)
virtual bool GetAllControlPointsVisible()
Convenience method.
virtual int GetNumberOfControlPoints()
Get number of control points.
virtual void GetInteractionHandleAxisWorld(int type, int index, double axis[3])
Get the axis for the handle specified by the index.
virtual void CanInteract(vtkMRMLInteractionEventData *interactionEventData, int &foundComponentType, int &foundComponentIndex, double &closestDistance2)
HandleInfo(int index, int componentType, double positionWorld[3], double positionLocal[3], double color[4])