ITK  5.1.0
Insight Toolkit
itkQuadEdgeMeshToQuadEdgeMeshFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 {
36 template <typename TInputMesh, typename TOutputMesh>
37 class ITK_TEMPLATE_EXPORT QuadEdgeMeshToQuadEdgeMeshFilter : 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
101  CopyInputMeshToOutputMesh();
102 
103  virtual void
104  CopyInputMeshToOutputMeshGeometry();
105 
106  virtual void
107  CopyInputMeshToOutputMeshPoints();
108 
109  virtual void
110  CopyInputMeshToOutputMeshCells();
111 
112  virtual void
113  CopyInputMeshToOutputMeshEdgeCells();
114 
115  virtual void
116  CopyInputMeshToOutputMeshFieldData();
117 
118  virtual void
119  CopyInputMeshToOutputMeshPointData();
120 
121  virtual void
122  CopyInputMeshToOutputMeshCellData();
123 };
124 
125 //
126 // Helper functions that copy selected pieces of a Mesh.
127 // These functions should be templated here in order to
128 // facilitate their reuse in multiple scenarios.
129 //
130 template <typename TInputMesh, typename TOutputMesh>
131 void
132 CopyMeshToMesh(const TInputMesh * in, TOutputMesh * out)
133 {
134  CopyMeshToMeshPoints(in, out);
135  CopyMeshToMeshEdgeCells(in, out);
136  CopyMeshToMeshCells(in, out);
137  CopyMeshToMeshPointData(in, out);
138  CopyMeshToMeshCellData(in, out);
139 }
140 
141 // ---------------------------------------------------------------------
142 template <typename TInputMesh, typename TOutputMesh>
143 void
144 CopyMeshToMeshCellData(const TInputMesh * in, TOutputMesh * out)
145 {
146  using InputCellDataContainer = typename TInputMesh::CellDataContainer;
147  using OutputCellDataContainer = typename TOutputMesh::CellDataContainer;
148  using InputCellDataContainerConstPointer = typename InputCellDataContainer::ConstPointer;
149  using OutputCellDataContainerPointer = typename OutputCellDataContainer::Pointer;
150 
151  InputCellDataContainerConstPointer inputCellData = in->GetCellData();
152 
153  if (inputCellData.IsNull())
154  {
155  // There is nothing to copy
156  return;
157  }
158 
159  OutputCellDataContainerPointer outputCellData = OutputCellDataContainer::New();
160  outputCellData->Reserve(inputCellData->Size());
161 
162  // Copy point data
163  using InputCellDataContainerConstIterator = typename InputCellDataContainer::ConstIterator;
164  InputCellDataContainerConstIterator inIt = inputCellData->Begin();
165  while (inIt != inputCellData->End())
166  {
167  typename OutputCellDataContainer::Element point(inIt.Value());
168  outputCellData->SetElement(inIt.Index(), point);
169  ++inIt;
170  }
171 
172  out->SetCellData(outputCellData);
173 }
174 
175 // ---------------------------------------------------------------------
176 template <typename TInputMesh, typename TOutputMesh>
177 void
178 CopyMeshToMeshPointData(const TInputMesh * in, TOutputMesh * out)
179 {
180  using OutputPointDataContainer = typename TOutputMesh::PointDataContainer;
181  using OutputPointDataContainerPointer = typename OutputPointDataContainer::Pointer;
182  using InputPointDataContainer = typename TInputMesh::PointDataContainer;
183 
184  const InputPointDataContainer * inputPointData = in->GetPointData();
185 
186  if (inputPointData == 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  using InputPointDataContainerConstIterator = typename InputPointDataContainer::ConstIterator;
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
211 CopyMeshToMeshCells(const TInputMesh * in, TOutputMesh * out)
212 {
213  // Copy cells
214  using InputCellsContainer = typename TInputMesh::CellsContainer;
215  using InputCellsContainerConstPointer = typename InputCellsContainer::ConstPointer;
216  using InputCellsContainerConstIterator = typename InputCellsContainer::ConstIterator;
217  using InputPolygonCellType = typename TInputMesh::PolygonCellType;
218  using InputPointIdList = typename TInputMesh::PointIdList;
219  using InputCellTraits = typename TInputMesh::CellTraits;
220  using InputPointsIdInternalIterator = typename InputCellTraits::PointIdInternalIterator;
221 
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  auto * 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
254 CopyMeshToMeshEdgeCells(const TInputMesh * in, TOutputMesh * out)
255 {
256  // Copy Edge Cells
257  using InputCellsContainer = typename TInputMesh::CellsContainer;
258  using InputCellsContainerConstPointer = typename InputCellsContainer::ConstPointer;
259  using InputCellsContainerConstIterator = typename InputCellsContainer::ConstIterator;
260  using InputEdgeCellType = typename TInputMesh::EdgeCellType;
261 
262  InputCellsContainerConstPointer inEdgeCells = in->GetEdgeCells();
263 
264  if (inEdgeCells)
265  {
266  InputCellsContainerConstIterator ecIt = inEdgeCells->Begin();
267  InputCellsContainerConstIterator ecEnd = inEdgeCells->End();
268 
269  while (ecIt != ecEnd)
270  {
271  auto * pe = dynamic_cast<InputEdgeCellType *>(ecIt.Value());
272  if (pe)
273  {
274  out->AddEdgeWithSecurePointList(pe->GetQEGeom()->GetOrigin(), pe->GetQEGeom()->GetDestination());
275  }
276  ++ecIt;
277  }
278  }
279 }
280 
281 // ---------------------------------------------------------------------
282 template <typename TInputMesh, typename TOutputMesh>
283 void
284 CopyMeshToMeshPoints(const TInputMesh * in, TOutputMesh * out)
285 {
286  // Copy points
287  using InputPointsContainerConstPointer = typename TInputMesh::PointsContainerConstPointer;
288  using InputPointsContainerConstIterator = typename TInputMesh::PointsContainerConstIterator;
289 
290  using OutputPointsContainer = typename TOutputMesh::PointsContainer;
291  using OutputPointsContainerPointer = typename TOutputMesh::PointsContainerPointer;
292  using OutputPointType = typename TOutputMesh::PointType;
293 
294  InputPointsContainerConstPointer inPoints = in->GetPoints();
295 
296  if (inPoints)
297  {
298  InputPointsContainerConstIterator inIt = inPoints->Begin();
299  InputPointsContainerConstIterator inEnd = inPoints->End();
300 
301  OutputPointsContainerPointer oPoints = out->GetPoints();
302  if (oPoints.IsNull())
303  {
304  oPoints = OutputPointsContainer::New();
305  out->SetPoints(oPoints);
306  }
307  OutputPointType pOut;
308 
309  while (inIt != inEnd)
310  {
311  pOut.CastFrom(inIt.Value());
312  oPoints->InsertElement(inIt.Index(), pOut);
313  ++inIt;
314  }
315  }
316 }
317 } // end namespace itk
318 
319 #ifndef ITK_MANUAL_INSTANTIATION
320 # include "itkQuadEdgeMeshToQuadEdgeMeshFilter.hxx"
321 #endif
322 
323 #endif
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputPointDataContainerConstPointer
typename InputPointDataContainer::ConstPointer InputPointDataContainerConstPointer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:61
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputQEPrimal
typename OutputMeshType::QEPrimal OutputQEPrimal
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:82
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputPointDataContainer
typename OutputMeshType::PointDataContainer OutputPointDataContainer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:89
itk::CopyMeshToMeshCellData
void CopyMeshToMeshCellData(const TInputMesh *in, TOutputMesh *out)
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:144
itk::MeshSource< TOutput >::OutputMeshPointer
typename OutputMeshType::Pointer OutputMeshPointer
Definition: itkMeshSource.h:69
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputPointsContainerPointer
typename OutputMeshType::PointsContainerPointer OutputPointsContainerPointer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:86
itk::MeshToMeshFilter< TInput, TOutput >::InputMeshPointer
typename InputMeshType::Pointer InputMeshPointer
Definition: itkMeshToMeshFilter.h:66
itk::GTest::TypedefsAndConstructors::Dimension2::VectorType
ImageBaseType::SpacingType VectorType
Definition: itkGTestTypedefsAndConstructors.h:53
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::CopyMeshToMeshPoints
void CopyMeshToMeshPoints(const TInputMesh *in, TOutputMesh *out)
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:284
itk::FixedArray::Begin
Iterator Begin()
itk::CopyMeshToMeshEdgeCells
void CopyMeshToMeshEdgeCells(const TInputMesh *in, TOutputMesh *out)
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:254
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputCellsContainerConstPointer
typename InputMeshType::CellsContainerConstPointer InputCellsContainerConstPointer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:65
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputPointsContainerConstPointer
typename OutputMeshType::PointsContainerConstPointer OutputPointsContainerConstPointer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:87
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputPointsContainerConstIterator
typename InputMeshType::PointsContainerConstIterator InputPointsContainerConstIterator
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:62
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputCellDataContainer
typename OutputMeshType::CellDataContainer OutputCellDataContainer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:90
itk::MeshEnums::MeshClassCellsAllocationMethod::CellsAllocatedDynamicallyCellByCell
itk::SmartPointer< Self >
itk::MeshToMeshFilter< TInput, TOutput >::InputMeshType
TInput InputMeshType
Definition: itkMeshToMeshFilter.h:65
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputQEPrimal
typename InputMeshType::QEPrimal InputQEPrimal
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:55
itk::CopyMeshToMeshCells
void CopyMeshToMeshCells(const TInputMesh *in, TOutputMesh *out)
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:211
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputMeshConstPointer
typename InputMeshType::ConstPointer InputMeshConstPointer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:51
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputPointType
typename InputMeshType::PointType InputPointType
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:53
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputPointIdList
typename InputMeshType::PointIdList InputPointIdList
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:69
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputPointIdentifier
typename InputMeshType::PointIdentifier InputPointIdentifier
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:54
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputCellTraits
typename InputMeshType::CellTraits InputCellTraits
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:70
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputVectorType
typename OutputMeshType::VectorType OutputVectorType
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:83
itk::CopyMeshToMesh
void CopyMeshToMesh(const TInputMesh *in, TOutputMesh *out)
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:132
itk::QuadEdgeMeshToQuadEdgeMeshFilter
Duplicates the content of a Mesh.
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:37
itk::MeshToMeshFilter
MeshToMeshFilter is the base class for all process objects that output mesh data, and require mesh da...
Definition: itkMeshToMeshFilter.h:47
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputCoordRepType
typename OutputMeshType::CoordRepType OutputCoordRepType
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:79
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputEdgeCellType
typename InputMeshType::EdgeCellType InputEdgeCellType
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:67
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputPointDataContainer
typename InputMeshType::PointDataContainer InputPointDataContainer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:58
itkMeshToMeshFilter.h
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputPointsContainerConstPointer
typename InputMeshType::PointsContainerConstPointer InputPointsContainerConstPointer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:63
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputCoordRepType
typename InputMeshType::CoordRepType InputCoordRepType
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:52
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputPolygonCellType
typename InputMeshType::PolygonCellType InputPolygonCellType
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:68
itk::CopyMeshToMeshPointData
void CopyMeshToMeshPointData(const TInputMesh *in, TOutputMesh *out)
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:178
itk::MeshSource< TOutput >::OutputMeshType
TOutput OutputMeshType
Definition: itkMeshSource.h:68
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputVectorType
typename InputMeshType::VectorType InputVectorType
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:56
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputCellDataContainer
typename InputMeshType::CellDataContainer InputCellDataContainer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:59
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputQEIterator
typename OutputQEPrimal::IteratorGeom OutputQEIterator
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:84
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputPointsIdInternalIterator
typename InputCellTraits::PointIdInternalIterator InputPointsIdInternalIterator
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:71
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputPointIdentifier
typename OutputMeshType::PointIdentifier OutputPointIdentifier
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:81
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputPointType
typename OutputMeshType::PointType OutputPointType
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:80
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputMeshConstPointer
typename OutputMeshType::ConstPointer OutputMeshConstPointer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:78
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputPointsContainerIterator
typename OutputMeshType::PointsContainerIterator OutputPointsContainerIterator
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:85
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputCellsContainerConstIterator
typename InputMeshType::CellsContainerConstIterator InputCellsContainerConstIterator
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:64
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputQEIterator
typename InputQEPrimal::IteratorGeom InputQEIterator
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:73