19 #ifndef __otbAddCarvingPathFilter_txx
20 #define __otbAddCarvingPathFilter_txx
30 template <
class TInputImage,
class TInputPath,
class TOutputImage>
40 template <
class TInputImage,
class TInputPath,
class TOutputImage>
45 this->SetPathInput(path);
47 template <
class TInputImage,
class TInputPath,
class TOutputImage>
52 return this->GetPathInput();
55 template <
class TInputImage,
class TInputPath,
class TOutputImage>
65 outputImage->SetBufferedRegion(outputImage->GetRequestedRegion());
66 outputImage->Allocate();
69 inputImage->GetLargestPossibleRegion());
71 outputImage->GetLargestPossibleRegion());
88 inputIterator.SetSecondDirection(dir1);
89 inputIterator.GoToBegin();
90 outputIterator.SetFirstDirection(dir0);
91 outputIterator.SetSecondDirection(dir1);
92 outputIterator.GoToBegin();
95 typename InputImageType::IndexType index;
96 typename InputPathType::VertexListType::ConstPointer vertexList = inputPath->GetVertexList();
97 typename InputPathType::VertexListType::ConstIterator pathIterator;
98 typename InputImageType::IndexType indexToAdd;
99 typedef typename InputImageType::IndexType::IndexValueType IndexValueType;
101 typename InputImageType::SizeType inputSize;
102 inputSize = inputImage->GetLargestPossibleRegion().GetSize();
105 pathIterator = vertexList->Begin();
106 while (pathIterator != vertexList->End())
112 while (!outputIterator.IsAtEnd())
114 while (!outputIterator.IsAtEndOfSlice())
117 while (!outputIterator.IsAtEndOfLine())
119 index = outputIterator.GetIndex();
121 if (index[dir1] != line)
124 typename InputImageType::PointType tmpIndex;
125 inputImage->TransformContinuousIndexToPhysicalPoint(pathIterator.Value(), tmpIndex);
126 inputImage->TransformPhysicalPointToIndex(tmpIndex, indexToAdd);
127 if (pathIterator != vertexList->Begin())
131 if (index[dir1] != indexToAdd[dir1])
133 itkExceptionMacro(<<
"Error : " << index[dir1] <<
" , " << indexToAdd[dir1]);
138 || ((index[dir0] != indexToAdd[dir0])
139 && (index[dir0] < static_cast<IndexValueType>(inputSize[dir0]))))
141 outputIterator.Set(inputIterator.Get());
153 newValue = tmpIterator.
Get();
156 tmpIterator = inputIterator;
160 newValue += tmpIterator.
Get();
165 outputIterator.Set(newValue);
171 if ((outputIterator.GetIndex())[dir0] != (inputIterator.GetIndex())[dir0] + 1)
173 itkExceptionMacro(<<
"Error 2: " << (outputIterator.GetIndex())[dir0] <<
" , "
174 << (inputIterator.GetIndex())[dir0]);
176 inputIterator.NextLine();
177 outputIterator.NextLine();
179 inputIterator.NextSlice();
180 outputIterator.NextSlice();
188 template <
class TInputImage,
class TInputPath,
class TOutputImage>
193 Superclass::PrintSelf(os, indent);
194 os << indent <<
"Path Value: " << m_Value << std::endl;
197 template <
class TInputImage,
class TInputPath,
class TOutputImage>
203 Superclass::GenerateOutputInformation();
212 if (m_Direction == 0)
225 const typename TInputImage::SpacingType&
226 inputSpacing = inputPtr->GetSpacing();
227 const typename TInputImage::SizeType& inputSize
228 = inputPtr->GetLargestPossibleRegion().GetSize();
229 const typename TInputImage::IndexType& inputStartIndex
230 = inputPtr->GetLargestPossibleRegion().GetIndex();
232 typename TOutputImage::SpacingType outputSpacing;
233 typename TOutputImage::SizeType outputSize;
234 typename TOutputImage::IndexType outputStartIndex;
236 for (
unsigned int i = 0; i < TOutputImage::ImageDimension; ++i)
238 outputSpacing[i] = inputSpacing[i];
239 outputSize[i] = (
unsigned int) (inputSize[i]);
240 outputStartIndex[i] = inputStartIndex[i];
243 outputSize[dir0] = inputSize[dir0] + 1;
245 outputPtr->SetSpacing(outputSpacing);
247 typename TOutputImage::RegionType outputLargestPossibleRegion;
248 outputLargestPossibleRegion.SetSize(outputSize);
249 outputLargestPossibleRegion.SetIndex(outputStartIndex);
251 outputPtr->SetLargestPossibleRegion(outputLargestPossibleRegion);
254 template <
class TInputImage,
class TInputPath,
class TOutputImage>
260 Superclass::GenerateInputRequestedRegion();
266 itkExceptionMacro(<<
"Input has not been set.");
269 inputPtr->SetRequestedRegion(inputPtr->GetLargestPossibleRegion());