Slicer  5.1
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,
125  };
126 
127  bool UpdateWindowLevelFromRectangle(int layer, int cornerPoint1[2], int cornerPoint2[2]);
128 
129  static const char* GetInteractionNodeAdjustWindowLevelModeAttributeName() { return "AdjustWindowLevelMode"; };
130 
131  static const char* GetAdjustWindowLevelModeAsString(int id);
132  static int GetAdjustWindowLevelModeFromString(const char* name);
133 
134 protected:
136  ~vtkMRMLWindowLevelWidget() override;
137 
138  bool ProcessStartMouseDrag(vtkMRMLInteractionEventData* eventData);
139  bool ProcessMouseMove(vtkMRMLInteractionEventData* eventData);
140  bool ProcessEndMouseDrag(vtkMRMLInteractionEventData* eventData);
141 
142  bool ProcessAdjustWindowLevelStart(vtkMRMLInteractionEventData* eventData);
143  void ProcessAdjustWindowLevel(vtkMRMLInteractionEventData* eventData);
144 
145  bool ProcessSetWindowLevelFromRegionStart(vtkMRMLInteractionEventData* eventData);
146  void ProcessSetWindowLevelFromRegion(vtkMRMLInteractionEventData* eventData);
147  // If updateWindowLevel is set to false then the operation is cancelled without changing the window/level
148  bool ProcessSetWindowLevelFromRegionEnd(vtkMRMLInteractionEventData* eventData, bool updateWindowLevel=true);
149 
150  bool ProcessResetWindowLevel(vtkMRMLInteractionEventData* eventData);
151 
152  int GetEditableLayerAtEventPosition(vtkMRMLInteractionEventData* eventData);
153 
154  vtkMRMLVolumeNode* GetVolumeNodeFromSliceLayer(int editedLayer);
155 
156  bool SetVolumeWindowLevel(double window, double level, bool isAutoWindowLevel);
157 
159  vtkGetMacro(CenteredRubberBand, bool);
160  vtkSetMacro(CenteredRubberBand, bool);
161  vtkBooleanMacro(CenteredRubberBand, bool);
162 
163  vtkWeakPointer<vtkMRMLSliceNode> SliceNode;
164  vtkWeakPointer<vtkMRMLSliceLogic> SliceLogic;
165 
167 
168  int StartEventPosition[2];
169  int PreviousEventPosition[2];
170 
171  double VolumeScalarRange[2];
172 
173  // Auto window/level was active before starting to adjust it
175  double StartVolumeWindowLevel[2];
176  double LastVolumeWindowLevel[2];
177 
179 
182 
184 
185 private:
187  void operator=(const vtkMRMLWindowLevelWidget&) = delete;
188 };
189 
190 #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.
this is a starting index that can be used for widget-specific events
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.
this is a starting index that can be used for widget-specific states
Slicer logic class for slice manipulation.