Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkMaskStampWidget.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 
13 #include "QmitkMaskStampWidget.h"
14 
15 #include <mitkLabelSetImage.h>
16 #include <mitkRenderingManager.h>
18 
19 #include <QMessageBox>
20 
21 QmitkMaskStampWidget::QmitkMaskStampWidget(QWidget *parent, const char * /*name*/)
22  : QWidget(parent), m_ToolManager(nullptr), m_DataStorage(nullptr)
23 {
24  m_Controls.setupUi(this);
25  m_Controls.m_InformationWidget->hide();
26 
28  assert(m_ToolManager);
29  m_ToolManager->ActivateTool(-1);
30 
35 
37  maskPredicate->AddPredicate(isMask);
38  maskPredicate->AddPredicate(mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("helper object")));
39 
40  m_Controls.m_cbMaskNodeSelector->SetPredicate(maskPredicate);
41 
42  connect(m_Controls.m_pbStamp, SIGNAL(clicked()), this, SLOT(OnStamp()));
43  connect(m_Controls.m_cbShowInformation, SIGNAL(toggled(bool)), this, SLOT(OnShowInformation(bool)));
44  m_Controls.m_InformationWidget->hide();
45 }
46 
48 {
49 }
50 
52 {
53  m_DataStorage = storage;
54  m_Controls.m_cbMaskNodeSelector->SetDataStorage(m_DataStorage);
55 }
56 
58 {
59  mitk::DataNode *maskNode = m_Controls.m_cbMaskNodeSelector->GetSelectedNode();
60 
61  if (!maskNode)
62  {
63  QMessageBox::information(this, "Mask Stamp", "Please load and select a mask before starting some action.");
64  return;
65  }
66 
67  mitk::Image *mask = dynamic_cast<mitk::Image *>(maskNode->GetData());
68  if (!mask)
69  {
70  QMessageBox::information(this, "Mask Stamp", "Please load and select a mask before starting some action.");
71  return;
72  }
73 
74  mitk::DataNode *workingNode = m_ToolManager->GetWorkingData(0);
75 
76  if (!workingNode)
77  {
78  QMessageBox::information(this, "Mask Stamp", "Please load and select a segmentation before starting some action.");
79  return;
80  }
81 
82  mitk::LabelSetImage *workingImage = dynamic_cast<mitk::LabelSetImage *>(workingNode->GetData());
83 
84  if (!workingImage)
85  {
86  QMessageBox::information(this, "Mask Stamp", "Please load and select a segmentation before starting some action.");
87  return;
88  }
89 
90  QApplication::setOverrideCursor(QCursor(Qt::BusyCursor));
91  try
92  {
93  workingImage->MaskStamp(mask, m_Controls.m_chkOverwrite->isChecked());
94  }
95  catch (mitk::Exception &e)
96  {
97  QApplication::restoreOverrideCursor();
98  MITK_ERROR << "Exception caught: " << e.GetDescription();
99  QMessageBox::information(this, "Mask Stamp", "Could not stamp the selected mask.\n See error log for details.\n");
100  return;
101  }
102 
103  QApplication::restoreOverrideCursor();
104 
105  maskNode->SetVisibility(false);
106 
108 }
109 
111 {
112  if (on)
113  m_Controls.m_InformationWidget->show();
114  else
115  m_Controls.m_InformationWidget->hide();
116 }
Data management class that handles &#39;was created by&#39; relations.
static Pointer New()
void SetVisibility(bool visible, const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="visible")
Convenience method for setting visibility properties (instances of BoolProperty)
QmitkMaskStampWidget(QWidget *parent=nullptr, const char *name=nullptr)
#define MITK_ERROR
Definition: mitkLogMacros.h:20
virtual mitk::ToolManager * GetToolManager()
Returns ToolManager object.
bool ActivateTool(int id)
static Pointer New()
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
mitk::DataStorage::Pointer m_DataStorage
An object of this class represents an exception of MITK. Please don&#39;t instantiate exceptions manually...
Definition: mitkException.h:45
static RenderingManager * GetInstance()
static Pointer New(const mitk::NodePredicateBase *_arg)
Image class for storing images.
Definition: mitkImage.h:72
void SetDataStorage(mitk::DataStorage *storage)
static Pointer New(const char *_arg)
LabelSetImage class for handling labels and layers in a segmentation session.
void MaskStamp(mitk::Image *mask, bool forceOverwrite)
mitk::Image::Pointer mask
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57
DataVectorType GetWorkingData()
static mitk::ToolManagerProvider * GetInstance()
Returns an instance of ToolManagerProvider service.