Slicer 5.9
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 {
147 };
148
149 virtual int GetActiveComponentType() = 0;
150 virtual void SetActiveComponentType(int type) = 0;
151
152 virtual int GetActiveComponentIndex() = 0;
153 virtual void SetActiveComponentIndex(int index) = 0;
154
156
157 virtual vtkTransform* GetHandleToWorldTransform();
158
159 virtual int GetNumberOfHandles(int type);
160 virtual int GetNumberOfHandles();
161
162 vtkSetMacro(Interacting, bool);
163 vtkGetMacro(Interacting, bool);
164 vtkBooleanMacro(Interacting, bool);
165
168 virtual void GetHandleColor(int type, int index, double color[4]);
170 virtual double GetHandleOpacity(int type, int index);
172 virtual bool GetHandleVisibility(int type, int index);
174 virtual int GetHandleGlyphType(int type, int index);
176 virtual bool GetApplyScaleToPosition(int type, int index);
179 virtual void GetInteractionHandlePositionLocal(int type, int index, double position[3]);
182 virtual void GetInteractionHandlePositionWorld(int type, int index, double position[3]);
183
187 virtual void UpdateHandleToWorldTransform(vtkTransform* handleToWorldTransform) = 0;
189
190protected:
193
194 class VTK_MRML_DISPLAYABLEMANAGER_EXPORT InteractionPipeline
195 {
196 public:
199
200 vtkSmartPointer<vtkPolyData> ArrowPolyData;
201 vtkSmartPointer<vtkPolyData> CirclePolyData;
202 vtkSmartPointer<vtkPolyData> RingPolyData;
203 vtkSmartPointer<vtkPolyData> ArrowOutlinePolyData;
204 vtkSmartPointer<vtkPolyData> CircleOutlinePolyData;
205 vtkSmartPointer<vtkPolyData> RingOutlinePolyData;
206
207 std::map<std::pair<int, int>, vtkSmartPointer<vtkPolyData>> HandleGlyphPolyDataMap;
208 std::map<std::pair<int, int>, vtkSmartPointer<vtkPolyData>> HandleOutlineGlyphPolyDataMap;
209
210 vtkSmartPointer<vtkPolyData> RotationHandlePoints;
211 vtkSmartPointer<vtkPolyData> TranslationHandlePoints;
212 vtkSmartPointer<vtkPolyData> ScaleHandlePoints;
213
214 vtkSmartPointer<vtkAppendPolyData> Append;
215 vtkSmartPointer<vtkTransformPolyDataFilter> HandleToWorldTransformFilter;
216 vtkSmartPointer<vtkTransform> HandleToWorldTransform;
217 vtkSmartPointer<vtkLookupTable> ColorTable;
218
219 vtkSmartPointer<vtkPolyDataMapper> Mapper3D;
220 vtkSmartPointer<vtkProperty> Property3D;
221 vtkSmartPointer<vtkActor> Actor3D;
222
223 vtkSmartPointer<vtkTransform> WorldToSliceTransform;
224 vtkSmartPointer<vtkTransformPolyDataFilter> WorldToSliceTransformFilter;
225 };
226
228 {
229 HandleInfo(int index, int componentType, double positionWorld[3], double positionLocal[3], double color[4], int glyphType, bool applyScaleToPosition)
230 : Index(index)
231 , ComponentType(componentType)
232 , GlyphType(glyphType)
233 , ApplyScaleToPosition(applyScaleToPosition)
234 {
235 for (int i = 0; i < 3; ++i)
236 {
237 this->PositionWorld[i] = positionWorld[i];
238 }
239 this->PositionWorld[3] = 1.0;
240 for (int i = 0; i < 3; ++i)
241 {
242 this->PositionLocal[i] = positionLocal[i];
243 }
244 this->PositionLocal[3] = 1.0;
245 for (int i = 0; i < 4; ++i)
246 {
247 this->Color[i] = color[i];
248 }
249 }
250 int Index;
253 double PositionLocal[4];
254 double PositionWorld[4];
255 double Color[4];
258 {
259 double epsilon = 0.001;
260 return this->Color[3] > epsilon;
261 }
262 };
263
265 typedef std::vector<HandleInfo> HandleInfoList;
267 virtual HandleInfo GetHandleInfo(int type, int index);
268
269 virtual void InitializePipeline();
270 virtual void CreateRotationHandles();
272 virtual void CreateScaleHandles();
273 virtual void UpdateHandleColors();
274 virtual int UpdateHandleColors(int type, int startIndex);
275 virtual vtkPolyData* GetHandlePolydata(int type);
276
281
283 virtual void SetWidgetScale(double scale);
284
287 virtual void GetHandleToCameraVectorWorld(double handlePosition_World[3], double normal_World[3]);
288
290 virtual void OrthoganalizeTransform(vtkTransform* transform);
291
293 virtual void UpdateViewScaleFactor();
294
295 virtual void UpdateHandleSize();
297 virtual double GetInteractionSizeMm();
299
301 int& foundComponentType,
302 int& foundComponentIndex,
303 double& closestDistance2,
304 HandleInfo& handleInfo);
305 virtual void CanInteractWithArrowHandle(vtkMRMLInteractionEventData* interactionEventData,
306 int& foundComponentType,
307 int& foundComponentIndex,
308 double& closestDistance2,
309 HandleInfo& handleInfo);
310 virtual void CanInteractWithRingHandle(vtkMRMLInteractionEventData* interactionEventData,
311 int& foundComponentType,
312 int& foundComponentIndex,
313 double& closestDistance2,
314 HandleInfo& handleInfo);
315
317 double StartFadeAngleDegrees{ 10.0 };
319 double EndFadeAngleDegrees{ 8.0 };
320
322 double ScreenSizePixel; // diagonal size of the screen
323
324 vtkSmartPointer<vtkPlane> SlicePlane;
325
330 double InteractionSize{ 1.0 };
331
332 double WidgetScale{ 1.0 };
333
334 bool Interacting{ false };
335
336 vtkSmartPointer<vtkPointPlacer> PointPlacer;
337
340
341private:
343 void operator=(const vtkMRMLInteractionWidgetRepresentation&) = delete;
344};
345
346#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)