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);
00128
00129 while ( it != poly->PointIdsEnd() )
00130 {
00131 m_Mesh->GetPoint(*it, &p);
00132 center += p.GetVectorFromOrigin();
00133 it++;
00134 }
00135
00136 center[0] /= poly->GetNumberOfPoints();
00137 center[1] /= poly->GetNumberOfPoints();
00138 center[2] /= poly->GetNumberOfPoints();
00139
00140 m_CenterMap->InsertElement(cellId, center);
00141 }
00142
00143 PointMapPointer GetCenterMap()
00144 {
00145 return m_CenterMap;
00146 }
00147
00148 void SetMesh(InputMeshPointer mesh)
00149 {
00150 m_Mesh = mesh;
00151 }
00152
00153 protected:
00154 InputMeshPointer m_Mesh;
00155 PointMapPointer m_CenterMap;
00156 };
00157
00158 typedef itk::CellInterfaceVisitorImplementation<InputPixelType,
00159 InputCellTraitsType,
00160 SimplexPolygonType,
00161 SimplexCellVisitor>
00162 SimplexVisitorInterfaceType;
00163
00164 typedef typename SimplexVisitorInterfaceType::Pointer SimplexVisitorInterfacePointer;
00165 typedef typename SimplexCellType::MultiVisitor CellMultiVisitorType;
00166 typedef typename CellMultiVisitorType::Pointer CellMultiVisitorPointer;
00167
00169 itkSetObjectMacro(SimplexMesh, InputMeshType);
00170
00172 void Compute(void);
00173
00175 itkGetConstMacro(Volume, double);
00176
00178 itkGetConstMacro(Area, double);
00179
00180 protected:
00181 SimplexMeshVolumeCalculator();
00182 virtual ~SimplexMeshVolumeCalculator();
00183 void PrintSelf(std::ostream& os, Indent indent) const;
00184
00185 private:
00186 SimplexMeshVolumeCalculator(const Self&);
00187 void operator=(const Self&);
00188
00189 void Initialize();
00190 void Finalize();
00191
00193 void CreateTriangles();
00194
00196 void CalculateTriangleVolume(InputPointType p1, InputPointType p2, InputPointType p3);
00197
00199 unsigned long FindCellId(unsigned long id1, unsigned long id2, unsigned long id3);
00200
00202 PointMapPointer m_Centers;
00203
00204 InputMeshPointer m_SimplexMesh;
00205
00206 double m_Volume;
00207 double m_VolumeX;
00208 double m_VolumeY;
00209 double m_VolumeZ;
00210 double m_Area;
00211 double m_Kx;
00212 double m_Ky;
00213 double m_Kz;
00214 double m_Wxyz;
00215 double m_Wxy;
00216 double m_Wxz;
00217 double m_Wyz;
00218 long m_Muncx;
00219 long m_Muncy;
00220 long m_Muncz;
00221
00222 long m_NumberOfTriangles;
00223 };
00224
00225 }
00226
00227 #ifndef ITK_MANUAL_INSTANTIATION
00228 #include "itkSimplexMeshVolumeCalculator.txx"
00229 #endif
00230
00231 #endif
00232