Medical Imaging Interaction Toolkit  2016.11.0
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,
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 <itkImageRegionIterator.h>
22 
24 {
25  OutputType::Pointer output = dynamic_cast<OutputType *>(this->MakeOutput(0).GetPointer());
26  this->SetNumberOfRequiredInputs(1);
27  this->SetNumberOfIndexedOutputs(1);
28  this->SetNthOutput(0, output.GetPointer());
29 }
30 
32 {
33 }
34 
36 {
37  this->SetInput(0, input);
38 }
39 
42 {
43  if (idx + 1 > this->GetNumberOfInputs())
44  {
45  this->SetNumberOfRequiredInputs(idx + 1);
46  }
47  if (input != static_cast<InputType *>(this->ProcessObject::GetInput(idx)))
48  {
49  this->ProcessObject::SetNthInput(idx, const_cast<InputType *>(input));
50  this->Modified();
51  }
52 }
53 
55 {
56  if (this->GetNumberOfInputs() < 1)
57  return nullptr;
58  return static_cast<const mitk::ImageToLiveWireContourFilter::InputType *>(this->ProcessObject::GetInput(0));
59 }
60 
62 {
63  if (this->GetNumberOfInputs() < 1)
64  return nullptr;
65  return static_cast<const mitk::ImageToLiveWireContourFilter::InputType *>(this->ProcessObject::GetInput(idx));
66 }
67 
69 {
70  mitk::Image::ConstPointer input = dynamic_cast<const mitk::Image *>(this->GetInput());
71 
72  if (!input)
73  {
74  MITK_ERROR << "No input available.";
75  itkExceptionMacro("mitk::ImageToLiveWireContourFilter: No input available. Please set the input!");
76  return;
77  }
78 
79  if (input->GetDimension() != 2)
80  {
81  MITK_ERROR << "Filter is only working on 2D images.";
82  itkExceptionMacro("mitk::ImageToLiveWireContourFilter: Filter is only working on 2D images.. Please make sure that "
83  "the input is 2D!");
84  return;
85  }
86 
87  input->GetGeometry()->WorldToIndex(m_StartPoint, m_StartPointInIndex);
88  input->GetGeometry()->WorldToIndex(m_EndPoint, m_EndPointInIndex);
89 
90  AccessFixedDimensionByItk(input, ItkProcessImage, 2);
91 }
92 
93 template <typename TPixel, unsigned int VImageDimension>
94 void mitk::ImageToLiveWireContourFilter::ItkProcessImage(const itk::Image<TPixel, VImageDimension> *)
95 {
96  // typedef itk::Image< TPixel, VImageDimension > InputImageType;
97  // typedef itk::Image< float, 2 > FloatImageType;
98 
99  // typedef typename itk::ShortestPathImageFilter< InputImageType, InputImageType > ShortestPathImageFilterType;
100  // typedef typename itk::ShortestPathCostFunctionLiveWire< InputImageType > CostFunctionType;
101 
102  // typedef InputImageType::IndexType IndexType;
103 
105 
106  // typename IndexType startPoint, endPoint;
107  //
108  // startPoint[0] = m_StartPointInIndex[0];
109  // startPoint[1] = m_StartPointInIndex[1];
110 
111  // endPoint[0] = m_EndPointInIndex[0];
112  // endPoint[1] = m_EndPointInIndex[1];
113 
115  // typename IndexType startRegion;
116  // startRegion[0] = startPoint[0] < endPoint[0] ? startPoint[0] : endPoint[0];
117  // startRegion[1] = startPoint[1] < endPoint[1] ? startPoint[1] : endPoint[1];
118 
120  // typename InputImageType::SizeType size;
121  // size[0] = startPoint[0] > endPoint[0] ? startPoint[0] : endPoint[0];
122  // size[1] = startPoint[1] > endPoint[1] ? startPoint[1] : endPoint[1];
123 
124  // typename InputImageType::RegionType region;
125  // region.SetSize( size );
126  // region.SetIndex( startRegion );
128 
130  // typename CostFunctionType::Pointer costFunction = CostFunctionType::New();
131  // costFunction->SetImage(inputImage);
132  // costFunction->SetStartIndex(startPoint);
133  // costFunction->SetEndIndex(endPoint);
134  // costFunction->SetRequestedRegion(region);
136 
138  // ShortestPathImageFilterType::Pointer shortestPathFilter = ShortestPathImageFilterType::New();
139  // shortestPathFilter->SetFullNeighborsMode(true);
140  // shortestPathFilter->SetInput(inputImage);
141  // shortestPathFilter->SetMakeOutputImage(true);
142  // shortestPathFilter->SetStoreVectorOrder(false);
144  // shortestPathFilter->SetStartIndex(startPoint);
145  // shortestPathFilter->SetEndIndex(endPoint);
146 
147  // shortestPathFilter->Update();
148 
150 
153  // std::vector< itk::Index<3> > shortestPath = shortestPathFilter->GetVectorPath();
154 
156  // OutputType::Pointer outputContour = this->GetOutput();
157  // mitk::Image::ConstPointer input = dynamic_cast<const mitk::Image*>(this->GetInput());
158 
159  // std::vector< itk::Index<3> >::iterator pathIterator = shortestPath.begin();
160 
161  // while(pathIterator != shortestPath.end())
162  //{
163  // mitk::Point3D currentPoint;
164  // currentPoint[0] = (*pathIterator)[0];
165  // currentPoint[1] = (*pathIterator)[1];
166 
167  // input->GetGeometry(0)->IndexToWorld(currentPoint, currentPoint);
168  // outputContour->AddVertex(currentPoint);
169  //
170  // pathIterator++;
171  //}
172  /*---------------------------------------------*/
173 }
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:24
virtual mitkBaseDataSourceGetOutputDeclarations itk::DataObject::Pointer MakeOutput(DataObjectPointerArraySizeType idx) override
Image class for storing images.
Definition: mitkImage.h:76
virtual void SetInput(const InputType *input)