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: 2007-12-21 15:25:33 $
00007   Version:   $Revision: 1.16 $
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::PointHashType   PointHashType;
00123   typedef typename MeshType::PointType       PointType;
00124   typedef typename MeshType::CellType        CellType;
00125   typedef typename MeshType::Pointer         MeshPointer;
00126   typedef typename PointType::CoordRepType   CoordinateType;
00127   typedef typename CellType::CellAutoPointer CellAutoPointer;
00128 
00130   typedef VertexCell< CellType >             VertexCell;
00131   typedef LineCell< CellType >               LineCell;
00132   typedef TriangleCell< CellType >           TriangleCell;
00133   typedef QuadrilateralCell< CellType >      QuadrilateralCell;
00134   typedef TetrahedronCell< CellType >        TetrahedronCell;
00135   typedef HexahedronCell< CellType >         HexahedronCell;
00136 
00139   typedef unsigned long IdentifierType;
00140 
00142   typedef Array< IdentifierType >              IdentifierArrayType;
00143 
00146   typedef itk::hash_map<
00147     PointType,
00148     IdentifierType,
00149     StructHashFunction< PointHashType > >          PointHashMap;
00150 
00152   itkStaticConstMacro(PointDimension, unsigned int,
00153                       MeshType::PointDimension);
00154   itkStaticConstMacro(MaxTopologicalDimension, unsigned int,
00155                       MeshType::MaxTopologicalDimension);
00157 
00159   itkNewMacro(Self);  
00160 
00162   itkTypeMacro(AutomaticTopologyMeshSource, MeshSource);
00163 
00165   IdentifierType AddPoint( const PointType& p0 );
00166   IdentifierType AddPoint( const CoordinateType* p0);
00168 
00174   IdentifierType AddPoint( CoordinateType x0 = 0, CoordinateType x1 = 0,
00175                            CoordinateType x2 = 0, CoordinateType x3 = 0,
00176                            CoordinateType x4 = 0, CoordinateType x5 = 0 );
00177 
00179   IdentifierType AddVertex( const IdentifierArrayType& pointIds );
00180   IdentifierType AddVertex( IdentifierType pointId0 );
00181   IdentifierType AddVertex( const PointType& p0 );
00182   IdentifierType AddVertex( const CoordinateType* p0);
00184 
00189   IdentifierType AddLine( const IdentifierArrayType& pointIds );
00190   IdentifierType AddLine(
00191     IdentifierType pointId0, IdentifierType pointId1 );
00192   IdentifierType AddLine( const PointType& p0, const PointType& p1 );
00193   IdentifierType AddLine( const CoordinateType* p0,
00194                           const CoordinateType* p1);
00196 
00207   IdentifierType AddTriangle(      const IdentifierArrayType& pointIds );
00208   IdentifierType AddTriangle(
00209     IdentifierType pointId0, IdentifierType pointId1,
00210     IdentifierType pointId2 );
00211   IdentifierType AddTriangle( const PointType& p0, const PointType& p1,
00212                               const PointType& p2 );
00213   IdentifierType AddTriangle( const CoordinateType* p0,
00214                               const CoordinateType* p1,
00215                               const CoordinateType* p2);
00217 
00238   IdentifierType AddQuadrilateral( const IdentifierArrayType& pointIds );
00239   IdentifierType AddQuadrilateral(
00240     IdentifierType pointId0, IdentifierType pointId1,
00241     IdentifierType pointId2, IdentifierType pointId3 );
00242   IdentifierType AddQuadrilateral( const PointType& p0, const PointType& p1,
00243                                    const PointType& p2, const PointType& p3 );
00244   IdentifierType AddQuadrilateral( const CoordinateType* p0,
00245                                    const CoordinateType* p1,
00246                                    const CoordinateType* p2,
00247                                    const CoordinateType* p3);
00248 
00261   IdentifierType AddTetrahedron(   const IdentifierArrayType& pointIds );
00262   IdentifierType AddTetrahedron(
00263     IdentifierType pointId0, IdentifierType pointId1,
00264     IdentifierType pointId2, IdentifierType pointId3 );
00265   IdentifierType AddTetrahedron( const PointType& p0, const PointType& p1,
00266                                  const PointType& p2, const PointType& p3 );
00267   IdentifierType AddTetrahedron( const CoordinateType* p0,
00268                                  const CoordinateType* p1,
00269                                  const CoordinateType* p2,
00270                                  const CoordinateType* p3);
00272 
00301   IdentifierType AddHexahedron(    const IdentifierArrayType& pointIds );
00302   IdentifierType AddHexahedron(
00303     IdentifierType pointId0, IdentifierType pointId1,
00304     IdentifierType pointId2, IdentifierType pointId3,
00305     IdentifierType pointId4, IdentifierType pointId5,
00306     IdentifierType pointId6, IdentifierType pointId7 );
00307   IdentifierType AddHexahedron(
00308     const PointType& p0, const PointType& p1, const PointType& p2,
00309     const PointType& p3, const PointType& p4, const PointType& p5,
00310     const PointType& p6, const PointType& p7
00311     );
00312   IdentifierType AddHexahedron( const CoordinateType* p0,
00313                                 const CoordinateType* p1,
00314                                 const CoordinateType* p2,
00315                                 const CoordinateType* p3,
00316                                 const CoordinateType* p4,
00317                                 const CoordinateType* p5,
00318                                 const CoordinateType* p6,
00319                                 const CoordinateType* p7);
00321 
00322 
00323   class IdentifierArrayHashFunction
00324     {
00325   public:
00326     unsigned long operator()( Array< unsigned long > identifierArray) const
00327       {
00328       typedef unsigned long Ulong;
00329 
00330       Ulong size = identifierArray.Size();
00331 
00332       std::sort( identifierArray.begin(), identifierArray.end() );
00333 
00334       Ulong hash = 0;
00335       Ulong* id = &identifierArray[ 0 ];
00336 
00337       while( size-- )
00338         {
00339         hash += *id++;
00340         hash = (hash << 7) | (hash >> 25); // Rotate left by 7.
00341         }
00342 
00343       return hash;
00344       }
00345     };
00346 
00347   class IdentifierArrayEqualsFunction
00348     {
00349   public:
00350     bool operator()(
00351       Array< unsigned long > identifierArray1,
00352       Array< unsigned long > identifierArray2
00353       ) const
00354       {
00355       typedef unsigned long Ulong;
00356 
00357       
00358       Ulong size1 = identifierArray1.Size();
00359       Ulong size2 = identifierArray2.Size();
00360 
00361       if( size1 != size2 )
00362         {
00363         return false;
00364         }
00365 
00366       std::sort( identifierArray1.begin(), identifierArray1.end() );
00367       std::sort( identifierArray2.begin(), identifierArray2.end() );
00368 
00369       return ( identifierArray1 == identifierArray2 );
00370       }
00371 
00372     };
00373 
00374 protected:
00375   AutomaticTopologyMeshSource();
00376   ~AutomaticTopologyMeshSource();
00377 
00378   void GenerateData() {}; // GenerateData is a no-op, since the entries 
00379                           // are controlled manually
00380 
00381 private:
00382   AutomaticTopologyMeshSource(const Self&);  //purposely not implemented
00383   void operator=(const Self&);               //purposely not implemented
00384 
00385   typedef itk::hash_map<
00386     Array< IdentifierType >,
00387     IdentifierType,
00388     IdentifierArrayHashFunction,
00389     IdentifierArrayEqualsFunction >          CellHashMap;
00390 
00391   PointHashMap m_PointsHashTable;
00392   CellHashMap  m_CellsHashTable;
00393   MeshPointer  m_OutputMesh;   // Retained for convenience.
00394   
00395 };
00396 
00397 } // end namespace itk
00398 
00399 #ifndef ITK_MANUAL_INSTANTIATION
00400 #include "itkAutomaticTopologyMeshSource.txx"
00401 #endif
00402 
00403 #endif // __itkAutomaticTopologyMeshSource_h
00404 

Generated at Mon Apr 14 11:36:56 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000