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 
27 namespace itk
28 {
53 template <typename TInputMesh>
54 class ITK_TEMPLATE_EXPORT SimplexMeshVolumeCalculator : public Object
55 {
56 public:
57  ITK_DISALLOW_COPY_AND_MOVE(SimplexMeshVolumeCalculator);
58 
61 
63  using Superclass = Object;
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 
114  SimplexCellVisitor() { m_CenterMap = PointMapType::New(); }
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 
162  using SimplexVisitorInterfaceType = itk::
163  CellInterfaceVisitorImplementation<InputPixelType, InputCellTraitsType, SimplexPolygonType, SimplexCellVisitor>;
164 
166  using CellMultiVisitorType = typename SimplexCellType::MultiVisitor;
168 
170  itkSetObjectMacro(SimplexMesh, InputMeshType);
171 
173  void
174  Compute();
175 
177  itkGetConstMacro(Volume, double);
178 
180  itkGetConstMacro(Area, double);
181 
182 protected:
183  SimplexMeshVolumeCalculator() = default;
184  ~SimplexMeshVolumeCalculator() override = default;
185  void
186  PrintSelf(std::ostream & os, Indent indent) const override;
187 
188 private:
189  void
190  Initialize();
191 
192  void
193  Finalize();
194 
196  void
197  CreateTriangles();
198 
200  void
201  CalculateTriangleVolume(InputPointType p1, InputPointType p2, InputPointType p3);
202 
205  FindCellId(IdentifierType id1, IdentifierType id2, IdentifierType id3);
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 */
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:94
itk::SimplexMeshVolumeCalculator::InputPointsContainer
typename InputMeshType::PointsContainer InputPointsContainer
Definition: itkSimplexMeshVolumeCalculator.h:83
itk::SimplexMeshVolumeCalculator::InputPointsContainerPointer
typename InputPointsContainer::ConstPointer InputPointsContainerPointer
Definition: itkSimplexMeshVolumeCalculator.h:84
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::SimplexMeshVolumeCalculator::VectorType
typename InputPointType::VectorType VectorType
Definition: itkSimplexMeshVolumeCalculator.h:97
itk::SimplexMeshVolumeCalculator::CellMultiVisitorPointer
typename CellMultiVisitorType::Pointer CellMultiVisitorPointer
Definition: itkSimplexMeshVolumeCalculator.h:167
itk::SimplexMeshVolumeCalculator::SimplexCellVisitor::m_Mesh
InputMeshPointer m_Mesh
Definition: itkSimplexMeshVolumeCalculator.h:158
itk::PolygonCell
Represents a polygon in a Mesh.
Definition: itkPolygonCell.h:49
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::SimplexMeshVolumeCalculator::PointMapPointer
typename PointMapType::Pointer PointMapPointer
Definition: itkSimplexMeshVolumeCalculator.h:95
itk::IndexValueType
long IndexValueType
Definition: itkIntTypes.h:93
itk::MapContainer
A wrapper of the STL "map" container.
Definition: itkMapContainer.h:45
itk::PolygonCell::GetNumberOfPoints
unsigned int GetNumberOfPoints() const override
itk::SimplexMeshVolumeCalculator::SimplexVisitorInterfacePointer
typename SimplexVisitorInterfaceType::Pointer SimplexVisitorInterfacePointer
Definition: itkSimplexMeshVolumeCalculator.h:165
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::CellInterfaceVisitorImplementation
A template class used to implement a visitor object.
Definition: itkCellInterfaceVisitor.h:100
itk::SimplexMeshVolumeCalculator::SimplexCellVisitor::SimplexCellVisitor
SimplexCellVisitor()
Definition: itkSimplexMeshVolumeCalculator.h:114
itk::SimplexMeshVolumeCalculator::SimplexCellType
typename InputMeshType::CellType SimplexCellType
Definition: itkSimplexMeshVolumeCalculator.h:90
itk::SimplexMeshVolumeCalculator::InputNeighbors
typename InputMeshType::NeighborListType InputNeighbors
Definition: itkSimplexMeshVolumeCalculator.h:87
itk::SimplexMeshVolumeCalculator::InputPointType
typename InputMeshType::PointType InputPointType
Definition: itkSimplexMeshVolumeCalculator.h:79
itk::PolygonCell::PointIdsEnd
PointIdIterator PointIdsEnd() override
itk::SimplexMesh
The class represents a 2-simplex mesh.
Definition: itkSimplexMesh.h:47
itk::SimplexMeshVolumeCalculator::SimplexCellVisitor::Visit
void Visit(IdentifierType cellId, SimplexPolygonType *poly)
visits all polygon cells and compute the cell centers
Definition: itkSimplexMeshVolumeCalculator.h:122
itk::SimplexMeshVolumeCalculator::InputMeshType
TInputMesh InputMeshType
Definition: itkSimplexMeshVolumeCalculator.h:75
itkIntTypes.h
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:70
itk::SimplexMeshVolumeCalculator::InputCellTraitsType
typename InputMeshType::MeshTraits::CellTraits InputCellTraitsType
Definition: itkSimplexMeshVolumeCalculator.h:81
itkVectorContainer.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::SimplexMeshVolumeCalculator
Adapted from itkSimplexMeshToTriangleFilter to calculate the volume of a simplex mesh using the baryc...
Definition: itkSimplexMeshVolumeCalculator.h:54
itk::SimplexMeshVolumeCalculator::InputNeighborsIterator
typename InputMeshType::NeighborListType::iterator InputNeighborsIterator
Definition: itkSimplexMeshVolumeCalculator.h:88
itk::SimplexMeshVolumeCalculator::SimplexCellVisitor
Definition: itkSimplexMeshVolumeCalculator.h:107
itk::SimplexMeshVolumeCalculator::SimplexCellVisitor::SetMesh
void SetMesh(InputMeshPointer mesh)
Definition: itkSimplexMeshVolumeCalculator.h:152
itk::SimplexMeshVolumeCalculator::InputPointsContainerIterator
typename InputPointsContainer::ConstIterator InputPointsContainerIterator
Definition: itkSimplexMeshVolumeCalculator.h:85
itkPolygonCell.h
itkVector.h
itk::SimplexMeshVolumeCalculator::InputMeshPointer
typename InputMeshType::Pointer InputMeshPointer
Definition: itkSimplexMeshVolumeCalculator.h:76
Area
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::SimplexMeshVolumeCalculator::SimplexCellVisitor::GetCenterMap
PointMapPointer GetCenterMap()
Definition: itkSimplexMeshVolumeCalculator.h:146
itk::SimplexMeshVolumeCalculator::CellMultiVisitorType
typename SimplexCellType::MultiVisitor CellMultiVisitorType
Definition: itkSimplexMeshVolumeCalculator.h:166
New
static Pointer New()
itk::PolygonCell::PointIdsBegin
PointIdIterator PointIdsBegin() override
itkSimplexMesh.h
itk::SimplexMeshVolumeCalculator::InputMeshConstPointer
typename InputMeshType::ConstPointer InputMeshConstPointer
Definition: itkSimplexMeshVolumeCalculator.h:77
itk::SimplexMeshVolumeCalculator::SimplexCellVisitor::m_CenterMap
PointMapPointer m_CenterMap
Definition: itkSimplexMeshVolumeCalculator.h:159
itk::IdentifierType
SizeValueType IdentifierType
Definition: itkIntTypes.h:90
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86
itk::SimplexMeshVolumeCalculator::InputPixelType
typename InputMeshType::PixelType InputPixelType
Definition: itkSimplexMeshVolumeCalculator.h:80