Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkImageToLiveWireContourFilter.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 <itkImageRegionIterator.h>
18 
20 {
21  OutputType::Pointer output = dynamic_cast<OutputType *>(this->MakeOutput(0).GetPointer());
22  this->SetNumberOfRequiredInputs(1);
23  this->SetNumberOfIndexedOutputs(1);
24  this->SetNthOutput(0, output.GetPointer());
25 }
26 
28 {
29 }
30 
32 {
33  this->SetInput(0, input);
34 }
35 
38 {
39  if (idx + 1 > this->GetNumberOfInputs())
40  {
41  this->SetNumberOfRequiredInputs(idx + 1);
42  }
43  if (input != static_cast<InputType *>(this->ProcessObject::GetInput(idx)))
44  {
45  this->ProcessObject::SetNthInput(idx, const_cast<InputType *>(input));
46  this->Modified();
47  }
48 }
49 
51 {
52  if (this->GetNumberOfInputs() < 1)
53  return nullptr;
54  return static_cast<const mitk::ImageToLiveWireContourFilter::InputType *>(this->ProcessObject::GetInput(0));
55 }
56 
58 {
59  if (this->GetNumberOfInputs() < 1)
60  return nullptr;
61  return static_cast<const mitk::ImageToLiveWireContourFilter::InputType *>(this->ProcessObject::GetInput(idx));
62 }
63 
65 {
66  mitk::Image::ConstPointer input = dynamic_cast<const mitk::Image *>(this->GetInput());
67 
68  if (!input)
69  {
70  MITK_ERROR << "No input available.";
71  itkExceptionMacro("mitk::ImageToLiveWireContourFilter: No input available. Please set the input!");
72  return;
73  }
74 
75  if (input->GetDimension() != 2)
76  {
77  MITK_ERROR << "Filter is only working on 2D images.";
78  itkExceptionMacro("mitk::ImageToLiveWireContourFilter: Filter is only working on 2D images.. Please make sure that "
79  "the input is 2D!");
80  return;
81  }
82 
83  input->GetGeometry()->WorldToIndex(m_StartPoint, m_StartPointInIndex);
84  input->GetGeometry()->WorldToIndex(m_EndPoint, m_EndPointInIndex);
85 
86  AccessFixedDimensionByItk(input, ItkProcessImage, 2);
87 }
88 
89 template <typename TPixel, unsigned int VImageDimension>
90 void mitk::ImageToLiveWireContourFilter::ItkProcessImage(const itk::Image<TPixel, VImageDimension> *)
91 {
92  // typedef itk::Image< TPixel, VImageDimension > InputImageType;
93  // typedef itk::Image< float, 2 > FloatImageType;
94 
95  // typedef typename itk::ShortestPathImageFilter< InputImageType, InputImageType > ShortestPathImageFilterType;
96  // typedef typename itk::ShortestPathCostFunctionLiveWire< InputImageType > CostFunctionType;
97 
98  // typedef InputImageType::IndexType IndexType;
99 
101 
102  // typename IndexType startPoint, endPoint;
103  //
104  // startPoint[0] = m_StartPointInIndex[0];
105  // startPoint[1] = m_StartPointInIndex[1];
106 
107  // endPoint[0] = m_EndPointInIndex[0];
108  // endPoint[1] = m_EndPointInIndex[1];
109 
111  // typename IndexType startRegion;
112  // startRegion[0] = startPoint[0] < endPoint[0] ? startPoint[0] : endPoint[0];
113  // startRegion[1] = startPoint[1] < endPoint[1] ? startPoint[1] : endPoint[1];
114 
116  // typename InputImageType::SizeType size;
117  // size[0] = startPoint[0] > endPoint[0] ? startPoint[0] : endPoint[0];
118  // size[1] = startPoint[1] > endPoint[1] ? startPoint[1] : endPoint[1];
119 
120  // typename InputImageType::RegionType region;
121  // region.SetSize( size );
122  // region.SetIndex( startRegion );
124 
126  // typename CostFunctionType::Pointer costFunction = CostFunctionType::New();
127  // costFunction->SetImage(inputImage);
128  // costFunction->SetStartIndex(startPoint);
129  // costFunction->SetEndIndex(endPoint);
130  // costFunction->SetRequestedRegion(region);
132 
134  // ShortestPathImageFilterType::Pointer shortestPathFilter = ShortestPathImageFilterType::New();
135  // shortestPathFilter->SetFullNeighborsMode(true);
136  // shortestPathFilter->SetInput(inputImage);
137  // shortestPathFilter->SetMakeOutputImage(true);
138  // shortestPathFilter->SetStoreVectorOrder(false);
140  // shortestPathFilter->SetStartIndex(startPoint);
141  // shortestPathFilter->SetEndIndex(endPoint);
142 
143  // shortestPathFilter->Update();
144 
146 
149  // std::vector< itk::Index<3> > shortestPath = shortestPathFilter->GetVectorPath();
150 
152  // OutputType::Pointer outputContour = this->GetOutput();
153  // mitk::Image::ConstPointer input = dynamic_cast<const mitk::Image*>(this->GetInput());
154 
155  // std::vector< itk::Index<3> >::iterator pathIterator = shortestPath.begin();
156 
157  // while(pathIterator != shortestPath.end())
158  //{
159  // mitk::Point3D currentPoint;
160  // currentPoint[0] = (*pathIterator)[0];
161  // currentPoint[1] = (*pathIterator)[1];
162 
163  // input->GetGeometry(0)->IndexToWorld(currentPoint, currentPoint);
164  // outputContour->AddVertex(currentPoint);
165  //
166  // pathIterator++;
167  //}
168  /*---------------------------------------------*/
169 }
ContourModel is a structure of linked vertices defining a contour in 3D space. The vertices are store...
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
#define MITK_ERROR
Definition: mitkLogMacros.h:20
mitkBaseDataSourceGetOutputDeclarations itk::DataObject::Pointer MakeOutput(DataObjectPointerArraySizeType idx) override
Image class for storing images.
Definition: mitkImage.h:72
virtual void SetInput(const InputType *input)