Orfeo Toolbox  3.16
itkImageToListGenerator.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkImageToListGenerator.txx,v $
5  Language: C++
6  Date: $Date: 2007-12-19 17:22:48 $
7  Version: $Revision: 1.6 $
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  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkImageToListGenerator_txx
18 #define __itkImageToListGenerator_txx
19 
22 
23 namespace itk {
24 namespace Statistics {
25 
26 template < class TImage, class TMaskImage >
29 {
30  this->SetNumberOfRequiredInputs(1);
31  this->SetNumberOfRequiredOutputs(1);
32  typename ListSampleOutputType::Pointer listSampleDecorator =
33  static_cast< ListSampleOutputType * >( this->MakeOutput(0).GetPointer() );
34  this->ProcessObject::SetNthOutput(0, listSampleDecorator.GetPointer());
35  m_MaskValue = NumericTraits<MaskPixelType>::max();
36 }
37 
38 template < class TImage, class TMaskImage >
39 void
41 ::PrintSelf(std::ostream& os, Indent indent) const
42 {
43  Superclass::PrintSelf(os,indent);
44  os << indent << "MaskValue: "
45  << static_cast<typename NumericTraits<MaskPixelType>::PrintType>(
46  m_MaskValue)
47  << std::endl;
48 }
49 
50 template < class TImage, class TMaskImage >
51 void
53 ::SetInput(const ImageType* image)
54 {
55  // Process object is not const-correct so the const_cast is required here
57  const_cast< ImageType* >( image ) );
58 }
59 
60 template < class TImage, class TMaskImage >
61 void
64 {
65  // Process object is not const-correct so the const_cast is required here
67  const_cast< MaskImageType* >( image ) );
68 }
69 
70 template < class TImage, class TMaskImage >
71 const TImage*
73 ::GetInput() const
74 {
75  if (this->GetNumberOfInputs() < 1)
76  {
77  return 0;
78  }
79 
80  return static_cast<const ImageType * >
81  (this->ProcessObject::GetInput(0) );
82 }
83 
84 template < class TImage, class TMaskImage >
85 const TMaskImage*
88 {
89  if (this->GetNumberOfInputs() < 2)
90  {
91  return 0;
92  }
93 
94  return static_cast<const MaskImageType * >
95  (this->ProcessObject::GetInput(1) );
96 }
97 
98 template < class TImage, class TMaskImage >
101 ::MakeOutput(unsigned int itkNotUsed(idx))
102 {
103  typename ListSampleOutputType::Pointer decoratedOutput =
104  ListSampleOutputType::New();
105  decoratedOutput->Set( ListSampleType::New() );
106  return static_cast< DataObject * >(decoratedOutput.GetPointer());
107 }
108 
109 template < class TImage, class TMaskImage >
110 void
113 {
114  ListSampleOutputType * decoratedOutput =
115  static_cast< ListSampleOutputType * >(
116  this->ProcessObject::GetOutput(0));
117 
118  ListSampleType *output =
119  const_cast< ListSampleType * >( decoratedOutput->Get() );
120 
121  const ImageType *input = this->GetInput();
122  MaskImageType *maskImage = NULL;
123 
124  output->Clear();
125 
126  if (this->GetNumberOfInputs() > 1)
127  {
128  maskImage = const_cast< MaskImageType * >(this->GetMaskImage());
129  }
130 
131  typedef ImageRegionConstIterator< ImageType > IteratorType;
132  IteratorType it( input, input->GetBufferedRegion() );
133  it.GoToBegin();
134 
135  if (maskImage) // mask specified
136  {
137  typedef ImageRegionConstIterator< MaskImageType > MaskIteratorType;
138  MaskIteratorType mit( maskImage, input->GetBufferedRegion() );
139  mit.GoToBegin();
140  while (!it.IsAtEnd())
141  {
142  if (mit.Get() == this->m_MaskValue)
143  {
145  m[0] = it.Get();
146  output->PushBack(m);
147  }
148  ++mit;
149  ++it;
150  }
151  }
152  else // no mask specified
153  {
154  while (!it.IsAtEnd())
155  {
157  m[0] = it.Get();
158  output->PushBack(m);
159  ++it;
160  }
161  }
162 }
163 
164 template < class TImage, class TMaskImage >
165 void
168 {
169  Superclass::GenerateOutputInformation();
170 
171  ListSampleOutputType * decoratedOutput =
172  static_cast< ListSampleOutputType * >(
173  this->ProcessObject::GetOutput(0));
174  ListSampleType *output =
175  const_cast< ListSampleType *>( decoratedOutput->Get() );
176  output->SetMeasurementVectorSize(
177  itkGetStaticConstMacro( MeasurementVectorSize ));
178 }
179 
180 template < class TImage, class TMaskImage >
181 void
184 {
185  // call the superclass' implementation of this method. this should
186  // copy the output requested region to the input requested region
187  Superclass::GenerateInputRequestedRegion();
188 
189  // Make sure that the mask's requested region, if specified is at least
190  // as large as the input image's buffered region. If not funny things can
191  // happen such as the mask iterator going out of bounds etc..
192  //
193  // TODO: Why don't most other ITK filters that take multiple inputs check
194  // for this ?
195  //
196  if (this->GetNumberOfInputs() > 1)
197  {
198  MaskImageType *maskImage =
199  const_cast< MaskImageType * >(this->GetMaskImage());
200  ImageType *image =
201  const_cast< ImageType * >( this->GetInput() );
202  if (!image->GetBufferedRegion().IsInside( maskImage->GetBufferedRegion()) )
203  {
204  maskImage->SetRequestedRegion( image->GetBufferedRegion() );
205  }
206  }
207 }
208 
209 template < class TImage, class TMaskImage >
213 {
214  const ListSampleOutputType * decoratedOutput =
215  static_cast< const ListSampleOutputType * >(
216  this->ProcessObject::GetOutput(0));
217  return decoratedOutput->Get();
218 }
219 
220 } // end of namespace Statistics
221 } // end of namespace itk
222 
223 #endif

Generated at Sat Feb 2 2013 23:45:12 for Orfeo Toolbox with doxygen 1.8.1.1