ITK  5.4.0
Insight Toolkit
itkSimplexMeshToTriangleMeshFilter.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  * https://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 itkSimplexMeshToTriangleMeshFilter_h
19 #define itkSimplexMeshToTriangleMeshFilter_h
20 
21 #include "itkPolygonCell.h"
22 
23 #include "itkSimplexMesh.h"
24 #include "itkMeshToMeshFilter.h"
25 #include "itkVectorContainer.h"
27 
28 namespace itk
29 {
42 template <typename TInputMesh, typename TOutputMesh>
43 class ITK_TEMPLATE_EXPORT SimplexMeshToTriangleMeshFilter : public MeshToMeshFilter<TInputMesh, TOutputMesh>
44 {
45 public:
46  ITK_DISALLOW_COPY_AND_MOVE(SimplexMeshToTriangleMeshFilter);
47 
50 
53 
57 
59  itkNewMacro(Self);
60 
62  itkOverrideGetNameOfClassMacro(SimplexMeshToTriangleMeshFilter);
63 
64  using InputMeshType = TInputMesh;
67  using InputPixelType = typename InputMeshType::PixelType;
68  using InputCellTraitsType = typename InputMeshType::MeshTraits::CellTraits;
69  using PointIdentifier = typename InputMeshType::PointIdentifier;
70  using CellIdentifier = typename InputMeshType::CellIdentifier;
71 
72  using InputPointsContainer = typename InputMeshType::PointsContainer;
74  using InputPointsContainerIterator = typename InputPointsContainer::Iterator;
75 
76  using InputNeighbors = typename InputMeshType::NeighborListType;
77  using InputNeighborsIterator = typename InputMeshType::NeighborListType::iterator;
78 
80 
81  using SimplexCellType = typename InputMeshType::CellType;
83 
84  // stores the center for each simplex mesh cell, key is the point id
87 
95  {
96  public:
100  SimplexCellVisitor() { m_CenterMap = PointMapType::New(); }
101 
105  virtual ~SimplexCellVisitor() = default;
106 
110  void
112  {
113  using PointIdIterator = typename SimplexPolygonType::PointIdIterator;
114  PointIdIterator it = poly->PointIdsBegin();
115  InputPointType center;
116  center.Fill(0);
119  InputPointType p;
120  p.Fill(0);
121 
122  while (it != poly->PointIdsEnd())
123  {
124  this->m_Mesh->GetPoint(*it, &p);
125  center += p.GetVectorFromOrigin();
126  ++it;
127  }
128 
129  center[0] /= poly->GetNumberOfPoints();
130  center[1] /= poly->GetNumberOfPoints();
131  center[2] /= poly->GetNumberOfPoints();
132 
133  m_CenterMap->InsertElement(cellId, center);
134  }
135 
138  {
139  return m_CenterMap;
140  }
141 
142  void
143  SetMesh(const InputMeshType * mesh)
144  {
145  this->m_Mesh = mesh;
146  }
147 
148  protected:
151  };
152 
153  using SimplexVisitorInterfaceType = itk::
154  CellInterfaceVisitorImplementation<InputPixelType, InputCellTraitsType, SimplexPolygonType, SimplexCellVisitor>;
155 
157  using CellMultiVisitorType = typename SimplexCellType::MultiVisitor;
159 
160 protected:
162  ~SimplexMeshToTriangleMeshFilter() override = default;
163 
164  void
165  PrintSelf(std::ostream & os, Indent indent) const override;
166 
167  void
168  GenerateData() override;
169 
170  void
171  Initialize();
172 
174  void
175  CreateTriangles();
176 
179  FindCellId(CellIdentifier id1, CellIdentifier id2, CellIdentifier id3);
180 
182  PointMapPointer m_Centers{};
183 };
184 } // namespace itk
185 
186 #ifndef ITK_MANUAL_INSTANTIATION
187 # include "itkSimplexMeshToTriangleMeshFilter.hxx"
188 #endif
189 
190 #endif //__SimplexMeshToTriangleMeshFilter_h
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::SimplexMeshToTriangleMeshFilter::CellIdentifier
typename InputMeshType::CellIdentifier CellIdentifier
Definition: itkSimplexMeshToTriangleMeshFilter.h:70
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:94
itk::SimplexMeshToTriangleMeshFilter::SimplexCellVisitor::Visit
void Visit(CellIdentifier cellId, SimplexPolygonType *poly)
visits all polygon cells and compute the cell centers
Definition: itkSimplexMeshToTriangleMeshFilter.h:111
itk::SimplexMeshToTriangleMeshFilter::InputNeighborsIterator
typename InputMeshType::NeighborListType::iterator InputNeighborsIterator
Definition: itkSimplexMeshToTriangleMeshFilter.h:77
itk::SimplexMeshToTriangleMeshFilter::PointMapPointer
typename PointMapType::Pointer PointMapPointer
Definition: itkSimplexMeshToTriangleMeshFilter.h:86
itk::SimplexMeshToTriangleMeshFilter::SimplexCellVisitor
Definition: itkSimplexMeshToTriangleMeshFilter.h:94
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::SimplexMeshToTriangleMeshFilter::SimplexCellType
typename InputMeshType::CellType SimplexCellType
Definition: itkSimplexMeshToTriangleMeshFilter.h:81
itk::SimplexMeshToTriangleMeshFilter::InputNeighbors
typename InputMeshType::NeighborListType InputNeighbors
Definition: itkSimplexMeshToTriangleMeshFilter.h:76
itk::PolygonCell
Represents a polygon in a Mesh.
Definition: itkPolygonCell.h:53
itk::SmartPointer< Self >
itk::AutomaticTopologyMeshSource
Convenience class for generating meshes.
Definition: itkAutomaticTopologyMeshSource.h:111
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::SimplexMeshToTriangleMeshFilter::SimplexCellVisitor::SimplexCellVisitor
SimplexCellVisitor()
Definition: itkSimplexMeshToTriangleMeshFilter.h:100
itk::MeshToMeshFilter::InputMeshType
TInputMesh InputMeshType
Definition: itkMeshToMeshFilter.h:65
itk::MapContainer
A wrapper of the STL "map" container.
Definition: itkMapContainer.h:45
itk::SimplexMeshToTriangleMeshFilter::InputPointsContainerPointer
typename InputPointsContainer::Pointer InputPointsContainerPointer
Definition: itkSimplexMeshToTriangleMeshFilter.h:73
itk::PolygonCell::GetNumberOfPoints
unsigned int GetNumberOfPoints() const override
itk::SimplexMeshToTriangleMeshFilter::InputPixelType
typename InputMeshType::PixelType InputPixelType
Definition: itkSimplexMeshToTriangleMeshFilter.h:67
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::SimplexMeshToTriangleMeshFilter::SimplexCellVisitor::SetMesh
void SetMesh(const InputMeshType *mesh)
Definition: itkSimplexMeshToTriangleMeshFilter.h:143
itk::SimplexMeshToTriangleMeshFilter
This filter converts a 2-simplex mesh into a triangle mesh.
Definition: itkSimplexMeshToTriangleMeshFilter.h:43
itk::CellInterfaceVisitorImplementation
A template class used to implement a visitor object.
Definition: itkCellInterfaceVisitor.h:100
itk::PolygonCell::PointIdsEnd
PointIdIterator PointIdsEnd() override
itk::SimplexMeshToTriangleMeshFilter::InputPointType
typename InputMeshType::PointType InputPointType
Definition: itkSimplexMeshToTriangleMeshFilter.h:66
itk::SimplexMeshToTriangleMeshFilter::SimplexVisitorInterfacePointer
typename SimplexVisitorInterfaceType::Pointer SimplexVisitorInterfacePointer
Definition: itkSimplexMeshToTriangleMeshFilter.h:156
itk::MeshToMeshFilter
MeshToMeshFilter is the base class for all process objects that output mesh data, and require mesh da...
Definition: itkMeshToMeshFilter.h:47
itk::SimplexMeshToTriangleMeshFilter::InputCellTraitsType
typename InputMeshType::MeshTraits::CellTraits InputCellTraitsType
Definition: itkSimplexMeshToTriangleMeshFilter.h:68
itkAutomaticTopologyMeshSource.h
itk::SimplexMeshToTriangleMeshFilter::CellMultiVisitorPointer
typename CellMultiVisitorType::Pointer CellMultiVisitorPointer
Definition: itkSimplexMeshToTriangleMeshFilter.h:158
itk::SimplexMeshToTriangleMeshFilter::CellMultiVisitorType
typename SimplexCellType::MultiVisitor CellMultiVisitorType
Definition: itkSimplexMeshToTriangleMeshFilter.h:157
itk::SimplexMeshToTriangleMeshFilter::InputPointsContainer
typename InputMeshType::PointsContainer InputPointsContainer
Definition: itkSimplexMeshToTriangleMeshFilter.h:72
itkMeshToMeshFilter.h
itk::SimplexMeshToTriangleMeshFilter::SimplexCellVisitor::GetCenterMap
PointMapPointer GetCenterMap()
Definition: itkSimplexMeshToTriangleMeshFilter.h:137
itkVectorContainer.h
itk::SimplexMeshToTriangleMeshFilter::SimplexCellVisitor::m_Mesh
InputMeshConstPointer m_Mesh
Definition: itkSimplexMeshToTriangleMeshFilter.h:149
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itkPolygonCell.h
itk::SimplexMeshToTriangleMeshFilter::SimplexCellVisitor::m_CenterMap
PointMapPointer m_CenterMap
Definition: itkSimplexMeshToTriangleMeshFilter.h:150
itk::SimplexMeshToTriangleMeshFilter::InputPointsContainerIterator
typename InputPointsContainer::Iterator InputPointsContainerIterator
Definition: itkSimplexMeshToTriangleMeshFilter.h:74
New
static Pointer New()
itk::PolygonCell::PointIdsBegin
PointIdIterator PointIdsBegin() override
itk::SimplexMeshToTriangleMeshFilter::PointIdentifier
typename InputMeshType::PointIdentifier PointIdentifier
Definition: itkSimplexMeshToTriangleMeshFilter.h:69
itkSimplexMesh.h
itk::SimplexMeshToTriangleMeshFilter::InputMeshConstPointer
typename InputMeshType::ConstPointer InputMeshConstPointer
Definition: itkSimplexMeshToTriangleMeshFilter.h:65