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: 2005/01/21 20:18:10 $
00007 Version:   $Revision: 1.3 $
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 __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   // 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 
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&); //purposely not implemented
00184   void operator=(const Self&); //purposely not implemented
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 } //end of namespace
00212 
00213 #ifndef ITK_MANUAL_INSTANTIATION
00214 #include "itkSimplexMeshVolumeCalculator.txx"
00215 #endif
00216 
00217 #endif /* __SimplexMeshVolumeCalculator_h */

Generated at Thu May 25 00:04:41 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000