ITK  5.0.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 >
36 class ITK_TEMPLATE_EXPORT QuadEdgeMeshToQuadEdgeMeshFilter:
37  public MeshToMeshFilter< TInputMesh, TOutputMesh >
38 {
39 public:
40  ITK_DISALLOW_COPY_AND_ASSIGN(QuadEdgeMeshToQuadEdgeMeshFilter);
41 
47 
49  using InputMeshType = TInputMesh;
50  using InputMeshPointer = typename InputMeshType::Pointer;
51  using InputMeshConstPointer = typename InputMeshType::ConstPointer;
52  using InputCoordRepType = typename InputMeshType::CoordRepType;
54  using InputPointIdentifier = typename InputMeshType::PointIdentifier;
55  using InputQEPrimal = typename InputMeshType::QEPrimal;
57 
58  using InputPointDataContainer = typename InputMeshType::PointDataContainer;
59  using InputCellDataContainer = typename InputMeshType::CellDataContainer;
60 
61  using InputPointDataContainerConstPointer = typename InputPointDataContainer::ConstPointer;
62  using InputPointsContainerConstIterator = typename InputMeshType::PointsContainerConstIterator;
63  using InputPointsContainerConstPointer = typename InputMeshType::PointsContainerConstPointer;
64  using InputCellsContainerConstIterator = typename InputMeshType::CellsContainerConstIterator;
65  using InputCellsContainerConstPointer = typename InputMeshType::CellsContainerConstPointer;
66 
67  using InputEdgeCellType = typename InputMeshType::EdgeCellType;
68  using InputPolygonCellType = typename InputMeshType::PolygonCellType;
69  using InputPointIdList = typename InputMeshType::PointIdList;
70  using InputCellTraits = typename InputMeshType::CellTraits;
71  using InputPointsIdInternalIterator = typename InputCellTraits::PointIdInternalIterator;
72 
73  using InputQEIterator = typename InputQEPrimal::IteratorGeom;
74 
76  using OutputMeshType = TOutputMesh;
77  using OutputMeshPointer = typename OutputMeshType::Pointer;
78  using OutputMeshConstPointer = typename OutputMeshType::ConstPointer;
79  using OutputCoordRepType = typename OutputMeshType::CoordRepType;
81  using OutputPointIdentifier = typename OutputMeshType::PointIdentifier;
82  using OutputQEPrimal = typename OutputMeshType::QEPrimal;
84  using OutputQEIterator = typename OutputQEPrimal::IteratorGeom;
85  using OutputPointsContainerIterator = typename OutputMeshType::PointsContainerIterator;
86  using OutputPointsContainerPointer = typename OutputMeshType::PointsContainerPointer;
87  using OutputPointsContainerConstPointer = typename OutputMeshType::PointsContainerConstPointer;
88 
89  using OutputPointDataContainer = typename OutputMeshType::PointDataContainer;
90  using OutputCellDataContainer = typename OutputMeshType::CellDataContainer;
91 
92 public:
93  itkNewMacro(Self);
95 
96 protected:
98  ~QuadEdgeMeshToQuadEdgeMeshFilter() override = default;
99 
100  virtual void CopyInputMeshToOutputMesh();
101 
102  virtual void CopyInputMeshToOutputMeshGeometry();
103 
104  virtual void CopyInputMeshToOutputMeshPoints();
105 
106  virtual void CopyInputMeshToOutputMeshCells();
107 
108  virtual void CopyInputMeshToOutputMeshEdgeCells();
109 
110  virtual void CopyInputMeshToOutputMeshFieldData();
111 
112  virtual void CopyInputMeshToOutputMeshPointData();
113 
114  virtual void CopyInputMeshToOutputMeshCellData();
115 };
116 
117 //
118 // Helper functions that copy selected pieces of a Mesh.
119 // These functions should be templated here in order to
120 // facilitate their reuse in multiple scenarios.
121 //
122 template< typename TInputMesh, typename TOutputMesh >
123 void CopyMeshToMesh(const TInputMesh *in, TOutputMesh *out)
124 {
125  CopyMeshToMeshPoints(in, out);
126  CopyMeshToMeshEdgeCells(in, out);
127  CopyMeshToMeshCells(in, out);
128  CopyMeshToMeshPointData(in, out);
129  CopyMeshToMeshCellData(in, out);
130 }
131 
132 // ---------------------------------------------------------------------
133 template< typename TInputMesh, typename TOutputMesh >
134 void CopyMeshToMeshCellData(const TInputMesh *in, TOutputMesh *out)
135 {
136  using InputCellDataContainer = typename TInputMesh::CellDataContainer;
137  using OutputCellDataContainer = typename TOutputMesh::CellDataContainer;
138  using InputCellDataContainerConstPointer = typename InputCellDataContainer::ConstPointer;
139  using OutputCellDataContainerPointer = typename OutputCellDataContainer::Pointer;
140 
141  InputCellDataContainerConstPointer inputCellData = in->GetCellData();
142 
143  if ( inputCellData.IsNull() )
144  {
145  // There is nothing to copy
146  return;
147  }
148 
149  OutputCellDataContainerPointer outputCellData = OutputCellDataContainer::New();
150  outputCellData->Reserve( inputCellData->Size() );
151 
152  // Copy point data
153  using InputCellDataContainerConstIterator = typename InputCellDataContainer::ConstIterator;
154  InputCellDataContainerConstIterator inIt = inputCellData->Begin();
155  while ( inIt != inputCellData->End() )
156  {
157  typename OutputCellDataContainer::Element point(inIt.Value());
158  outputCellData->SetElement( inIt.Index(), point );
159  ++inIt;
160  }
161 
162  out->SetCellData(outputCellData);
163 }
164 
165 // ---------------------------------------------------------------------
166 template< typename TInputMesh, typename TOutputMesh >
167 void CopyMeshToMeshPointData(const TInputMesh *in, TOutputMesh *out)
168 {
169  using OutputPointDataContainer = typename TOutputMesh::PointDataContainer;
170  using OutputPointDataContainerPointer = typename OutputPointDataContainer::Pointer;
171  using InputPointDataContainer = typename TInputMesh::PointDataContainer;
172 
173  const InputPointDataContainer *inputPointData = in->GetPointData();
174 
175  if ( inputPointData == nullptr )
176  {
177  // There is nothing to copy
178  return;
179  }
180 
181  OutputPointDataContainerPointer outputPointData = OutputPointDataContainer::New();
182  outputPointData->Reserve( inputPointData->Size() );
183 
184  // Copy point data
185  using InputPointDataContainerConstIterator = typename InputPointDataContainer::ConstIterator;
186  InputPointDataContainerConstIterator inIt = inputPointData->Begin();
187  while ( inIt != inputPointData->End() )
188  {
189  typename OutputPointDataContainer::Element point( inIt.Value() );
190  outputPointData->SetElement( inIt.Index(), point );
191  ++inIt;
192  }
193 
194  out->SetPointData(outputPointData);
195 }
196 
197 // ---------------------------------------------------------------------
198 template< typename TInputMesh, typename TOutputMesh >
199 void CopyMeshToMeshCells(const TInputMesh *in, TOutputMesh *out)
200 {
201  // Copy cells
202  using InputCellsContainer = typename TInputMesh::CellsContainer;
203  using InputCellsContainerConstPointer = typename InputCellsContainer::ConstPointer;
204  using InputCellsContainerConstIterator = typename InputCellsContainer::ConstIterator;
205  using InputPolygonCellType = typename TInputMesh::PolygonCellType;
206  using InputPointIdList = typename TInputMesh::PointIdList;
207  using InputCellTraits = typename TInputMesh::CellTraits;
208  using InputPointsIdInternalIterator = typename InputCellTraits::PointIdInternalIterator;
209 
210  out->SetCellsAllocationMethod(TOutputMesh::CellsAllocatedDynamicallyCellByCell);
211 
212  InputCellsContainerConstPointer inCells = in->GetCells();
213 
214  if ( inCells )
215  {
216  InputCellsContainerConstIterator cIt = inCells->Begin();
217  InputCellsContainerConstIterator cEnd = inCells->End();
218  while ( cIt != cEnd )
219  {
220  auto * pe = dynamic_cast< InputPolygonCellType * >( cIt.Value() );
221  if ( pe )
222  {
223  InputPointIdList points;
224  InputPointsIdInternalIterator pIt = pe->InternalPointIdsBegin();
225  InputPointsIdInternalIterator pEnd = pe->InternalPointIdsEnd();
226 
227  while ( pIt != pEnd )
228  {
229  points.push_back( ( *pIt ) );
230  ++pIt;
231  }
232  out->AddFaceWithSecurePointList(points, false);
233  }
234  ++cIt;
235  }
236  }
237 }
238 
239 // ---------------------------------------------------------------------
240 template< typename TInputMesh, typename TOutputMesh >
241 void CopyMeshToMeshEdgeCells(const TInputMesh *in, TOutputMesh *out)
242 {
243  // Copy Edge Cells
244  using InputCellsContainer = typename TInputMesh::CellsContainer;
245  using InputCellsContainerConstPointer = typename InputCellsContainer::ConstPointer;
246  using InputCellsContainerConstIterator = typename InputCellsContainer::ConstIterator;
247  using InputEdgeCellType = typename TInputMesh::EdgeCellType;
248 
249  InputCellsContainerConstPointer inEdgeCells = in->GetEdgeCells();
250 
251  if ( inEdgeCells )
252  {
253  InputCellsContainerConstIterator ecIt = inEdgeCells->Begin();
254  InputCellsContainerConstIterator ecEnd = inEdgeCells->End();
255 
256  while ( ecIt != ecEnd )
257  {
258  auto * pe = dynamic_cast< InputEdgeCellType * >( ecIt.Value() );
259  if ( pe )
260  {
261  out->AddEdgeWithSecurePointList( pe->GetQEGeom()->GetOrigin(),
262  pe->GetQEGeom()->GetDestination() );
263  }
264  ++ecIt;
265  }
266  }
267 }
268 
269 // ---------------------------------------------------------------------
270 template< typename TInputMesh, typename TOutputMesh >
271 void CopyMeshToMeshPoints(const TInputMesh *in, TOutputMesh *out)
272 {
273  // Copy points
274  using InputPointsContainerConstPointer = typename TInputMesh::PointsContainerConstPointer;
275  using InputPointsContainerConstIterator = typename TInputMesh::PointsContainerConstIterator;
276 
277  using OutputPointsContainer = typename TOutputMesh::PointsContainer;
278  using OutputPointsContainerPointer = typename TOutputMesh::PointsContainerPointer;
279  using OutputPointType = typename TOutputMesh::PointType;
280 
281  InputPointsContainerConstPointer inPoints = in->GetPoints();
282 
283  if ( inPoints )
284  {
285  InputPointsContainerConstIterator inIt = inPoints->Begin();
286  InputPointsContainerConstIterator inEnd = inPoints->End();
287 
288  OutputPointsContainerPointer oPoints = out->GetPoints();
289  if( oPoints.IsNull() )
290  {
291  oPoints = OutputPointsContainer::New();
292  out->SetPoints( oPoints );
293  }
294  OutputPointType pOut;
295 
296  while ( inIt != inEnd )
297  {
298  pOut.CastFrom( inIt.Value() );
299  oPoints->InsertElement(inIt.Index(), pOut);
300  ++inIt;
301  }
302  }
303 }
304 } // end namespace itk
305 
306 #ifndef ITK_MANUAL_INSTANTIATION
307 #include "itkQuadEdgeMeshToQuadEdgeMeshFilter.hxx"
308 #endif
309 
310 #endif
void CopyMeshToMeshCells(const TInputMesh *in, TOutputMesh *out)
Light weight base class for most itk classes.
void CopyMeshToMesh(const TInputMesh *in, TOutputMesh *out)
TCellSubdivisionFilter::OutputMeshType OutputMeshType
Definition: itkMeshSource.h:68
void CopyMeshToMeshEdgeCells(const TInputMesh *in, TOutputMesh *out)
MeshToMeshFilter is the base class for all process objects that output mesh data, and require mesh da...
Iterator Begin()
void CopyMeshToMeshCellData(const TInputMesh *in, TOutputMesh *out)
void CopyMeshToMeshPointData(const TInputMesh *in, TOutputMesh *out)
void CopyMeshToMeshPoints(const TInputMesh *in, TOutputMesh *out)