00001 #ifndef PointRefineVertex_HEADER
00002 #define PointRefineVertex_HEADER
00003
00004 #ifdef HAVE_CONFIG_H
00005 # include <config.h>
00006 #endif
00007
00008 #include <geometry/Point.h>
00009 #include <delaunay/PointVertex.h>
00010 #include <utilities/IntrusiveList.h>
00011 #include <utilities/SmallList.h>
00012 #include <refine-common/ConcentricShells.h>
00013
00016
00017
00018 #if 0
00019 #define dprintf(...) printf(__VA_ARGS__);
00020 #define dputs(str) puts(str);
00021 #else
00022 #define dprintf(...)
00023 #define dputs(str)
00024 #endif
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 template <unsigned d, class Simplex>
00052 class PointRefineVertex : public PointVertex<d> {
00053
00054 typedef Geometry::Point<d> Point;
00055 typedef PointRefineVertex Uninserted;
00056
00057 public:
00058 PointRefineVertex(const Point& p, size_t ID = size_t(-1)) : PointVertex<d>(p) {
00059 visited_ = 0;
00060 inMesh_ = false;
00061 ID_ = ID;
00062 isSteiner_ = (ID == size_t(-1));
00063 #ifdef MAINTAIN_NN
00064 NN2_ = std::numeric_limits<double>::infinity();
00065 #endif
00066 }
00067
00068 ~PointRefineVertex() {
00069 if (inMesh()) {
00070 get().~Simplex();
00071 }
00072 }
00073
00074 #ifdef NDEBUG
00075 # define unused(sym)
00076 #else
00077 # define unused(sym) sym
00078 #endif
00079
00081 void *operator new(size_t unused(sz)) {
00082 assert(sz == sizeof(PointRefineVertex));
00083 return hudson::SmallMemoryPool::allocate<sizeof(PointRefineVertex)>();
00084 }
00085
00086 void *operator new(size_t unused(sz), void *ptr) {
00087 assert(sz == sizeof(PointRefineVertex));
00088 return ptr;
00089 }
00090
00092 void operator delete(void *v, size_t unused(sz)) {
00093 assert(sz == sizeof(PointRefineVertex));
00094 hudson::SmallMemoryPool::deallocate<sizeof(PointRefineVertex)>(v);
00095 }
00096 #undef unused
00097
00098
00099
00100
00101
00102 size_t id() const { return ID_; }
00103 bool isSteiner() const { return isSteiner_; }
00104 void setID(size_t i) { ID_ = i; }
00105
00106
00107
00108
00109 double dist2(const PointRefineVertex *other) const {
00110 return this->toPoint().dist2(other->toPoint());
00111 }
00112 double dist2(const Point& other) const {
00113 return this->toPoint().dist2(other);
00114 }
00115
00117 #ifdef MAINTAIN_NN
00118 double getNN2() const {
00119 return NN2_;
00120 }
00121 #endif
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 void reassign(PointRefineVertex *newv) {
00135 #ifdef MAINTAIN_NN
00136 double pq2 = dist2(newv);
00137 if (pq2 < NN2_) { NN2_ = pq2; }
00138 #endif
00139
00140 annuli_.reassignTo(this->toPoint(), newv->annuli_, newv->toPoint());
00141 }
00142
00143 pair<Uninserted*, double> findClosest(const Point& q, double r2) const {
00144 return annuli_.findClosest(this->toPoint(), q, r2);
00145 }
00146
00147 pair<Uninserted*, double> findPoint(const Point& q, double r2) const {
00148 return annuli_.findPoint(this->toPoint(), q, r2);
00149 }
00150
00151 void assign(Uninserted *u) {
00152
00153
00154 if (u == this) return;
00155 annuli_.add(this->toPoint(), u);
00156 }
00157
00158
00159
00160
00161 bool isCrowded() const {
00162 return !annuli_.empty();
00163 }
00164 Uninserted *getFarPoint() const {
00165 return annuli_.getFarItem();
00166 }
00167
00168
00169
00170
00171
00172 const Simplex& getHandle() const { return get(); }
00173 void setHandle(const Simplex& s) { get() = s; }
00174 void initHandle(const Simplex& s) {
00175 assert(!inMesh());
00176 new (&getUnchecked()) Simplex(s);
00177 inMesh_ = true;
00178 }
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 typedef unsigned FlagType;
00189 FlagType visitedFlag() const { return visited_; }
00190 void setVisited(FlagType i) { visited_ = i; }
00191 void clearVisited() { visited_ = 0; }
00192
00193
00194 private:
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 bool inMesh() const { return inMesh_; }
00208 Simplex& getUnchecked() { return *(Simplex*)&handle_[0]; }
00209 Simplex& get() {
00210 assert(inMesh());
00211 return getUnchecked();
00212 }
00213 const Simplex& get() const {
00214 assert(inMesh());
00215 return *(Simplex*)&handle_[0];
00216 }
00217
00218
00219
00220
00221
00222 #ifdef MAINTAIN_NN
00223 double NN2_;
00224 #endif
00225
00226 char handle_[sizeof(Simplex)];
00227
00228
00229 ConcentricShells<Uninserted, Point> annuli_;
00230
00231 size_t ID_:(sizeof(size_t)*8 - 2);
00232 bool isSteiner_:1;
00233 bool inMesh_:1;
00234 FlagType visited_;
00235 };
00236 #undef dprintf
00237 #undef dputs
00238 #undef MAINTAIN_NN
00239
00240 #endif