SimplexData.h

Go to the documentation of this file.
00001 #ifndef SimplexData_HEADER
00002 #define SimplexData_HEADER
00003 
00004 #ifdef HAVE_CONFIG_H
00005 # include <config.h>
00006 #endif
00007 
00008 #include "MeshTypes.h"
00009 #include <boost/foreach.hpp>
00010 #include <list>
00011 
00012 /***************************************************************************
00013  * Storage for the point location data needed by SVR.
00014  * We attach this to each simplex.  TODO: the information is better
00015  * stored in the vertices.
00016  *
00017  * This structure is fairly dumb; mostly it is just storage.
00018  *
00019  * TODO:
00020  * - if ambient == topological, there are no uppers to store
00021  * - if topological == 1, there are no lowers to store (just vertices)
00022  * It would be a SMOP to specialize the class for this.  This would almost halve
00023  * the overhead of each simplex (as of this writing, it is 60 bytes!)
00024  ***************************************************************************/
00025 template <size_t ambient, size_t topological>
00026 class SimplexData {
00027   typedef typename MeshTypes<ambient>::Vertex Vertex;
00028   typedef typename MeshTypes<ambient>::Ball Ball;
00029   typedef typename MeshTypes<ambient>::BallSet BallSet;
00030   typedef typename MeshTypes<ambient>::Point Point;
00031 
00032   // The ball is owned elsewhere, not here.  Important: the ball points to the
00033   // simplex whose data this is, so we can't here have a ref-counted pointer to
00034   // the ball, as that would make a loop.
00035   Ball *ball_;
00036 
00037   // TODO: these are a huge amount of storage!  Fixes:
00038   // (1) use a better list<> class (singly-linked, no size field)
00039   // (2) specialize for when there are no uppers/lowers (depends on dimension)
00040   BallSet uppers_;
00041   BallSet lowers_;
00042 
00043   public:
00044   typedef typename BallSet::const_iterator lower_it;
00045   typedef typename BallSet::const_iterator upper_it;
00046   typedef typename list<Vertex*>::const_iterator vertex_it;
00047 
00048   SimplexData() { ball_ = NULL; }
00049   ~SimplexData() { /* TODO: delete the ball. */ }
00050 
00058   Ball *toBall() const { return ball_; }
00059 
00063   void setBall(Ball *b) {
00064     assert(ball_ == NULL);
00065     ball_ = b;
00066     assert(ball_->topological() == topological);
00067   }
00068 
00071   bool isCrowded() const {
00072     BOUNDED_FOREACH(Vertex * v, ball_->begin_vertices(), ball_->end_vertices()) {
00073       if (v->template isCrowded<topological>()) {
00074         return true;
00075       }
00076     }
00077     return false;
00078   }
00079 
00084   Vertex *findWarpVertex(const Point& p, double& r2) const {
00085     Vertex *best = NULL;
00086 
00087     BOUNDED_FOREACH(Vertex * v, ball_->begin_vertices(), ball_->end_vertices()) {
00088       pair<Vertex*, double> p = v->findClosest(p, r2);
00089       r2 = p.second;
00090       best = p.first;
00091     }
00092     return best;
00093   }
00094 
00096   lower_it begin_lowers() const { return lowers_.begin(); }
00098   lower_it end_lowers() const { return lowers_.end(); }
00099 
00101   upper_it begin_uppers() const { return uppers_.begin(); }
00103   upper_it end_uppers() const { return uppers_.end(); }
00104 
00105 
00107   void removeLower(Ball *b) { assert(b->topological() < topological); lowers_.erase(b); }
00110   void blindlyAddLower(Ball *b) { assert(b->topological() < topological); lowers_.insert(b); }
00111 
00113   void removeUpper(Ball *b) { assert(b->topological() > topological); uppers_.erase(b); }
00116   void blindlyAddUpper(Ball *b) { assert(b->topological() > topological); uppers_.insert(b); }
00117 
00118   void unlink() {
00119     BOOST_FOREACH(Ball *lower, lowers_) {
00120       lower->removeUpper(ball_);
00121     }
00122     BOOST_FOREACH(Ball *upper, uppers_) {
00123       upper->removeLower(ball_);
00124     }
00125   }
00126 
00129   void gatherLowers(BallSet& output) const {
00130     output.insert(lowers_.begin(), lowers_.end());
00131   }
00132 
00135   void gatherUppers(BallSet& output) const {
00136     output.insert(uppers_.begin(), uppers_.end());
00137   }
00138 };
00139 
00140 #endif

Generated on Thu Mar 27 19:04:14 2008 by  doxygen 1.4.6