ITK  4.2.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 public:
99  itkNewMacro(Self);
101 protected:
104 
105  virtual void CopyMeshToMesh(const TInputMesh *in, TOutputMesh *out);
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 
134 // ---------------------------------------------------------------------
135 template< class TInputMesh, class TOutputMesh >
136 void CopyMeshToMeshCellData(const TInputMesh *in, TOutputMesh *out)
137 {
138  typedef typename TInputMesh::CellDataContainer InputCellDataContainer;
139  typedef typename TOutputMesh::CellDataContainer OutputCellDataContainer;
140  typedef typename InputCellDataContainer::ConstPointer InputCellDataContainerConstPointer;
141  typedef typename OutputCellDataContainer::Pointer OutputCellDataContainerPointer;
142 
143  InputCellDataContainerConstPointer inputCellData = in->GetCellData();
144 
145  if ( inputCellData.IsNull() )
146  {
147  // There is nothing to copy
148  return;
149  }
150 
151  OutputCellDataContainerPointer outputCellData = OutputCellDataContainer::New();
152  outputCellData->Reserve( inputCellData->Size() );
153 
154  // Copy point data
155  typedef typename InputCellDataContainer::ConstIterator InputCellDataContainerConstIterator;
156  InputCellDataContainerConstIterator inIt = inputCellData->Begin();
157  while ( inIt != inputCellData->End() )
158  {
159  outputCellData->SetElement( inIt.Index(), inIt.Value() );
160  inIt++;
161  }
162 
163  out->SetCellData(outputCellData);
164 }
165 
166 // ---------------------------------------------------------------------
167 template< class TInputMesh, class TOutputMesh >
168 void CopyMeshToMeshPointData(const TInputMesh *in, TOutputMesh *out)
169 {
170  typedef typename TOutputMesh::PointDataContainer OutputPointDataContainer;
171  typedef typename OutputPointDataContainer::Pointer OutputPointDataContainerPointer;
172  typedef typename TInputMesh::PointDataContainer InputPointDataContainer;
173 
174  const InputPointDataContainer *inputPointData = in->GetPointData();
175 
176  if ( inputPointData == NULL )
177  {
178  // There is nothing to copy
179  return;
180  }
181 
182  OutputPointDataContainerPointer outputPointData = OutputPointDataContainer::New();
183  outputPointData->Reserve( inputPointData->Size() );
184 
185  // Copy point data
186  typedef typename InputPointDataContainer::ConstIterator InputPointDataContainerConstIterator;
187  InputPointDataContainerConstIterator inIt = inputPointData->Begin();
188  while ( inIt != inputPointData->End() )
189  {
190  outputPointData->SetElement( inIt.Index(), inIt.Value() );
191  inIt++;
192  }
193 
194  out->SetPointData(outputPointData);
195 }
196 
197 // ---------------------------------------------------------------------
198 template< class TInputMesh, class TOutputMesh >
199 void CopyMeshToMeshCells(const TInputMesh *in, TOutputMesh *out)
200 {
201  // Copy cells
202  typedef typename TInputMesh::CellsContainer InputCellsContainer;
203  typedef typename InputCellsContainer::ConstPointer InputCellsContainerConstPointer;
204  typedef typename InputCellsContainer::ConstIterator InputCellsContainerConstIterator;
205  typedef typename TInputMesh::PolygonCellType InputPolygonCellType;
206  typedef typename TInputMesh::PointIdList InputPointIdList;
207  typedef typename TInputMesh::CellTraits InputCellTraits;
208  typedef typename InputCellTraits::PointIdInternalIterator
209  InputPointsIdInternalIterator;
210 
211  out->SetCellsAllocationMethod(TOutputMesh::CellsAllocatedDynamicallyCellByCell);
212 
213  InputCellsContainerConstPointer inCells = in->GetCells();
214 
215  if ( inCells )
216  {
217  InputCellsContainerConstIterator cIt = inCells->Begin();
218  while ( cIt != inCells->End() )
219  {
220  InputPolygonCellType *pe = dynamic_cast< InputPolygonCellType * >( cIt.Value() );
221  if ( pe )
222  {
223  InputPointIdList points;
224  InputPointsIdInternalIterator pit = pe->InternalPointIdsBegin();
225  while ( pit != pe->InternalPointIdsEnd() )
226  {
227  points.push_back( ( *pit ) );
228  ++pit;
229  }
230  out->AddFaceWithSecurePointList(points, false);
231  }
232  cIt++;
233  }
234  }
235 }
236 
237 // ---------------------------------------------------------------------
238 template< class TInputMesh, class TOutputMesh >
239 void CopyMeshToMeshEdgeCells(const TInputMesh *in, TOutputMesh *out)
240 {
241  // Copy Edge Cells
242  typedef typename TInputMesh::CellsContainer InputCellsContainer;
243  typedef typename InputCellsContainer::ConstPointer InputCellsContainerConstPointer;
244  typedef typename InputCellsContainer::ConstIterator InputCellsContainerConstIterator;
245  typedef typename TInputMesh::EdgeCellType InputEdgeCellType;
246 
247  InputCellsContainerConstPointer inEdgeCells = in->GetEdgeCells();
248 
249  if ( inEdgeCells )
250  {
251  InputCellsContainerConstIterator ecIt = inEdgeCells->Begin();
252  while ( ecIt != inEdgeCells->End() )
253  {
254  InputEdgeCellType *pe = dynamic_cast< InputEdgeCellType * >( ecIt.Value() );
255  if ( pe )
256  {
257  out->AddEdgeWithSecurePointList( pe->GetQEGeom()->GetOrigin(),
258  pe->GetQEGeom()->GetDestination() );
259  }
260  ecIt++;
261  }
262  }
263 }
264 
265 // ---------------------------------------------------------------------
266 template< class TInputMesh, class TOutputMesh >
267 void CopyMeshToMeshPoints(const TInputMesh *in, TOutputMesh *out)
268 {
269  // Copy points
270  typedef typename TInputMesh::PointsContainer InputPointsContainer;
271  typedef typename InputPointsContainer::ConstPointer InputPointsContainerConstPointer;
272  typedef typename InputPointsContainer::ConstIterator InputPointsContainerConstIterator;
273  typedef typename TOutputMesh::PointType OutputPointType;
274 
275  InputPointsContainerConstPointer inPoints = in->GetPoints();
276 
277  if ( inPoints )
278  {
279  InputPointsContainerConstIterator inIt = inPoints->Begin();
280  OutputPointType pOut;
281 
282  while ( inIt != inPoints->End() )
283  {
284  pOut.CastFrom( inIt.Value() );
285  out->SetPoint(inIt.Index(), pOut);
286  inIt++;
287  }
288  }
289 }
290 } // end namespace itk
291 
292 #ifndef ITK_MANUAL_INSTANTIATION
293 #include "itkQuadEdgeMeshToQuadEdgeMeshFilter.hxx"
294 #endif
295 
296 #endif
297