dune-grid
2.1.1
|
00001 #ifndef DUNE_GEOGRID_INTERSECTIONITERATOR_HH 00002 #define DUNE_GEOGRID_INTERSECTIONITERATOR_HH 00003 00004 #include <dune/grid/geometrygrid/entitypointer.hh> 00005 #include <dune/grid/geometrygrid/intersection.hh> 00006 00007 namespace Dune 00008 { 00009 00010 // External Forward Declataions 00011 // ---------------------------- 00012 00013 namespace GeoGrid 00014 { 00015 00016 // Internal Forward Declarations 00017 // ----------------------------- 00018 00019 template< class Grid > 00020 class LeafIntersectionIterator; 00021 00022 template< class Grid > 00023 class LevelIntersectionIterator; 00024 00025 00026 00027 // IntersectionIterator 00028 // -------------------- 00029 00030 template< class Traits > 00031 class IntersectionIterator 00032 { 00033 typedef typename Traits::HostIntersectionIterator HostIntersectionIterator; 00034 00035 typedef typename Traits::GridTraits GridTraits; 00036 00037 public: 00038 typedef typename Traits::Intersection Intersection; 00039 typedef typename GridTraits::Grid Grid; 00040 00041 typedef typename GridTraits::template Codim< 0 >::EntityPointer EntityPointer; 00042 00043 private: 00044 typedef typename Traits::IntersectionImpl IntersectionImpl; 00045 00046 typedef typename GridTraits::template Codim< 0 >::EntityPointerImpl EntityPointerImpl; 00047 typedef typename GridTraits::template Codim< 0 >::Geometry ElementGeometry; 00048 00049 public: 00050 template< class Entity > 00051 IntersectionIterator ( const Entity &inside, 00052 const HostIntersectionIterator &hostIterator ) 00053 : hostIterator_( hostIterator ), 00054 intersection_( IntersectionImpl( inside.grid(), inside.geometry() ) ) 00055 {} 00056 00057 IntersectionIterator ( const IntersectionIterator &other ) 00058 : hostIterator_( other.hostIterator_ ), 00059 intersection_( IntersectionImpl( Grid::getRealImplementation( other.intersection_ ) ) ) 00060 {} 00061 00062 IntersectionIterator &operator= ( const IntersectionIterator &other ) 00063 { 00064 hostIterator_ = other.hostIterator_; 00065 Grid::getRealImplementation( intersection_ ) = Grid::getRealImplementation( other.intersection_ ); 00066 return *this; 00067 } 00068 00069 bool equals ( const IntersectionIterator &other ) const 00070 { 00071 return (hostIterator_ == other.hostIterator_); 00072 } 00073 00074 void increment () 00075 { 00076 ++hostIterator_; 00077 intersectionImpl().invalidate(); 00078 } 00079 00080 const Intersection &dereference () const 00081 { 00082 if( !intersectionImpl() ) 00083 intersectionImpl().initialize( *hostIterator_ ); 00084 return intersection_; 00085 } 00086 00087 private: 00088 IntersectionImpl &intersectionImpl () const 00089 { 00090 return Grid::getRealImplementation( intersection_ ); 00091 } 00092 00093 HostIntersectionIterator hostIterator_; 00094 mutable Intersection intersection_; 00095 }; 00096 00097 00098 00099 // LeafIntersectionIteratorTraits 00100 // ------------------------------ 00101 00102 template< class Grid > 00103 struct LeafIntersectionIteratorTraits 00104 { 00105 typedef typename remove_const< Grid >::type::Traits GridTraits; 00106 00107 typedef typename GridTraits::LeafIntersection Intersection; 00108 typedef LeafIntersection< const Grid > IntersectionImpl; 00109 00110 typedef typename GridTraits::HostGrid::Traits::LeafIntersectionIterator 00111 HostIntersectionIterator; 00112 }; 00113 00114 00115 00116 // LeafIntersectionIterator 00117 // ------------------------ 00118 00119 template< class Grid > 00120 class LeafIntersectionIterator 00121 : public IntersectionIterator< LeafIntersectionIteratorTraits< Grid > > 00122 { 00123 typedef LeafIntersectionIteratorTraits< Grid > Traits; 00124 typedef IntersectionIterator< Traits > Base; 00125 00126 typedef typename Traits :: HostIntersectionIterator HostIntersectionIterator; 00127 00128 public: 00129 typedef typename Traits :: Intersection Intersection; 00130 00131 public: 00132 template< class Entity > 00133 LeafIntersectionIterator ( const Entity &inside, 00134 const HostIntersectionIterator &hostIterator ) 00135 : Base( inside, hostIterator ) 00136 {} 00137 }; 00138 00139 00140 00141 // LevelIntersectionIteratorTraits 00142 // ------------------------------- 00143 00144 template< class Grid > 00145 struct LevelIntersectionIteratorTraits 00146 { 00147 typedef typename remove_const< Grid >::type::Traits GridTraits; 00148 00149 typedef typename GridTraits::LevelIntersection Intersection; 00150 typedef LevelIntersection< const Grid > IntersectionImpl; 00151 00152 typedef typename GridTraits::HostGrid::Traits::LevelIntersectionIterator 00153 HostIntersectionIterator; 00154 }; 00155 00156 00157 00158 // LevelIntersectionIterator 00159 // ------------------------- 00160 00161 template< class Grid > 00162 class LevelIntersectionIterator 00163 : public IntersectionIterator< LevelIntersectionIteratorTraits< Grid > > 00164 { 00165 typedef LevelIntersectionIteratorTraits< Grid > Traits; 00166 typedef IntersectionIterator< Traits > Base; 00167 00168 typedef typename Traits :: HostIntersectionIterator HostIntersectionIterator; 00169 00170 public: 00171 typedef typename Traits :: Intersection Intersection; 00172 00173 public: 00174 template< class Entity > 00175 LevelIntersectionIterator ( const Entity &inside, 00176 const HostIntersectionIterator &hostIterator ) 00177 : Base( inside, hostIterator ) 00178 {} 00179 }; 00180 00181 } 00182 00183 } 00184 00185 #endif // #ifndef DUNE_GEOGRID_INTERSECTIONITERATOR_HH