ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkSimplexMeshVolumeCalculator.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 {
49 template< typename TInputMesh >
50 class ITK_TEMPLATE_EXPORT SimplexMeshVolumeCalculator:public Object
51 {
52 public:
53  ITK_DISALLOW_COPY_AND_ASSIGN(SimplexMeshVolumeCalculator);
54 
57 
59  using Superclass = Object;
60 
64 
66  itkNewMacro(Self);
67 
69  itkTypeMacro(SimplexMeshVolumeCalculator, Object);
70 
71  using InputMeshType = TInputMesh;
72  using InputMeshPointer = typename InputMeshType::Pointer;
73  using InputMeshConstPointer = typename InputMeshType::ConstPointer;
74 
76  using InputPixelType = typename InputMeshType::PixelType;
77  using InputCellTraitsType = typename InputMeshType::MeshTraits::CellTraits;
78 
79  using InputPointsContainer = typename InputMeshType::PointsContainer;
80  using InputPointsContainerPointer = typename InputPointsContainer::ConstPointer;
81  using InputPointsContainerIterator = typename InputPointsContainer::ConstIterator;
82 
83  using InputNeighbors = typename InputMeshType::NeighborListType;
84  using InputNeighborsIterator = typename InputMeshType::NeighborListType::iterator;
85 
86  using SimplexCellType = typename InputMeshType::CellType;
88 
89  // stores the center for each simplex mesh cell, key is the point id
92 
95  typename VectorType::ValueType, 3 >;
96 
105  {
106 public:
107 
112  {
113  m_CenterMap = PointMapType::New();
114  }
115  virtual ~SimplexCellVisitor() = default;
117 
122  {
123  using PointIdIterator = typename SimplexPolygonType::PointIdIterator;
124  PointIdIterator it = poly->PointIdsBegin();
125  InputPointType center, p;
126  center.Fill(0);
127  p.Fill(0.0);
129 
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 
145  {
146  return m_CenterMap;
147  }
148 
150  {
151  m_Mesh = mesh;
152  }
153 
154 protected:
157  };
158 
164 
166  using CellMultiVisitorType = typename SimplexCellType::MultiVisitor;
167  using CellMultiVisitorPointer = typename CellMultiVisitorType::Pointer;
168 
170  itkSetObjectMacro(SimplexMesh, InputMeshType);
171 
173  void Compute();
174 
176  itkGetConstMacro(Volume, double);
177 
179  itkGetConstMacro(Area, double);
180 
181 protected:
182  SimplexMeshVolumeCalculator() = default;
183  ~SimplexMeshVolumeCalculator() override = default;
184  void PrintSelf(std::ostream & os, Indent indent) const override;
185 
186 private:
187  void Initialize();
188 
189  void Finalize();
190 
192  void CreateTriangles();
193 
195  void CalculateTriangleVolume(InputPointType p1, InputPointType p2, InputPointType p3);
196 
199 
202 
204 
205  double m_Volume{0.0};
206  double m_VolumeX{0.0};
207  double m_VolumeY{0.0};
208  double m_VolumeZ{0.0};
209  double m_Area{0.0};
210  double m_Kx{0.0};
211  double m_Ky{0.0};
212  double m_Kz{0.0};
213  double m_Wxyz{0.0};
214  double m_Wxy{0.0};
215  double m_Wxz{0.0};
216  double m_Wyz{0.0};
217 
218  IndexValueType m_Muncx{0};
219  IndexValueType m_Muncy{0};
220  IndexValueType m_Muncz{0};
221 
222  SizeValueType m_NumberOfTriangles{0};
223 };
224 } //end of namespace
225 
226 #ifndef ITK_MANUAL_INSTANTIATION
227 #include "itkSimplexMeshVolumeCalculator.hxx"
228 #endif
229 
230 #endif /* __SimplexMeshVolumeCalculator_h */
typename InputMeshType::PointType InputPointType
typename SimplexVisitorInterfaceType::Pointer SimplexVisitorInterfacePointer
typename InputMeshType::MeshTraits::CellTraits InputCellTraitsType
Light weight base class for most itk classes.
typename InputMeshType::NeighborListType::iterator InputNeighborsIterator
A template class used to implement a visitor object.
PointMapPointer GetCenterMap()
visits all polygon cells and compute the cell centers
unsigned long SizeValueType
Definition: itkIntTypes.h:83
The class represents a 2-simplex mesh.
A wrapper of the STL &quot;map&quot; container.
typename InputMeshType::NeighborListType InputNeighbors
typename InputPointsContainer::ConstIterator InputPointsContainerIterator
typename InputMeshType::ConstPointer InputMeshConstPointer
PointIdIterator PointIdsBegin() override
typename InputMeshType::PixelType InputPixelType
typename SimplexCellType::MultiVisitor CellMultiVisitorType
SizeValueType IdentifierType
Definition: itkIntTypes.h:87
typename InputMeshType::Pointer InputMeshPointer
signed long IndexValueType
Definition: itkIntTypes.h:90
PointMapPointer m_CenterMap
visits all polygon cells and compute the cell centers
Represents a polygon in a Mesh.
typename CellMultiVisitorType::Pointer CellMultiVisitorPointer
void SetMesh(InputMeshPointer mesh)
visits all polygon cells and compute the cell centers
Adapted from itkSimplexMeshToTriangleFilter to calculate the volume of a simplex mesh using the baryc...
Control indentation during Print() invocation.
Definition: itkIndent.h:49
InputMeshPointer m_Mesh
visits all polygon cells and compute the cell centers
typename InputMeshType::PointsContainer InputPointsContainer
typename InputPointType::VectorType VectorType
void Visit(IdentifierType cellId, SimplexPolygonType *poly)
visits all polygon cells and compute the cell centers
typename InputPointsContainer::ConstPointer InputPointsContainerPointer
Base class for most ITK classes.
Definition: itkObject.h:60
A templated class holding a n-Dimensional covariant vector.
unsigned int GetNumberOfPoints() const override
typename InputMeshType::CellType SimplexCellType
typename PointMapType::Pointer PointMapPointer
PointIdIterator PointIdsEnd() override