Orfeo Toolbox  3.16
itkAutoCropLabelMapFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkAutoCropLabelMapFilter.txx,v $
5  Language: C++
6  Date: $Date: 2010-07-07 12:31:09 $
7  Version: $Revision: 1.5 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  Portions of this code are covered under the VTK copyright.
13  See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
14 
15  This software is distributed WITHOUT ANY WARRANTY; without even
16  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17  PURPOSE. See the above copyright notices for more information.
18 
19 =========================================================================*/
20 #ifndef __itkAutoCropLabelMapFilter_txx
21 #define __itkAutoCropLabelMapFilter_txx
23 
24 
25 namespace itk
26 {
27 
28 template <class TInputImage>
31 {
32  m_CropBorder.Fill( 0 );
33 }
34 
35 template <class TInputImage>
36 void
39 {
40 
41  const InputImageType * input = this->GetInput();
42 
43  //
44  // FIXME: This way of implementing a GenerateOutputInformation() method is suspicious.
45  // Needs to be revisited.
46  //
47  if( !(input->GetMTime() > m_CropTimeStamp) && !(this->GetMTime() > m_CropTimeStamp) )
48  {
49  // early exit, crop sizes already computed
50  return;
51  }
52 
53  // update the input if needed
54  if( input->GetSource() )
55  {
56  ProcessObject * upstream = input->GetSource();
57  if (upstream)
58  {
59  upstream->Update();
60  }
61  }
62 
63  this->FindBoundingBox();
64  this->SetAndPadCropRegion();
65 }
66 
67 template <class TInputImage>
68 void
71 {
72  typedef typename InputImageType::IndexValueType IndexValueType;
73 
74  // find the bounding box of the objects
75  this->m_MinIndex.Fill( NumericTraits< IndexValueType >::max() );
76  this->m_MaxIndex.Fill( NumericTraits< IndexValueType >::NonpositiveMin() );
77 
78  const InputImageType * inputImage = this->GetInput();
79 
80  // iterate over all the lines
81  typename InputImageType::LabelObjectContainerType container = inputImage->GetLabelObjectContainer();
82  typename InputImageType::LabelObjectContainerType::const_iterator loit = container.begin();
83 
84  while( loit != container.end() )
85  {
86  const LabelObjectType * labelObject = loit->second;
87  typename LabelObjectType::LineContainerType::const_iterator lit;
88  const typename LabelObjectType::LineContainerType & lineContainer = labelObject->GetLineContainer();
89 
90  lit = lineContainer.begin();
91 
92  while( lit != lineContainer.end() )
93  {
94  const IndexType & idx = lit->GetIndex();
95  IndexValueType length = lit->GetLength();
96 
97  // update the mins and maxs
98  for( int i=0; i<ImageDimension; i++)
99  {
100  if( idx[i] < this->m_MinIndex[i] )
101  {
102  this->m_MinIndex[i] = idx[i];
103  }
104  if( idx[i] > this->m_MaxIndex[i] )
105  {
106  this->m_MaxIndex[i] = idx[i];
107  }
108  }
109  // must fix the max for the axis 0
110  if( idx[0] + (IndexValueType)length > this->m_MaxIndex[0] )
111  {
112  this->m_MaxIndex[0] = idx[0] + length - 1;
113  }
114  lit++;
115  }
116  loit++;
117  }
118 
119 }
120 
121 template <class TInputImage>
122 void
125 {
126  const InputImageType * input = this->GetInput();
127 
128  // prefetch image region and size
129  InputImageRegionType cropRegion = input->GetLargestPossibleRegion();
130 
131  // final computation
132  SizeType regionSize;
133  for( int i=0; i<ImageDimension; i++ )
134  {
135  regionSize[i] = this->m_MaxIndex[i] - this->m_MinIndex[i] + 1;
136  }
137  cropRegion.SetIndex( this->m_MinIndex );
138  cropRegion.SetSize( regionSize );
139 
140  // pad the crop border while ensuring border is not larger than the largest
141  // possible region of the input image
142  cropRegion.PadByRadius( m_CropBorder );
143  cropRegion.Crop( input->GetLargestPossibleRegion() );
144 
145  // finally set that region as the largest output region
146  this->SetRegion(cropRegion);
147  m_CropTimeStamp.Modified();
148 
149  Superclass::GenerateOutputInformation();
150 
151 
152 }
153 
154 template <class TImage>
155 void
157 ::PrintSelf(std::ostream& os, Indent indent) const
158 {
159  Superclass::PrintSelf(os,indent);
160 
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;
165 }
166 
167 } // end namespace itk
168 
169 #endif

Generated at Sat Feb 2 2013 23:24:50 for Orfeo Toolbox with doxygen 1.8.1.1