ITK  5.1.0
Insight 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 : public MeshToMeshFilter<TInputMesh, TOutputMesh>
37 {
38 public:
39  ITK_DISALLOW_COPY_AND_ASSIGN(QuadEdgeMeshToQuadEdgeMeshFilter);
40 
46 
48  using InputMeshType = TInputMesh;
49  using InputMeshPointer = typename InputMeshType::Pointer;
50  using InputMeshConstPointer = typename InputMeshType::ConstPointer;
51  using InputCoordRepType = typename InputMeshType::CoordRepType;
53  using InputPointIdentifier = typename InputMeshType::PointIdentifier;
54  using InputQEPrimal = typename InputMeshType::QEPrimal;
56 
57  using InputPointDataContainer = typename InputMeshType::PointDataContainer;
58  using InputCellDataContainer = typename InputMeshType::CellDataContainer;
59 
60  using InputPointDataContainerConstPointer = typename InputPointDataContainer::ConstPointer;
61  using InputPointsContainerConstIterator = typename InputMeshType::PointsContainerConstIterator;
62  using InputPointsContainerConstPointer = typename InputMeshType::PointsContainerConstPointer;
63  using InputCellsContainerConstIterator = typename InputMeshType::CellsContainerConstIterator;
64  using InputCellsContainerConstPointer = typename InputMeshType::CellsContainerConstPointer;
65 
66  using InputEdgeCellType = typename InputMeshType::EdgeCellType;
67  using InputPolygonCellType = typename InputMeshType::PolygonCellType;
68  using InputPointIdList = typename InputMeshType::PointIdList;
69  using InputCellTraits = typename InputMeshType::CellTraits;
70  using InputPointsIdInternalIterator = typename InputCellTraits::PointIdInternalIterator;
71 
72  using InputQEIterator = typename InputQEPrimal::IteratorGeom;
73 
75  using OutputMeshType = TOutputMesh;
76  using OutputMeshPointer = typename OutputMeshType::Pointer;
77  using OutputMeshConstPointer = typename OutputMeshType::ConstPointer;
78  using OutputCoordRepType = typename OutputMeshType::CoordRepType;
80  using OutputPointIdentifier = typename OutputMeshType::PointIdentifier;
81  using OutputQEPrimal = typename OutputMeshType::QEPrimal;
83  using OutputQEIterator = typename OutputQEPrimal::IteratorGeom;
84  using OutputPointsContainerIterator = typename OutputMeshType::PointsContainerIterator;
85  using OutputPointsContainerPointer = typename OutputMeshType::PointsContainerPointer;
86  using OutputPointsContainerConstPointer = typename OutputMeshType::PointsContainerConstPointer;
87 
88  using OutputPointDataContainer = typename OutputMeshType::PointDataContainer;
89  using OutputCellDataContainer = typename OutputMeshType::CellDataContainer;
90 
91 public:
92  itkNewMacro(Self);
94 
95 protected:
97  ~QuadEdgeMeshToQuadEdgeMeshFilter() override = default;
98 
99  virtual void
100  CopyInputMeshToOutputMesh();
101 
102  virtual void
103  CopyInputMeshToOutputMeshGeometry();
104 
105  virtual void
106  CopyInputMeshToOutputMeshPoints();
107 
108  virtual void
109  CopyInputMeshToOutputMeshCells();
110 
111  virtual void
112  CopyInputMeshToOutputMeshEdgeCells();
113 
114  virtual void
115  CopyInputMeshToOutputMeshFieldData();
116 
117  virtual void
118  CopyInputMeshToOutputMeshPointData();
119 
120  virtual void
121  CopyInputMeshToOutputMeshCellData();
122 };
123 
124 //
125 // Helper functions that copy selected pieces of a Mesh.
126 // These functions should be templated here in order to
127 // facilitate their reuse in multiple scenarios.
128 //
129 template <typename TInputMesh, typename TOutputMesh>
130 void
131 CopyMeshToMesh(const TInputMesh * in, TOutputMesh * out)
132 {
133  CopyMeshToMeshPoints(in, out);
134  CopyMeshToMeshEdgeCells(in, out);
135  CopyMeshToMeshCells(in, out);
136  CopyMeshToMeshPointData(in, out);
137  CopyMeshToMeshCellData(in, out);
138 }
139 
140 // ---------------------------------------------------------------------
141 template <typename TInputMesh, typename TOutputMesh>
142 void
143 CopyMeshToMeshCellData(const TInputMesh * in, TOutputMesh * out)
144 {
145  using InputCellDataContainer = typename TInputMesh::CellDataContainer;
146  using OutputCellDataContainer = typename TOutputMesh::CellDataContainer;
147  using InputCellDataContainerConstPointer = typename InputCellDataContainer::ConstPointer;
148  using OutputCellDataContainerPointer = typename OutputCellDataContainer::Pointer;
149 
150  InputCellDataContainerConstPointer inputCellData = in->GetCellData();
151 
152  if (inputCellData.IsNull())
153  {
154  // There is nothing to copy
155  return;
156  }
157 
158  OutputCellDataContainerPointer outputCellData = OutputCellDataContainer::New();
159  outputCellData->Reserve(inputCellData->Size());
160 
161  // Copy point data
162  using InputCellDataContainerConstIterator = typename InputCellDataContainer::ConstIterator;
163  InputCellDataContainerConstIterator inIt = inputCellData->Begin();
164  while (inIt != inputCellData->End())
165  {
166  typename OutputCellDataContainer::Element point(inIt.Value());
167  outputCellData->SetElement(inIt.Index(), point);
168  ++inIt;
169  }
170 
171  out->SetCellData(outputCellData);
172 }
173 
174 // ---------------------------------------------------------------------
175 template <typename TInputMesh, typename TOutputMesh>
176 void
177 CopyMeshToMeshPointData(const TInputMesh * in, TOutputMesh * out)
178 {
179  using OutputPointDataContainer = typename TOutputMesh::PointDataContainer;
180  using OutputPointDataContainerPointer = typename OutputPointDataContainer::Pointer;
181  using InputPointDataContainer = typename TInputMesh::PointDataContainer;
182 
183  const InputPointDataContainer * inputPointData = in->GetPointData();
184 
185  if (inputPointData == nullptr)
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  using InputPointDataContainerConstIterator = typename InputPointDataContainer::ConstIterator;
196  InputPointDataContainerConstIterator inIt = inputPointData->Begin();
197  while (inIt != inputPointData->End())
198  {
199  typename OutputPointDataContainer::Element point(inIt.Value());
200  outputPointData->SetElement(inIt.Index(), point);
201  ++inIt;
202  }
203 
204  out->SetPointData(outputPointData);
205 }
206 
207 // ---------------------------------------------------------------------
208 template <typename TInputMesh, typename TOutputMesh>
209 void
210 CopyMeshToMeshCells(const TInputMesh * in, TOutputMesh * out)
211 {
212  // Copy cells
213  using InputCellsContainer = typename TInputMesh::CellsContainer;
214  using InputCellsContainerConstPointer = typename InputCellsContainer::ConstPointer;
215  using InputCellsContainerConstIterator = typename InputCellsContainer::ConstIterator;
216  using InputPolygonCellType = typename TInputMesh::PolygonCellType;
217  using InputPointIdList = typename TInputMesh::PointIdList;
218  using InputCellTraits = typename TInputMesh::CellTraits;
219  using InputPointsIdInternalIterator = typename InputCellTraits::PointIdInternalIterator;
220 
221  out->SetCellsAllocationMethod(TOutputMesh::CellsAllocationMethodType::CellsAllocatedDynamicallyCellByCell);
222 
223  InputCellsContainerConstPointer inCells = in->GetCells();
224 
225  if (inCells)
226  {
227  InputCellsContainerConstIterator cIt = inCells->Begin();
228  InputCellsContainerConstIterator cEnd = inCells->End();
229  while (cIt != cEnd)
230  {
231  auto * pe = dynamic_cast<InputPolygonCellType *>(cIt.Value());
232  if (pe)
233  {
234  InputPointIdList points;
235  InputPointsIdInternalIterator pIt = pe->InternalPointIdsBegin();
236  InputPointsIdInternalIterator pEnd = pe->InternalPointIdsEnd();
237 
238  while (pIt != pEnd)
239  {
240  points.push_back((*pIt));
241  ++pIt;
242  }
243  out->AddFaceWithSecurePointList(points, false);
244  }
245  ++cIt;
246  }
247  }
248 }
249 
250 // ---------------------------------------------------------------------
251 template <typename TInputMesh, typename TOutputMesh>
252 void
253 CopyMeshToMeshEdgeCells(const TInputMesh * in, TOutputMesh * out)
254 {
255  // Copy Edge Cells
256  using InputCellsContainer = typename TInputMesh::CellsContainer;
257  using InputCellsContainerConstPointer = typename InputCellsContainer::ConstPointer;
258  using InputCellsContainerConstIterator = typename InputCellsContainer::ConstIterator;
259  using InputEdgeCellType = typename TInputMesh::EdgeCellType;
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  auto * pe = dynamic_cast<InputEdgeCellType *>(ecIt.Value());
271  if (pe)
272  {
273  out->AddEdgeWithSecurePointList(pe->GetQEGeom()->GetOrigin(), pe->GetQEGeom()->GetDestination());
274  }
275  ++ecIt;
276  }
277  }
278 }
279 
280 // ---------------------------------------------------------------------
281 template <typename TInputMesh, typename TOutputMesh>
282 void
283 CopyMeshToMeshPoints(const TInputMesh * in, TOutputMesh * out)
284 {
285  // Copy points
286  using InputPointsContainerConstPointer = typename TInputMesh::PointsContainerConstPointer;
287  using InputPointsContainerConstIterator = typename TInputMesh::PointsContainerConstIterator;
288 
289  using OutputPointsContainer = typename TOutputMesh::PointsContainer;
290  using OutputPointsContainerPointer = typename TOutputMesh::PointsContainerPointer;
291  using OutputPointType = typename TOutputMesh::PointType;
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
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputPointDataContainerConstPointer
typename InputPointDataContainer::ConstPointer InputPointDataContainerConstPointer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:60
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputQEPrimal
typename OutputMeshType::QEPrimal OutputQEPrimal
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:81
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputPointDataContainer
typename OutputMeshType::PointDataContainer OutputPointDataContainer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:88
itk::CopyMeshToMeshCellData
void CopyMeshToMeshCellData(const TInputMesh *in, TOutputMesh *out)
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:143
itk::MeshSource< TOutput >::OutputMeshPointer
typename OutputMeshType::Pointer OutputMeshPointer
Definition: itkMeshSource.h:69
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputPointsContainerPointer
typename OutputMeshType::PointsContainerPointer OutputPointsContainerPointer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:85
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:283
itk::FixedArray::Begin
Iterator Begin()
itk::CopyMeshToMeshEdgeCells
void CopyMeshToMeshEdgeCells(const TInputMesh *in, TOutputMesh *out)
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:253
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputCellsContainerConstPointer
typename InputMeshType::CellsContainerConstPointer InputCellsContainerConstPointer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:64
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputPointsContainerConstPointer
typename OutputMeshType::PointsContainerConstPointer OutputPointsContainerConstPointer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:86
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputPointsContainerConstIterator
typename InputMeshType::PointsContainerConstIterator InputPointsContainerConstIterator
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:61
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputCellDataContainer
typename OutputMeshType::CellDataContainer OutputCellDataContainer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:89
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:54
itk::CopyMeshToMeshCells
void CopyMeshToMeshCells(const TInputMesh *in, TOutputMesh *out)
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:210
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputMeshConstPointer
typename InputMeshType::ConstPointer InputMeshConstPointer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:50
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputPointType
typename InputMeshType::PointType InputPointType
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:52
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:68
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputPointIdentifier
typename InputMeshType::PointIdentifier InputPointIdentifier
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:53
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputCellTraits
typename InputMeshType::CellTraits InputCellTraits
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:69
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputVectorType
typename OutputMeshType::VectorType OutputVectorType
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:82
itk::CopyMeshToMesh
void CopyMeshToMesh(const TInputMesh *in, TOutputMesh *out)
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:131
itk::QuadEdgeMeshToQuadEdgeMeshFilter
Duplicates the content of a Mesh.
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:36
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:78
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputEdgeCellType
typename InputMeshType::EdgeCellType InputEdgeCellType
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:66
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputPointDataContainer
typename InputMeshType::PointDataContainer InputPointDataContainer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:57
itkMeshToMeshFilter.h
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputPointsContainerConstPointer
typename InputMeshType::PointsContainerConstPointer InputPointsContainerConstPointer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:62
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:51
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputPolygonCellType
typename InputMeshType::PolygonCellType InputPolygonCellType
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:67
itk::CopyMeshToMeshPointData
void CopyMeshToMeshPointData(const TInputMesh *in, TOutputMesh *out)
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:177
itk::MeshSource< TOutput >::OutputMeshType
TOutput OutputMeshType
Definition: itkMeshSource.h:68
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputVectorType
typename InputMeshType::VectorType InputVectorType
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:55
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputCellDataContainer
typename InputMeshType::CellDataContainer InputCellDataContainer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:58
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputQEIterator
typename OutputQEPrimal::IteratorGeom OutputQEIterator
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:83
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputPointsIdInternalIterator
typename InputCellTraits::PointIdInternalIterator InputPointsIdInternalIterator
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:70
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputPointIdentifier
typename OutputMeshType::PointIdentifier OutputPointIdentifier
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:80
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputPointType
typename OutputMeshType::PointType OutputPointType
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:79
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputMeshConstPointer
typename OutputMeshType::ConstPointer OutputMeshConstPointer
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:77
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::OutputPointsContainerIterator
typename OutputMeshType::PointsContainerIterator OutputPointsContainerIterator
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:84
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputCellsContainerConstIterator
typename InputMeshType::CellsContainerConstIterator InputCellsContainerConstIterator
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:63
itk::QuadEdgeMeshToQuadEdgeMeshFilter< TInput, TOutput >::InputQEIterator
typename InputQEPrimal::IteratorGeom InputQEIterator
Definition: itkQuadEdgeMeshToQuadEdgeMeshFilter.h:72