Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkDataNodeColorMapAction.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 <mitkImage.h>
18 #include <mitkLookupTable.h>
19 #include <mitkRenderingManager.h>
21 
22 // mitk gui common plugin
23 #include <mitkDataNodeSelection.h>
24 
25 // qt
26 #include <QMenu>
27 
29  : QAction(parent)
30  , QmitkAbstractDataNodeAction(workbenchpartSite)
31 {
32  setText(tr("Colormap"));
34 }
35 
37  : QAction(parent)
38  , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite))
39 {
40  setText(tr("Colormap"));
42 }
43 
45 {
46  setCheckable(true);
47 
48  setMenu(new QMenu);
49  connect(menu(), &QMenu::aboutToShow, this, &QmitkDataNodeColorMapAction::OnMenuAboutShow);
50 }
51 
52 void QmitkDataNodeColorMapAction::OnMenuAboutShow()
53 {
54  auto dataNode = GetSelectedNode();
55  if (dataNode.IsNull())
56  {
57  return;
58  }
59 
61 
62  mitk::LookupTableProperty::Pointer lookupTableProperty = dynamic_cast<mitk::LookupTableProperty*>(dataNode->GetProperty("LookupTable", baseRenderer));
63  if (lookupTableProperty.IsNull())
64  {
66  lookupTableProperty = mitk::LookupTableProperty::New();
67  lookupTableProperty->SetLookupTable(mitkLut);
68  dataNode->SetProperty("LookupTable", lookupTableProperty, baseRenderer);
69  }
70 
71  mitk::LookupTable::Pointer lookupTable = lookupTableProperty->GetValue();
72  if (lookupTable.IsNull())
73  {
74  return;
75  }
76 
77  menu()->clear();
78  QAction* lutAction;
79  for (const auto& lutTypeString : lookupTable->typenameList)
80  {
81  lutAction = menu()->addAction(QString::fromStdString(lutTypeString));
82  lutAction->setCheckable(true);
83 
84  if (lutTypeString == lookupTable->GetActiveTypeAsString())
85  {
86  lutAction->setChecked(true);
87  }
88 
89  connect(lutAction, &QAction::triggered, this, &QmitkDataNodeColorMapAction::OnActionTriggered);
90  }
91 }
92 
93 void QmitkDataNodeColorMapAction::OnActionTriggered(bool /*checked*/)
94 {
96 
97  auto selectedNodes = GetSelectedNodes();
98  for (auto& dataNode : selectedNodes)
99  {
100  if (dataNode.IsNull())
101  {
102  continue;
103  }
104  mitk::LookupTableProperty::Pointer lookupTableProperty = dynamic_cast<mitk::LookupTableProperty*>(dataNode->GetProperty("LookupTable", baseRenderer));
105  if (lookupTableProperty.IsNull())
106  {
107  continue;
108  }
109 
110  mitk::LookupTable::Pointer lookupTable = lookupTableProperty->GetValue();
111  if (lookupTable.IsNull())
112  {
113  continue;
114  }
115 
116  mitk::LookupTable::Pointer renderWindowSpecificLuT = lookupTable->Clone();
117 
118  QAction* senderAction = qobject_cast<QAction*>(QObject::sender());
119  if (nullptr == senderAction)
120  {
121  continue;
122  }
123 
124  // set lookup table type defined by the action string
125  std::string activatedItem = senderAction->text().toStdString();
126  renderWindowSpecificLuT->SetType(activatedItem);
127  dataNode->SetProperty("LookupTable", mitk::LookupTableProperty::New(renderWindowSpecificLuT), baseRenderer);
128 
129  if (mitk::LookupTable::LookupTableType::MULTILABEL == lookupTable->GetActiveType())
130  {
131  // special case: multilabel => set the level window to include the whole pixel range
132  UseWholePixelRange(dataNode);
133  }
134 
135  mitk::RenderingModeProperty::Pointer renderingMode = dynamic_cast<mitk::RenderingModeProperty*>(dataNode->GetProperty("Image Rendering.Mode", baseRenderer));
137 
138  if (nullptr == baseRenderer)
139  {
141  }
142  else
143  {
144  mitk::RenderingManager::GetInstance()->RequestUpdate(baseRenderer->GetRenderWindow());
145  }
146  }
147 }
148 
150 {
151  auto image = dynamic_cast<mitk::Image*>(node->GetData());
152  if (nullptr != image)
153  {
154  mitk::LevelWindow levelWindow;
155  levelWindow.SetToImageRange(image);
156  node->SetLevelWindow(levelWindow);
157  }
158 }
mitk::BaseRenderer::Pointer GetBaseRenderer()
Grants access to the base renderer stored for the action. Will return nullptr if renderer was never s...
void SetToImageRange(const Image *image)
sets level/window to the min/max greyvalues of the given Image
QList< mitk::DataNode::Pointer > GetSelectedNodes() const
QmitkDataNodeColorMapAction(QWidget *parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite)
The LevelWindow class Class to store level/window values.
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
The LookupTableProperty class Property to associate mitk::LookupTable to an mitk::DataNode.
static Pointer New()
static RenderingManager * GetInstance()
The custom viewer plugin implements simple viewer functionality presented in a customized look and feel It was developed to demonstrate extensibility and customizability of the blueberry application framework As an example for the GUI customization capabilities provided by the BlueBerry application the custom viewer plugin was developed It features simple viewer functionality presented in a customized look and feel The custom viewer consists of two i e a viewer perspective and a DICOM perspective As part of the viewer an instance of QmitkDataManagerView allows for data selection Visualization of the selected data is then performed by a simple render window view According data can either be directly loaded from file or be imported as DICOM data DICOM import functionality is accessible from the DICOM perspective incorporating the QmitkDicomExternalDataWidget The customization of Qt Stylesheets is used to give the application a non native look and feel This is further emphasized by a Tab Widget like unification of the perspectives with the according perspective bar In addition to an absence of menu
Image class for storing images.
Definition: mitkImage.h:72
mitk::DataNode::Pointer GetSelectedNode() const
mitk::Image::Pointer image
void RequestUpdate(vtkRenderWindow *renderWindow)
void UseWholePixelRange(mitk::DataNode *node)
void SetLevelWindow(mitk::LevelWindow levelWindow, const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="levelwindow")
Convenience method for setting level-window properties (instances of LevelWindowProperty) ...
static Pointer New()
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57