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