Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkDataNodeComponentAction.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 <mitkDataNode.h>
17 #include <mitkImage.h>
18 #include <mitkRenderingManager.h>
19 
20 // mitk gui common plugin
21 #include <mitkDataNodeSelection.h>
22 
23 // qt
24 #include <QHBoxLayout>
25 #include <QLabel>
26 
28  : QWidgetAction(parent)
29  , QmitkAbstractDataNodeAction(workbenchpartSite)
30 {
32 }
33 
35  : QWidgetAction(parent)
36  , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite))
37 {
39 }
40 
42 {
43  setCheckable(true);
44 
45  m_ComponentSlider = new QmitkNumberPropertySlider;
46  m_ComponentSlider->setOrientation(Qt::Horizontal);
47 
48  QLabel* componentLabel = new QLabel(tr("Component: "));
49  QHBoxLayout* componentWidgetLayout = new QHBoxLayout;
50  componentWidgetLayout->setContentsMargins(4, 4, 4, 4);
51  componentWidgetLayout->addWidget(componentLabel);
52  componentWidgetLayout->addWidget(m_ComponentSlider);
53  QLabel* componentValueLabel = new QLabel();
54  componentWidgetLayout->addWidget(componentValueLabel);
55  connect(m_ComponentSlider, &QmitkNumberPropertySlider::valueChanged, componentValueLabel, static_cast<void (QLabel::*)(int)>(&QLabel::setNum));
56 
57  QWidget* componentWidget = new QWidget;
58  componentWidget->setLayout(componentWidgetLayout);
59 
60  setDefaultWidget(componentWidget);
61 
62  connect(this, &QmitkDataNodeComponentAction::changed, this, &QmitkDataNodeComponentAction::OnActionChanged);
63 }
64 
66 {
67  if (nullptr == dataNode)
68  {
69  m_ComponentSlider->SetProperty(static_cast<mitk::IntProperty*>(nullptr));
70  return;
71  }
72 
73  mitk::Image* img = dynamic_cast<mitk::Image*>(dataNode->GetData());
74  if (nullptr == img)
75  {
76  m_ComponentSlider->SetProperty(static_cast<mitk::IntProperty*>(nullptr));
77  return;
78  }
79 
81 
82  int numComponents = 0;
83  numComponents = img->GetPixelType().GetNumberOfComponents();
84  mitk::IntProperty* componentProperty = dynamic_cast<mitk::IntProperty*>(dataNode->GetProperty("Image.Displayed Component", baseRenderer));
85  if (numComponents <= 1 || nullptr == componentProperty)
86  {
87  m_ComponentSlider->SetProperty(static_cast<mitk::IntProperty*>(nullptr));
88  return;
89  }
90 
91  m_ComponentSlider->SetProperty(componentProperty);
92  m_ComponentSlider->setMinValue(0);
93  m_ComponentSlider->setMaxValue(numComponents - 1);
94 }
95 
96 void QmitkDataNodeComponentAction::OnActionChanged()
97 {
98  auto dataNode = GetSelectedNode();
99 
100  InitializeWithDataNode(dataNode);
101 }
mitk::BaseRenderer::Pointer GetBaseRenderer()
Grants access to the base renderer stored for the action. Will return nullptr if renderer was never s...
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...
const mitk::PixelType GetPixelType(int n=0) const
Returns the PixelType of channel n.
Definition: mitkImage.cpp:101
vcl_size_t GetNumberOfComponents() const
Get the number of components of which each element consists.
void InitializeWithDataNode(const mitk::DataNode *dataNode) override
void SetProperty(mitk::IntProperty *property)
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
Image class for storing images.
Definition: mitkImage.h:72
mitk::DataNode::Pointer GetSelectedNode() const
QmitkDataNodeComponentAction(QWidget *parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite)
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57