ITK  4.13.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:
55 
57  typedef Object Superclass;
58 
62 
64  itkNewMacro(Self);
65 
68 
69  typedef TInputMesh InputMeshType;
70  typedef typename InputMeshType::Pointer InputMeshPointer;
71  typedef typename InputMeshType::ConstPointer InputMeshConstPointer;
72 
74  typedef typename InputMeshType::PixelType InputPixelType;
75  typedef typename InputMeshType::MeshTraits::CellTraits InputCellTraitsType;
76 
77  typedef typename InputMeshType::PointsContainer InputPointsContainer;
78  typedef typename InputPointsContainer::ConstPointer InputPointsContainerPointer;
79  typedef typename InputPointsContainer::ConstIterator InputPointsContainerIterator;
80 
81  typedef typename InputMeshType::NeighborListType InputNeighbors;
82  typedef typename InputMeshType::NeighborListType::iterator InputNeighborsIterator;
83 
84  typedef typename InputMeshType::CellType SimplexCellType;
86 
87  // stores the center for each simplex mesh cell, key is the point id
90 
92  typedef CovariantVector<
93  typename VectorType::ValueType, 3 > CovariantVectorType;
94 
103  {
104 public:
105 
110  {
111  m_CenterMap = PointMapType::New();
112  }
113  virtual ~SimplexCellVisitor() {}
115 
120  {
121  typedef typename SimplexPolygonType::PointIdIterator PointIdIterator;
122  PointIdIterator it = poly->PointIdsBegin();
123  InputPointType center, p;
124  center.Fill(0);
125  p.Fill(0.0);
127 
128  while ( it != poly->PointIdsEnd() )
129  {
130  m_Mesh->GetPoint(*it, &p);
131  center += p.GetVectorFromOrigin();
132  it++;
133  }
134 
135  center[0] /= poly->GetNumberOfPoints();
136  center[1] /= poly->GetNumberOfPoints();
137  center[2] /= poly->GetNumberOfPoints();
138 
139  m_CenterMap->InsertElement(cellId, center);
140  }
141 
143  {
144  return m_CenterMap;
145  }
146 
148  {
149  m_Mesh = mesh;
150  }
151 
152 protected:
155  };
156 
162 
164  typedef typename SimplexCellType::MultiVisitor CellMultiVisitorType;
165  typedef typename CellMultiVisitorType::Pointer CellMultiVisitorPointer;
166 
168  itkSetObjectMacro(SimplexMesh, InputMeshType);
169 
171  void Compute();
172 
174  itkGetConstMacro(Volume, double);
175 
177  itkGetConstMacro(Area, double);
178 
179 protected:
181  virtual ~SimplexMeshVolumeCalculator() ITK_OVERRIDE;
182  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
183 
184 private:
185  ITK_DISALLOW_COPY_AND_ASSIGN(SimplexMeshVolumeCalculator);
186 
187  void Initialize();
188 
189  void Finalize();
190 
192  void CreateTriangles();
193 
195  void CalculateTriangleVolume(InputPointType p1, InputPointType p2, InputPointType p3);
196 
199 
201  PointMapPointer m_Centers;
202 
203  InputMeshPointer m_SimplexMesh;
204 
205  double m_Volume;
206  double m_VolumeX;
207  double m_VolumeY;
208  double m_VolumeZ;
209  double m_Area;
210  double m_Kx;
211  double m_Ky;
212  double m_Kz;
213  double m_Wxyz;
214  double m_Wxy;
215  double m_Wxz;
216  double m_Wyz;
217 
218  IndexValueType m_Muncx;
219  IndexValueType m_Muncy;
220  IndexValueType m_Muncz;
221 
222  SizeValueType m_NumberOfTriangles;
223 };
224 } //end of namespace
225 
226 #ifndef ITK_MANUAL_INSTANTIATION
227 #include "itkSimplexMeshVolumeCalculator.hxx"
228 #endif
229 
230 #endif /* __SimplexMeshVolumeCalculator_h */
Light weight base class for most itk classes.
A template class used to implement a visitor object.
PointMapPointer GetCenterMap()
visits all polygon cells and compute the cell centers
itk::CellInterfaceVisitorImplementation< InputPixelType, InputCellTraitsType, SimplexPolygonType, SimplexCellVisitor > SimplexVisitorInterfaceType
The class represents a 2-simplex mesh.
A wrapper of the STL &quot;map&quot; container.
InputMeshType::NeighborListType InputNeighbors
signed long IndexValueType
Definition: itkIntTypes.h:150
InputMeshType::MeshTraits::CellTraits InputCellTraitsType
InputMeshType::PointsContainer InputPointsContainer
itk::PolygonCell< SimplexCellType > SimplexPolygonType
virtual PointIdIterator PointIdsEnd(void) override
unsigned long SizeValueType
Definition: itkIntTypes.h:143
SizeValueType IdentifierType
Definition: itkIntTypes.h:147
InputMeshType::ConstPointer InputMeshConstPointer
CovariantVector< typename VectorType::ValueType, 3 > CovariantVectorType
virtual PointIdIterator PointIdsBegin(void) override
itk::MapContainer< IdentifierType, InputPointType > PointMapType
PointMapPointer m_CenterMap
visits all polygon cells and compute the cell centers
Represents a polygon in a Mesh.
void SetMesh(InputMeshPointer mesh)
visits all polygon cells and compute the cell centers
InputMeshType::NeighborListType::iterator InputNeighborsIterator
InputPointsContainer::ConstIterator InputPointsContainerIterator
Adapted from itkSimplexMeshToTriangleFilter to calculate the volume of a simplex mesh using the baryc...
Control indentation during Print() invocation.
Definition: itkIndent.h:49
CellMultiVisitorType::Pointer CellMultiVisitorPointer
InputMeshPointer m_Mesh
visits all polygon cells and compute the cell centers
virtual unsigned int GetNumberOfPoints(void) const override
void Visit(IdentifierType cellId, SimplexPolygonType *poly)
visits all polygon cells and compute the cell centers
Base class for most ITK classes.
Definition: itkObject.h:59
A templated class holding a n-Dimensional covariant vector.
InputPointsContainer::ConstPointer InputPointsContainerPointer
SimplexCellType::MultiVisitor CellMultiVisitorType
SimplexVisitorInterfaceType::Pointer SimplexVisitorInterfacePointer