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

itkAutomaticTopologyMeshSource.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkAutomaticTopologyMeshSource.h,v $
00005   Language:  C++
00006   Date:      $Date: 2005/07/26 15:05:01 $
00007   Version:   $Revision: 1.14 $
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 __itkAutomaticTopologyMeshSource_h
00018 #define __itkAutomaticTopologyMeshSource_h
00019 
00020 #include "itkArray.h"
00021 #include "itkDefaultStaticMeshTraits.h"
00022 #include "itk_hash_map.h"
00023 #include "itkHexahedronCell.h"
00024 #include "itkLineCell.h"
00025 #include "itkMesh.h"
00026 #include "itkMeshSource.h"
00027 #include "itkQuadrilateralCell.h"
00028 #include "itkStructHashFunction.h"
00029 #include "itkTriangleCell.h"
00030 #include "itkTetrahedronCell.h"
00031 #include "itkVertexCell.h"
00032 
00033 namespace itk
00034 {
00110 template <class TOutputMesh>
00111 class ITK_EXPORT AutomaticTopologyMeshSource : public MeshSource<TOutputMesh>
00112 {
00113 public:
00115   typedef AutomaticTopologyMeshSource   Self;
00116   typedef MeshSource<TOutputMesh>       Superclass;
00117   typedef SmartPointer<Self>            Pointer;
00118   typedef SmartPointer<const Self>      ConstPointer;
00119 
00121   typedef          TOutputMesh               MeshType;
00122   typedef typename MeshType::PointType       PointType;
00123   typedef typename MeshType::CellType        CellType;
00124   typedef typename MeshType::Pointer         MeshPointer;
00125   typedef typename PointType::CoordRepType   CoordinateType;
00126   typedef typename CellType::CellAutoPointer CellAutoPointer;
00127 
00129   typedef VertexCell< CellType >             VertexCell;
00130   typedef LineCell< CellType >               LineCell;
00131   typedef TriangleCell< CellType >           TriangleCell;
00132   typedef QuadrilateralCell< CellType >      QuadrilateralCell;
00133   typedef TetrahedronCell< CellType >        TetrahedronCell;
00134   typedef HexahedronCell< CellType >         HexahedronCell;
00135 
00138   typedef unsigned long IdentifierType;
00139 
00141   typedef Array< IdentifierType >              IdentifierArrayType;
00142 
00145   typedef itk::hash_map<
00146     PointType,
00147     IdentifierType,
00148     StructHashFunction< PointType > >          PointHashMap;
00149 
00151   itkStaticConstMacro(PointDimension, unsigned int,
00152                       MeshType::PointDimension);
00153   itkStaticConstMacro(MaxTopologicalDimension, unsigned int,
00154                       MeshType::MaxTopologicalDimension);
00155 
00157   itkNewMacro(Self);  
00158 
00160   itkTypeMacro(AutomaticTopologyMeshSource, MeshSource);
00161 
00163   IdentifierType AddPoint( const PointType& p0 );
00164   IdentifierType AddPoint( const CoordinateType* p0);
00165 
00171   IdentifierType AddPoint( CoordinateType x0 = 0, CoordinateType x1 = 0,
00172                            CoordinateType x2 = 0, CoordinateType x3 = 0,
00173                            CoordinateType x4 = 0, CoordinateType x5 = 0 );
00174 
00176   IdentifierType AddVertex( const IdentifierArrayType& pointIds );
00177   IdentifierType AddVertex( IdentifierType pointId0 );
00178   IdentifierType AddVertex( const PointType& p0 );
00179   IdentifierType AddVertex( const CoordinateType* p0);
00180 
00185   IdentifierType AddLine( const IdentifierArrayType& pointIds );
00186   IdentifierType AddLine(
00187     IdentifierType pointId0, IdentifierType pointId1 );
00188   IdentifierType AddLine( const PointType& p0, const PointType& p1 );
00189   IdentifierType AddLine( const CoordinateType* p0,
00190                           const CoordinateType* p1);
00191 
00202   IdentifierType AddTriangle(      const IdentifierArrayType& pointIds );
00203   IdentifierType AddTriangle(
00204     IdentifierType pointId0, IdentifierType pointId1,
00205     IdentifierType pointId2 );
00206   IdentifierType AddTriangle( const PointType& p0, const PointType& p1,
00207                               const PointType& p2 );
00208   IdentifierType AddTriangle( const CoordinateType* p0,
00209                               const CoordinateType* p1,
00210                               const CoordinateType* p2);
00211 
00232   IdentifierType AddQuadrilateral( const IdentifierArrayType& pointIds );
00233   IdentifierType AddQuadrilateral(
00234     IdentifierType pointId0, IdentifierType pointId1,
00235     IdentifierType pointId2, IdentifierType pointId3 );
00236   IdentifierType AddQuadrilateral( const PointType& p0, const PointType& p1,
00237                                    const PointType& p2, const PointType& p3 );
00238   IdentifierType AddQuadrilateral( const CoordinateType* p0,
00239                                    const CoordinateType* p1,
00240                                    const CoordinateType* p2,
00241                                    const CoordinateType* p3);
00242 
00255   IdentifierType AddTetrahedron(   const IdentifierArrayType& pointIds );
00256   IdentifierType AddTetrahedron(
00257     IdentifierType pointId0, IdentifierType pointId1,
00258     IdentifierType pointId2, IdentifierType pointId3 );
00259   IdentifierType AddTetrahedron( const PointType& p0, const PointType& p1,
00260                                  const PointType& p2, const PointType& p3 );
00261   IdentifierType AddTetrahedron( const CoordinateType* p0,
00262                                  const CoordinateType* p1,
00263                                  const CoordinateType* p2,
00264                                  const CoordinateType* p3);
00265 
00294   IdentifierType AddHexahedron(    const IdentifierArrayType& pointIds );
00295   IdentifierType AddHexahedron(
00296     IdentifierType pointId0, IdentifierType pointId1,
00297     IdentifierType pointId2, IdentifierType pointId3,
00298     IdentifierType pointId4, IdentifierType pointId5,
00299     IdentifierType pointId6, IdentifierType pointId7 );
00300   IdentifierType AddHexahedron(
00301     const PointType& p0, const PointType& p1, const PointType& p2,
00302     const PointType& p3, const PointType& p4, const PointType& p5,
00303     const PointType& p6, const PointType& p7
00304     );
00305   IdentifierType AddHexahedron( const CoordinateType* p0,
00306                                 const CoordinateType* p1,
00307                                 const CoordinateType* p2,
00308                                 const CoordinateType* p3,
00309                                 const CoordinateType* p4,
00310                                 const CoordinateType* p5,
00311                                 const CoordinateType* p6,
00312                                 const CoordinateType* p7);
00313 
00314 
00315   class IdentifierArrayHashFunction
00316   {
00317   public:
00318     unsigned long operator()( Array< unsigned long > identifierArray) const
00319     {
00320       typedef unsigned long Ulong;
00321 
00322       Ulong size = identifierArray.Size();
00323 
00324       std::sort( identifierArray.begin(), identifierArray.end() );
00325 
00326       Ulong hash = 0;
00327       Ulong* id = &identifierArray[ 0 ];
00328 
00329       while( size-- )
00330         {
00331         hash += *id++;
00332         hash = (hash << 7) | (hash >> 25); // Rotate left by 7.
00333         }
00334 
00335       return hash;
00336     }
00337   };
00338 
00339   class IdentifierArrayEqualsFunction
00340   {
00341   public:
00342     bool operator()(
00343       Array< unsigned long > identifierArray1,
00344       Array< unsigned long > identifierArray2
00345       ) const
00346     {
00347       typedef unsigned long Ulong;
00348 
00349       
00350       Ulong size1 = identifierArray1.Size();
00351       Ulong size2 = identifierArray2.Size();
00352 
00353       if( size1 != size2 )
00354         {
00355         return false;
00356         }
00357 
00358       std::sort( identifierArray1.begin(), identifierArray1.end() );
00359       std::sort( identifierArray2.begin(), identifierArray2.end() );
00360 
00361       return ( identifierArray1 == identifierArray2 );
00362 
00363     }
00364 
00365   };
00366 
00367 
00368 
00369 protected:
00370   AutomaticTopologyMeshSource();
00371   ~AutomaticTopologyMeshSource();
00372 
00373   void GenerateData() {}; // GenerateData is a no-op, since the entries 
00374                           // are controlled manually
00375 
00376 private:
00377   AutomaticTopologyMeshSource(const Self&);  //purposely not implemented
00378   void operator=(const Self&);               //purposely not implemented
00379 
00380   typedef itk::hash_map<
00381     Array< IdentifierType >,
00382     IdentifierType,
00383     IdentifierArrayHashFunction,
00384     IdentifierArrayEqualsFunction >          CellHashMap;
00385 
00386   PointHashMap m_PointsHashTable;
00387   CellHashMap  m_CellsHashTable;
00388   MeshPointer  m_OutputMesh;   // Retained for convenience.
00389   
00390 };
00391 
00392 } // end namespace itk
00393 
00394 #ifndef ITK_MANUAL_INSTANTIATION
00395 #include "itkAutomaticTopologyMeshSource.txx"
00396 #endif
00397 
00398 #endif // __itkAutomaticTopologyMeshSource_h

Generated at Wed May 24 22:47:13 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000