Orfeo Toolbox  3.16
itkPointSetToImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: itkPointSetToImageFilter.txx,v $
5 Language: C++
6 Date: $Date: 2008-11-07 19:39:44 $
7 Version: $Revision: 1.14 $
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 __itkPointSetToImageFilter_txx
18 #define __itkPointSetToImageFilter_txx
19 
22 #include <itkNumericTraits.h>
23 
24 namespace itk
25 {
26 
28 template <class TInputPointSet, class TOutputImage>
31 {
32  this->SetNumberOfRequiredInputs(1);
33  m_Size.Fill(0);
34  m_Origin.Fill(0.0);
35  m_Spacing.Fill(1.0);
36  m_Direction.SetIdentity();
37  m_InsideValue = NumericTraits< ValueType >::OneValue();
38  m_OutsideValue = NumericTraits< ValueType >::ZeroValue();
39 }
40 
42 template <class TInputPointSet, class TOutputImage>
45 {
46 }
47 
48 
50 template <class TInputPointSet, class TOutputImage>
51 void
54 {
55  // Process object is not const-correct so the const_cast is required here
57  const_cast< InputPointSetType * >( input ) );
58 }
59 
60 
62 template <class TInputPointSet, class TOutputImage>
63 void
65 ::SetInput( unsigned int index, const TInputPointSet * pointset )
66 {
67  // Process object is not const-correct so the const_cast is required here
68  this->ProcessObject::SetNthInput(index,
69  const_cast< TInputPointSet *>( pointset ) );
70 }
71 
73 template <class TInputPointSet, class TOutputImage>
76 ::GetInput(void)
77 {
78  if (this->GetNumberOfInputs() < 1)
79  {
80  return 0;
81  }
82 
83  return static_cast<const TInputPointSet * >
84  (this->ProcessObject::GetInput(0) );
85 }
86 
88 template <class TInputPointSet, class TOutputImage>
91 ::GetInput(unsigned int idx)
92 {
93  return static_cast< const TInputPointSet * >
94  (this->ProcessObject::GetInput(idx));
95 }
96 
97 template <class TInputPointSet, class TOutputImage>
98 void
100 ::SetSpacing(const float* v)
101 {
103  SpacingType spacing;
104  spacing.CastFrom(vf);
105  this->SetSpacing(spacing);
106 }
107 
108 template <class TInputPointSet, class TOutputImage>
109 void
111 ::SetSpacing(const double* v)
112 {
113  SpacingType spacing(v);
114  this->SetSpacing(spacing);
115 }
116 
117 template <class TInputPointSet, class TOutputImage>
118 void
120 ::SetOrigin(const float* v)
121 {
123  PointType origin;
124  origin.CastFrom(pf);
125  this->SetOrigin(origin);
126 }
127 
128 template <class TInputPointSet, class TOutputImage>
129 void
131 ::SetOrigin(const double* v)
132 {
133  PointType origin(v);
134  this->SetOrigin(origin);
135 }
136 
137 //----------------------------------------------------------------------------
138 
140 template <class TInputPointSet, class TOutputImage>
141 void
144 {
145  unsigned int i;
146  itkDebugMacro(<< "PointSetToImageFilter::Update() called");
147 
148  // Get the input and output pointers
149  const InputPointSetType * InputPointSet = this->GetInput();
150  OutputImagePointer OutputImage = this->GetOutput();
151 
152  // Generate the image
153  double origin[InputPointSetDimension];
154  SizeType size;
155 
156  typedef typename InputPointSetType::BoundingBoxType BoundingBoxType;
157  const BoundingBoxType * bb = InputPointSet->GetBoundingBox();
158 
159  for(i=0;i<InputPointSetDimension;i++)
160  {
161  size[i] = (unsigned long)(bb->GetBounds()[2*i+1]-bb->GetBounds()[2*i]);
162  origin[i]= 0; //bb->GetBounds()[2*i];
163  }
164 
165 
166  typename OutputImageType::RegionType region;
167 
168  // If the size of the output has been explicitly specified, the filter
169  // will set the output size to the explicit size, otherwise the size from the spatial
170  // PointSet's bounding box will be used as default.
171 
172  bool specified = false;
173  for (i = 0; i < OutputImageDimension; i++)
174  {
175  if (m_Size[i] != 0)
176  {
177  specified = true;
178  break;
179  }
180  }
181 
182  if (specified)
183  {
184  region.SetSize( m_Size );
185  }
186  else
187  {
188  region.SetSize( size );
189  }
190 
191  OutputImage->SetRegions( region);
192 
193  // If the spacing has been explicitly specified, the filter
194  // will set the output spacing to that explicit spacing, otherwise the spacing from
195  // the point-set is used as default.
196 
197  specified = false;
198  for (i = 0; i < OutputImageDimension; i++)
199  {
200  if (m_Spacing[i] != 0)
201  {
202  specified = true;
203  break;
204  }
205  }
206 
207  if (specified)
208  {
209  OutputImage->SetSpacing(this->m_Spacing); // set spacing
210  }
211 
212 
213  specified = false;
214  for (i = 0; i < OutputImageDimension; i++)
215  {
216  if (m_Origin[i] != 0)
217  {
218  specified = true;
219  break;
220  }
221  }
222 
223  if (specified)
224  {
225  for (i = 0; i < OutputImageDimension; i++)
226  {
227  origin[i] = m_Origin[i]; // set origin
228  }
229  }
230 
231  OutputImage->SetOrigin(origin); // and origin
232  OutputImage->SetDirection(m_Direction); // and Direction
233  OutputImage->Allocate(); // allocate the image
234  OutputImage->FillBuffer(m_OutsideValue);
235 
236  typedef typename InputPointSetType::PointsContainer::ConstIterator PointIterator;
237  PointIterator pointItr = InputPointSet->GetPoints()->Begin();
238  PointIterator pointEnd = InputPointSet->GetPoints()->End();
239 
240  typename OutputImageType::IndexType index;
241 
242  while( pointItr != pointEnd )
243  {
244  if(OutputImage->TransformPhysicalPointToIndex(pointItr.Value(),index))
245  {
246  OutputImage->SetPixel(index,m_InsideValue);
247  }
248  pointItr++;
249  }
250 
251  itkDebugMacro(<< "PointSetToImageFilter::Update() finished");
252 
253 } // end update function
254 
255 
256 template<class TInputPointSet, class TOutputImage>
257 void
259 ::PrintSelf(std::ostream& os, Indent indent) const
260 {
261  Superclass::PrintSelf(os, indent);
262  os << indent << "Size : " << m_Size << std::endl;
263  os << indent << "Origin: " << m_Origin << std::endl;
264  os << indent << "Spacing: " << m_Spacing << std::endl;
265  os << indent << "Direction: " << m_Direction << std::endl;
266  os << indent << "Inside Value : "
267  << static_cast<typename NumericTraits<ValueType>::PrintType>(m_InsideValue)
268  << std::endl;
269  os << indent << "Outside Value : "
270  << static_cast<typename NumericTraits<ValueType>::PrintType>(m_OutsideValue)
271  << std::endl;
272 
273 }
274 } // end namespace itk
275 
276 #endif

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