00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __SimplexMeshVolumeCalculator_h
00018 #define __SimplexMeshVolumeCalculator_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
00105 class SimplexCellVisitor
00106 {
00107 public:
00111 SimplexCellVisitor()
00112 {
00113 m_CenterMap = PointMapType::New();
00114 }
00115
00119 void Visit(unsigned long cellId, SimplexPolygonType * poly)
00120 {
00121 typedef typename SimplexPolygonType::PointIdIterator PointIdIterator;
00122 PointIdIterator it = poly->PointIdsBegin();
00123 InputPointType center,p;
00124 center.Fill(0);
00125
00126 while ( it != poly->PointIdsEnd() )
00127 {
00128 m_Mesh->GetPoint(*it, &p);
00129 center += p.GetVectorFromOrigin();
00130 it++;
00131 }
00132
00133 center[0] /= poly->GetNumberOfPoints();
00134 center[1] /= poly->GetNumberOfPoints();
00135 center[2] /= poly->GetNumberOfPoints();
00136
00137 m_CenterMap->InsertElement(cellId, center);
00138 }
00139
00140 PointMapPointer GetCenterMap()
00141 {
00142 return m_CenterMap;
00143 }
00144
00145 void SetMesh(InputMeshPointer mesh)
00146 {
00147 m_Mesh = mesh;
00148 }
00149
00150 protected:
00151 InputMeshPointer m_Mesh;
00152 PointMapPointer m_CenterMap;
00153 };
00154
00155 typedef itk::CellInterfaceVisitorImplementation<InputPixelType,
00156 InputCellTraitsType,
00157 SimplexPolygonType,
00158 SimplexCellVisitor>
00159 SimplexVisitorInterfaceType;
00160
00161 typedef typename SimplexVisitorInterfaceType::Pointer SimplexVisitorInterfacePointer;
00162 typedef typename SimplexCellType::MultiVisitor CellMultiVisitorType;
00163 typedef typename CellMultiVisitorType::Pointer CellMultiVisitorPointer;
00164
00166 itkSetObjectMacro(SimplexMesh, InputMeshType);
00167
00169 void Compute(void);
00170
00172 itkGetMacro(Volume, double);
00173
00175 itkGetMacro(Area, double);
00176
00177 protected:
00178 SimplexMeshVolumeCalculator();
00179 virtual ~SimplexMeshVolumeCalculator();
00180 void PrintSelf(std::ostream& os, Indent indent) const;
00181
00182 private:
00183 SimplexMeshVolumeCalculator(const Self&);
00184 void operator=(const Self&);
00185
00186 void Initialize();
00187 void Finalize();
00188
00190 void CreateTriangles();
00191
00193 void CalculateTriangleVolume(InputPointType p1, InputPointType p2, InputPointType p3);
00194
00196 unsigned long FindCellId(unsigned long id1, unsigned long id2, unsigned long id3);
00197
00199 PointMapPointer m_Centers;
00200
00201 InputMeshPointer m_SimplexMesh;
00202 double m_Volume, m_VolumeX, m_VolumeY, m_VolumeZ;
00203 double m_Area;
00204 double m_Kx, m_Ky, m_Kz;
00205 double m_Wxyz, m_Wxy, m_Wxz, m_Wyz;
00206 long m_Muncx, m_Muncy, m_Muncz;
00207
00208 long m_NumberOfTriangles;
00209 };
00210
00211 }
00212
00213 #ifndef ITK_MANUAL_INSTANTIATION
00214 #include "itkSimplexMeshVolumeCalculator.txx"
00215 #endif
00216
00217 #endif