Orfeo Toolbox  3.16
itkSpatialObjectToPointSetFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: itkSpatialObjectToPointSetFilter.txx,v $
5 Language: C++
6 Date: $Date: 2008-10-18 16:11:14 $
7 Version: $Revision: 1.10 $
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 __itkSpatialObjectToPointSetFilter_txx
18 #define __itkSpatialObjectToPointSetFilter_txx
19 
21 
22 namespace itk
23 {
24 
26 template <class TInputSpatialObject, class TOutputPointSet>
29 {
30  this->SetNumberOfRequiredInputs(1);
31  m_ChildrenDepth = 0;
32  m_SamplingFactor = 1;
33 }
34 
36 template <class TInputSpatialObject, class TOutputPointSet>
39 {
40 }
41 
42 
44 template <class TInputSpatialObject, class TOutputPointSet>
45 void
48 {
49  // Process object is not const-correct so the const_cast is required here
51  const_cast< InputSpatialObjectType * >( input ) );
52 }
53 
54 
56 template <class TInputSpatialObject, class TOutputPointSet>
57 void
59 ::SetInput( unsigned int index, const TInputSpatialObject * object )
60 {
61  // Process object is not const-correct so the const_cast is required here
62  this->ProcessObject::SetNthInput(index,
63  const_cast< TInputSpatialObject *>( object ) );
64 }
65 
66 
68 template <class TInputSpatialObject, class TOutputPointSet>
71 ::GetInput(void)
72 {
73  if (this->GetNumberOfInputs() < 1)
74  {
75  return 0;
76  }
77 
78  return static_cast<const TInputSpatialObject * >
79  (this->ProcessObject::GetInput(0) );
80 }
81 
83 template <class TInputSpatialObject, class TOutputPointSet>
86 ::GetInput(unsigned int idx)
87 {
88  return static_cast< const TInputSpatialObject * >
89  (this->ProcessObject::GetInput(idx));
90 }
91 
92 
94 template <class TInputSpatialObject, class TOutputPointSet>
95 void
98 {
99  itkDebugMacro(<< "SpatialObjectToPointSetFilter::Update() called");
100 
101  // Get the input and output pointers
102  const InputSpatialObjectType * inputObject = this->GetInput();
103  typename OutputPointSetType::Pointer outputPointSet = this->GetOutput();
104 
105  // Look for the number of points to allocate
106  unsigned long numberOfPoints = 0;
107  if(dynamic_cast<const PointBasedSpatialObjectType*>(inputObject))
108  {
109  numberOfPoints = dynamic_cast<const PointBasedSpatialObjectType*>(inputObject)->GetNumberOfPoints()/m_SamplingFactor;
110  }
111 
112  ChildrenListType* children = inputObject->GetChildren(m_ChildrenDepth);
113  typename ChildrenListType::const_iterator it = children->begin();
114 
115  for(;it!=children->end();it++)
116  {
117  if(dynamic_cast<const PointBasedSpatialObjectType*>((*it).GetPointer()))
118  {
119  numberOfPoints += dynamic_cast<const PointBasedSpatialObjectType*>((*it).GetPointer())->GetNumberOfPoints()/m_SamplingFactor;
120  }
121  }
122 
123  typedef typename OutputPointSetType::PointDataContainer DataContainer;
124  outputPointSet->SetPointData( DataContainer::New());
125 
126  outputPointSet->GetPoints()->Reserve( numberOfPoints );
127  outputPointSet->GetPointData()->Reserve( numberOfPoints );
128 
129  typename OutputPointSetType::PointIdentifier pointId = 0;
130  typename OutputPointSetType::PointType point;
131 
132  // add the object it itself
133  unsigned long n;
134  if(dynamic_cast<const PointBasedSpatialObjectType*>(inputObject))
135  {
136  n = dynamic_cast<const PointBasedSpatialObjectType*>(inputObject)->GetNumberOfPoints();
137  for(unsigned int i=0;i<n;i+=m_SamplingFactor)
138  {
139  typename InputSpatialObjectType::PointType transformedPoint
140  = inputObject->GetIndexToWorldTransform()->TransformPoint(
141  dynamic_cast<const PointBasedSpatialObjectType*>(inputObject)->GetPoint(i)->GetPosition());
142 
143  for(unsigned int j=0;j< itkGetStaticConstMacro(ObjectDimension); j++)
144  {
145  point[j] = transformedPoint[j];
146  }
147  outputPointSet->SetPoint(pointId++, point );
148  }
149  }
150 
151  // then add children points
152  it = children->begin();
153 
154  for(;it!=children->end();it++)
155  {
156  if(dynamic_cast<const PointBasedSpatialObjectType*>((*it).GetPointer()))
157  {
158  n = dynamic_cast<const PointBasedSpatialObjectType*>((*it).GetPointer())->GetNumberOfPoints();
159  for(unsigned int i=0;i<n;i+=m_SamplingFactor)
160  {
161  typename InputSpatialObjectType::PointType transformedPoint
162  = inputObject->GetIndexToWorldTransform()->TransformPoint(dynamic_cast<const PointBasedSpatialObjectType*>((*it).GetPointer())->GetPoint(i)->GetPosition());
163 
164  for(unsigned int j=0;j< itkGetStaticConstMacro(ObjectDimension); j++)
165  {
166  point[j] = transformedPoint[j];
167  }
168  outputPointSet->SetPoint(pointId++, point );
169  }
170  }
171  }
172 
173  delete children;
174 
175  itkDebugMacro(<< "SpatialObjectToPointSetFilter::Update() finished");
176 
177 } // end update function
178 
179 
180 template<class TInputSpatialObject, class TOutputPointSet>
181 void
183 ::PrintSelf(std::ostream& os, Indent indent) const
184 {
185  Superclass::PrintSelf(os, indent);
186  os << indent << "Children depth : " << m_ChildrenDepth << std::endl;
187  os << indent << "Sampling Factor : " << m_SamplingFactor << std::endl;
188 }
189 
190 } // end namespace itk
191 
192 #endif

Generated at Sun Feb 3 2013 00:08:18 for Orfeo Toolbox with doxygen 1.8.1.1