ITK  4.3.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< class TInputMesh >
50 class ITK_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 
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  {
111  m_CenterMap = PointMapType::New();
112  }
113  virtual ~SimplexCellVisitor() {}
115 
119  void Visit(IdentifierType cellId, SimplexPolygonType *poly)
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 
142  PointMapPointer GetCenterMap()
143  {
144  return m_CenterMap;
145  }
146 
147  void SetMesh(InputMeshPointer mesh)
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(void);
172 
174  itkGetConstMacro(Volume, double);
175 
177  itkGetConstMacro(Area, double);
178 
179 protected:
181  virtual ~SimplexMeshVolumeCalculator();
182  void PrintSelf(std::ostream & os, Indent indent) const;
183 
184 private:
185  SimplexMeshVolumeCalculator(const Self &); //purposely not implemented
186  void operator=(const Self &); //purposely not implemented
187 
188  void Initialize();
189 
190  void Finalize();
191 
193  void CreateTriangles();
194 
196  void CalculateTriangleVolume(InputPointType p1, InputPointType p2, InputPointType p3);
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 */
232