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