Orfeo Toolbox  3.16
itkMeshToMeshFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkMeshToMeshFilter.txx,v $
5  Language: C++
6  Date: $Date: 2009-09-17 11:14:57 $
7  Version: $Revision: 1.21 $
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 __itkMeshToMeshFilter_txx
21 #define __itkMeshToMeshFilter_txx
22 
23 #include "itkMeshToMeshFilter.h"
24 
25 
26 namespace itk
27 {
28 
32 template <class TInputMesh, class TOutputMesh>
35 {
36  // Modify superclass default values, can be overridden by subclasses
37  this->SetNumberOfRequiredInputs(1);
38 
39 }
40 
41 
45 template <class TInputMesh, class TOutputMesh>
46 void
48 ::SetInput(const TInputMesh *input)
49 {
50  // Process object is not const-correct so the const_cast is required here
52  const_cast< TInputMesh * >( input ) );
53 }
54 
55 
59 template <class TInputMesh, class TOutputMesh>
62 ::GetInput() const
63 {
64  if (this->GetNumberOfInputs() < 1)
65  {
66  return 0;
67  }
68 
69  return static_cast< const TInputMesh * >
70  (this->ProcessObject::GetInput(0));
71 }
72 
73 
77 template <class TInputMesh, class TOutputMesh>
80 ::GetInput(unsigned int idx) const
81 {
82  return dynamic_cast<const TInputMesh*>
83  (this->ProcessObject::GetInput(idx));
84 }
85 
86 
87 template <class TInputMesh, class TOutputMesh>
88 void
91 {
92  const InputMeshType * inputMesh = this->GetInput();
93  OutputMeshPointer outputMesh = this->GetOutput();
94 
95  typedef typename TOutputMesh::PointsContainer OutputPointsContainer;
96  typedef typename TInputMesh::PointsContainer InputPointsContainer;
97 
98  typename OutputPointsContainer::Pointer outputPoints = OutputPointsContainer::New();
99  const InputPointsContainer * inputPoints = inputMesh->GetPoints();
100 
101  if( inputPoints )
102  {
103  outputPoints->Reserve( inputPoints->Size() );
104 
105  typename InputPointsContainer::ConstIterator inputItr = inputPoints->Begin();
106  typename InputPointsContainer::ConstIterator inputEnd = inputPoints->End();
107 
108  typename OutputPointsContainer::Iterator outputItr = outputPoints->Begin();
109 
110  while( inputItr != inputEnd )
111  {
112  outputItr.Value() = inputItr.Value();
113  ++inputItr;
114  ++outputItr;
115  }
116 
117  outputMesh->SetPoints( outputPoints );
118  }
119 }
120 
121 
122 template <class TInputMesh, class TOutputMesh>
123 void
126 {
127  const InputMeshType * inputMesh = this->GetInput();
128  OutputMeshPointer outputMesh = this->GetOutput();
129 
130  typedef typename TOutputMesh::PointDataContainer OutputPointDataContainer;
131  typedef typename TInputMesh::PointDataContainer InputPointDataContainer;
132 
133  typename OutputPointDataContainer::Pointer outputPointData = OutputPointDataContainer::New();
134  const InputPointDataContainer * inputPointData = inputMesh->GetPointData();
135 
136  if( inputPointData )
137  {
138  outputPointData->Reserve( inputPointData->Size() );
139 
140  typename InputPointDataContainer::ConstIterator inputItr = inputPointData->Begin();
141  typename InputPointDataContainer::ConstIterator inputEnd = inputPointData->End();
142 
143  typename OutputPointDataContainer::Iterator outputItr = outputPointData->Begin();
144 
145  while( inputItr != inputEnd )
146  {
147  outputItr.Value() = inputItr.Value();
148  ++inputItr;
149  ++outputItr;
150  }
151 
152  outputMesh->SetPointData( outputPointData );
153  }
154 }
155 
156 
157 template <class TInputMesh, class TOutputMesh>
158 void
161 {
162  const InputMeshType * inputMesh = this->GetInput();
163  OutputMeshPointer outputMesh = this->GetOutput();
164 
165  typedef typename TOutputMesh::CellLinksContainer OutputCellLinksContainer;
166  typedef typename TInputMesh::CellLinksContainer InputCellLinksContainer;
167 
168  typename OutputCellLinksContainer::Pointer outputCellLinks = OutputCellLinksContainer::New();
169  const InputCellLinksContainer * inputCellLinks = inputMesh->GetCellLinks();
170 
171  if( inputCellLinks )
172  {
173  outputCellLinks->Reserve( inputCellLinks->Size() );
174 
175  typename InputCellLinksContainer::ConstIterator inputItr = inputCellLinks->Begin();
176  typename InputCellLinksContainer::ConstIterator inputEnd = inputCellLinks->End();
177 
178  typename OutputCellLinksContainer::Iterator outputItr = outputCellLinks->Begin();
179 
180  while( inputItr != inputEnd )
181  {
182  outputItr.Value() = inputItr.Value();
183  ++inputItr;
184  ++outputItr;
185  }
186 
187  outputMesh->SetCellLinks( outputCellLinks );
188  }
189 }
190 
191 
192 template <class TInputMesh, class TOutputMesh>
193 void
196 {
197  const InputMeshType * inputMesh = this->GetInput();
198  OutputMeshPointer outputMesh = this->GetOutput();
199 
200  typedef typename TOutputMesh::CellsContainer OutputCellsContainer;
201  typedef typename TInputMesh::CellsContainer InputCellsContainer;
202  typedef typename TOutputMesh::CellAutoPointer CellAutoPointer;
203 
204  outputMesh->SetCellsAllocationMethod( OutputMeshType::CellsAllocatedDynamicallyCellByCell );
205 
206  typename OutputCellsContainer::Pointer outputCells = OutputCellsContainer::New();
207  const InputCellsContainer * inputCells = inputMesh->GetCells();
208 
209  if( inputCells )
210  {
211  outputCells->Reserve( inputCells->Size() );
212 
213  typename InputCellsContainer::ConstIterator inputItr = inputCells->Begin();
214  typename InputCellsContainer::ConstIterator inputEnd = inputCells->End();
215 
216  typename OutputCellsContainer::Iterator outputItr = outputCells->Begin();
217 
218  CellAutoPointer clone;
219 
220  while( inputItr != inputEnd )
221  {
222 // outputItr.Value() = inputItr.Value();
223  // BUG: FIXME: Here we are copying a pointer, which is a mistake. What we should do is to clone the cell.
224  inputItr.Value()->MakeCopy( clone );
225  outputItr.Value() = clone.ReleaseOwnership();
226 
227  ++inputItr;
228  ++outputItr;
229  }
230 
231  outputMesh->SetCells( outputCells );
232  }
233 }
234 
235 
236 template <class TInputMesh, class TOutputMesh>
237 void
240 {
241  const InputMeshType * inputMesh = this->GetInput();
242  OutputMeshPointer outputMesh = this->GetOutput();
243 
244  typedef typename TOutputMesh::CellDataContainer OutputCellDataContainer;
245  typedef typename TInputMesh::CellDataContainer InputCellDataContainer;
246 
247  typename OutputCellDataContainer::Pointer outputCellData = OutputCellDataContainer::New();
248  const InputCellDataContainer * inputCellData = inputMesh->GetCellData();
249 
250  if( inputCellData )
251  {
252  outputCellData->Reserve( inputCellData->Size() );
253 
254  typename InputCellDataContainer::ConstIterator inputItr = inputCellData->Begin();
255  typename InputCellDataContainer::ConstIterator inputEnd = inputCellData->End();
256 
257  typename OutputCellDataContainer::Iterator outputItr = outputCellData->Begin();
258 
259  while( inputItr != inputEnd )
260  {
261  outputItr.Value() = inputItr.Value();
262  ++inputItr;
263  ++outputItr;
264  }
265 
266  outputMesh->SetCellData( outputCellData );
267  }
268 }
269 
270 
271 } // end namespace itk
272 
273 #endif

Generated at Sat Feb 2 2013 23:52:43 for Orfeo Toolbox with doxygen 1.8.1.1