Medical Imaging Interaction Toolkit  2018.4.99-389bf124
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 
15 // mitk core
16 #include <mitkRenderingManager.h>
17 
18 // mitk qt widgets
21 
22 // qt
23 #include <QCursor>
24 
26  : QWidget(parent, f)
27 {
30 }
31 
33 {
34  m_LevelWindowPreset->Delete();
35 }
36 
37 void QmitkLevelWindowWidgetContextMenu::OnSetPreset(const QAction *presetAction)
38 {
39  QString item = presetAction->text();
40  if (!(presetAction == m_PresetAction))
41  {
42  double dlevel = m_LevelWindowPreset->getLevel(item.toStdString());
43  double dwindow = m_LevelWindowPreset->getWindow(item.toStdString());
44  if ((dlevel + dwindow / 2) > m_LevelWindow.GetRangeMax())
45  {
46  double lowerBound = (dlevel - dwindow / 2);
47  if (!(lowerBound > m_LevelWindow.GetRangeMax()))
48  {
49  dwindow = m_LevelWindow.GetRangeMax() - lowerBound;
50  dlevel = lowerBound + dwindow / 2;
51  }
52  else
53  {
54  dlevel = m_LevelWindow.GetRangeMax() - 1;
55  dwindow = 2;
56  }
57  }
58  else if ((dlevel - dwindow / 2) < m_LevelWindow.GetRangeMin())
59  {
60  double upperBound = (dlevel + dwindow / 2);
61  if (!(upperBound < m_LevelWindow.GetRangeMin()))
62  {
63  dwindow = m_LevelWindow.GetRangeMin() + upperBound;
64  dlevel = upperBound - dwindow / 2;
65  }
66  else
67  {
68  dlevel = m_LevelWindow.GetRangeMin() + 1;
69  dwindow = 2;
70  }
71  }
72  m_LevelWindow.SetLevelWindow(dlevel, dwindow);
75  }
76 }
77 
79 {
80  m_Manager = levelWindowManager;
81 }
82 
84 {
88  QString::number((int)m_LevelWindow.GetLevel()),
89  QString::number((int)m_LevelWindow.GetWindow()));
90  if (addPreset.exec())
91  {
93  }
94 }
95 
97 {
100 }
101 
103 {
107 }
108 
110 {
114 }
115 
117 {
121 }
122 
124 {
128 }
129 
131 {
136 }
137 
139 {
140  QmitkLevelWindowRangeChangeDialog changeRange(this);
143  if (changeRange.exec())
144  {
145  m_LevelWindow.SetRangeMinMax(changeRange.getLowerLimit(), changeRange.getUpperLimit());
149  }
150 }
151 
153 {
154  if (imageAction == m_AutoTopmostAction)
155  {
156  if (m_Manager->IsAutoTopMost() == false)
157  {
159  }
160  else
161  {
163  }
164  }
165  else if(imageAction == m_SelectedImagesAction)
166  {
167  if (m_Manager->IsSelectedImages() == false)
168  {
170  }
171  else
172  {
174  }
175  }
176  else
177  {
178  m_Manager->SetLevelWindowProperty(m_Images.at(imageAction));
179  }
180 }
181 
183 {
184  if (nullptr == contextMenu)
185  {
186  return;
187  }
188 
189  try
190  {
192 
193  QAction *sliderFixed = contextMenu->addAction(tr("Set slider fixed"), this, &QmitkLevelWindowWidgetContextMenu::OnSetFixed);
194  sliderFixed->setCheckable(true);
195  sliderFixed->setChecked(m_LevelWindow.IsFixed());
196  contextMenu->addSeparator();
197  contextMenu->addAction(tr("Use whole image grey values"), this, &QmitkLevelWindowWidgetContextMenu::OnUseAllGreyvaluesFromImage);
198  contextMenu->addAction(tr("Use optimized level-window"), this, &QmitkLevelWindowWidgetContextMenu::OnUseOptimizedLevelWindow);
199  contextMenu->addSeparator();
200  contextMenu->addAction(tr("Set maximum window"), this, &QmitkLevelWindowWidgetContextMenu::OnSetMaximumWindow);
201  contextMenu->addAction(tr("Default level-window"), this, &QmitkLevelWindowWidgetContextMenu::OnSetDefaultLevelWindow);
202  contextMenu->addSeparator();
203  contextMenu->addAction(tr("Change scale range"), this, &QmitkLevelWindowWidgetContextMenu::OnChangeScaleRange);
204  contextMenu->addAction(tr("Default scale range"), this, &QmitkLevelWindowWidgetContextMenu::OnSetDefaultScaleRange);
205  contextMenu->addSeparator();
206 
207  m_PresetSubmenu = new QMenu(this);
208  m_PresetSubmenu->setTitle("Presets");
209  m_PresetAction = m_PresetSubmenu->addAction(tr("Preset definition"), this, &QmitkLevelWindowWidgetContextMenu::OnAddPreset);
210  m_PresetSubmenu->addSeparator();
211  std::map<std::string, double> preset = m_LevelWindowPreset->getLevelPresets();
212  for (auto iter = preset.begin(); iter != preset.end(); iter++)
213  {
214  QString item = ((*iter).first.c_str());
215  m_PresetSubmenu->addAction(item);
216  }
217 
218  connect(m_PresetSubmenu, &QMenu::triggered, this, &QmitkLevelWindowWidgetContextMenu::OnSetPreset);
219  contextMenu->addMenu(m_PresetSubmenu);
220  contextMenu->addSeparator();
221  m_ImageSubmenu = new QMenu(this);
222  m_ImageSubmenu->setTitle("Images");
223 
224  // add action for "auto topmost image" action
225  m_AutoTopmostAction = m_ImageSubmenu->addAction(tr("Set topmost image"));
226  m_AutoTopmostAction->setCheckable(true);
227  if (m_Manager->IsAutoTopMost())
228  {
229  m_AutoTopmostAction->setChecked(true);
230  }
231 
232  // add action for "selected images" action
233  m_ImageSubmenu->addSeparator();
234  m_SelectedImagesAction = m_ImageSubmenu->addAction(tr("Use selected images"));
235  m_SelectedImagesAction->setCheckable(true);
237  {
238  m_SelectedImagesAction->setChecked(true);
239  }
240 
241  // add action for individual images
242  m_ImageSubmenu->addSeparator();
243 
244  mitk::DataStorage::SetOfObjects::ConstPointer allObjects = m_Manager->GetRelevantNodes();
245  for (mitk::DataStorage::SetOfObjects::ConstIterator objectIter = allObjects->Begin();
246  objectIter != allObjects->End();
247  ++objectIter)
248  {
249  mitk::DataNode *node = objectIter->Value();
250  if (nullptr == node)
251  {
252  continue;
253  }
254 
255  bool isHelperObject = false;
256  node->GetBoolProperty("helper object", isHelperObject);
257 
258  if (isHelperObject)
259  {
260  continue;
261  }
262 
263  if (!node->IsVisible(nullptr))
264  {
265  continue;
266  }
267 
268  mitk::LevelWindowProperty::Pointer levelWindowProperty =
269  dynamic_cast<mitk::LevelWindowProperty *>(node->GetProperty("levelwindow"));
270 
271  if (levelWindowProperty.IsNotNull())
272  {
273  std::string name;
274  node->GetName(name);
275  QString item = name.c_str();
276  QAction *id = m_ImageSubmenu->addAction(item);
277  id->setCheckable(true);
278  m_Images[id] = levelWindowProperty;
279  if (levelWindowProperty == m_Manager->GetLevelWindowProperty())
280  {
281  id->setChecked(true);
282  }
283  }
284  }
285 
286  connect(m_ImageSubmenu, &QMenu::triggered, this, &QmitkLevelWindowWidgetContextMenu::OnSetImage);
287 
288  contextMenu->addMenu(m_ImageSubmenu);
289  contextMenu->exec(QCursor::pos());
290  }
291  catch (...)
292  {
293  }
294 }
295 
297 {
298  auto contextMenu = new QMenu(this);
299  GetContextMenu(contextMenu);
300  delete contextMenu;
301 }
mitk::BaseProperty * GetProperty(const char *propertyKey, const mitk::BaseRenderer *renderer=nullptr, bool fallBackOnDataProperties=true) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList of the rendere...
ScalarType GetLevel() const
method that returns the level value, i.e. the center of the current grey value interval ...
void GetContextMenu()
returns the contextmenu with standard functions for Level/Window
void OnUseAllGreyvaluesFromImage()
calls the mitkLevelWindow SetToImageRange method, so that the greyvalues from whole image will be use...
void OnSetImage(QAction *imageAction)
sets the selected image or the topmost layer image to the new current image
The LevelWindowProperty class Property for the mitk::LevelWindow.
void ResetDefaultLevelWindow()
Resets the level and the window value to the default values.
void OnSetPreset(const QAction *presetAction)
sets level and window value of the current image to the values defined for the selected preset ...
void OnAddPreset()
adds a new Preset for presets-contextmenu
void SetLevelWindow(const LevelWindow &levelWindow)
Set new Level/Window values and inform all listeners about changes.
void SetLevelWindowManager(mitk::LevelWindowManager *levelWindowManager)
lets this object know about the LevelWindowManager to get all images and tell 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 OnSetMaximumWindow()
sets the window to its maximum Size to fit the scalerange
void OnSetDefaultLevelWindow()
resets the current images Level/Window to its default values
const LevelWindow & GetLevelWindow()
Return Level/Window values for the current image.
bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for bool properties (instances of BoolProperty)
std::map< std::string, double > & getLevelPresets()
std::map< QAction *, mitk::LevelWindowProperty::Pointer > m_Images
DataStorage::SetOfObjects::ConstPointer GetRelevantNodes()
Returns all nodes in the DataStorage that have the following properties:
void SetRangeMinMax(ScalarType min, ScalarType max)
void SetSelectedImages(bool selectedImagesMode, const DataNode *removedNode=nullptr)
(Re-)Initialize the LevelWindowManager by setting the selected images. Use the removedNode parameter ...
void OnChangeScaleRange()
changes the current images scalerange
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:462
bool IsAutoTopMost()
Return true, if the changes on slider or line-edits will affect the topmost layer image...
void ResetDefaultRangeMinMax()
the default min and max range for image will be reset
QMenu * m_ImageSubmenu
submenu with all images for contextmenu
void OnSetDefaultScaleRange()
resets the current images scalerange to its default values
LevelWindowProperty::Pointer GetLevelWindowProperty()
Return the current LevelWindowProperty object from the image that is affected by changes.
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
void OnSetFixed()
sets the level window slider to be fixed
void SetLevelWindowProperty(LevelWindowProperty::Pointer levelWindowProperty)
Set a specific LevelWindowProperty; all changes will affect the image belonging to this property...
ScalarType GetRangeMax() const
ScalarType GetWindow() const
returns the current window size, i.e the range size of the current grey value interval ...
QmitkLevelWindowWidgetContextMenu(QWidget *parent, Qt::WindowFlags f=nullptr)
constructor
bool IsSelectedImages()
Return true, if changes on slider or line-edits will affect the currently selected images...
double getWindow(std::string window)
ScalarType GetRangeMin() const
std::map< std::string, double > & getWindowPresets()
void SetAutoTopMostImage(bool autoTopMost, const DataNode *removedNode=nullptr)
(Re-)Initialize the LevelWindowManager by setting the topmost image. Use the removedNode parameter if...
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.
QMenu * m_PresetSubmenu
submenu with all presets for contextmenu
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57
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:369