Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkSimplexMeshVolumeCalculator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003 Program:   Insight Segmentation & Registration Toolkit
00004 Module:    $RCSfile: itkSimplexMeshVolumeCalculator.h,v $
00005 Language:  C++
00006 Date:      $Date: 2009-06-10 12:07:17 $
00007 Version:   $Revision: 1.6 $
00008 
00009 Copyright (c) Insight Software Consortium. All rights reserved.
00010 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012 This software is distributed WITHOUT ANY WARRANTY; without even 
00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014 PURPOSE.  See the above copyright notices for more information.
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   // stores the center for each simplex mesh cell, key is the point id
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&); //purposely not implemented
00188   void operator=(const Self&); //purposely not implemented
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 } //end of namespace
00227 
00228 #ifndef ITK_MANUAL_INSTANTIATION
00229 #include "itkSimplexMeshVolumeCalculator.txx"
00230 #endif
00231 
00232 #endif /* __SimplexMeshVolumeCalculator_h */
00233 

Generated at Mon Jul 12 2010 19:54:47 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000