Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
vtkMRMLSliceLogic.h
Go to the documentation of this file.
1/*=auto=========================================================================
2
3 Portions (c) Copyright 2005 Brigham and Women's Hospital (BWH) All Rights Reserved.
4
5 See COPYRIGHT.txt
6 or http://www.slicer.org/copyright/copyright.txt for details.
7
8 Program: 3D Slicer
9 Module: $RCSfile: vtkMRMLSliceLogic.h,v $
10 Date: $Date$
11 Version: $Revision: 18866
12
13=========================================================================auto=*/
14
15#ifndef __vtkMRMLSliceLogic_h
16#define __vtkMRMLSliceLogic_h
17
18// MRMLLogic includes
20
21// STD includes
22#include <deque>
23#include <vector>
24
25// MRML includes
35
36// VTK includes
37#include <vtkObject.h>
38#include <vtkWeakPointer.h>
39class vtkAlgorithmOutput;
40class vtkCollection;
41class vtkImageBlend;
42class vtkImageMathematics;
43class vtkImageReslice;
44
45struct BlendPipeline;
46struct SliceLayerInfo;
47
60class VTK_MRML_LOGIC_EXPORT vtkMRMLSliceLogic : public vtkMRMLAbstractLogic
61{
62public:
66 void PrintSelf(ostream& os, vtkIndent indent) override;
67
69 enum
70 {
72 };
73
74 enum
75 {
80 Layer_Last // must be last
81 };
82
84 vtkGetObjectMacro(SliceNode, vtkMRMLSliceNode);
85 void SetSliceNode(vtkMRMLSliceNode* newSliceNode);
86
88 vtkMRMLSliceNode* AddSliceNode(const char* layoutName);
89
95
101
107
113
115 void SetNthLayer(int layerIndex, vtkMRMLSliceLayerLogic* layer);
116
117 vtkAlgorithmOutput* GetNthLayerImageDataConnection(int layerIndex);
118 vtkAlgorithmOutput* GetNthLayerImageDataConnectionUVW(int layerIndex);
119
123
125 void SetBackgroundWindowLevel(double window, double level);
126
129 void GetBackgroundWindowLevelAndRange(double& window, double& level, double& rangeLow, double& rangeHigh, bool& autoWindowLevel);
130
132 void GetBackgroundWindowLevelAndRange(double& window, double& level, double& rangeLow, double& rangeHigh);
133
135 void SetForegroundWindowLevel(double window, double level);
136
139 void GetForegroundWindowLevelAndRange(double& window, double& level, double& rangeLow, double& rangeHigh, bool& autoWindowLevel);
140
142 void GetForegroundWindowLevelAndRange(double& window, double& level, double& rangeLow, double& rangeHigh);
143
145 vtkGetObjectMacro(SliceModelNode, vtkMRMLModelNode);
146
150
153
156
159 vtkImageBlend* GetBlend();
160 vtkImageBlend* GetBlendUVW();
161
164 vtkGetObjectMacro(ExtractModelTexture, vtkImageReslice);
165
168 vtkAlgorithmOutput* GetImageDataConnection();
169
172 bool HasInputs();
173
177
180
183
186 virtual bool EnterMRMLCallback() const;
187
190
193
196
202
204 static void GetVolumeRASBox(vtkMRMLVolumeNode* volumeNode, double rasDimensions[3], double rasCenter[3]);
205
207 void GetVolumeSliceDimensions(vtkMRMLVolumeNode* volumeNode, double sliceDimensions[3], double sliceCenter[3]);
208
212 double* GetVolumeSliceSpacing(vtkMRMLVolumeNode* volumeNode) VTK_SIZEHINT(3);
213
219 void GetVolumeSliceBounds(vtkMRMLVolumeNode* volumeNode, double sliceBounds[6], bool useVoxelCenter = false);
220
222 void FitSliceToVolume(vtkMRMLVolumeNode* volumeNode, int width, int height);
223
225 void FitSliceToVolumes(vtkCollection* volumeNodes, int width, int height);
226
228 void GetBackgroundRASBox(double rasDimensions[3], double rasCenter[3]);
229
231 void GetBackgroundSliceDimensions(double sliceDimensions[3], double sliceCenter[3]);
232
236 double* GetBackgroundSliceSpacing() VTK_SIZEHINT(3);
237
241 void GetBackgroundSliceBounds(double sliceBounds[6]);
242
247 void RotateSliceToLowestVolumeAxes(bool forceSlicePlaneToSingleSlice = true);
248
250 void FitSliceToFirst(int width = -1, int height = -1);
251
256 void FitSliceToBackground(int width = -1, int height = -1);
257
259 void FitSliceToAll(int width = -1, int height = -1);
260
263 void FitFOVToBackground(double fov);
264
270 void ResizeSliceNode(double newWidth, double newHeight);
271
277 double* GetLowestVolumeSliceSpacing() VTK_SIZEHINT(3);
278
285 void GetLowestVolumeSliceBounds(double sliceBounds[6], bool useVoxelCenter = false);
286
290 void SetSliceOffset(double offset);
292
294 void GetSliceBounds(double sliceBounds[6]);
295
298
302 void StartSliceNodeInteraction(unsigned int parameters);
303
306
310 void StartSliceCompositeNodeInteraction(unsigned int parameters);
311
314
317
320
324
325 static const int SLICE_INDEX_ROTATED;
327 static const int SLICE_INDEX_NO_VOLUME;
328
334 int GetSliceIndexFromOffset(double sliceOffset, vtkMRMLVolumeNode* volumeNode);
335
344 int GetSliceIndexFromOffset(double sliceOffset);
345
351
358
362 static const std::string SLICE_MODEL_NODE_NAME_SUFFIX;
363
367 static bool IsSliceModelNode(vtkMRMLNode* mrmlNode);
372 static bool IsSliceModelDisplayNode(vtkMRMLDisplayNode* mrmlDisplayNode);
373
378 int GetEditableLayerAtWorldPosition(double worldPos[3], bool backgroundVolumeEditable = true, bool foregroundVolumeEditable = true);
379
382 bool GetSliceOffsetRangeResolution(double range[2], double& resolution);
383
386 vtkGetObjectMacro(DisplayableManagerGroup, vtkObject);
387 void SetDisplayableManagerGroup(vtkObject* obj);
389
390protected:
392 ~vtkMRMLSliceLogic() override;
393
394 void SetMRMLSceneInternal(vtkMRMLScene* newScene) override;
395
397 void ProcessMRMLLogicsEvents(vtkObject* caller, unsigned long event, void* callData) override;
399
400 void OnMRMLSceneNodeAdded(vtkMRMLNode* node) override;
402 void UpdateFromMRMLScene() override;
403 void OnMRMLSceneStartClose() override;
404 void OnMRMLSceneEndImport() override;
405 void OnMRMLSceneEndRestore() override;
406
409
410 void OnMRMLNodeModified(vtkMRMLNode* node) override;
411 static vtkMRMLSliceCompositeNode* GetSliceCompositeNode(vtkMRMLScene* scene, const char* layoutName);
412 static vtkMRMLSliceNode* GetSliceNode(vtkMRMLScene* scene, const char* layoutName);
413
415 void SetNthLayerVolumeNode(int layerIndex, vtkMRMLVolumeNode* volumeNode);
416
419 void SetWindowLevel(int layer, double window, double level);
420 void GetWindowLevelAndRange(int layer, double& window, double& level, double& rangeLow, double& rangeHigh, bool& autoWindowLevel);
422
427 static bool UpdateBlendLayers(vtkImageBlend* blend, const std::deque<SliceLayerInfo>& layers, bool clipToBackgroundVolume);
428
430 static bool UpdateAddSubOperation(vtkImageMathematics* addSubMath, int compositing);
431
433 static bool UpdateFractions(vtkImageMathematics* fraction, double opacity);
434
436 static bool UpdateFractions(BlendPipeline* pipeline, const std::vector<vtkAlgorithmOutput*>& imagePorts, const std::vector<double>& opacities);
437
439 static void UpdateReconstructionSlab(vtkMRMLSliceLogic* sliceLogic, vtkMRMLSliceLayerLogic* sliceLayerLogic);
440
443 bool IsEventInsideVolume(bool background, double worldPos[3]);
444
449
451 bool VolumeWindowLevelEditable(const char* vtkNotUsed(volumeNodeID))
452 {
453 vtkWarningMacro(
454 "vtkMRMLSliceLogic::VolumeWindowLevelEditable method is deprecated. Volume Window Level is always editable. Use the interaction node to check if in editing mode. "
455 "e.g. slicer.app.applicationLogic().GetInteractionNode().GetCurrentInteractionMode() == slicer.vtkMRMLInteractionNode.AdjustWindowLevel");
456 return true;
457 };
458
459 typedef vtkSmartPointer<vtkMRMLSliceLayerLogic> LayerListItem;
460 typedef std::vector<LayerListItem> LayerList;
461 typedef std::vector<LayerListItem>::iterator LayerListIterator;
462 typedef std::vector<LayerListItem>::const_iterator LayerListConstIterator;
463
465
467
470
471 BlendPipeline* Pipeline;
472 BlendPipeline* PipelineUVW;
473 vtkImageReslice* ExtractModelTexture;
474 vtkAlgorithmOutput* ImageDataConnection;
475
479 double SliceSpacing[3];
480
481 // Weak reference to the view's displayable manager group.
482 //
483 // Stored as vtkObject to keep MRMLLogic independent of
484 // MRMLDisplayableManager headers. The expected dynamic type is
485 // vtkMRMLDisplayableManagerGroup.
486 //
487 // Set by the layout factories when the view widget is created, and used by
488 // vtkSlicerApplicationLogic::GetViewDisplayableManagerByClassName() to
489 // resolve managers without Qt. This works because vtkSlicerApplicationLogic
490 // lives in SlicerBaseLogic, which can depend on MRMLDisplayableManager.
491 //
492 // Ownership: the group is owned by the view/widget; this logic holds only a
493 // weak pointer. May be nullptr (e.g., headless or before view creation).
494 // Type is validated in SetDisplayableManagerGroup().
495 vtkWeakPointer<vtkObject> DisplayableManagerGroup;
496
497private:
498 vtkMRMLSliceLogic(const vtkMRMLSliceLogic&) = delete;
499 void operator=(const vtkMRMLSliceLogic&) = delete;
500};
501
502#endif
Abstract class that contains graphical display properties for displayable nodes.
MRML node for representing a linear transformation.
MRML node to represent a display property of 3D surface model.
MRML node to represent a 3D surface model.
Abstract Superclass for all specific types of MRML nodes.
A set of MRML Nodes that supports serialization and undo/redo.
MRML node for storing a slice through RAS space.
MRML node to store display properties of slice nodes.
vtkAlgorithmOutput * GetNthLayerImageDataConnectionUVW(int layerIndex)
void GetBackgroundSliceBounds(double sliceBounds[6])
std::vector< LayerListItem >::iterator LayerListIterator
void UpdateSliceNode()
Manage and synchronize the SliceNode.
void OnMRMLSceneEndRestore() override
void GetBackgroundSliceDimensions(double sliceDimensions[3], double sliceCenter[3])
Get the size of the volume, transformed to slice space.
void SetNthLayer(int layerIndex, vtkMRMLSliceLayerLogic *layer)
void OnMRMLSceneNodeRemoved(vtkMRMLNode *node) override
vtkMRMLVolumeNode * GetNthLayerVolumeNode(int layerIndex)
vtkMRMLSliceLayerLogic * GetForegroundLayer()
void FitSliceToBackground(int width=-1, int height=-1)
void SetDisplayableManagerGroup(vtkObject *obj)
void PrintSelf(ostream &os, vtkIndent indent) override
void SetSliceCompositeNode(vtkMRMLSliceCompositeNode *SliceCompositeNode)
void StartSliceCompositeNodeInteraction(unsigned int parameters)
void SetForegroundLayer(vtkMRMLSliceLayerLogic *ForegroundLayer)
void UpdateImageData()
Internally used by UpdatePipeline.
vtkMRMLSliceNode * AddSliceNode(const char *layoutName)
Convenience function for adding a slice node and setting it in this logic.
void OnMRMLSceneStartClose() override
vtkImageBlend * GetBlendUVW()
void GetVolumeSliceDimensions(vtkMRMLVolumeNode *volumeNode, double sliceDimensions[3], double sliceCenter[3])
Get the size of the volume, transformed to slice space.
vtkMRMLSliceDisplayNode * GetSliceDisplayNode()
Slice plane display properties.
void GetSliceBounds(double sliceBounds[6])
Get the largest slice bounding box for all volumes in layers.
void SnapSliceOffsetToIJK()
vtkMRMLSliceLayerLogic * GetBackgroundLayer()
double GetSliceOffset()
bool GetSliceOffsetRangeResolution(double range[2], double &resolution)
void OnMRMLNodeModified(vtkMRMLNode *node) override
BlendPipeline * Pipeline
bool IsEventInsideVolume(bool background, double worldPos[3])
double * GetBackgroundSliceSpacing() VTK_SIZEHINT(3)
static bool UpdateBlendLayers(vtkImageBlend *blend, const std::deque< SliceLayerInfo > &layers, bool clipToBackgroundVolume)
void OnMRMLSceneEndImport() override
void FitSliceToVolumes(vtkCollection *volumeNodes, int width, int height)
adjust the node's field of view to match the extent of the volume
vtkMRMLModelNode * SliceModelNode
void UpdateFromMRMLScene() override
void SetBackgroundWindowLevel(double window, double level)
Helper to set the background layer Window/Level.
bool VolumeWindowLevelEditable(const char *vtkNotUsed(volumeNodeID))
Deprecated. Returns true if the volume's window/level values are editable on the GUI.
vtkMRMLSliceLayerLogic * GetNthLayer(int layerIndex)
void SetSliceNode(vtkMRMLSliceNode *newSliceNode)
static bool IsSliceModelNode(vtkMRMLNode *mrmlNode)
BlendPipeline * PipelineUVW
void GetBackgroundWindowLevelAndRange(double &window, double &level, double &rangeLow, double &rangeHigh)
Helper to get the background layer Window/Level and intensity range.
static const int SLICE_INDEX_NO_VOLUME
void FitFOVToBackground(double fov)
static vtkMRMLSliceLogic * New()
The Usual VTK class functions.
void GetBackgroundWindowLevelAndRange(double &window, double &level, double &rangeLow, double &rangeHigh, bool &autoWindowLevel)
std::vector< LayerListItem > LayerList
vtkSmartPointer< vtkMRMLSliceLayerLogic > LayerListItem
vtkAlgorithmOutput * GetNthLayerImageDataConnection(int layerIndex)
void FitSliceToVolume(vtkMRMLVolumeNode *volumeNode, int width, int height)
adjust the node's field of view to match the extent of the volume
void GetWindowLevelAndRange(int layer, double &window, double &level, double &rangeLow, double &rangeHigh, bool &autoWindowLevel)
static bool UpdateAddSubOperation(vtkImageMathematics *addSubMath, int compositing)
Helper to update the operation to perform based on compositing mode.
void StartSliceNodeInteraction(unsigned int parameters)
std::vector< LayerListItem >::const_iterator LayerListConstIterator
vtkMRMLVolumeNode * GetLayerVolumeNode(int layer)
double * GetLowestVolumeSliceSpacing() VTK_SIZEHINT(3)
void SetWindowLevel(int layer, double window, double level)
vtkImageBlend * GetBlend()
void ResizeSliceNode(double newWidth, double newHeight)
static bool IsSliceModelDisplayNode(vtkMRMLDisplayNode *mrmlDisplayNode)
static bool UpdateFractions(vtkImageMathematics *fraction, double opacity)
Helper to update layer opacity when adding/subtracting the background layer.
void SetLabelLayer(vtkMRMLSliceLayerLogic *LabelLayer)
vtkMRMLSliceCompositeNode * SliceCompositeNode
static void UpdateReconstructionSlab(vtkMRMLSliceLogic *sliceLogic, vtkMRMLSliceLayerLogic *sliceLayerLogic)
Helper to update reconstruction slab settings for a given layer.
void OnMRMLSceneNodeAdded(vtkMRMLNode *node) override
void GetBackgroundRASBox(double rasDimensions[3], double rasCenter[3])
Get the size of the volume, transformed to RAS space.
vtkMRMLLinearTransformNode * SliceModelTransformNode
static void GetVolumeRASBox(vtkMRMLVolumeNode *volumeNode, double rasDimensions[3], double rasCenter[3])
Get the size of the volume, transformed to RAS space.
static const std::string SLICE_MODEL_NODE_NAME_SUFFIX
void StartSliceOffsetInteraction()
Indicate the slice offset value is starting to change.
void SetForegroundWindowLevel(double window, double level)
Helper to set the foreground layer Window/Level.
void ProcessMRMLLogicsEvents(vtkObject *caller, unsigned long event, void *callData) override
process logic events
void SetSliceExtentsToSliceNode()
Set slice extents to all layers.
void GetVolumeSliceBounds(vtkMRMLVolumeNode *volumeNode, double sliceBounds[6], bool useVoxelCenter=false)
vtkAlgorithmOutput * GetImageDataConnection()
vtkWeakPointer< vtkObject > DisplayableManagerGroup
static const int SLICE_INDEX_ROTATED
void EndSliceCompositeNodeInteraction()
Indicate an interaction with the slice composite node has been completed.
vtkMRMLSliceLayerLogic * GetLabelLayer()
void SetMRMLSceneInternal(vtkMRMLScene *newScene) override
std::vector< vtkMRMLDisplayNode * > GetPolyDataDisplayNodes()
Get all slice displaynodes creating PolyData models like glyphs etc.
vtkImageReslice * ExtractModelTexture
double * GetVolumeSliceSpacing(vtkMRMLVolumeNode *volumeNode) VTK_SIZEHINT(3)
void SetSliceOffset(double offset)
void SetBackgroundLayer(vtkMRMLSliceLayerLogic *BackgroundLayer)
static const int SLICE_INDEX_OUT_OF_VOLUME
virtual vtkMRMLSliceNode * GetSliceNode()
The MRML slice node for this slice logic.
vtkAlgorithmOutput * ImageDataConnection
vtkMRMLSliceNode * SliceNode
void UpdateSliceNodeFromLayout()
Update slicer node given a layout name.
void FitSliceToAll(int width=-1, int height=-1)
adjust the node's field of view to match the extent of all volume layers
void GetForegroundWindowLevelAndRange(double &window, double &level, double &rangeLow, double &rangeHigh, bool &autoWindowLevel)
int GetEditableLayerAtWorldPosition(double worldPos[3], bool backgroundVolumeEditable=true, bool foregroundVolumeEditable=true)
void RotateSliceToLowestVolumeAxes(bool forceSlicePlaneToSingleSlice=true)
vtkMRMLVolumeNode * GetFirstVolumeNode()
void UpdatePipeline()
update the pipeline to reflect the current state of the nodes
virtual bool EnterMRMLCallback() const
void GetLowestVolumeSliceBounds(double sliceBounds[6], bool useVoxelCenter=false)
void SetNthLayerVolumeNode(int layerIndex, vtkMRMLVolumeNode *volumeNode)
Set volume associated with a layer.
int GetSliceIndexFromOffset(double sliceOffset, vtkMRMLVolumeNode *volumeNode)
void EndSliceOffsetInteraction()
Indicate the slice offset value has completed its change.
virtual vtkMRMLSliceCompositeNode * GetSliceCompositeNode()
void SetupCrosshairNode()
void FitSliceToFirst(int width=-1, int height=-1)
adjust the node's field of view to match the extent of the first selected volume (background,...
vtkMRMLModelDisplayNode * SliceModelDisplayNode
void UpdateSliceCompositeNode()
Manage and synchronize the SliceCompositeNode.
void GetForegroundWindowLevelAndRange(double &window, double &level, double &rangeLow, double &rangeHigh)
Helper to get the foreground layer Window/Level and intensity range.
void EndSliceNodeInteraction()
Indicate an interaction with the slice node has been completed.
MRML node for storing a slice through RAS space.
MRML node for representing a volume (image stack).