ITK  6.0.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{};
118  InputPointType p{};
119 
120  while (it != poly->PointIdsEnd())
121  {
122  this->m_Mesh->GetPoint(*it, &p);
123  center += p.GetVectorFromOrigin();
124  ++it;
125  }
126 
127  center[0] /= poly->GetNumberOfPoints();
128  center[1] /= poly->GetNumberOfPoints();
129  center[2] /= poly->GetNumberOfPoints();
130 
131  m_CenterMap->InsertElement(cellId, center);
132  }
133 
136  {
137  return m_CenterMap;
138  }
139 
140  void
141  SetMesh(const InputMeshType * mesh)
142  {
143  this->m_Mesh = mesh;
144  }
145 
146  protected:
149  };
150 
151  using SimplexVisitorInterfaceType = itk::
152  CellInterfaceVisitorImplementation<InputPixelType, InputCellTraitsType, SimplexPolygonType, SimplexCellVisitor>;
153 
155  using CellMultiVisitorType = typename SimplexCellType::MultiVisitor;
157 
158 protected:
160  ~SimplexMeshToTriangleMeshFilter() override = default;
161 
162  void
163  PrintSelf(std::ostream & os, Indent indent) const override;
164 
165  void
166  GenerateData() override;
167 
168  void
169  Initialize();
170 
172  void
173  CreateTriangles();
174 
177  FindCellId(CellIdentifier id1, CellIdentifier id2, CellIdentifier id3);
178 
180  PointMapPointer m_Centers{};
181 };
182 } // namespace itk
183 
184 #ifndef ITK_MANUAL_INSTANTIATION
185 # include "itkSimplexMeshToTriangleMeshFilter.hxx"
186 #endif
187 
188 #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:49
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:141
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:154
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:156
itk::SimplexMeshToTriangleMeshFilter::CellMultiVisitorType
typename SimplexCellType::MultiVisitor CellMultiVisitorType
Definition: itkSimplexMeshToTriangleMeshFilter.h:155
itk::SimplexMeshToTriangleMeshFilter::InputPointsContainer
typename InputMeshType::PointsContainer InputPointsContainer
Definition: itkSimplexMeshToTriangleMeshFilter.h:72
itkMeshToMeshFilter.h
itk::SimplexMeshToTriangleMeshFilter::SimplexCellVisitor::GetCenterMap
PointMapPointer GetCenterMap()
Definition: itkSimplexMeshToTriangleMeshFilter.h:135
itkVectorContainer.h
itk::SimplexMeshToTriangleMeshFilter::SimplexCellVisitor::m_Mesh
InputMeshConstPointer m_Mesh
Definition: itkSimplexMeshToTriangleMeshFilter.h:147
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itkPolygonCell.h
itk::SimplexMeshToTriangleMeshFilter::SimplexCellVisitor::m_CenterMap
PointMapPointer m_CenterMap
Definition: itkSimplexMeshToTriangleMeshFilter.h:148
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