ITK  6.0.0
Insight Toolkit
itkSimplexMeshVolumeCalculator.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 itkSimplexMeshVolumeCalculator_h
19#define itkSimplexMeshVolumeCalculator_h
20
21#include "itkIntTypes.h"
22#include "itkPolygonCell.h"
23#include "itkVector.h"
24#include "itkSimplexMesh.h"
25#include "itkVectorContainer.h"
26
27namespace itk
28{
53template <typename TInputMesh>
54class ITK_TEMPLATE_EXPORT SimplexMeshVolumeCalculator : public Object
55{
56public:
57 ITK_DISALLOW_COPY_AND_MOVE(SimplexMeshVolumeCalculator);
58
61
64
68
70 itkNewMacro(Self);
71
73 itkOverrideGetNameOfClassMacro(SimplexMeshVolumeCalculator);
74
75 using InputMeshType = TInputMesh;
78
80 using InputPixelType = typename InputMeshType::PixelType;
81 using InputCellTraitsType = typename InputMeshType::MeshTraits::CellTraits;
82
83 using InputPointsContainer = typename InputMeshType::PointsContainer;
85 using InputPointsContainerIterator = typename InputPointsContainer::ConstIterator;
86
87 using InputNeighbors = typename InputMeshType::NeighborListType;
88 using InputNeighborsIterator = typename InputMeshType::NeighborListType::iterator;
89
90 using SimplexCellType = typename InputMeshType::CellType;
92
93 // stores the center for each simplex mesh cell, key is the point id
96
99
108 {
109 public:
110
115 virtual ~SimplexCellVisitor() = default;
121 void
123 {
124 using PointIdIterator = typename SimplexPolygonType::PointIdIterator;
125 PointIdIterator it = poly->PointIdsBegin();
126 InputPointType center, p;
127 center.Fill(0);
128 p.Fill(0.0);
131 while (it != poly->PointIdsEnd())
132 {
133 m_Mesh->GetPoint(*it, &p);
134 center += p.GetVectorFromOrigin();
135 ++it;
136 }
137
138 center[0] /= poly->GetNumberOfPoints();
139 center[1] /= poly->GetNumberOfPoints();
140 center[2] /= poly->GetNumberOfPoints();
141
142 m_CenterMap->InsertElement(cellId, center);
143 }
144
147 {
148 return m_CenterMap;
149 }
150
151 void
153 {
154 m_Mesh = mesh;
155 }
156
157 protected:
160 };
161
163 CellInterfaceVisitorImplementation<InputPixelType, InputCellTraitsType, SimplexPolygonType, SimplexCellVisitor>;
164
166 using CellMultiVisitorType = typename SimplexCellType::MultiVisitor;
168
170 itkSetObjectMacro(SimplexMesh, InputMeshType);
171
173 void
175
177 itkGetConstMacro(Volume, double);
178
180 itkGetConstMacro(Area, double);
181
182protected:
184 ~SimplexMeshVolumeCalculator() override = default;
185 void
186 PrintSelf(std::ostream & os, Indent indent) const override;
187
188private:
189 void
191
192 void
194
196 void
198
200 void
202
206
208 PointMapPointer m_Centers{};
209
210 InputMeshPointer m_SimplexMesh{};
211
212 double m_Volume{ 0.0 };
213 double m_VolumeX{ 0.0 };
214 double m_VolumeY{ 0.0 };
215 double m_VolumeZ{ 0.0 };
216 double m_Area{ 0.0 };
217 double m_Kx{ 0.0 };
218 double m_Ky{ 0.0 };
219 double m_Kz{ 0.0 };
220 double m_Wxyz{ 0.0 };
221 double m_Wxy{ 0.0 };
222 double m_Wxz{ 0.0 };
223 double m_Wyz{ 0.0 };
224
225 IndexValueType m_Muncx{ 0 };
226 IndexValueType m_Muncy{ 0 };
227 IndexValueType m_Muncz{ 0 };
228
229 SizeValueType m_NumberOfTriangles{ 0 };
230};
231} // namespace itk
232
233#ifndef ITK_MANUAL_INSTANTIATION
234# include "itkSimplexMeshVolumeCalculator.hxx"
235#endif
236
237#endif /* __SimplexMeshVolumeCalculator_h */
A template class used to implement a visitor object.
A templated class holding a n-Dimensional covariant vector.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
A wrapper of the STL "map" container.
Base class for most ITK classes.
Definition: itkObject.h:62
Represents a polygon in a Mesh.
unsigned int GetNumberOfPoints() const override
PointIdIterator PointIdsEnd() override
PointIdIterator PointIdsBegin() override
void Visit(IdentifierType cellId, SimplexPolygonType *poly)
visits all polygon cells and compute the cell centers
Adapted from itkSimplexMeshToTriangleFilter to calculate the volume of a simplex mesh using the baryc...
typename CellMultiVisitorType::Pointer CellMultiVisitorPointer
typename InputMeshType::PointType InputPointType
typename InputMeshType::ConstPointer InputMeshConstPointer
typename SimplexCellType::MultiVisitor CellMultiVisitorType
typename SimplexVisitorInterfaceType::Pointer SimplexVisitorInterfacePointer
typename InputMeshType::NeighborListType::iterator InputNeighborsIterator
typename InputMeshType::Pointer InputMeshPointer
typename PointMapType::Pointer PointMapPointer
IdentifierType FindCellId(IdentifierType id1, IdentifierType id2, IdentifierType id3)
typename InputPointsContainer::ConstIterator InputPointsContainerIterator
typename InputPointType::VectorType VectorType
typename InputPointsContainer::ConstPointer InputPointsContainerPointer
~SimplexMeshVolumeCalculator() override=default
typename InputMeshType::MeshTraits::CellTraits InputCellTraitsType
typename InputMeshType::PixelType InputPixelType
void CalculateTriangleVolume(InputPointType p1, InputPointType p2, InputPointType p3)
typename InputMeshType::NeighborListType InputNeighbors
typename InputMeshType::PointsContainer InputPointsContainer
void PrintSelf(std::ostream &os, Indent indent) const override
typename InputMeshType::CellType SimplexCellType
The class represents a 2-simplex mesh.
SmartPointer< const Self > ConstPointer
static Pointer New()
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
long IndexValueType
Definition: itkIntTypes.h:93
SizeValueType IdentifierType
Definition: itkIntTypes.h:90
unsigned long SizeValueType
Definition: itkIntTypes.h:86