Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkLevelWindowWidgetContextMenu.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
19 #include <QCursor>
21 #include <mitkRenderingManager.h>
22 
24  : QWidget(parent, f)
25 {
28 }
29 
31 {
32  m_LevelWindowPreset->Delete();
33 }
34 
36 {
37  QString item = presetAction->text();
38  if (!(presetAction == m_PresetAction))
39  {
40  double dlevel = m_LevelWindowPreset->getLevel(item.toStdString());
41  double dwindow = m_LevelWindowPreset->getWindow(item.toStdString());
42  if ((dlevel + dwindow / 2) > m_LevelWindow.GetRangeMax())
43  {
44  double lowerBound = (dlevel - dwindow / 2);
45  if (!(lowerBound > m_LevelWindow.GetRangeMax()))
46  {
47  dwindow = m_LevelWindow.GetRangeMax() - lowerBound;
48  dlevel = lowerBound + dwindow / 2;
49  }
50  else
51  {
52  dlevel = m_LevelWindow.GetRangeMax() - 1;
53  dwindow = 2;
54  }
55  }
56  else if ((dlevel - dwindow / 2) < m_LevelWindow.GetRangeMin())
57  {
58  double upperBound = (dlevel + dwindow / 2);
59  if (!(upperBound < m_LevelWindow.GetRangeMin()))
60  {
61  dwindow = m_LevelWindow.GetRangeMin() + upperBound;
62  dlevel = upperBound - dwindow / 2;
63  }
64  else
65  {
66  dlevel = m_LevelWindow.GetRangeMin() + 1;
67  dwindow = 2;
68  }
69  }
70  m_LevelWindow.SetLevelWindow(dlevel, dwindow);
73  }
74 }
75 
77 {
78  m_Manager = levelWindowManager;
79 }
80 
82 {
86  QString::number((int)m_LevelWindow.GetLevel()),
87  QString::number((int)m_LevelWindow.GetWindow()));
88  if (addPreset.exec())
89  {
91  }
92 }
93 
95 {
98 }
99 
101 {
105 }
106 
108 {
112 }
113 
115 {
119 }
120 
122 {
126 }
127 
129 {
134 }
135 
137 {
138  QmitkLevelWindowRangeChangeDialog changeRange(this);
141  if (changeRange.exec())
142  {
143  m_LevelWindow.SetRangeMinMax(changeRange.getLowerLimit(), changeRange.getUpperLimit());
147  }
148 }
149 
151 {
152  if (imageAction == m_ImageAction)
153  if (m_Manager->isAutoTopMost() == false)
155  else
157  else
159 }
160 
162 {
163  try
164  {
166 
167  QMenu *contextMenu = contextmenu;
168  Q_CHECK_PTR(contextMenu);
169  // contextMenu->setCheckable(true);
170  QAction *sliderFixed = contextMenu->addAction(tr("Set Slider Fixed"), this, SLOT(setFixed()));
171  sliderFixed->setCheckable(true);
172  sliderFixed->setChecked(m_LevelWindow.IsFixed());
173  contextMenu->addSeparator();
174  contextMenu->addAction(tr("Use whole image grey values"), this, SLOT(useAllGreyvaluesFromImage()));
175  contextMenu->addAction(tr("Use optimized levelwindow"), this, SLOT(useOptimizedLevelWindow()));
176  contextMenu->addSeparator();
177  contextMenu->addAction(tr("Set Maximum Window"), this, SLOT(setMaximumWindow()));
178  contextMenu->addAction(tr("Default Level/Window"), this, SLOT(setDefaultLevelWindow()));
179  contextMenu->addSeparator();
180  contextMenu->addAction(tr("Change Scale Range"), this, SLOT(changeScaleRange()));
181  contextMenu->addAction(tr("Default Scale Range"), this, SLOT(setDefaultScaleRange()));
182  contextMenu->addSeparator();
183 
184  m_PresetSubmenu = new QMenu(this);
185  Q_CHECK_PTR(m_PresetSubmenu);
186  m_PresetSubmenu->setTitle("Presets");
187  m_PresetAction = m_PresetSubmenu->addAction(tr("Preset Definition"), this, SLOT(addPreset()));
188  m_PresetSubmenu->addSeparator();
189  std::map<std::string, double> preset = m_LevelWindowPreset->getLevelPresets();
190  for (auto iter = preset.begin(); iter != preset.end(); iter++)
191  {
192  QString item = ((*iter).first.c_str());
193  m_PresetSubmenu->addAction(item);
194  }
195  connect(m_PresetSubmenu, SIGNAL(triggered(QAction *)), this, SLOT(setPreset(QAction *)));
196  contextMenu->addMenu(m_PresetSubmenu);
197  contextMenu->addSeparator();
198 
199  m_ImageSubmenu = new QMenu(this);
200  m_ImageSubmenu->setTitle("Images");
201  // m_ImageSubmenu->setCheckable(true);
202  m_ImageAction = m_ImageSubmenu->addAction(tr("Set Topmost Image"));
203  m_ImageAction->setCheckable(true);
204  if (m_Manager->isAutoTopMost())
205  m_ImageAction->setChecked(true);
206  m_ImageSubmenu->addSeparator();
207  Q_CHECK_PTR(m_ImageSubmenu);
209  for (mitk::DataStorage::SetOfObjects::ConstIterator objectIter = allObjects->Begin();
210  objectIter != allObjects->End();
211  ++objectIter)
212  {
213  mitk::DataNode *node = objectIter->Value();
214  if (node)
215  {
216  if (node->IsVisible(nullptr) == false)
217  continue;
218  mitk::LevelWindowProperty::Pointer levelWindowProperty =
219  dynamic_cast<mitk::LevelWindowProperty *>(node->GetProperty("levelwindow"));
220  bool isHelperObject = false;
221  node->GetBoolProperty("helper object", isHelperObject);
222  if (levelWindowProperty.IsNotNull() && !isHelperObject)
223  {
224  std::string name;
225  node->GetName(name);
226  QString item = name.c_str();
227  QAction *id = m_ImageSubmenu->addAction(item);
228  id->setCheckable(true);
229  m_Images[id] = levelWindowProperty;
230  if (levelWindowProperty == m_Manager->GetLevelWindowProperty())
231  {
232  id->setChecked(true);
233  }
234  }
235  }
236  }
237  connect(m_ImageSubmenu, SIGNAL(triggered(QAction *)), this, SLOT(setImage(QAction *)));
238  contextMenu->addMenu(m_ImageSubmenu);
239 
240  contextMenu->exec(QCursor::pos());
241  }
242  catch (...)
243  {
244  }
245 }
246 
248 {
249  try
250  {
252 
253  auto contextMenu = new QMenu(this);
254  Q_CHECK_PTR(contextMenu);
255  // contextMenu->setCheckable(true);
256  QAction *sliderFixed = contextMenu->addAction(tr("Set Slider Fixed"), this, SLOT(setFixed()));
257  sliderFixed->setCheckable(true);
258  sliderFixed->setChecked(m_LevelWindow.IsFixed());
259  contextMenu->addSeparator();
260  contextMenu->addAction(tr("Use whole image grey values"), this, SLOT(useAllGreyvaluesFromImage()));
261  contextMenu->addAction(tr("Use optimized levelwindow"), this, SLOT(useOptimizedLevelWindow()));
262  contextMenu->addSeparator();
263  contextMenu->addAction(tr("Set Maximum Window"), this, SLOT(setMaximumWindow()));
264  contextMenu->addAction(tr("Default Level/Window"), this, SLOT(setDefaultLevelWindow()));
265  contextMenu->addSeparator();
266  contextMenu->addAction(tr("Change Scale Range"), this, SLOT(changeScaleRange()));
267  contextMenu->addAction(tr("Default Scale Range"), this, SLOT(setDefaultScaleRange()));
268  contextMenu->addSeparator();
269 
270  m_PresetSubmenu = new QMenu(this);
271  Q_CHECK_PTR(m_PresetSubmenu);
272  m_PresetSubmenu->setTitle("Presets");
273  m_PresetAction = m_PresetSubmenu->addAction(tr("Preset Definition"), this, SLOT(addPreset()));
274  m_PresetSubmenu->addSeparator();
275  std::map<std::string, double> preset = m_LevelWindowPreset->getLevelPresets();
276  for (auto iter = preset.begin(); iter != preset.end(); iter++)
277  {
278  QString item = ((*iter).first.c_str());
279  m_PresetSubmenu->addAction(item);
280  }
281  connect(m_PresetSubmenu, SIGNAL(triggered(QAction *)), this, SLOT(setPreset(QAction *)));
282  contextMenu->addMenu(m_PresetSubmenu);
283  contextMenu->addSeparator();
284 
285  m_ImageSubmenu = new QMenu(this);
286  m_ImageSubmenu->setTitle("Images");
287  // m_ImageSubmenu->setCheckable(true);
288  m_ImageAction = m_ImageSubmenu->addAction(tr("Set Topmost Image"));
289  m_ImageAction->setCheckable(true);
290  if (m_Manager->isAutoTopMost())
291  m_ImageAction->setChecked(true);
292  m_ImageSubmenu->addSeparator();
293  Q_CHECK_PTR(m_ImageSubmenu);
295  for (mitk::DataStorage::SetOfObjects::ConstIterator objectIter = allObjects->Begin();
296  objectIter != allObjects->End();
297  ++objectIter)
298  {
299  mitk::DataNode *node = objectIter->Value();
300  if (node)
301  {
302  mitk::LevelWindowProperty::Pointer levelWindowProperty =
303  dynamic_cast<mitk::LevelWindowProperty *>(node->GetProperty("levelwindow"));
304  bool isHelperObject = false;
305  node->GetBoolProperty("helper object", isHelperObject);
306  if (levelWindowProperty.IsNotNull() && !isHelperObject)
307  {
308  std::string name;
309  node->GetName(name);
310  QString item = name.c_str();
311  QAction *id = m_ImageSubmenu->addAction(item);
312  id->setCheckable(true);
313  m_Images[id] = levelWindowProperty;
314  if (levelWindowProperty == m_Manager->GetLevelWindowProperty())
315  {
316  id->setChecked(true);
317  }
318  }
319  }
320  }
321  connect(m_ImageSubmenu, SIGNAL(activated(int)), this, SLOT(setImage(int)));
322  contextMenu->addMenu(m_ImageSubmenu);
323 
324  contextMenu->exec(QCursor::pos());
325  delete contextMenu;
326  }
327  catch (...)
328  {
329  }
330 }
The LevelWindowProperty class Property for the mitk::LevelWindow.
void ResetDefaultLevelWindow()
Resets the level and the window value to the default values.
void setFixed()
sets the level window slider to be fixed
void SetLevelWindow(const LevelWindow &levelWindow)
Sets new Level/Window values and informs all listeners about changes.
void SetFixed(bool fixed)
double ScalarType
void SetToImageRange(const Image *image)
sets level/window to the min/max greyvalues of the given Image
void setDefaultScaleRange()
resets the current images scalerange to its default values
void setLevelWindowManager(mitk::LevelWindowManager *levelWindowManager)
lets this object know about the LevelWindowManager to get all images and tell about changes ...
void changeScaleRange()
changes the current images scalerange
void useAllGreyvaluesFromImage()
calls the mitkLevelWindow SetToImageRange method, so that the greyvalues from whole image will be use...
bool GetName(std::string &nodeName, const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="name") const
Convenience access method for accessing the name of an object (instance of StringProperty with proper...
Definition: mitkDataNode.h:366
bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for bool properties (instances of BoolProperty)
const LevelWindow & GetLevelWindow()
mitk::BaseProperty * GetProperty(const char *propertyKey, const mitk::BaseRenderer *renderer=nullptr) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList of the rendere...
std::map< std::string, double > & getLevelPresets()
std::map< QAction *, mitk::LevelWindowProperty::Pointer > m_Images
itk::SmartPointer< const Self > ConstPointer
DataStorage::SetOfObjects::ConstPointer GetRelevantNodes()
void setPreset(QAction *presetAction)
sets level and window value of the current image to the values defined for the selected preset ...
bool IsVisible(const mitk::BaseRenderer *renderer, const char *propertyKey="visible", bool defaultIsOn=true) const
Convenience access method for visibility properties (instances of BoolProperty). Return value is the ...
Definition: mitkDataNode.h:453
void SetRangeMinMax(ScalarType min, ScalarType max)
void setMaximumWindow()
sets the window to its maximum Size to fit the scalerange
bool IsFixed() const
QAction * m_PresetAction
ID of preset selected in contextmenu.
void ResetDefaultRangeMinMax()
the default min and max range for image will be reset
QMenu * m_ImageSubmenu
submenu with all images for contextmenu
LevelWindowProperty::Pointer GetLevelWindowProperty()
static RenderingManager * GetInstance()
void setPresets(std::map< std::string, double > &level, std::map< std::string, double > &window, QString initLevel, QString initWindow)
void newPresets(std::map< std::string, double > newLevel, std::map< std::string, double > newWindow)
void SetAuto(const Image *image, bool tryPicTags=true, bool guessByCentralSlice=true, unsigned selectedComponent=0)
sets level/window to optimize the contrast of the given Image
bool GetFixed() const
void SetLevelWindowProperty(LevelWindowProperty::Pointer levelWindowProperty)
Sets an specific LevelWindowProperty, all changes will affect the image belonging to this property...
void getContextMenu()
returns the contextmenu with standard functions for Level/Window
QAction * m_ImageAction
ID of image selected in contextmenu.
QmitkLevelWindowWidgetContextMenu(QWidget *parent, Qt::WindowFlags f=nullptr)
constructor
ScalarType GetRangeMax() const
void setImage(QAction *imageAction)
sets the selected image or the topmost layer image to the new current image
void setDefaultLevelWindow()
resets the current images Level/Window to its default values
double getWindow(std::string window)
std::map< std::string, double > & getWindowPresets()
ScalarType GetRangeMin() const
void SetAutoTopMostImage(bool autoTopMost, const DataNode *removedNode=nullptr)
(Re-)Initializes the LevelWindowManager by setting the topmost image. Use the removedNode parameter i...
static LevelWindowPreset * New()
void SetLevelWindow(ScalarType level, ScalarType window, bool expandRangesIfNecessary=true)
Provides access to the LevelWindowProperty object and LevelWindow of the "current" image...
double getLevel(std::string name)
Image * GetCurrentImage()
return the currently active image
ScalarType GetWindow() const
returns the current window size, i.e the range size of the current grey value interval ...
QMenu * m_PresetSubmenu
submenu with all presets for contextmenu
void addPreset()
adds a new Preset for presets-contextmenu
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66
ScalarType GetLevel() const
method that returns the level value, i.e. the center of the current grey value interval ...