NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
niftkMultiViewerVisibilityManager.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  NifTK: A software platform for medical image computing.
4 
5  Copyright (c) University College London (UCL). All rights reserved.
6 
7  This software is distributed WITHOUT ANY WARRANTY; without even
8  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9  PURPOSE.
10 
11  See LICENSE.txt in the top level directory for details.
12 
13 =============================================================================*/
14 
15 #ifndef niftkMultiViewerVisibilityManager_h
16 #define niftkMultiViewerVisibilityManager_h
17 
18 #include <niftkDnDDisplayExports.h>
19 
20 #include <QObject>
21 
22 #include <itkImage.h>
23 
24 #include <mitkDataStorage.h>
25 #include <mitkProperties.h>
26 
28 
29 #include "niftkDnDDisplayEnums.h"
30 
31 
32 namespace niftk
33 {
34 
35 class SingleViewerWidget;
36 
61 class NIFTKDNDDISPLAY_EXPORT MultiViewerVisibilityManager : public QObject, public DataNodePropertyListener
62 {
63  Q_OBJECT
64 
65 public:
66 
68  mitkNewMacro1Param(MultiViewerVisibilityManager, const mitk::DataStorage::Pointer)
69 
70 
71  MultiViewerVisibilityManager(mitk::DataStorage::Pointer dataStorage);
72 
75 
76  MultiViewerVisibilityManager(const MultiViewerVisibilityManager&); // Purposefully not implemented.
77  MultiViewerVisibilityManager& operator=(const MultiViewerVisibilityManager&); // Purposefully not implemented.
78 
80  void RegisterViewer(SingleViewerWidget *viewer);
81 
84  void DeregisterViewers(std::size_t startIndex = 0, std::size_t endIndex = -1);
85 
88  void ClearViewers(std::size_t startIndex = 0, std::size_t endIndex = -1);
89 
91  DnDDisplayDropType GetDropType() const { return m_DropType; }
92 
94  void SetDropType(DnDDisplayDropType dropType) { m_DropType = dropType; }
95 
97  DnDDisplayInterpolationType GetInterpolationType() const { return m_InterpolationType; }
98 
100  void SetInterpolationType(DnDDisplayInterpolationType interpolationType) { m_InterpolationType = interpolationType; }
101 
103  WindowLayout GetDefaultWindowLayout() const { return m_DefaultWindowLayout; }
104 
106  void SetDefaultWindowLayout(WindowLayout windowLayout) { m_DefaultWindowLayout = windowLayout; }
107 
109  bool GetAutomaticallyAddChildren() const { return m_AutomaticallyAddChildren; }
110 
112  void SetAutomaticallyAddChildren(bool autoAdd) { m_AutomaticallyAddChildren = autoAdd; }
113 
115  bool GetAccumulateWhenDropped() const { return m_Accumulate; }
116 
118  void SetAccumulateWhenDropping(bool accumulate) { m_Accumulate = accumulate; }
119 
121  void OnFocusChanged();
122 
123 public slots:
124 
126  void OnNodesDropped(std::vector<mitk::DataNode*> nodes);
127 
128 protected:
129 
132  virtual void OnNodeAdded(mitk::DataNode* node) override;
133 
135  virtual void OnNodeRemoved(mitk::DataNode* node) override;
136 
139  virtual void OnPropertyChanged(mitk::DataNode* node, const mitk::BaseRenderer* renderer) override;
140 
142  virtual void AddNodeToViewer(int windowIndex, mitk::DataNode* node, bool visibility=true);
143 
145  virtual void RemoveNodesFromViewer(int windowIndex);
146 
147 private:
148 
151  void UpdateGlobalVisibilities(mitk::BaseRenderer* renderer);
152 
154  virtual int GetNodesInViewer(int windowIndex);
155 
157  WindowLayout GetWindowLayout(std::vector<mitk::DataNode*> nodes);
158 
160  template<typename TPixel, unsigned int VImageDimension>
161  void GetAsAcquiredOrientation(itk::Image<TPixel, VImageDimension>* itkImage, WindowOrientation& outputOrientation);
162 
163  // Will retrieve the correct geometry from a list of nodes.
164  // If nodeIndex < 0 (for single drop case).
165  // Search for first available image
166  // Failing that, first geometry.
167  // If node index >=0, and < nodes.size()
168  // Picks out the geometry of the object for that index.
169  // Else
170  // Picks out the first geometry.
171  mitk::TimeGeometry::Pointer GetTimeGeometry(std::vector<mitk::DataNode*> nodes, int nodeIndex);
172 
173  // We maintain a set of data nodes present in each window.
174  // So, it's a vector, as we have one set for each of the registered windows.
175  std::vector< std::set<mitk::DataNode*> > m_DataNodesPerViewer;
176 
177  // Additionally, we manage a list of viewers, where m_DataNodes.size() == m_Viewers.size() should always be true.
178  std::vector< SingleViewerWidget* > m_Viewers;
179 
180  // Keeps track of the current mode, as it effects the response when images are dropped, as images are spread over single, multiple or all windows.
181  DnDDisplayDropType m_DropType;
182 
183  // Keeps track of the default window layout, as it affects the response when images are dropped, as the image should be oriented axial, coronal, sagittal, or as acquired (as per the X-Y plane).
184  WindowLayout m_DefaultWindowLayout;
185 
186  // Keeps track of the default interpolation, as it affects the response when images are dropped,
187  // as the dropped image should switch to that interpolation type, although as it is a node based property will affect all windows.
188  DnDDisplayInterpolationType m_InterpolationType;
189 
190  // Boolean to indicate whether to automatically add children, default to true.
191  bool m_AutomaticallyAddChildren;
192 
193  // Boolean to indicate whether successive drops into the same window are cumulative.
194  bool m_Accumulate;
195 
196  unsigned long m_FocusManagerObserverTag;
197 };
198 
199 }
200 
201 #endif
DnDDisplayInterpolationType GetInterpolationType() const
Returns the default interpolation type, which takes effect when a new image is dropped.
Definition: niftkMultiViewerVisibilityManager.h:97
WindowOrientation
Describes the different types of orientation, axial, sagittal, coronal, that can be achieved in the D...
Definition: niftkDnDDisplayEnums.h:29
DnDDisplayDropType
Describes the different modes that can be used when drag and dropping into the DnD Display window...
Definition: niftkDnDDisplayEnums.h:163
Definition: niftkDataNodePropertyListener.h:45
void SetDefaultWindowLayout(WindowLayout windowLayout)
Sets the default render window layout for when images are dropped into a render window.
Definition: niftkMultiViewerVisibilityManager.h:106
WindowLayout GetDefaultWindowLayout() const
Returns the default render window layout for when images are dropped into a render window...
Definition: niftkMultiViewerVisibilityManager.h:103
bool GetAccumulateWhenDropped() const
Gets the flag deciding whether we accumulate images each time we drop.
Definition: niftkMultiViewerVisibilityManager.h:115
WindowLayout
Describes the different render window layouts. So one WindowLayout could have multiple windows of dif...
Definition: niftkDnDDisplayEnums.h:49
void SetInterpolationType(DnDDisplayInterpolationType interpolationType)
Sets the default interpolation type, which takes effect when a new image is dropped.
Definition: niftkMultiViewerVisibilityManager.h:100
A widget to wrap a single MultiWindowWidget, providing methods for switching the render window layout...
Definition: niftkSingleViewerWidget.h:78
void SetDropType(DnDDisplayDropType dropType)
Set the drop type, which controls the behaviour when multiple images are dropped into a single viewer...
Definition: niftkMultiViewerVisibilityManager.h:94
DnDDisplayDropType GetDropType() const
Get the drop type, which controls the behaviour when multiple images are dropped into a single viewer...
Definition: niftkMultiViewerVisibilityManager.h:91
DnDDisplayInterpolationType
Describes what the interpolation type should be set to when an image is dropped.
Definition: niftkDnDDisplayEnums.h:174
void SetAccumulateWhenDropping(bool accumulate)
Sets the flag deciding whether we prefer to accumulate images each time they are dropped.
Definition: niftkMultiViewerVisibilityManager.h:118
bool GetAutomaticallyAddChildren() const
When we drop nodes onto a window, if true, we add all the children.
Definition: niftkMultiViewerVisibilityManager.h:109
WindowLayout GetWindowLayout(const std::string &windowLayoutName)
Definition: niftkDnDDisplayEnums.h:94
Maintains a list of SingleViewerWidgets and coordinates visibility properties by listening to AddNode...
Definition: niftkMultiViewerVisibilityManager.h:61
Definition: niftkExceptionObject.h:21
void SetAutomaticallyAddChildren(bool autoAdd)
When we drop nodes onto a window, if true, we add all the children.
Definition: niftkMultiViewerVisibilityManager.h:112
ImageOrientation GetAsAcquiredOrientation(ImageOrientation defaultOrientation, const mitk::Image *image)
Returns the ImageOrientation corresponding to the XY plane, or else returns the supplied default...
Definition: niftkImageUtils.cxx:80