Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkSimplexMeshVolumeCalculator_h
00018 #define __itkSimplexMeshVolumeCalculator_h
00019
00020 #include <itkMesh.h>
00021 #include <itkLineCell.h>
00022 #include <itkPolygonCell.h>
00023 #include <itkVertexCell.h>
00024 #include <itkMapContainer.h>
00025 #include "itkCovariantVector.h"
00026 #include "itkVector.h"
00027 #include "itkSimplexMesh.h"
00028 #include "itkVectorContainer.h"
00029
00030 namespace itk
00031 {
00032
00033
00053 template <class TInputMesh>
00054 class ITK_EXPORT SimplexMeshVolumeCalculator : public Object
00055 {
00056
00057 public:
00059 typedef SimplexMeshVolumeCalculator Self;
00060
00062 typedef Object Superclass;
00063
00065 typedef SmartPointer<Self> Pointer;
00066 typedef SmartPointer<const Self> ConstPointer;
00067
00069 itkNewMacro(Self);
00070
00072 itkTypeMacro(SimplexMeshVolumeCalculator, Object);
00073
00074 typedef TInputMesh InputMeshType;
00075 typedef typename InputMeshType::Pointer InputMeshPointer;
00076 typedef typename InputMeshType::ConstPointer InputMeshConstPointer;
00077
00078 typedef typename InputMeshType::PointType InputPointType;
00079 typedef typename InputMeshType::PixelType InputPixelType;
00080 typedef typename InputMeshType::MeshTraits::CellTraits InputCellTraitsType;
00081
00082 typedef typename InputMeshType::PointsContainer InputPointsContainer;
00083 typedef typename InputPointsContainer::ConstPointer InputPointsContainerPointer;
00084 typedef typename InputPointsContainer::ConstIterator InputPointsContainerIterator;
00085
00086 typedef typename InputMeshType::NeighborListType InputNeighbors;
00087 typedef typename InputMeshType::NeighborListType::iterator InputNeighborsIterator;
00088
00089 typedef typename InputMeshType::CellType SimplexCellType;
00090 typedef itk::PolygonCell<SimplexCellType> SimplexPolygonType;
00091
00092
00093 typedef itk::MapContainer<unsigned long, InputPointType> PointMapType;
00094 typedef typename PointMapType::Pointer PointMapPointer;
00095
00096 typedef typename InputPointType::VectorType VectorType;
00097 typedef CovariantVector<
00098 typename VectorType::ValueType, 3 > CovariantVectorType;
00099
00106 class SimplexCellVisitor
00107 {
00108 public:
00109
00113 SimplexCellVisitor()
00114 {
00115 m_CenterMap = PointMapType::New();
00116 }
00117
00121 void Visit(unsigned long cellId, SimplexPolygonType * poly)
00122 {
00123 typedef typename SimplexPolygonType::PointIdIterator PointIdIterator;
00124 PointIdIterator it = poly->PointIdsBegin();
00125 InputPointType center,p;
00126 center.Fill(0);
00127 p.Fill(0.0);
00129
00130 while ( it != poly->PointIdsEnd() )
00131 {
00132 m_Mesh->GetPoint(*it, &p);
00133 center += p.GetVectorFromOrigin();
00134 it++;
00135 }
00136
00137 center[0] /= poly->GetNumberOfPoints();
00138 center[1] /= poly->GetNumberOfPoints();
00139 center[2] /= poly->GetNumberOfPoints();
00140
00141 m_CenterMap->InsertElement(cellId, center);
00142 }
00143
00144 PointMapPointer GetCenterMap()
00145 {
00146 return m_CenterMap;
00147 }
00148
00149 void SetMesh(InputMeshPointer mesh)
00150 {
00151 m_Mesh = mesh;
00152 }
00153
00154 protected:
00155 InputMeshPointer m_Mesh;
00156 PointMapPointer m_CenterMap;
00157 };
00158
00159 typedef itk::CellInterfaceVisitorImplementation<InputPixelType,
00160 InputCellTraitsType,
00161 SimplexPolygonType,
00162 SimplexCellVisitor>
00163 SimplexVisitorInterfaceType;
00164
00165 typedef typename SimplexVisitorInterfaceType::Pointer SimplexVisitorInterfacePointer;
00166 typedef typename SimplexCellType::MultiVisitor CellMultiVisitorType;
00167 typedef typename CellMultiVisitorType::Pointer CellMultiVisitorPointer;
00168
00170 itkSetObjectMacro(SimplexMesh, InputMeshType);
00171
00173 void Compute(void);
00174
00176 itkGetConstMacro(Volume, double);
00177
00179 itkGetConstMacro(Area, double);
00180
00181 protected:
00182 SimplexMeshVolumeCalculator();
00183 virtual ~SimplexMeshVolumeCalculator();
00184 void PrintSelf(std::ostream& os, Indent indent) const;
00185
00186 private:
00187 SimplexMeshVolumeCalculator(const Self&);
00188 void operator=(const Self&);
00189
00190 void Initialize();
00191 void Finalize();
00192
00194 void CreateTriangles();
00195
00197 void CalculateTriangleVolume(InputPointType p1, InputPointType p2, InputPointType p3);
00198
00200 unsigned long FindCellId(unsigned long id1, unsigned long id2, unsigned long id3);
00201
00203 PointMapPointer m_Centers;
00204
00205 InputMeshPointer m_SimplexMesh;
00206
00207 double m_Volume;
00208 double m_VolumeX;
00209 double m_VolumeY;
00210 double m_VolumeZ;
00211 double m_Area;
00212 double m_Kx;
00213 double m_Ky;
00214 double m_Kz;
00215 double m_Wxyz;
00216 double m_Wxy;
00217 double m_Wxz;
00218 double m_Wyz;
00219 long m_Muncx;
00220 long m_Muncy;
00221 long m_Muncz;
00222
00223 long m_NumberOfTriangles;
00224 };
00225
00226 }
00227
00228 #ifndef ITK_MANUAL_INSTANTIATION
00229 #include "itkSimplexMeshVolumeCalculator.txx"
00230 #endif
00231
00232 #endif
00233