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 <vtkFloatArray.h>
55#include <vtkGlyph3DMapper.h>
56#include <vtkIntArray.h>
57#include <vtkPlane.h>
58#include <vtkPointPlacer.h>
59#include <vtkProperty.h>
60#include <vtkSmartPointer.h>
61#include <vtkTransform.h>
62#include <vtkUnsignedCharArray.h>
63#include <vtkWeakPointer.h>
64
65// STD includes
66#include <map>
67#include <memory>
68#include <vector>
69
73struct SharedHandleRenderer;
74
75class VTK_MRML_DISPLAYABLEMANAGER_EXPORT vtkMRMLInteractionWidgetRepresentation : public vtkMRMLAbstractWidgetRepresentation
76{
77public:
81 void PrintSelf(ostream& os, vtkIndent indent) override;
83
85 void UpdateFromMRML(vtkMRMLNode* caller, unsigned long event, void* callData = nullptr) override;
86
90 void SetRenderer(vtkRenderer* renderer) 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, int& foundComponentType, int& foundComponentIndex, double& closestDistance2);
107
108 virtual vtkPointPlacer* GetPointPlacer();
109
116
119 virtual bool IsDisplayable() = 0;
120
122 virtual void GetSliceToWorldCoordinates(const double slicePos[2], double worldPos[3]);
123
125
128
130 virtual void GetInteractionHandleAxisLocal(int type, int index, double axis[3]);
131
133 virtual void GetInteractionHandleAxisWorld(int type, int index, double axis[3]);
135 virtual void GetInteractionHandleOriginWorld(double origin[3]);
136
137 enum
138 {
144 };
145
146 enum
147 {
156 };
157
158 virtual int GetActiveComponentType() = 0;
159 virtual void SetActiveComponentType(int type) = 0;
160
161 virtual int GetActiveComponentIndex() = 0;
162 virtual void SetActiveComponentIndex(int index) = 0;
163
165
166 virtual vtkTransform* GetHandleToWorldTransform();
167
168 virtual int GetNumberOfHandles(int type);
169 virtual int GetNumberOfHandles();
170
171 vtkSetMacro(Interacting, bool);
172 vtkGetMacro(Interacting, bool);
173 vtkBooleanMacro(Interacting, bool);
174
177 virtual void GetHandleColor(int type, int index, double color[4]);
179 virtual double GetHandleOpacity(int type, int index);
186 virtual bool GetHandleVisibility(int type, int index);
188 virtual int GetHandleGlyphType(int type, int index);
190 virtual bool GetApplyScaleToPosition(int type, int index);
193 virtual void GetInteractionHandlePositionLocal(int type, int index, double position[3]);
196 virtual void GetInteractionHandlePositionWorld(int type, int index, double position[3]);
197
201 virtual void UpdateHandleToWorldTransform(vtkTransform* handleToWorldTransform) = 0;
203
204protected:
207
208 class VTK_MRML_DISPLAYABLEMANAGER_EXPORT InteractionPipeline
209 {
210 public:
213
214 vtkSmartPointer<vtkPolyData> ArrowPolyData;
215 vtkSmartPointer<vtkPolyData> CirclePolyData;
216 vtkSmartPointer<vtkPolyData> RingPolyData;
217 vtkSmartPointer<vtkPolyData> CrosshairPolyData;
218 vtkSmartPointer<vtkPolyData> ArrowOutlinePolyData;
219 vtkSmartPointer<vtkPolyData> CircleOutlinePolyData;
220 vtkSmartPointer<vtkPolyData> RingOutlinePolyData;
221 vtkSmartPointer<vtkPolyData> CrosshairOutlinePolyData;
222
223 vtkSmartPointer<vtkPolyData> RotationHandlePoints;
224 vtkSmartPointer<vtkPolyData> TranslationHandlePoints;
225 vtkSmartPointer<vtkPolyData> ScaleHandlePoints;
226
227 vtkSmartPointer<vtkTransform> HandleToWorldTransform;
228
229 vtkSmartPointer<vtkPolyData> InstancePolyData;
230 vtkSmartPointer<vtkFloatArray> GlyphOrientationArray;
231 vtkSmartPointer<vtkFloatArray> GlyphScaleArray;
232 vtkSmartPointer<vtkIntArray> GlyphSourceIndexArray;
233 vtkSmartPointer<vtkUnsignedCharArray> ColorArray;
234
235 vtkSmartPointer<vtkGlyph3DMapper> Mapper;
236 vtkSmartPointer<vtkProperty> Property;
237 vtkSmartPointer<vtkActor> Actor;
238
239 vtkSmartPointer<vtkTransform> WorldToSliceTransform;
240 vtkSmartPointer<vtkTransform> ActorTransform;
241 };
242
244 {
245 HandleInfo(int index, int componentType, double positionWorld[3], double positionLocal[3], double color[4], int glyphType, bool applyScaleToPosition)
246 : Index(index)
247 , ComponentType(componentType)
248 , GlyphType(glyphType)
249 , ApplyScaleToPosition(applyScaleToPosition)
250 {
251 for (int i = 0; i < 3; ++i)
252 {
253 this->PositionWorld[i] = positionWorld[i];
254 }
255 this->PositionWorld[3] = 1.0;
256 for (int i = 0; i < 3; ++i)
257 {
258 this->PositionLocal[i] = positionLocal[i];
259 }
260 this->PositionLocal[3] = 1.0;
261 for (int i = 0; i < 4; ++i)
262 {
263 this->Color[i] = color[i];
264 }
265 }
266 int Index;
269 double PositionLocal[4];
270 double PositionWorld[4];
271 double Color[4];
274 {
275 double epsilon = 0.001;
276 return this->Color[3] > epsilon;
277 }
278 };
279
281 typedef std::vector<HandleInfo> HandleInfoList;
283 virtual HandleInfo GetHandleInfo(int type, int index);
284
285 virtual void InitializePipeline();
286 virtual void CreateRotationHandles();
288 virtual void CreateScaleHandles();
289 virtual void UpdateInstanceArrays();
290 virtual void UpdateActorTransform();
291 virtual vtkPolyData* GetHandlePolydata(int type);
292
294 virtual void UpdateCameraState();
295
297 virtual void SetWidgetScale(double scale);
298
302 virtual void GetHandleToCameraVectorWorld(double handlePosition_World[3], double normal_World[3]);
303
305 virtual void OrthoganalizeTransform(vtkTransform* transform);
306
308 virtual void UpdateViewScaleFactor();
309
310 virtual void UpdateHandleSize();
312 virtual double GetInteractionSizeMm();
314
316 int& foundComponentType,
317 int& foundComponentIndex,
318 double& closestDistance2,
319 HandleInfo& handleInfo);
320 virtual void CanInteractWithArrowHandle(vtkMRMLInteractionEventData* interactionEventData,
321 int& foundComponentType,
322 int& foundComponentIndex,
323 double& closestDistance2,
324 HandleInfo& handleInfo);
325 virtual void CanInteractWithRingHandle(vtkMRMLInteractionEventData* interactionEventData,
326 int& foundComponentType,
327 int& foundComponentIndex,
328 double& closestDistance2,
329 HandleInfo& handleInfo);
330
332 double StartFadeAngleDegrees{ 10.0 };
334 double EndFadeAngleDegrees{ 8.0 };
335
337 double ScreenSizePixel; // diagonal size of the screen
338
339 vtkSmartPointer<vtkPlane> SlicePlane;
340
345 double InteractionSize{ 1.0 };
346
347 double WidgetScale{ 1.0 };
348
350 double CachedCameraPosition[3]{ 0.0, 0.0, 0.0 };
351 double CachedCameraDirection[3]{ 0.0, 0.0, 1.0 };
352 double CachedViewUp_World[3]{ 0.0, 1.0, 0.0 };
353
362 {
363 vtkMTimeType RepresentationMTime{ 0 };
364 vtkMTimeType SliceXYToRASMTime{ 0 };
365 double CameraPosition[3]{ 0.0, 0.0, 0.0 };
366 double CameraDirectionOfProjection[3]{ 0.0, 0.0, 0.0 };
367 double CameraViewUp[3]{ 0.0, 0.0, 0.0 };
368 double CameraParallelScale{ 0.0 };
369 double CameraViewAngle{ 0.0 };
371 int RendererSize[2]{ 0, 0 };
372 int ScreenSize[2]{ 0, 0 };
375
376 bool operator==(const RenderState& other) const;
377 bool operator!=(const RenderState& other) const { return !(*this == other); }
378 };
379
382
386
388 bool HasVisibleHandles{ false };
389
390 bool Interacting{ false };
391
392 vtkSmartPointer<vtkPointPlacer> PointPlacer;
393
396
402 static std::map<vtkRenderer*, std::unique_ptr<SharedHandleRenderer>> SharedHandleRenderers;
403 static SharedHandleRenderer* GetSharedHandleRenderer(vtkRenderer* renderer, bool create = false);
404 static void OnSharedRendererStartEvent(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
405 static void OnSharedRendererDelete(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
408 bool IsSharedRenderingRepresentation(SharedHandleRenderer* shared) const;
409 static void ConfigureHandleInstancePipeline(vtkSmartPointer<vtkPolyData>& instancePolyData,
410 vtkSmartPointer<vtkFloatArray>& orientationArray,
411 vtkSmartPointer<vtkFloatArray>& scaleArray,
412 vtkSmartPointer<vtkIntArray>& sourceIndexArray,
413 vtkSmartPointer<vtkUnsignedCharArray>& colorArray,
414 vtkSmartPointer<vtkGlyph3DMapper>& mapper,
415 vtkSmartPointer<vtkProperty>& property,
416 vtkSmartPointer<vtkActor>& actor);
417 static unsigned char ColorComponentToUChar(double c);
419
420private:
422 void operator=(const vtkMRMLInteractionWidgetRepresentation&) = delete;
423};
424
425#endif
Abstract class that contains graphical display properties for displayable nodes.
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.
bool IsSharedRenderingRepresentation(SharedHandleRenderer *shared) const
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.
static void OnSharedRendererDelete(vtkObject *caller, unsigned long eid, void *clientData, void *callData)
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
static SharedHandleRenderer * GetSharedHandleRenderer(vtkRenderer *renderer, bool create=false)
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.
static unsigned char ColorComponentToUChar(double c)
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])
static void OnSharedRendererStartEvent(vtkObject *caller, unsigned long eid, void *clientData, void *callData)
void SetRenderer(vtkRenderer *renderer) override
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()
RenderState GetCurrentRenderState()
Get the state that the handle instance arrays would be built for if they were rebuilt now.
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...
static std::map< vtkRenderer *, std::unique_ptr< SharedHandleRenderer > > SharedHandleRenderers
static void ConfigureHandleInstancePipeline(vtkSmartPointer< vtkPolyData > &instancePolyData, vtkSmartPointer< vtkFloatArray > &orientationArray, vtkSmartPointer< vtkFloatArray > &scaleArray, vtkSmartPointer< vtkIntArray > &sourceIndexArray, vtkSmartPointer< vtkUnsignedCharArray > &colorArray, vtkSmartPointer< vtkGlyph3DMapper > &mapper, vtkSmartPointer< vtkProperty > &property, vtkSmartPointer< vtkActor > &actor)
virtual void UpdateCameraState()
Cache camera state (direction, position, view up) for use by per-handle computations.
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)
bool operator==(const RenderState &other) const