Slicer  4.13
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkMRMLWindowLevelWidget.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Program: 3D Slicer
4 
5  Copyright (c) Kitware Inc.
6 
7  See COPYRIGHT.txt
8  or http://www.slicer.org/copyright/copyright.txt for details.
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16 ==============================================================================*/
17 
28 #ifndef vtkMRMLWindowLevelWidget_h
29 #define vtkMRMLWindowLevelWidget_h
30 
31 #include "vtkMRMLDisplayableManagerExport.h" // For export macro
32 #include "vtkMRMLAbstractWidget.h"
33 #include "vtkMRMLSliceLogic.h"
34 #include "vtkMRMLSliceNode.h"
35 
36 #include <vtkCallbackCommand.h>
37 #include <vtkCollection.h>
38 #include <vtkSmartPointer.h>
39 #include <vtkWeakPointer.h>
40 
41 class vtkSliceIntersectionRepresentation2D;
44 
45 
46 class VTK_MRML_DISPLAYABLEMANAGER_EXPORT vtkMRMLWindowLevelWidget : public vtkMRMLAbstractWidget
47 {
48 public:
52  static vtkMRMLWindowLevelWidget *New();
53 
54  enum
55  {
59  Mode_Last
60  };
61 
63 
67  void PrintSelf(ostream& os, vtkIndent indent) override;
69 
73  void CreateDefaultRepresentation();
74 
75  void SetSliceNode(vtkMRMLSliceNode* sliceNode);
76  vtkMRMLSliceNode* GetSliceNode();
77 
78  vtkMRMLSliceLogic* GetSliceLogic();
79 
80  vtkGetMacro(BackgroundVolumeEditable, bool);
81  vtkSetMacro(BackgroundVolumeEditable, bool);
82  vtkBooleanMacro(BackgroundVolumeEditable, bool);
83 
84  vtkGetMacro(ForegroundVolumeEditable, bool);
85  vtkSetMacro(ForegroundVolumeEditable, bool);
86  vtkBooleanMacro(ForegroundVolumeEditable, bool);
87 
88  void SetMRMLApplicationLogic(vtkMRMLApplicationLogic* applicationLogic) override;
89 
91  bool CanProcessInteractionEvent(vtkMRMLInteractionEventData* eventData, double &distance2) override;
92 
94  bool ProcessInteractionEvent(vtkMRMLInteractionEventData* eventData) override;
95 
97  void Leave(vtkMRMLInteractionEventData* eventData) override;
98 
100  enum
101  {
102  WidgetStateAdjustWindowLevel = WidgetStateUser,
106  };
107 
109  enum
110  {
111  WidgetEventResetWindowLevel = WidgetEventUser,
118  };
119 
120  bool UpdateWindowLevelFromRectangle(int layer, int cornerPoint1[2], int cornerPoint2[2]);
121 
122  static const char* GetInteractionNodeAdjustWindowLevelModeAttributeName() { return "AdjustWindowLevelMode"; };
123 
124  static const char* GetAdjustWindowLevelModeAsString(int id);
125  static int GetAdjustWindowLevelModeFromString(const char* name);
126 
127 protected:
129  ~vtkMRMLWindowLevelWidget() override;
130 
131  bool ProcessStartMouseDrag(vtkMRMLInteractionEventData* eventData);
132  bool ProcessMouseMove(vtkMRMLInteractionEventData* eventData);
133  bool ProcessEndMouseDrag(vtkMRMLInteractionEventData* eventData);
134 
135  bool ProcessAdjustWindowLevelStart(vtkMRMLInteractionEventData* eventData);
136  void ProcessAdjustWindowLevel(vtkMRMLInteractionEventData* eventData);
137 
138  bool ProcessSetWindowLevelFromRegionStart(vtkMRMLInteractionEventData* eventData);
139  void ProcessSetWindowLevelFromRegion(vtkMRMLInteractionEventData* eventData);
140  // If updateWindowLevel is set to false then the operation is cancelled without changing the window/level
141  bool ProcessSetWindowLevelFromRegionEnd(vtkMRMLInteractionEventData* eventData, bool updateWindowLevel=true);
142 
143  bool ProcessResetWindowLevel(vtkMRMLInteractionEventData* eventData);
144 
145  int GetEditableLayerAtEventPosition(vtkMRMLInteractionEventData* eventData);
146 
149  bool IsEventInsideVolume(bool background, vtkMRMLInteractionEventData* eventData);
150 
153  bool VolumeWindowLevelEditable(const char* volumeNodeID);
154 
155  vtkMRMLVolumeNode* GetVolumeNodeFromSliceLayer(int editedLayer);
156 
157  bool SetVolumeWindowLevel(double window, double level, bool isAutoWindowLevel);
158 
160  vtkGetMacro(CenteredRubberBand, bool);
161  vtkSetMacro(CenteredRubberBand, bool);
162  vtkBooleanMacro(CenteredRubberBand, bool);
163 
164  vtkWeakPointer<vtkMRMLSliceNode> SliceNode;
165  vtkWeakPointer<vtkMRMLSliceLogic> SliceLogic;
166 
168 
169  int StartEventPosition[2];
170  int PreviousEventPosition[2];
171 
172  double VolumeScalarRange[2];
173 
174  // Auto window/level was active before starting to adjust it
176  double StartVolumeWindowLevel[2];
177  double LastVolumeWindowLevel[2];
178 
180 
183 
185 
186 private:
188  void operator=(const vtkMRMLWindowLevelWidget&) = delete;
189 };
190 
191 #endif
virtual bool CanProcessInteractionEvent(vtkMRMLInteractionEventData *eventData, double &distance2)
MRML node for storing a slice through RAS space.
vtkWeakPointer< vtkMRMLSliceLogic > SliceLogic
vtkWeakPointer< vtkMRMLSliceNode > SliceNode
static const char * GetInteractionNodeAdjustWindowLevelModeAttributeName()
MRML node for representing segmentation display attributes.
MRML node for representing a volume (image stack).
virtual bool ProcessInteractionEvent(vtkMRMLInteractionEventData *eventData)
virtual void Leave(vtkMRMLInteractionEventData *eventData)
Called when the the widget loses the focus.
void PrintSelf(ostream &os, vtkIndent indent) override
Show slice intersection lines.
virtual void SetMRMLApplicationLogic(vtkMRMLApplicationLogic *applicationLogic)
Process interaction events to update state of MRML widget nodes.
Slicer logic class for slice manipulation.