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:
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&); //purposely not implemented
00186   void operator=(const Self&); //purposely not implemented
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 } //end of namespace
00214 
00215 #ifndef ITK_MANUAL_INSTANTIATION
00216 #include "itkSimplexMeshVolumeCalculator.txx"
00217 #endif
00218 
00219 #endif /* __SimplexMeshVolumeCalculator_h */
00220 

Generated at Mon Mar 12 03:04:30 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000