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{};
127  InputPointType p{};
130  while (it != poly->PointIdsEnd())
131  {
132  m_Mesh->GetPoint(*it, &p);
133  center += p.GetVectorFromOrigin();
134  ++it;
135  }
136 
137  center[0] /= poly->GetNumberOfPoints();
138  center[1] /= poly->GetNumberOfPoints();
139  center[2] /= poly->GetNumberOfPoints();
140 
141  m_CenterMap->InsertElement(cellId, center);
142  }
143 
146  {
147  return m_CenterMap;
148  }
149 
150  void
152  {
153  m_Mesh = mesh;
154  }
155 
156  protected:
159  };
160 
161  using SimplexVisitorInterfaceType = itk::
162  CellInterfaceVisitorImplementation<InputPixelType, InputCellTraitsType, SimplexPolygonType, SimplexCellVisitor>;
163 
165  using CellMultiVisitorType = typename SimplexCellType::MultiVisitor;
167 
169  itkSetObjectMacro(SimplexMesh, InputMeshType);
170 
172  void
173  Compute();
174 
176  itkGetConstMacro(Volume, double);
177 
179  itkGetConstMacro(Area, double);
180 
181 protected:
182  SimplexMeshVolumeCalculator() = default;
183  ~SimplexMeshVolumeCalculator() override = default;
184  void
185  PrintSelf(std::ostream & os, Indent indent) const override;
186 
187 private:
188  void
189  Initialize();
190 
191  void
192  Finalize();
193 
195  void
196  CreateTriangles();
197 
199  void
200  CalculateTriangleVolume(InputPointType p1, InputPointType p2, InputPointType p3);
201 
204  FindCellId(IdentifierType id1, IdentifierType id2, IdentifierType id3);
205 
207  PointMapPointer m_Centers{};
208 
209  InputMeshPointer m_SimplexMesh{};
210 
211  double m_Volume{ 0.0 };
212  double m_VolumeX{ 0.0 };
213  double m_VolumeY{ 0.0 };
214  double m_VolumeZ{ 0.0 };
215  double m_Area{ 0.0 };
216  double m_Kx{ 0.0 };
217  double m_Ky{ 0.0 };
218  double m_Kz{ 0.0 };
219  double m_Wxyz{ 0.0 };
220  double m_Wxy{ 0.0 };
221  double m_Wxz{ 0.0 };
222  double m_Wyz{ 0.0 };
223 
224  IndexValueType m_Muncx{ 0 };
225  IndexValueType m_Muncy{ 0 };
226  IndexValueType m_Muncz{ 0 };
227 
228  SizeValueType m_NumberOfTriangles{ 0 };
229 };
230 } // namespace itk
231 
232 #ifndef ITK_MANUAL_INSTANTIATION
233 # include "itkSimplexMeshVolumeCalculator.hxx"
234 #endif
235 
236 #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:166
itk::SimplexMeshVolumeCalculator::SimplexCellVisitor::m_Mesh
InputMeshPointer m_Mesh
Definition: itkSimplexMeshVolumeCalculator.h:157
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:164
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:151
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:145
itk::SimplexMeshVolumeCalculator::CellMultiVisitorType
typename SimplexCellType::MultiVisitor CellMultiVisitorType
Definition: itkSimplexMeshVolumeCalculator.h:165
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:158
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