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