ITK  4.9.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 >
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 
73  typedef typename InputMeshType::PointType InputPointType;
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 
91  typedef typename InputPointType::VectorType VectorType;
92  typedef CovariantVector<
93  typename VectorType::ValueType, 3 > CovariantVectorType;
94 
103  {
104 public:
105 
110  {
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:
182  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
183 
184 private:
185  SimplexMeshVolumeCalculator(const Self &) ITK_DELETE_FUNCTION;
186  void operator=(const Self &) ITK_DELETE_FUNCTION;
187 
188  void Initialize();
189 
190  void Finalize();
191 
193  void CreateTriangles();
194 
197 
200 
203 
205 
206  double m_Volume;
207  double m_VolumeX;
208  double m_VolumeY;
209  double m_VolumeZ;
210  double m_Area;
211  double m_Kx;
212  double m_Ky;
213  double m_Kz;
214  double m_Wxyz;
215  double m_Wxy;
216  double m_Wxz;
217  double m_Wyz;
218 
222 
224 };
225 } //end of namespace
226 
227 #ifndef ITK_MANUAL_INSTANTIATION
228 #include "itkSimplexMeshVolumeCalculator.hxx"
229 #endif
230 
231 #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
static Pointer New()
SizeValueType IdentifierType
Definition: itkIntTypes.h:147
InputMeshType::ConstPointer InputMeshConstPointer
CovariantVector< typename VectorType::ValueType, 3 > CovariantVectorType
void CalculateTriangleVolume(InputPointType p1, InputPointType p2, InputPointType p3)
virtual void PrintSelf(std::ostream &os, Indent indent) const override
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:57
A templated class holding a n-Dimensional covariant vector.
InputPointsContainer::ConstPointer InputPointsContainerPointer
IdentifierType FindCellId(IdentifierType id1, IdentifierType id2, IdentifierType id3)
SimplexCellType::MultiVisitor CellMultiVisitorType
SimplexVisitorInterfaceType::Pointer SimplexVisitorInterfacePointer