ITK  4.3.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< class TInputMesh, class 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< class TInputMesh, class 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< class TInputMesh, class 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 == NULL )
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< class TInputMesh, class 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  while ( cIt != inCells->End() )
228  {
229  InputPolygonCellType *pe = dynamic_cast< InputPolygonCellType * >( cIt.Value() );
230  if ( pe )
231  {
232  InputPointIdList points;
233  InputPointsIdInternalIterator pit = pe->InternalPointIdsBegin();
234  while ( pit != pe->InternalPointIdsEnd() )
235  {
236  points.push_back( ( *pit ) );
237  ++pit;
238  }
239  out->AddFaceWithSecurePointList(points, false);
240  }
241  cIt++;
242  }
243  }
244 }
245 
246 // ---------------------------------------------------------------------
247 template< class TInputMesh, class TOutputMesh >
248 void CopyMeshToMeshEdgeCells(const TInputMesh *in, TOutputMesh *out)
249 {
250  // Copy Edge Cells
251  typedef typename TInputMesh::CellsContainer InputCellsContainer;
252  typedef typename InputCellsContainer::ConstPointer InputCellsContainerConstPointer;
253  typedef typename InputCellsContainer::ConstIterator InputCellsContainerConstIterator;
254  typedef typename TInputMesh::EdgeCellType InputEdgeCellType;
255 
256  InputCellsContainerConstPointer inEdgeCells = in->GetEdgeCells();
257 
258  if ( inEdgeCells )
259  {
260  InputCellsContainerConstIterator ecIt = inEdgeCells->Begin();
261  while ( ecIt != inEdgeCells->End() )
262  {
263  InputEdgeCellType *pe = dynamic_cast< InputEdgeCellType * >( ecIt.Value() );
264  if ( pe )
265  {
266  out->AddEdgeWithSecurePointList( pe->GetQEGeom()->GetOrigin(),
267  pe->GetQEGeom()->GetDestination() );
268  }
269  ecIt++;
270  }
271  }
272 }
273 
274 // ---------------------------------------------------------------------
275 template< class TInputMesh, class TOutputMesh >
276 void CopyMeshToMeshPoints(const TInputMesh *in, TOutputMesh *out)
277 {
278  // Copy points
279  typedef typename TInputMesh::PointsContainer InputPointsContainer;
280  typedef typename InputPointsContainer::ConstPointer InputPointsContainerConstPointer;
281  typedef typename InputPointsContainer::ConstIterator InputPointsContainerConstIterator;
282  typedef typename TOutputMesh::PointType OutputPointType;
283 
284  InputPointsContainerConstPointer inPoints = in->GetPoints();
285 
286  if ( inPoints )
287  {
288  InputPointsContainerConstIterator inIt = inPoints->Begin();
289  OutputPointType pOut;
290 
291  while ( inIt != inPoints->End() )
292  {
293  pOut.CastFrom( inIt.Value() );
294  out->SetPoint(inIt.Index(), pOut);
295  inIt++;
296  }
297  }
298 }
299 } // end namespace itk
300 
301 #ifndef ITK_MANUAL_INSTANTIATION
302 #include "itkQuadEdgeMeshToQuadEdgeMeshFilter.hxx"
303 #endif
304 
305 #endif
306