ITK  4.8.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  typename OutputCellDataContainer::Element point(inIt.Value());
169  outputCellData->SetElement( inIt.Index(), point );
170  ++inIt;
171  }
172 
173  out->SetCellData(outputCellData);
174 }
175 
176 // ---------------------------------------------------------------------
177 template< typename TInputMesh, typename TOutputMesh >
178 void CopyMeshToMeshPointData(const TInputMesh *in, TOutputMesh *out)
179 {
180  typedef typename TOutputMesh::PointDataContainer OutputPointDataContainer;
181  typedef typename OutputPointDataContainer::Pointer OutputPointDataContainerPointer;
182  typedef typename TInputMesh::PointDataContainer InputPointDataContainer;
183 
184  const InputPointDataContainer *inputPointData = in->GetPointData();
185 
186  if ( inputPointData == ITK_NULLPTR )
187  {
188  // There is nothing to copy
189  return;
190  }
191 
192  OutputPointDataContainerPointer outputPointData = OutputPointDataContainer::New();
193  outputPointData->Reserve( inputPointData->Size() );
194 
195  // Copy point data
196  typedef typename InputPointDataContainer::ConstIterator InputPointDataContainerConstIterator;
197  InputPointDataContainerConstIterator inIt = inputPointData->Begin();
198  while ( inIt != inputPointData->End() )
199  {
200  typename OutputPointDataContainer::Element point( inIt.Value() );
201  outputPointData->SetElement( inIt.Index(), point );
202  inIt++;
203  }
204 
205  out->SetPointData(outputPointData);
206 }
207 
208 // ---------------------------------------------------------------------
209 template< typename TInputMesh, typename TOutputMesh >
210 void CopyMeshToMeshCells(const TInputMesh *in, TOutputMesh *out)
211 {
212  // Copy cells
213  typedef typename TInputMesh::CellsContainer InputCellsContainer;
214  typedef typename InputCellsContainer::ConstPointer InputCellsContainerConstPointer;
215  typedef typename InputCellsContainer::ConstIterator InputCellsContainerConstIterator;
216  typedef typename TInputMesh::PolygonCellType InputPolygonCellType;
217  typedef typename TInputMesh::PointIdList InputPointIdList;
218  typedef typename TInputMesh::CellTraits InputCellTraits;
219  typedef typename InputCellTraits::PointIdInternalIterator
220  InputPointsIdInternalIterator;
221 
222  out->SetCellsAllocationMethod(TOutputMesh::CellsAllocatedDynamicallyCellByCell);
223 
224  InputCellsContainerConstPointer inCells = in->GetCells();
225 
226  if ( inCells )
227  {
228  InputCellsContainerConstIterator cIt = inCells->Begin();
229  InputCellsContainerConstIterator cEnd = inCells->End();
230  while ( cIt != cEnd )
231  {
232  InputPolygonCellType *pe = dynamic_cast< InputPolygonCellType * >( cIt.Value() );
233  if ( pe )
234  {
235  InputPointIdList points;
236  InputPointsIdInternalIterator pIt = pe->InternalPointIdsBegin();
237  InputPointsIdInternalIterator pEnd = pe->InternalPointIdsEnd();
238 
239  while ( pIt != pEnd )
240  {
241  points.push_back( ( *pIt ) );
242  ++pIt;
243  }
244  out->AddFaceWithSecurePointList(points, false);
245  }
246  ++cIt;
247  }
248  }
249 }
250 
251 // ---------------------------------------------------------------------
252 template< typename TInputMesh, typename TOutputMesh >
253 void CopyMeshToMeshEdgeCells(const TInputMesh *in, TOutputMesh *out)
254 {
255  // Copy Edge Cells
256  typedef typename TInputMesh::CellsContainer InputCellsContainer;
257  typedef typename InputCellsContainer::ConstPointer InputCellsContainerConstPointer;
258  typedef typename InputCellsContainer::ConstIterator InputCellsContainerConstIterator;
259  typedef typename TInputMesh::EdgeCellType InputEdgeCellType;
260 
261  InputCellsContainerConstPointer inEdgeCells = in->GetEdgeCells();
262 
263  if ( inEdgeCells )
264  {
265  InputCellsContainerConstIterator ecIt = inEdgeCells->Begin();
266  InputCellsContainerConstIterator ecEnd = inEdgeCells->End();
267 
268  while ( ecIt != ecEnd )
269  {
270  InputEdgeCellType *pe = dynamic_cast< InputEdgeCellType * >( ecIt.Value() );
271  if ( pe )
272  {
273  out->AddEdgeWithSecurePointList( pe->GetQEGeom()->GetOrigin(),
274  pe->GetQEGeom()->GetDestination() );
275  }
276  ++ecIt;
277  }
278  }
279 }
280 
281 // ---------------------------------------------------------------------
282 template< typename TInputMesh, typename TOutputMesh >
283 void CopyMeshToMeshPoints(const TInputMesh *in, TOutputMesh *out)
284 {
285  // Copy points
286  typedef typename TInputMesh::PointsContainerConstPointer InputPointsContainerConstPointer;
287  typedef typename TInputMesh::PointsContainerConstIterator InputPointsContainerConstIterator;
288 
289  typedef typename TOutputMesh::PointsContainer OutputPointsContainer;
290  typedef typename TOutputMesh::PointsContainerPointer OutputPointsContainerPointer;
291  typedef typename TOutputMesh::PointType OutputPointType;
292 
293  InputPointsContainerConstPointer inPoints = in->GetPoints();
294 
295  if ( inPoints )
296  {
297  InputPointsContainerConstIterator inIt = inPoints->Begin();
298  InputPointsContainerConstIterator inEnd = inPoints->End();
299 
300  OutputPointsContainerPointer oPoints = out->GetPoints();
301  if( oPoints.IsNull() )
302  {
303  oPoints = OutputPointsContainer::New();
304  out->SetPoints( oPoints );
305  }
306  OutputPointType pOut;
307 
308  while ( inIt != inEnd )
309  {
310  pOut.CastFrom( inIt.Value() );
311  oPoints->InsertElement(inIt.Index(), pOut);
312  ++inIt;
313  }
314  }
315 }
316 } // end namespace itk
317 
318 #ifndef ITK_MANUAL_INSTANTIATION
319 #include "itkQuadEdgeMeshToQuadEdgeMeshFilter.hxx"
320 #endif
321 
322 #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