Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
vtkMRMLInteractionWidgetRepresentation.h
Go to the documentation of this file.
1/*==============================================================================
2
3 Copyright (c) Laboratory for Percutaneous Surgery (PerkLab)
4 Queen's University, Kingston, ON, Canada. All Rights Reserved.
5
6 See COPYRIGHT.txt
7 or http://www.slicer.org/copyright/copyright.txt for details.
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14
15 This file was originally developed by Kyle Sunderland, PerkLab, Queen's University
16 and was supported through CANARIE's Research Software Program, Cancer
17 Care Ontario, OpenAnatomy, and Brigham and Women's Hospital through NIH grant R01MH112748.
18
19==============================================================================*/
20
41
42#ifndef vtkSlicerInteractionRepresentation_h
43#define vtkSlicerInteractionRepresentation_h
44
45// MRMLDM includes
46#include "vtkMRMLDisplayableManagerExport.h"
48
49// MRML includes
50#include <vtkMRMLSliceNode.h>
51
52// VTK includes
53#include <vtkActor.h>
54#include <vtkActor2D.h>
55#include <vtkAppendPolyData.h>
56#include <vtkArrayCalculator.h>
57#include <vtkGlyph3D.h>
58#include <vtkLookupTable.h>
59#include <vtkPlane.h>
60#include <vtkPointPlacer.h>
61#include <vtkPointSetToLabelHierarchy.h>
62#include <vtkPolyDataMapper.h>
63#include <vtkPolyDataMapper2D.h>
64#include <vtkProperty.h>
65#include <vtkProperty2D.h>
66#include <vtkSmartPointer.h>
67#include <vtkSphereSource.h>
68#include <vtkTextActor.h>
69#include <vtkTextProperty.h>
70#include <vtkTensorGlyph.h>
71#include <vtkTransform.h>
72#include <vtkTransformPolyDataFilter.h>
73
77
78class VTK_MRML_DISPLAYABLEMANAGER_EXPORT vtkMRMLInteractionWidgetRepresentation
80{
81public:
82
86 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 bool GetTransformationReferencePoint(double referencePointWorld[3]);
102
106 virtual void CanInteract(vtkMRMLInteractionEventData* interactionEventData,
107 int &foundComponentType, int &foundComponentIndex, double &closestDistance2);
108
109 virtual vtkPointPlacer* GetPointPlacer();
110
113
116 virtual bool IsDisplayable() = 0;
117
119 virtual void GetSliceToWorldCoordinates(const double slicePos[2], double worldPos[3]);
120
122
125
126 virtual void UpdateHandlePolyData();
127
129 virtual void GetInteractionHandleAxisLocal(int type, int index, double axis[3]);
130
132 virtual void GetInteractionHandleAxisWorld(int type, int index, double axis[3]);
134 virtual void GetInteractionHandleOriginWorld(double origin[3]);
135
136 enum
137 {
143 };
144
145 enum
146 {
150 };
151
152 virtual int GetActiveComponentType() = 0;
153 virtual void SetActiveComponentType(int type) = 0;
154
155 virtual int GetActiveComponentIndex() = 0;
156 virtual void SetActiveComponentIndex(int index) = 0;
157
159
160 virtual vtkTransform* GetHandleToWorldTransform();
161
162 virtual int GetNumberOfHandles(int type);
163 virtual int GetNumberOfHandles();
164
165 vtkSetMacro(Interacting, bool);
166 vtkGetMacro(Interacting, bool);
167 vtkBooleanMacro(Interacting, bool);
168
171 virtual void GetHandleColor(int type, int index, double color[4]);
173 virtual double GetHandleOpacity(int type, int index);
175 virtual bool GetHandleVisibility(int type, int index);
177 virtual int GetHandleGlyphType(int type, int index);
179 virtual bool GetApplyScaleToPosition(int type, int index);
182 virtual void GetInteractionHandlePositionLocal(int type, int index, double position[3]);
185 virtual void GetInteractionHandlePositionWorld(int type, int index, double position[3]);
186
190 virtual void UpdateHandleToWorldTransform(vtkTransform* handleToWorldTransform) = 0;
192
193protected:
196
197 class VTK_MRML_DISPLAYABLEMANAGER_EXPORT InteractionPipeline
198 {
199 public:
202
203 vtkSmartPointer<vtkPolyData> ArrowPolyData;
204 vtkSmartPointer<vtkPolyData> CirclePolyData;
205 vtkSmartPointer<vtkPolyData> RingPolyData;
206 vtkSmartPointer<vtkPolyData> ArrowOutlinePolyData;
207 vtkSmartPointer<vtkPolyData> CircleOutlinePolyData;
208 vtkSmartPointer<vtkPolyData> RingOutlinePolyData;
209
210 std::map<std::pair<int, int>, vtkSmartPointer<vtkPolyData>> HandleGlyphPolyDataMap;
211 std::map<std::pair<int, int>, vtkSmartPointer<vtkPolyData>> HandleOutlineGlyphPolyDataMap;
212
213 vtkSmartPointer<vtkPolyData> RotationHandlePoints;
214 vtkSmartPointer<vtkPolyData> TranslationHandlePoints;
215 vtkSmartPointer<vtkPolyData> ScaleHandlePoints;
216
217 vtkSmartPointer<vtkAppendPolyData> Append;
218 vtkSmartPointer<vtkTransformPolyDataFilter> HandleToWorldTransformFilter;
219 vtkSmartPointer<vtkTransform> HandleToWorldTransform;
220 vtkSmartPointer<vtkLookupTable> ColorTable;
221
222 vtkSmartPointer<vtkPolyDataMapper> Mapper3D;
223 vtkSmartPointer<vtkProperty> Property3D;
224 vtkSmartPointer<vtkActor> Actor3D;
225
226 vtkSmartPointer<vtkTransform> WorldToSliceTransform;
227 vtkSmartPointer<vtkTransformPolyDataFilter> WorldToSliceTransformFilter;
228 };
229
231 {
232 HandleInfo(int index, int componentType, double positionWorld[3], double positionLocal[3], double color[4], int glyphType, bool applyScaleToPosition)
233 : Index(index)
234 , ComponentType(componentType)
235 , GlyphType(glyphType)
236 , ApplyScaleToPosition(applyScaleToPosition)
237 {
238 for (int i = 0; i < 3; ++i)
239 {
240 this->PositionWorld[i] = positionWorld[i];
241 }
242 this->PositionWorld[3] = 1.0;
243 for (int i = 0; i < 3; ++i)
244 {
245 this->PositionLocal[i] = positionLocal[i];
246 }
247 this->PositionLocal[3] = 1.0;
248 for (int i = 0; i < 4; ++i)
249 {
250 this->Color[i] = color[i];
251 }
252 }
253 int Index;
256 double PositionLocal[4];
257 double PositionWorld[4];
258 double Color[4];
261 {
262 double epsilon = 0.001;
263 return this->Color[3] > epsilon;
264 }
265 };
266
268 typedef std::vector<HandleInfo> HandleInfoList;
270 virtual HandleInfo GetHandleInfo(int type, int index);
271
272 virtual void InitializePipeline();
273 virtual void CreateRotationHandles();
275 virtual void CreateScaleHandles();
276 virtual void UpdateHandleColors();
277 virtual int UpdateHandleColors(int type, int startIndex);
278 virtual vtkPolyData* GetHandlePolydata(int type);
279
284
286 virtual void SetWidgetScale(double scale);
287
290 virtual void GetHandleToCameraVectorWorld(double handlePosition_World[3], double normal_World[3]);
291
293 virtual void OrthoganalizeTransform(vtkTransform* transform);
294
296 virtual void UpdateViewScaleFactor();
297
298 virtual void UpdateHandleSize();
300 virtual double GetInteractionSizeMm();
302
304 int& foundComponentType, int& foundComponentIndex, double& closestDistance2, HandleInfo& handleInfo);
305 virtual void CanInteractWithArrowHandle(vtkMRMLInteractionEventData* interactionEventData,
306 int& foundComponentType, int& foundComponentIndex, double& closestDistance2, HandleInfo& handleInfo);
307 virtual void CanInteractWithRingHandle(vtkMRMLInteractionEventData* interactionEventData,
308 int& foundComponentType, int& foundComponentIndex, double& closestDistance2, HandleInfo& handleInfo);
309
314
316 double ScreenSizePixel; // diagonal size of the screen
317
318 vtkSmartPointer<vtkPlane> SlicePlane;
319
324 double InteractionSize{1.0};
325
326 double WidgetScale{1.0};
327
328 bool Interacting{false};
329
330 vtkSmartPointer<vtkPointPlacer> PointPlacer;
331
334
335private:
337 void operator=(const vtkMRMLInteractionWidgetRepresentation&) = delete;
338};
339
340#endif
Abstract class that contains graphical display properties for displayable nodes.
std::map< std::pair< int, int >, vtkSmartPointer< vtkPolyData > > HandleGlyphPolyDataMap
std::map< std::pair< int, int >, vtkSmartPointer< vtkPolyData > > HandleOutlineGlyphPolyDataMap
virtual vtkPolyData * GetHandlePolydata(int type)
virtual void GetInteractionHandleAxisLocal(int type, int index, double axis[3])
Get the axis for the handle specified by the index in local coordinates.
virtual void SetActiveComponentIndex(int index)=0
double StartFadeAngleDegrees
The angle between the camera and the interaction axis at which point the interaction handle starts to...
virtual vtkPointPlacer * GetPointPlacer()
virtual void GetSliceToWorldCoordinates(const double slicePos[2], double worldPos[3])
virtual void GetInteractionHandleAxisWorld(int type, int index, double axis[3])
Get the axis for the handle specified by the index.
virtual int UpdateHandleColors(int type, int startIndex)
vtkTypeBool HasTranslucentPolygonalGeometry() override
int RenderTranslucentPolygonalGeometry(vtkViewport *viewport) override
virtual double GetHandleOpacity(int type, int index)
Get the opacity of the specified handle.
virtual void CanInteract(vtkMRMLInteractionEventData *interactionEventData, int &foundComponentType, int &foundComponentIndex, double &closestDistance2)
int RenderOverlay(vtkViewport *viewport) override
virtual HandleInfo GetHandleInfo(int type, int index)
virtual bool GetTransformationReferencePoint(double referencePointWorld[3])
Translation, rotation, scaling will happen around this position.
virtual void UpdateViewScaleFactor()
Calculate view size and scale factor.
virtual void CanInteractWithRingHandle(vtkMRMLInteractionEventData *interactionEventData, int &foundComponentType, int &foundComponentIndex, double &closestDistance2, HandleInfo &handleInfo)
virtual double GetMaximumHandlePickingDistance2()
virtual void CanInteractWithArrowHandle(vtkMRMLInteractionEventData *interactionEventData, int &foundComponentType, int &foundComponentIndex, double &closestDistance2, HandleInfo &handleInfo)
virtual void GetInteractionHandlePositionLocal(int type, int index, double position[3])
virtual void GetInteractionHandlePositionWorld(int type, int index, double position[3])
void GetActors(vtkPropCollection *) override
Methods to make this class behave as a vtkProp.
virtual bool GetHandleVisibility(int type, int index)
Get the visibility of the specified handle.
virtual void GetHandleColor(int type, int index, double color[4])
vtkProp * GetInteractionActor()
Returns the actor for the interaction widget.
void UpdateFromMRML(vtkMRMLNode *caller, unsigned long event, void *callData=nullptr) override
Update the representation from display node.
virtual HandleInfoList GetHandleInfoList()
virtual void GetHandleToCameraVectorWorld(double handlePosition_World[3], double normal_World[3])
virtual void SetWidgetScale(double scale)
Set the scale of the interaction handles in world coordinates.
virtual vtkTransform * GetHandleToWorldTransform()
virtual void UpdateInteractionPipeline()
Update the interaction pipeline.
void ReleaseGraphicsResources(vtkWindow *) override
virtual bool GetApplyScaleToPosition(int type, int index)
Get if the view scaling should be applied to the position of the handle.
double EndFadeAngleDegrees
The angle between the camera and the interaction axis at which point the interaction handle is comple...
void PrintSelf(ostream &os, vtkIndent indent) override
virtual int GetHandleGlyphType(int type, int index)
Get the type of glyph (Arrow, Circle, Ring, etc.) of the specified handle.
virtual vtkMRMLSliceNode * GetSliceNode()
virtual void SetActiveComponentType(int type)=0
virtual void UpdateHandleToWorldTransform(vtkTransform *handleToWorldTransform)=0
std::vector< HandleInfo > HandleInfoList
Get the list of info for all interaction handles.
virtual void OrthoganalizeTransform(vtkTransform *transform)
Orthogonalize the transform axes. The Z-axis will not be changed.
virtual int GetNumberOfHandles(int type)
virtual void GetInteractionHandleOriginWorld(double origin[3])
Get the origin of the interaction handle widget.
virtual void CanInteractWithCircleHandle(vtkMRMLInteractionEventData *interactionEventData, int &foundComponentType, int &foundComponentIndex, double &closestDistance2, HandleInfo &handleInfo)
int RenderOpaqueGeometry(vtkViewport *viewport) override
Abstract Superclass for all specific types of MRML nodes.
MRML node for storing a slice through RAS space.
HandleInfo(int index, int componentType, double positionWorld[3], double positionLocal[3], double color[4], int glyphType, bool applyScaleToPosition)