Slicer 5.13
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
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 : public vtkMRMLAbstractWidgetRepresentation
79{
80public:
84 void PrintSelf(ostream& os, vtkIndent indent) override;
86
88 void UpdateFromMRML(vtkMRMLNode* caller, unsigned long event, void* callData = nullptr) override;
89
91 void GetActors(vtkPropCollection*) override;
92 void ReleaseGraphicsResources(vtkWindow*) override;
93 int RenderOverlay(vtkViewport* viewport) override;
94 int RenderOpaqueGeometry(vtkViewport* viewport) override;
95 int RenderTranslucentPolygonalGeometry(vtkViewport* viewport) override;
96 vtkTypeBool HasTranslucentPolygonalGeometry() override;
97
99 virtual bool GetTransformationReferencePoint(double referencePointWorld[3]);
100
104 virtual void CanInteract(vtkMRMLInteractionEventData* interactionEventData, int& foundComponentType, int& foundComponentIndex, double& closestDistance2);
105
106 virtual vtkPointPlacer* GetPointPlacer();
107
110
113 virtual bool IsDisplayable() = 0;
114
116 virtual void GetSliceToWorldCoordinates(const double slicePos[2], double worldPos[3]);
117
119
122
123 virtual void UpdateHandlePolyData();
124
126 virtual void GetInteractionHandleAxisLocal(int type, int index, double axis[3]);
127
129 virtual void GetInteractionHandleAxisWorld(int type, int index, double axis[3]);
131 virtual void GetInteractionHandleOriginWorld(double origin[3]);
132
133 enum
134 {
140 };
141
142 enum
143 {
148 };
149
150 virtual int GetActiveComponentType() = 0;
151 virtual void SetActiveComponentType(int type) = 0;
152
153 virtual int GetActiveComponentIndex() = 0;
154 virtual void SetActiveComponentIndex(int index) = 0;
155
157
158 virtual vtkTransform* GetHandleToWorldTransform();
159
160 virtual int GetNumberOfHandles(int type);
161 virtual int GetNumberOfHandles();
162
163 vtkSetMacro(Interacting, bool);
164 vtkGetMacro(Interacting, bool);
165 vtkBooleanMacro(Interacting, bool);
166
169 virtual void GetHandleColor(int type, int index, double color[4]);
171 virtual double GetHandleOpacity(int type, int index);
178 virtual bool GetHandleVisibility(int type, int index);
180 virtual int GetHandleGlyphType(int type, int index);
182 virtual bool GetApplyScaleToPosition(int type, int index);
185 virtual void GetInteractionHandlePositionLocal(int type, int index, double position[3]);
188 virtual void GetInteractionHandlePositionWorld(int type, int index, double position[3]);
189
193 virtual void UpdateHandleToWorldTransform(vtkTransform* handleToWorldTransform) = 0;
195
196protected:
199
200 class VTK_MRML_DISPLAYABLEMANAGER_EXPORT InteractionPipeline
201 {
202 public:
205
206 vtkSmartPointer<vtkPolyData> ArrowPolyData;
207 vtkSmartPointer<vtkPolyData> CirclePolyData;
208 vtkSmartPointer<vtkPolyData> RingPolyData;
209 vtkSmartPointer<vtkPolyData> CrosshairPolyData;
210 vtkSmartPointer<vtkPolyData> ArrowOutlinePolyData;
211 vtkSmartPointer<vtkPolyData> CircleOutlinePolyData;
212 vtkSmartPointer<vtkPolyData> RingOutlinePolyData;
213 vtkSmartPointer<vtkPolyData> CrosshairOutlinePolyData;
214
215 std::map<std::pair<int, int>, vtkSmartPointer<vtkPolyData>> HandleGlyphPolyDataMap;
216 std::map<std::pair<int, int>, vtkSmartPointer<vtkPolyData>> HandleOutlineGlyphPolyDataMap;
217
218 vtkSmartPointer<vtkPolyData> RotationHandlePoints;
219 vtkSmartPointer<vtkPolyData> TranslationHandlePoints;
220 vtkSmartPointer<vtkPolyData> ScaleHandlePoints;
221
222 vtkSmartPointer<vtkAppendPolyData> Append;
223 vtkSmartPointer<vtkTransformPolyDataFilter> HandleToWorldTransformFilter;
224 vtkSmartPointer<vtkTransform> HandleToWorldTransform;
225 vtkSmartPointer<vtkLookupTable> ColorTable;
226
227 vtkSmartPointer<vtkPolyDataMapper> Mapper3D;
228 vtkSmartPointer<vtkProperty> Property3D;
229 vtkSmartPointer<vtkActor> Actor3D;
230
231 vtkSmartPointer<vtkTransform> WorldToSliceTransform;
232 vtkSmartPointer<vtkTransformPolyDataFilter> WorldToSliceTransformFilter;
233 };
234
236 {
237 HandleInfo(int index, int componentType, double positionWorld[3], double positionLocal[3], double color[4], int glyphType, bool applyScaleToPosition)
238 : Index(index)
239 , ComponentType(componentType)
240 , GlyphType(glyphType)
241 , ApplyScaleToPosition(applyScaleToPosition)
242 {
243 for (int i = 0; i < 3; ++i)
244 {
245 this->PositionWorld[i] = positionWorld[i];
246 }
247 this->PositionWorld[3] = 1.0;
248 for (int i = 0; i < 3; ++i)
249 {
250 this->PositionLocal[i] = positionLocal[i];
251 }
252 this->PositionLocal[3] = 1.0;
253 for (int i = 0; i < 4; ++i)
254 {
255 this->Color[i] = color[i];
256 }
257 }
258 int Index;
261 double PositionLocal[4];
262 double PositionWorld[4];
263 double Color[4];
266 {
267 double epsilon = 0.001;
268 return this->Color[3] > epsilon;
269 }
270 };
271
273 typedef std::vector<HandleInfo> HandleInfoList;
275 virtual HandleInfo GetHandleInfo(int type, int index);
276
277 virtual void InitializePipeline();
278 virtual void CreateRotationHandles();
280 virtual void CreateScaleHandles();
281 virtual void UpdateHandleColors();
282 virtual int UpdateHandleColors(int type, int startIndex);
283 virtual vtkPolyData* GetHandlePolydata(int type);
284
289
291 virtual void SetWidgetScale(double scale);
292
295 virtual void GetHandleToCameraVectorWorld(double handlePosition_World[3], double normal_World[3]);
296
298 virtual void OrthoganalizeTransform(vtkTransform* transform);
299
301 virtual void UpdateViewScaleFactor();
302
303 virtual void UpdateHandleSize();
305 virtual double GetInteractionSizeMm();
307
309 int& foundComponentType,
310 int& foundComponentIndex,
311 double& closestDistance2,
312 HandleInfo& handleInfo);
313 virtual void CanInteractWithArrowHandle(vtkMRMLInteractionEventData* interactionEventData,
314 int& foundComponentType,
315 int& foundComponentIndex,
316 double& closestDistance2,
317 HandleInfo& handleInfo);
318 virtual void CanInteractWithRingHandle(vtkMRMLInteractionEventData* interactionEventData,
319 int& foundComponentType,
320 int& foundComponentIndex,
321 double& closestDistance2,
322 HandleInfo& handleInfo);
323
325 double StartFadeAngleDegrees{ 10.0 };
327 double EndFadeAngleDegrees{ 8.0 };
328
330 double ScreenSizePixel; // diagonal size of the screen
331
332 vtkSmartPointer<vtkPlane> SlicePlane;
333
338 double InteractionSize{ 1.0 };
339
340 double WidgetScale{ 1.0 };
341
342 bool Interacting{ false };
343
344 vtkSmartPointer<vtkPointPlacer> PointPlacer;
345
348
349private:
351 void operator=(const vtkMRMLInteractionWidgetRepresentation&) = delete;
352};
353
354#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 double GetInteractionHandleOpacity()
Get the overall opacity multiplier applied to all interaction handles. Default is 1....
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)