ITK  4.6.0
Insight Segmentation and Registration Toolkit
itkQuadEdgeMeshToQuadEdgeMeshFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkQuadEdgeMeshToQuadEdgeMeshFilter_h
19 #define __itkQuadEdgeMeshToQuadEdgeMeshFilter_h
20 
21 #include "itkMeshToMeshFilter.h"
22 
23 namespace itk
24 {
35 template< typename TInputMesh, typename TOutputMesh >
37  public MeshToMeshFilter< TInputMesh, TOutputMesh >
38 {
39 public:
45 
47  typedef TInputMesh InputMeshType;
48  typedef typename InputMeshType::Pointer InputMeshPointer;
49  typedef typename InputMeshType::ConstPointer InputMeshConstPointer;
50  typedef typename InputMeshType::CoordRepType InputCoordRepType;
51  typedef typename InputMeshType::PointType InputPointType;
52  typedef typename InputMeshType::PointIdentifier InputPointIdentifier;
53  typedef typename InputMeshType::QEPrimal InputQEPrimal;
54  typedef typename InputMeshType::VectorType InputVectorType;
55 
56  typedef typename InputMeshType::PointDataContainer InputPointDataContainer;
57  typedef typename InputMeshType::CellDataContainer InputCellDataContainer;
58 
59  typedef typename InputPointDataContainer::ConstPointer
61  typedef typename InputMeshType::PointsContainerConstIterator
63  typedef typename InputMeshType::PointsContainerConstPointer
65  typedef typename InputMeshType::CellsContainerConstIterator
67  typedef typename InputMeshType::CellsContainerConstPointer
69 
70  typedef typename InputMeshType::EdgeCellType InputEdgeCellType;
71  typedef typename InputMeshType::PolygonCellType InputPolygonCellType;
72  typedef typename InputMeshType::PointIdList InputPointIdList;
73  typedef typename InputMeshType::CellTraits InputCellTraits;
74  typedef typename InputCellTraits::PointIdInternalIterator
76 
77  typedef typename InputQEPrimal::IteratorGeom InputQEIterator;
78 
80  typedef TOutputMesh OutputMeshType;
81  typedef typename OutputMeshType::Pointer OutputMeshPointer;
82  typedef typename OutputMeshType::ConstPointer OutputMeshConstPointer;
83  typedef typename OutputMeshType::CoordRepType OutputCoordRepType;
84  typedef typename OutputMeshType::PointType OutputPointType;
85  typedef typename OutputMeshType::PointIdentifier OutputPointIdentifier;
86  typedef typename OutputMeshType::QEPrimal OutputQEPrimal;
87  typedef typename OutputMeshType::VectorType OutputVectorType;
88  typedef typename OutputQEPrimal::IteratorGeom OutputQEIterator;
89  typedef typename OutputMeshType::PointsContainerIterator
91  typedef typename OutputMeshType::PointsContainerPointer
93  typedef typename OutputMeshType::PointsContainerConstPointer
95 
96  typedef typename OutputMeshType::PointDataContainer OutputPointDataContainer;
97  typedef typename OutputMeshType::CellDataContainer OutputCellDataContainer;
98 
99 public:
100  itkNewMacro(Self);
102 
103 protected:
106 
107  virtual void CopyInputMeshToOutputMesh();
108 
109  virtual void CopyInputMeshToOutputMeshGeometry();
110 
111  virtual void CopyInputMeshToOutputMeshPoints();
112 
113  virtual void CopyInputMeshToOutputMeshCells();
114 
115  virtual void CopyInputMeshToOutputMeshEdgeCells();
116 
117  virtual void CopyInputMeshToOutputMeshFieldData();
118 
119  virtual void CopyInputMeshToOutputMeshPointData();
120 
121  virtual void CopyInputMeshToOutputMeshCellData();
122 
123 private:
124  QuadEdgeMeshToQuadEdgeMeshFilter(const Self &); // Not impl.
125  void operator=(const Self &); // Not impl.
126 };
127 
128 //
129 // Helper functions that copy selected pieces of a Mesh.
130 // These functions should be templated here in order to
131 // facilitate their reuse in multiple scenarios.
132 //
133 template< typename TInputMesh, typename TOutputMesh >
134 void CopyMeshToMesh(const TInputMesh *in, TOutputMesh *out)
135 {
136  CopyMeshToMeshPoints(in, out);
137  CopyMeshToMeshEdgeCells(in, out);
138  CopyMeshToMeshCells(in, out);
139  CopyMeshToMeshPointData(in, out);
140  CopyMeshToMeshCellData(in, out);
141 }
142 
143 // ---------------------------------------------------------------------
144 template< typename TInputMesh, typename TOutputMesh >
145 void CopyMeshToMeshCellData(const TInputMesh *in, TOutputMesh *out)
146 {
147  typedef typename TInputMesh::CellDataContainer InputCellDataContainer;
148  typedef typename TOutputMesh::CellDataContainer OutputCellDataContainer;
149  typedef typename InputCellDataContainer::ConstPointer InputCellDataContainerConstPointer;
150  typedef typename OutputCellDataContainer::Pointer OutputCellDataContainerPointer;
151 
152  InputCellDataContainerConstPointer inputCellData = in->GetCellData();
153 
154  if ( inputCellData.IsNull() )
155  {
156  // There is nothing to copy
157  return;
158  }
159 
160  OutputCellDataContainerPointer outputCellData = OutputCellDataContainer::New();
161  outputCellData->Reserve( inputCellData->Size() );
162 
163  // Copy point data
164  typedef typename InputCellDataContainer::ConstIterator InputCellDataContainerConstIterator;
165  InputCellDataContainerConstIterator inIt = inputCellData->Begin();
166  while ( inIt != inputCellData->End() )
167  {
168  outputCellData->SetElement( inIt.Index(), inIt.Value() );
169  inIt++;
170  }
171 
172  out->SetCellData(outputCellData);
173 }
174 
175 // ---------------------------------------------------------------------
176 template< typename TInputMesh, typename TOutputMesh >
177 void CopyMeshToMeshPointData(const TInputMesh *in, TOutputMesh *out)
178 {
179  typedef typename TOutputMesh::PointDataContainer OutputPointDataContainer;
180  typedef typename OutputPointDataContainer::Pointer OutputPointDataContainerPointer;
181  typedef typename TInputMesh::PointDataContainer InputPointDataContainer;
182 
183  const InputPointDataContainer *inputPointData = in->GetPointData();
184 
185  if ( inputPointData == ITK_NULLPTR )
186  {
187  // There is nothing to copy
188  return;
189  }
190 
191  OutputPointDataContainerPointer outputPointData = OutputPointDataContainer::New();
192  outputPointData->Reserve( inputPointData->Size() );
193 
194  // Copy point data
195  typedef typename InputPointDataContainer::ConstIterator InputPointDataContainerConstIterator;
196  InputPointDataContainerConstIterator inIt = inputPointData->Begin();
197  while ( inIt != inputPointData->End() )
198  {
199  outputPointData->SetElement( inIt.Index(), inIt.Value() );
200  inIt++;
201  }
202 
203  out->SetPointData(outputPointData);
204 }
205 
206 // ---------------------------------------------------------------------
207 template< typename TInputMesh, typename TOutputMesh >
208 void CopyMeshToMeshCells(const TInputMesh *in, TOutputMesh *out)
209 {
210  // Copy cells
211  typedef typename TInputMesh::CellsContainer InputCellsContainer;
212  typedef typename InputCellsContainer::ConstPointer InputCellsContainerConstPointer;
213  typedef typename InputCellsContainer::ConstIterator InputCellsContainerConstIterator;
214  typedef typename TInputMesh::PolygonCellType InputPolygonCellType;
215  typedef typename TInputMesh::PointIdList InputPointIdList;
216  typedef typename TInputMesh::CellTraits InputCellTraits;
217  typedef typename InputCellTraits::PointIdInternalIterator
218  InputPointsIdInternalIterator;
219 
220  out->SetCellsAllocationMethod(TOutputMesh::CellsAllocatedDynamicallyCellByCell);
221 
222  InputCellsContainerConstPointer inCells = in->GetCells();
223 
224  if ( inCells )
225  {
226  InputCellsContainerConstIterator cIt = inCells->Begin();
227  InputCellsContainerConstIterator cEnd = inCells->End();
228  while ( cIt != cEnd )
229  {
230  InputPolygonCellType *pe = dynamic_cast< InputPolygonCellType * >( cIt.Value() );
231  if ( pe )
232  {
233  InputPointIdList points;
234  InputPointsIdInternalIterator pIt = pe->InternalPointIdsBegin();
235  InputPointsIdInternalIterator pEnd = pe->InternalPointIdsEnd();
236 
237  while ( pIt != pEnd )
238  {
239  points.push_back( ( *pIt ) );
240  ++pIt;
241  }
242  out->AddFaceWithSecurePointList(points, false);
243  }
244  ++cIt;
245  }
246  }
247 }
248 
249 // ---------------------------------------------------------------------
250 template< typename TInputMesh, typename TOutputMesh >
251 void CopyMeshToMeshEdgeCells(const TInputMesh *in, TOutputMesh *out)
252 {
253  // Copy Edge Cells
254  typedef typename TInputMesh::CellsContainer InputCellsContainer;
255  typedef typename InputCellsContainer::ConstPointer InputCellsContainerConstPointer;
256  typedef typename InputCellsContainer::ConstIterator InputCellsContainerConstIterator;
257  typedef typename TInputMesh::EdgeCellType InputEdgeCellType;
258 
259  InputCellsContainerConstPointer inEdgeCells = in->GetEdgeCells();
260 
261  if ( inEdgeCells )
262  {
263  InputCellsContainerConstIterator ecIt = inEdgeCells->Begin();
264  InputCellsContainerConstIterator ecEnd = inEdgeCells->End();
265 
266  while ( ecIt != ecEnd )
267  {
268  InputEdgeCellType *pe = dynamic_cast< InputEdgeCellType * >( ecIt.Value() );
269  if ( pe )
270  {
271  out->AddEdgeWithSecurePointList( pe->GetQEGeom()->GetOrigin(),
272  pe->GetQEGeom()->GetDestination() );
273  }
274  ++ecIt;
275  }
276  }
277 }
278 
279 // ---------------------------------------------------------------------
280 template< typename TInputMesh, typename TOutputMesh >
281 void CopyMeshToMeshPoints(const TInputMesh *in, TOutputMesh *out)
282 {
283  // Copy points
284  typedef typename TInputMesh::PointsContainerConstPointer InputPointsContainerConstPointer;
285  typedef typename TInputMesh::PointsContainerConstIterator InputPointsContainerConstIterator;
286 
287  typedef typename TOutputMesh::PointsContainer OutputPointsContainer;
288  typedef typename TOutputMesh::PointsContainerPointer OutputPointsContainerPointer;
289  typedef typename TOutputMesh::PointType OutputPointType;
290 
291  InputPointsContainerConstPointer inPoints = in->GetPoints();
292 
293  if ( inPoints )
294  {
295  InputPointsContainerConstIterator inIt = inPoints->Begin();
296  InputPointsContainerConstIterator inEnd = inPoints->End();
297 
298  OutputPointsContainerPointer oPoints = out->GetPoints();
299  if( oPoints.IsNull() )
300  {
301  oPoints = OutputPointsContainer::New();
302  out->SetPoints( oPoints );
303  }
304  OutputPointType pOut;
305 
306  while ( inIt != inEnd )
307  {
308  pOut.CastFrom( inIt.Value() );
309  oPoints->InsertElement(inIt.Index(), pOut);
310  ++inIt;
311  }
312  }
313 }
314 } // end namespace itk
315 
316 #ifndef ITK_MANUAL_INSTANTIATION
317 #include "itkQuadEdgeMeshToQuadEdgeMeshFilter.hxx"
318 #endif
319 
320 #endif
void CopyMeshToMeshCells(const TInputMesh *in, TOutputMesh *out)
InputMeshType::CellsContainerConstPointer InputCellsContainerConstPointer
virtual void CopyInputMeshToOutputMeshCellData()
Light weight base class for most itk classes.
void CopyMeshToMesh(const TInputMesh *in, TOutputMesh *out)
InputPointDataContainer::ConstPointer InputPointDataContainerConstPointer
void CopyMeshToMeshEdgeCells(const TInputMesh *in, TOutputMesh *out)
OutputMeshType::CellDataContainer OutputCellDataContainer
OutputMeshType::PointsContainerConstPointer OutputPointsContainerConstPointer
InputMeshType::PointDataContainer InputPointDataContainer
MeshToMeshFilter is the base class for all process objects that output mesh data, and require mesh da...
InputMeshType::PointsContainerConstPointer InputPointsContainerConstPointer
InputCellTraits::PointIdInternalIterator InputPointsIdInternalIterator
virtual void CopyInputMeshToOutputMeshGeometry()
OutputMeshType::PointsContainerPointer OutputPointsContainerPointer
InputMeshType::PointsContainerConstIterator InputPointsContainerConstIterator
OutputMeshType::PointDataContainer OutputPointDataContainer
void CopyMeshToMeshCellData(const TInputMesh *in, TOutputMesh *out)
void CopyMeshToMeshPointData(const TInputMesh *in, TOutputMesh *out)
virtual void CopyInputMeshToOutputMeshPointData()
virtual void CopyInputMeshToOutputMeshFieldData()
MeshToMeshFilter< TInputMesh, TOutputMesh > Superclass
void CopyMeshToMeshPoints(const TInputMesh *in, TOutputMesh *out)
OutputMeshType::PointsContainerIterator OutputPointsContainerIterator
virtual void CopyInputMeshToOutputMeshEdgeCells()
InputMeshType::CellsContainerConstIterator InputCellsContainerConstIterator