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
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00033
00034
00035 Ball *ball_;
00036
00037
00038
00039
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() { }
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