a48  2.0.2
include/adaptivepolicies.hh
Go to the documentation of this file.
00001 
00008 #ifndef A48_ADAPTIVE_POLICIES_HH
00009 #define A48_ADAPTIVE_POLICIES_HH
00010 
00011 //== INCLUDES =================================================================
00012 
00013 #include <limits>
00014 
00015 #include <adaptivemesht.hh>
00016 
00017 //== NAMESPACES ===============================================================
00018 
00019 namespace a48 {
00020 
00021 //== CLASS DEFINITION =========================================================
00022 
00034 template< class Traits = DefaultAdaptiveTraits >
00035 class ContainerBasedAP : public virtual BaseAdaptivePolicy< Traits > {
00036 
00037     typedef typename Traits::vertex_type vertex_type; 
00038     typedef typename Traits::halfedge_type halfedge_type; 
00039     typedef typename Traits::face_type face_type; 
00040 
00041     typedef AdaptiveMeshT< Traits > mesh_type; 
00042     typedef typename mesh_type::vertex_iterator vertex_iterator; 
00043     typedef typename mesh_type::halfedge_iterator halfedge_iterator; 
00044 
00045     typedef typename std::set< vertex_type* > simplification_container; 
00046     typedef typename std::set< halfedge_type* > refinement_container; 
00047 
00048     typedef typename simplification_container::iterator simplification_iterator; 
00049     typedef typename refinement_container::iterator refinement_iterator; 
00050 
00051 public:
00052 
00056     ContainerBasedAP( mesh_type *_m = 0 ) : m(_m) { }
00057 
00061     void set_mesh( mesh_type *_m ) { m = _m; }
00062 
00066     mesh_type* get_mesh( void ) { return m; }
00067 
00071     virtual void update_simplification( void ) {
00072         s.clear();
00073         for (vertex_iterator vit = m->vertices_begin(); vit != m->vertices_end(); ++vit)
00074             if( needs_simplification( *vit ) )
00075                 s.insert( *vit );
00076     }
00077 
00081     virtual void update_refinement( void ) {
00082         r.clear();
00083         for (halfedge_iterator hit = m->halfedges_begin(); hit != m->halfedges_end(); ++hit)
00084             if( (*hit)->is_split() and (*hit)->opposite() < (*hit) and needs_refinement( *hit ) )
00085                 r.insert( *hit );
00086     }
00087 
00092     virtual vertex_type* next_simplify_vertex( void ) {
00093         if( s.empty() ) return 0;
00094         vertex_type *v = *s.begin();
00095         s.erase(v);
00096         return v;
00097     }
00098 
00103     virtual halfedge_type* next_refine_halfedge( void ){
00104         if( r.empty() ) return 0;
00105         halfedge_type *h = *r.begin();
00106         r.erase(h);
00107         return h;
00108     }
00109 
00114     virtual void update_simplification( vertex_type *v ) {
00115         s.erase( v );
00116         for (halfedge_type *h = v->halfedge(); h != 0; h = v->star_next(h)) {
00117             r.erase( h );
00118             if( !h->is_boundary() )
00119                 r.erase( h->opposite() );
00120         }
00121     }
00122 
00127     virtual void update_simplification( halfedge_type *h ) {
00128         if( h->opposite() < h and needs_refinement( h ) )
00129             r.insert( h );
00130         vertex_type *v = h->next()->vertex();
00131         if( h->face()->weld_vertex() == v and needs_simplification(v) )
00132             s.insert( v );
00133         if( h->is_boundary() ) return;
00134         v = h->opposite()->next()->vertex();
00135         if( h->opposite()->face()->weld_vertex() == v and needs_simplification(v) )
00136             s.insert( v );
00137     }
00138 
00143     virtual void update_refinement( halfedge_type *h ) {
00144         r.erase( h );
00145         s.erase( h->next()->vertex() );
00146         if( !h->is_boundary() )
00147             s.erase( h->opposite()->next()->vertex() );
00148     }
00149 
00154     virtual void update_refinement( vertex_type *v ) {
00155         if( needs_simplification(v) )
00156             s.insert( v );
00157         for (halfedge_type *hcurr = v->halfedge(); hcurr != 0; hcurr = v->star_next(hcurr)) {
00158             halfedge_type *h = hcurr->previous();
00159             if( h->is_split() and h->opposite() < h and needs_refinement(h) )
00160                 r.insert( h );
00161         }
00162     }
00163 
00164 protected:
00165 
00175     virtual bool needs_simplification( vertex_type *v ) = 0;
00176 
00186     virtual bool needs_refinement( halfedge_type *h ) = 0;
00187 
00188 private:
00189 
00190     simplification_container s; 
00191     refinement_container r; 
00192 
00193     mesh_type *m; 
00194 
00195 };
00202 //== CLASS DEFINITION =========================================================
00203 
00212 template< class Traits >
00213 class UniformLevelAP : public ContainerBasedAP< Traits > {
00214 
00215     typedef typename Traits::vertex_type vertex_type; 
00216     typedef typename Traits::halfedge_type halfedge_type; 
00217     typedef typename Traits::face_type face_type; 
00218 
00219     typedef AdaptiveMeshT< Traits > mesh_type; 
00220 
00221 public:
00222 
00227     UniformLevelAP( mesh_type *_m = 0,
00228                     const unsigned int& _tl = 0 ) : ContainerBasedAP< Traits >( _m ), tl( _tl ) { }
00229 
00233     void set_target_level( const unsigned int& _tl ) { tl = _tl; }
00234 
00238     unsigned int get_target_level( void ) const { return tl; }
00239 
00243     void inc_target_level( const unsigned int& _max = std::numeric_limits<unsigned int>::max() ) { if( tl < _max ) ++tl; }
00244 
00248     void dec_target_level( const unsigned int& _min = 0 ) { if( tl > _min ) --tl; }
00249 
00250 protected:
00251 
00257     bool needs_simplification( vertex_type *v ) {
00258         return v->level() > tl;
00259     }
00260 
00266     bool needs_refinement( halfedge_type *h ) {
00267         return h->next()->vertex()->level() < tl;
00268     }
00269 
00270 private:
00271 
00272     unsigned int tl; 
00273 
00274 };
00275 
00276 //== CLASS DEFINITION =========================================================
00277 
00288 template< class Traits >
00289 class RangeLevelAP : public ContainerBasedAP< Traits > {
00290 
00291     typedef typename Traits::vertex_type vertex_type; 
00292     typedef typename Traits::halfedge_type halfedge_type; 
00293     typedef typename Traits::face_type face_type; 
00294 
00295     typedef AdaptiveMeshT< Traits > mesh_type; 
00296 
00297 public:
00298 
00305     RangeLevelAP( mesh_type *_m,
00306                   float (*_fp)( vertex_type* ),
00307                   const unsigned int& _minl,
00308                   const unsigned int& _maxl ) : ContainerBasedAP< Traits >( _m ), fp( _fp ),
00309                                                 minl( _minl ), maxl( _maxl ) { }
00310 
00314     void set_min_level( const unsigned int& _minl ) { minl = _minl; }
00315 
00319     unsigned int get_min_level( void ) const { return minl; }
00320 
00324     void set_max_level( const unsigned int& _maxl ) { maxl = _maxl; }
00325 
00329     unsigned int get_max_level( void ) const { return maxl; }
00330 
00334     void inc_min_level( const unsigned int& _max = std::numeric_limits<unsigned int>::max() ) { if( minl < _max ) ++minl; }
00335 
00339     void dec_min_level( const unsigned int& _min = 0 ) { if( minl > _min ) --minl; }
00340 
00344     void inc_max_level( const unsigned int& _max = std::numeric_limits<unsigned int>::max() ) { if( maxl < _max ) ++maxl; }
00345 
00349     void dec_max_level( const unsigned int& _min = 0 ) { if( maxl > _min ) --maxl; }
00350 
00351 protected:
00352 
00357     inline unsigned int target_level( vertex_type *v ) const {
00358         float t = fp(v);
00359         return (unsigned int)( t * maxl + (1.f - t) * minl );
00360     }
00361 
00367     bool needs_simplification( vertex_type *v ) {
00368         return v->level() > target_level(v);
00369     }
00370 
00376     bool needs_refinement( halfedge_type *h ) {
00377         return h->next()->vertex()->level() < target_level(h->next()->vertex());
00378     }
00379 
00380 private:
00381 
00382     float (*fp)( vertex_type* ); 
00383     unsigned int minl, maxl; 
00384 
00385 };
00386 
00387 //=============================================================================
00388 } // namespace a48
00389 //=============================================================================
00390 #endif // A48_ADAPTIVEPOLICIES_HH
00391 //=============================================================================
 All Classes Namespaces Files Functions Typedefs