Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkLabelSetImageToSurfaceThreadedFilter.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 
18 
19 #include "mitkLabelSetImage.h"
21 
22 namespace mitk
23 {
25  {
26  }
27 
30  {
31  Superclass::Initialize(other);
32  }
33 
35  {
36  Image::Pointer image;
37  GetPointerParameter("Input", image);
38 
39  return image.IsNotNull() && GetGroupNode();
40  }
41 
43  {
45  this->GetPointerParameter("Input", image);
46 
47  // ProcessObserver::Pointer obsv;
48  /*
49  try
50  {
51  this->GetPointerParameter("Observer", obsv);
52  }
53  catch (std::invalid_argument&)
54  {
55  // MITK_WARN << "None observer provided.";
56  }
57  */
58  bool useSmoothing(false);
59  try
60  {
61  this->GetParameter("Smooth", useSmoothing);
62  }
63  catch (std::invalid_argument &)
64  {
65  MITK_WARN << "\"Smooth\" parameter was not set: will use the default value (" << useSmoothing << ").";
66  }
67 
68  try
69  {
70  this->GetParameter("RequestedLabel", m_RequestedLabel);
71  }
72  catch (std::invalid_argument &)
73  {
74  MITK_WARN << "\"RequestedLabel\" parameter was not set: will use the default value (" << m_RequestedLabel << ").";
75  }
76 
78  filter->SetInput(image);
79  // filter->SetObserver(obsv);
80  filter->SetGenerateAllLabels(false);
81  filter->SetRequestedLabel(m_RequestedLabel);
82  filter->SetUseSmoothing(useSmoothing);
83 
84  try
85  {
86  filter->Update();
87  }
88  catch (itk::ExceptionObject &e)
89  {
90  MITK_ERROR << "Exception caught: " << e.GetDescription();
91  return false;
92  }
93  catch (std::exception &e)
94  {
95  MITK_ERROR << "Exception caught: " << e.what();
96  return false;
97  }
98  catch (...)
99  {
100  MITK_ERROR << "Unknown exception caught";
101  return false;
102  }
103 
104  m_Result = filter->GetOutput();
105 
106  if (m_Result.IsNull() || !m_Result->GetVtkPolyData())
107  return false;
108 
109  m_Result->DisconnectPipeline();
110 
111  return true;
112  }
113 
115  {
117  this->GetPointerParameter("Input", image);
118 
119  std::string name = this->GetGroupNode()->GetName();
120  name.append("-surf");
121 
123  node->SetData(m_Result);
124  node->SetName(name);
125 
126  mitk::Color color = image->GetLabel(m_RequestedLabel, image->GetActiveLayer())->GetColor();
127  node->SetColor(color);
128 
129  this->InsertBelowGroupNode(node);
130 
131  Superclass::ThreadedUpdateSuccessful();
132  }
133 
134 } // namespace
void InsertBelowGroupNode(mitk::DataNode *node)
virtual void Initialize(const NonBlockingAlgorithm *other=nullptr) override
#define MITK_ERROR
Definition: mitkLogMacros.h:24
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:366
DataCollection - Class to facilitate loading/accessing structured data.
#define MITK_WARN
Definition: mitkLogMacros.h:23
static Pointer New()
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
void GetPointerParameter(const char *parameter, itk::SmartPointer< T > &value) const
void GetParameter(const char *parameter, T &value) const