20 #ifndef __itkAutoCropLabelMapFilter_txx
21 #define __itkAutoCropLabelMapFilter_txx
28 template <
class TInputImage>
32 m_CropBorder.Fill( 0 );
35 template <
class TInputImage>
47 if( !(input->GetMTime() > m_CropTimeStamp) && !(this->GetMTime() > m_CropTimeStamp) )
54 if( input->GetSource() )
63 this->FindBoundingBox();
64 this->SetAndPadCropRegion();
67 template <
class TInputImage>
72 typedef typename InputImageType::IndexValueType IndexValueType;
75 this->m_MinIndex.Fill( NumericTraits< IndexValueType >::max() );
76 this->m_MaxIndex.Fill( NumericTraits< IndexValueType >::NonpositiveMin() );
81 typename InputImageType::LabelObjectContainerType container = inputImage->GetLabelObjectContainer();
82 typename InputImageType::LabelObjectContainerType::const_iterator loit = container.begin();
84 while( loit != container.end() )
87 typename LabelObjectType::LineContainerType::const_iterator lit;
88 const typename LabelObjectType::LineContainerType & lineContainer = labelObject->GetLineContainer();
90 lit = lineContainer.begin();
92 while( lit != lineContainer.end() )
95 IndexValueType length = lit->GetLength();
98 for(
int i=0; i<ImageDimension; i++)
100 if( idx[i] < this->m_MinIndex[i] )
102 this->m_MinIndex[i] = idx[i];
104 if( idx[i] > this->m_MaxIndex[i] )
106 this->m_MaxIndex[i] = idx[i];
110 if( idx[0] + (IndexValueType)length > this->m_MaxIndex[0] )
112 this->m_MaxIndex[0] = idx[0] + length - 1;
121 template <
class TInputImage>
133 for(
int i=0; i<ImageDimension; i++ )
135 regionSize[i] = this->m_MaxIndex[i] - this->m_MinIndex[i] + 1;
137 cropRegion.SetIndex( this->m_MinIndex );
138 cropRegion.SetSize( regionSize );
142 cropRegion.PadByRadius( m_CropBorder );
143 cropRegion.Crop( input->GetLargestPossibleRegion() );
146 this->SetRegion(cropRegion);
147 m_CropTimeStamp.Modified();
149 Superclass::GenerateOutputInformation();
154 template <
class TImage>
159 Superclass::PrintSelf(os,indent);
161 os << indent <<
"Crop Border: " << m_CropBorder << std::endl;
162 os << indent <<
"Crop Time Stamp: " << m_CropTimeStamp << std::endl;
163 os << indent <<
"Min Indexes : " << m_MinIndex << std::endl;
164 os << indent <<
"Max Indexes : " << m_MaxIndex << std::endl;