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);
00156 
00158   itkNewMacro(Self);  
00159 
00161   itkTypeMacro(AutomaticTopologyMeshSource, MeshSource);
00162 
00164   IdentifierType AddPoint( const PointType& p0 );
00165   IdentifierType AddPoint( const CoordinateType* p0);
00167 
00173   IdentifierType AddPoint( CoordinateType x0 = 0, CoordinateType x1 = 0,
00174                            CoordinateType x2 = 0, CoordinateType x3 = 0,
00175                            CoordinateType x4 = 0, CoordinateType x5 = 0 );
00176 
00178   IdentifierType AddVertex( const IdentifierArrayType& pointIds );
00179   IdentifierType AddVertex( IdentifierType pointId0 );
00180   IdentifierType AddVertex( const PointType& p0 );
00181   IdentifierType AddVertex( const CoordinateType* p0);
00183 
00188   IdentifierType AddLine( const IdentifierArrayType& pointIds );
00189   IdentifierType AddLine(
00190     IdentifierType pointId0, IdentifierType pointId1 );
00191   IdentifierType AddLine( const PointType& p0, const PointType& p1 );
00192   IdentifierType AddLine( const CoordinateType* p0,
00193                           const CoordinateType* p1);
00195 
00206   IdentifierType AddTriangle(      const IdentifierArrayType& pointIds );
00207   IdentifierType AddTriangle(
00208     IdentifierType pointId0, IdentifierType pointId1,
00209     IdentifierType pointId2 );
00210   IdentifierType AddTriangle( const PointType& p0, const PointType& p1,
00211                               const PointType& p2 );
00212   IdentifierType AddTriangle( const CoordinateType* p0,
00213                               const CoordinateType* p1,
00214                               const CoordinateType* p2);
00216 
00237   IdentifierType AddQuadrilateral( const IdentifierArrayType& pointIds );
00238   IdentifierType AddQuadrilateral(
00239     IdentifierType pointId0, IdentifierType pointId1,
00240     IdentifierType pointId2, IdentifierType pointId3 );
00241   IdentifierType AddQuadrilateral( const PointType& p0, const PointType& p1,
00242                                    const PointType& p2, const PointType& p3 );
00243   IdentifierType AddQuadrilateral( const CoordinateType* p0,
00244                                    const CoordinateType* p1,
00245                                    const CoordinateType* p2,
00246                                    const CoordinateType* p3);
00247 
00260   IdentifierType AddTetrahedron(   const IdentifierArrayType& pointIds );
00261   IdentifierType AddTetrahedron(
00262     IdentifierType pointId0, IdentifierType pointId1,
00263     IdentifierType pointId2, IdentifierType pointId3 );
00264   IdentifierType AddTetrahedron( const PointType& p0, const PointType& p1,
00265                                  const PointType& p2, const PointType& p3 );
00266   IdentifierType AddTetrahedron( const CoordinateType* p0,
00267                                  const CoordinateType* p1,
00268                                  const CoordinateType* p2,
00269                                  const CoordinateType* p3);
00271 
00300   IdentifierType AddHexahedron(    const IdentifierArrayType& pointIds );
00301   IdentifierType AddHexahedron(
00302     IdentifierType pointId0, IdentifierType pointId1,
00303     IdentifierType pointId2, IdentifierType pointId3,
00304     IdentifierType pointId4, IdentifierType pointId5,
00305     IdentifierType pointId6, IdentifierType pointId7 );
00306   IdentifierType AddHexahedron(
00307     const PointType& p0, const PointType& p1, const PointType& p2,
00308     const PointType& p3, const PointType& p4, const PointType& p5,
00309     const PointType& p6, const PointType& p7
00310     );
00311   IdentifierType AddHexahedron( const CoordinateType* p0,
00312                                 const CoordinateType* p1,
00313                                 const CoordinateType* p2,
00314                                 const CoordinateType* p3,
00315                                 const CoordinateType* p4,
00316                                 const CoordinateType* p5,
00317                                 const CoordinateType* p6,
00318                                 const CoordinateType* p7);
00320 
00321 
00322   class IdentifierArrayHashFunction
00323   {
00324   public:
00325     unsigned long operator()( Array< unsigned long > identifierArray) const
00326     {
00327       typedef unsigned long Ulong;
00328 
00329       Ulong size = identifierArray.Size();
00330 
00331       std::sort( identifierArray.begin(), identifierArray.end() );
00332 
00333       Ulong hash = 0;
00334       Ulong* id = &identifierArray[ 0 ];
00335 
00336       while( size-- )
00337         {
00338         hash += *id++;
00339         hash = (hash << 7) | (hash >> 25); // Rotate left by 7.
00340         }
00341 
00342       return hash;
00343     }
00344   };
00345 
00346   class IdentifierArrayEqualsFunction
00347   {
00348   public:
00349     bool operator()(
00350       Array< unsigned long > identifierArray1,
00351       Array< unsigned long > identifierArray2
00352       ) const
00353     {
00354       typedef unsigned long Ulong;
00355 
00356       
00357       Ulong size1 = identifierArray1.Size();
00358       Ulong size2 = identifierArray2.Size();
00359 
00360       if( size1 != size2 )
00361         {
00362         return false;
00363         }
00364 
00365       std::sort( identifierArray1.begin(), identifierArray1.end() );
00366       std::sort( identifierArray2.begin(), identifierArray2.end() );
00367 
00368       return ( identifierArray1 == identifierArray2 );
00369 
00370     }
00371 
00372   };
00373 
00374 
00375 
00376 protected:
00377   AutomaticTopologyMeshSource();
00378   ~AutomaticTopologyMeshSource();
00379 
00380   void GenerateData() {}; // GenerateData is a no-op, since the entries 
00381                           // are controlled manually
00382 
00383 private:
00384   AutomaticTopologyMeshSource(const Self&);  //purposely not implemented
00385   void operator=(const Self&);               //purposely not implemented
00386 
00387   typedef itk::hash_map<
00388     Array< IdentifierType >,
00389     IdentifierType,
00390     IdentifierArrayHashFunction,
00391     IdentifierArrayEqualsFunction >          CellHashMap;
00392 
00393   PointHashMap m_PointsHashTable;
00394   CellHashMap  m_CellsHashTable;
00395   MeshPointer  m_OutputMesh;   // Retained for convenience.
00396   
00397 };
00398 
00399 } // end namespace itk
00400 
00401 #ifndef ITK_MANUAL_INSTANTIATION
00402 #include "itkAutomaticTopologyMeshSource.txx"
00403 #endif
00404 
00405 #endif // __itkAutomaticTopologyMeshSource_h
00406 

Generated at Sun Mar 11 23:28:35 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000