HeTriang.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _HE_TRIANG_H_
00027 #define _HE_TRIANG_H_
00028
00029
00030 #define TTL_USE_NODE_ID // Each node gets it's own unique id
00031 #define TTL_USE_NODE_FLAG // Each node gets a flag (can be set to true or false)
00032
00033
00034 #include <list>
00035 #include <vector>
00036 #include <iostream>
00037 #include <fstream>
00038 #include <ttl/ttl.h>
00039 #include <ttl/ttl_util.h>
00040 #include <ttl/utils/HandleId.h>
00041 #include <ttl/utils/Handle.h>
00042
00043
00044 using namespace std;
00045
00046
00047
00048
00049
00050 namespace hed {
00051
00052
00053
00054
00055
00066 class Node : public virtual HandleId {
00067
00068 #ifdef TTL_USE_NODE_ID
00070 static int id_count;
00071 #endif
00072
00073 double x_, y_, z_;
00074
00075 #ifdef TTL_USE_NODE_ID
00077 int id_;
00078 #endif
00079
00080 #ifdef TTL_USE_NODE_FLAG
00082 bool flag_;
00083 #endif
00084
00085 public:
00087 Node() { init(0, 0, 0); }
00088
00090 Node(double x, double y, double z = 0.0) { init(x, y, z); }
00091
00093 ~Node() {}
00094
00096 void init(double x, double y, double z) {
00097
00098 #ifdef TTL_USE_NODE_ID
00099 id_ = id_count++;
00100 #endif
00101
00102 x_ = x; y_ = y; z_ = z;
00103 }
00104
00106 const double& x() const { return x_; }
00107
00109 const double& y() const { return y_; }
00110
00112 const double& z() const { return z_; }
00113
00114 #ifdef TTL_USE_NODE_ID
00116 const int& id() const { return id_; }
00117 #endif
00118
00119 #ifdef TTL_USE_NODE_FLAG
00121 void setFlag(bool flag) { flag_ = flag; }
00122
00124 const bool& getFlag() const { return flag_; }
00125 #endif
00126
00127 };
00128
00129
00130
00131
00132
00133
00138 class Edge {
00139
00140 Handle<Node> sourceNode_;
00141 Edge* twinEdge_;
00142 Edge* nextEdgeInFace_;
00143
00144 struct {
00145 unsigned char isLeadingEdge_ : 1;
00146 unsigned char isConstrained_ : 1;
00147 } flags_;
00148
00149 public:
00151 Edge() { sourceNode_ = NULL; twinEdge_ = NULL; nextEdgeInFace_ = NULL;
00152 flags_.isLeadingEdge_ = 0; flags_.isConstrained_ = 0; }
00153
00155 ~Edge() { if(twinEdge_) twinEdge_->setTwinEdge(NULL); }
00156
00158 void setSourceNode(Node* node) { sourceNode_ = node; }
00159
00161 void setNextEdgeInFace(Edge* edge) { nextEdgeInFace_ = edge; }
00162
00164 void setTwinEdge(Edge* edge) { twinEdge_ = edge; }
00165
00167 void setAsLeadingEdge(bool val=true) { flags_.isLeadingEdge_ = (val == true ? 1 : 0); }
00168
00170 bool isLeadingEdge() const { return flags_.isLeadingEdge_ == 1 ? true : false; }
00171
00173 void setConstrained(bool val=true) { unsigned char cstr = (val == true ? 1 : 0);
00174 flags_.isConstrained_ = cstr; if (twinEdge_) twinEdge_->flags_.isConstrained_ = cstr; }
00175
00177 bool isConstrained() const { return flags_.isConstrained_ == 1 ? true : false; }
00178
00180 Edge* getTwinEdge() const { return twinEdge_; };
00181
00183 Edge* getNextEdgeInFace() const { return nextEdgeInFace_; }
00184
00186 Node* getSourceNode() { return sourceNode_.getPtr(); }
00187
00189 Node* getTargetNode() { return getNextEdgeInFace()->getSourceNode(); }
00190
00191 };
00192
00193
00194
00195 class Dart;
00196
00197
00198
00199
00200
00201
00206 class Triangulation {
00207
00208 protected:
00209 list<Edge*> leadingEdges_;
00210 void addLeadingEdge(Edge* edge) { edge->setAsLeadingEdge(); leadingEdges_.push_front(edge); }
00211 bool removeLeadingEdgeFromList(Edge* leadingEdge);
00212 void cleanAll();
00213
00214 public:
00216 Triangulation() {}
00217
00219 Triangulation(const Triangulation& tr) {
00220 cout << "Triangulation: Copy constructor not present - EXIT.";
00221 exit(-1);
00222 }
00223
00225 ~Triangulation() { cleanAll(); }
00226
00228 void createDelaunay(vector<Node*>::iterator first,
00229 vector<Node*>::iterator last);
00230
00232
00233
00234 Edge* initTwoEnclosingTriangles(vector<Node*>::iterator first,
00235 vector<Node*>::iterator last);
00236
00237
00238
00239
00241 void swapEdge(Edge& diagonal);
00242
00244 Edge* splitTriangle(Edge& edge, Node& point);
00245
00246
00247
00248
00250 void removeTriangle(Edge& edge);
00251
00253 void reverse_splitTriangle(Edge& edge);
00254
00255
00257 Dart createDart();
00258
00260 const list<Edge*>& getLeadingEdges() const { return leadingEdges_; }
00261
00263 int noTriangles() const { return leadingEdges_.size(); }
00264
00266 list<Edge*>* getEdges(bool skip_boundary_edges = false) const;
00267
00268 #ifdef TTL_USE_NODE_FLAG
00270 void flagNodes(bool flag) const;
00271
00273 list<Node*>* getNodes() const;
00274 #endif
00275
00277 void optimizeDelaunay();
00278
00280 bool checkDelaunay() const;
00281
00283 Edge* getInteriorNode() const;
00284
00286 Edge* getBoundaryEdge() const;
00287
00289 void printEdges(ofstream& os) const;
00290
00291 };
00292
00293
00294 };
00295
00296 #endif