17 #ifndef __itkGrayscaleGeodesicErodeImageFilter_txx
18 #define __itkGrayscaleGeodesicErodeImageFilter_txx
23 #include "itkNumericTraits.h"
36 template <
class TInputImage,
class TOutputImage>
40 m_RunOneIteration =
false;
41 m_NumberOfIterationsUsed = 0;
42 this->SetNumberOfRequiredInputs(2);
43 m_FullyConnected =
false;
47 template <
class TInputImage,
class TOutputImage>
53 this->SetNthInput(0, const_cast<MarkerImageType *>( markerImage ));
57 template <
class TInputImage,
class TOutputImage>
62 return this->GetInput(0);
66 template <
class TInputImage,
class TOutputImage>
72 this->SetNthInput(1, const_cast<MaskImageType *>( maskImage ));
76 template <
class TInputImage,
class TOutputImage>
81 return this->GetInput(1);
85 template <
class TInputImage,
class TOutputImage>
91 Superclass::GenerateInputRequestedRegion();
100 if ( !markerPtr || !maskPtr )
110 if (m_RunOneIteration)
124 markerRequestedRegion = markerPtr->GetRequestedRegion();
127 markerRequestedRegion.PadByRadius( 1 );
130 if ( markerRequestedRegion.Crop(markerPtr->GetLargestPossibleRegion()) )
132 markerPtr->SetRequestedRegion( markerRequestedRegion );
141 markerPtr->SetRequestedRegion( markerRequestedRegion );
146 e.
SetDescription(
"Requested region for the marker image is (at least partially) outside the largest possible region.");
156 markerPtr->SetRequestedRegion(markerPtr->GetLargestPossibleRegion());
157 maskPtr->SetRequestedRegion(maskPtr->GetLargestPossibleRegion());
162 template <
class TInputImage,
class TOutputImage>
168 if ( !m_RunOneIteration)
171 ->SetRequestedRegion( this->GetOutput()->GetLargestPossibleRegion() );
176 template<
class TInputImage,
class TOutputImage>
187 if (m_RunOneIteration)
189 Superclass::GenerateData();
190 m_NumberOfIterationsUsed = 1;
208 singleIteration->RunOneIterationOn();
209 singleIteration->SetMarkerImage( this->GetMarkerImage() );
210 singleIteration->SetMaskImage( this->GetMaskImage() );
211 singleIteration->GetOutput()
212 ->SetRequestedRegion( this->GetOutput()->GetRequestedRegion() );
216 progress->SetMiniPipelineFilter(
this);
217 progress->RegisterInternalFilter(singleIteration,1.0f);
223 singleIteration->Update();
229 singleIteration->GetMarkerImage(),
230 singleIteration->GetOutput()->GetRequestedRegion() );
232 singleIteration->GetOutput(),
233 singleIteration->GetOutput()->GetRequestedRegion() );
236 while ( !singleOutIt.IsAtEnd() )
239 if (singleInIt.Get() != singleOutIt.Get())
255 marker->DisconnectPipeline();
257 singleIteration->SetMarkerImage( marker );
260 singleIteration->GetOutput()
261 ->SetRequestedRegion( this->GetOutput()->GetRequestedRegion() );
264 m_NumberOfIterationsUsed++;
270 typename OutputImageType::Pointer outputPtr = this->GetOutput();
271 outputPtr->SetBufferedRegion( outputPtr->GetRequestedRegion() );
272 outputPtr->Allocate();
276 outputPtr->GetRequestedRegion() );
279 outputPtr->GetRequestedRegion());
282 while( !outIt.IsAtEnd() )
284 outIt.
Set( static_cast<OutputImagePixelType>( singleIt.Get() ) );
290 template<
class TInputImage,
class TOutputImage>
299 outputRegionForThread.GetNumberOfPixels(),
318 kernelRadius.
Fill(1);
319 faceList = fC(this->GetMarkerImage(), outputRegionForThread, kernelRadius);
324 typename NeighborhoodIteratorType::OffsetValueType i;
325 typename NeighborhoodIteratorType::OffsetType offset;
331 for (fit = faceList.begin(); fit != faceList.end(); ++fit)
333 NeighborhoodIteratorType markerIt(kernelRadius, this->GetMarkerImage(), *fit);
337 markerIt.OverrideBoundaryCondition(&BC);
338 markerIt.GoToBegin();
340 if ( !m_FullyConnected )
345 markerIt.ActivateOffset(offset);
346 for (d=0; d < TInputImage::ImageDimension; ++d)
348 for (i=-1; i<=1; i+=2)
351 markerIt.ActivateOffset(offset);
359 for (d=0; d < markerIt.GetCenterNeighborhoodIndex()*2+1; ++d)
361 markerIt.ActivateOffset(markerIt.GetOffset(d));
364 markerIt.DeactivateOffset(offset);
373 typename NeighborhoodIteratorType::ConstIterator sIt;
374 for (sIt = markerIt.Begin(); !sIt.IsAtEnd(); sIt++)
380 if (value < erodeValue)
389 maskValue = maskIt.
Get();
391 if (maskValue > erodeValue)
393 erodeValue = maskValue;
397 oIt.
Set( static_cast<OutputImagePixelType>( erodeValue ) );
404 progress.CompletedPixel();
409 template<
class TInputImage,
class TOutputImage>
414 Superclass::PrintSelf(os, indent);
416 os << indent <<
"Run one iteration: " << (m_RunOneIteration ?
"on" :
"off")
418 os << indent <<
"Number of iterations used to produce current output: "
419 << m_NumberOfIterationsUsed << std::endl;
420 os << indent <<
"FullyConnected: " << m_FullyConnected << std::endl;