libsurf
Programmer's Documentation

dcedge.h (r6227/r5385)
1 
2 /* Copyright (C) 2015 David Eller <david@larosterna.com>
3  *
4  * Commercial License Usage
5  * Licensees holding valid commercial licenses may use this file in accordance
6  * with the terms contained in their respective non-exclusive license agreement.
7  * For further information contact david@larosterna.com .
8  *
9  * GNU General Public License Usage
10  * Alternatively, this file may be used under the terms of the GNU General
11  * Public License version 3.0 as published by the Free Software Foundation and
12  * appearing in the file gpl.txt included in the packaging of this file.
13  */
14 
15 #ifndef SURF_DCEDGE_H
16 #define SURF_DCEDGE_H
17 
18 #include <genua/defines.h>
19 #include <boost/functional/hash.hpp>
20 #include <boost/unordered/unordered_set.hpp>
21 
39 class DcEdge
40 {
41 public:
42 
43  enum Flags { None = 0,
45  Feature = 2,
46  NeverSplit = 4,
48  };
49 
51  DcEdge() : flags(0) {
52  vix[0] = vix[1] = NotFound;
53  fix[0] = fix[1] = NotFound;
54  }
55 
57  explicit DcEdge(uint32_t s, uint32_t t) : flags(0) {
58  assign(s,t);
59  fix[0] = fix[1] = NotFound;
60  }
61 
63  bool checkFlag(int f) const {
64  return (flags & f) == f;
65  }
66 
68  void setFlag(int f) {
69  flags |= f;
70  }
71 
73  void unsetFlag(int f) {
74  flags &= (~f);
75  }
76 
78  int getFlags() const {return flags;}
79 
81  int topoId() const {
82  return (flags >> 16);
83  }
84 
86  void topoId(int id) {
87  flags = (flags & 0x0000ffff) | (id << 16);
88  }
89 
91  bool canFlip() const {
92  const int noflipflag = Constrained | Feature | SurfaceIntersection;
93  return (flags & noflipflag) == 0;
94  }
95 
97  bool valid() const {return (vix[0] != NotFound) and (vix[1] != NotFound);}
98 
100  void invalidate() { vix[0] = NotFound; }
101 
103  uint32_t source() const {return vix[0];}
104 
106  uint32_t target() const {return vix[1];}
107 
109  bool connects(uint32_t s, uint32_t t) const {
110  if (s < t)
111  return (s == source()) and (t == target());
112  else
113  return (t == source()) and (s == target());
114  }
115 
117  const uint32_t *faces() const {return fix;}
118 
120  uint32_t nfaces() const {
121  return (fix[0] != NotFound) + (fix[1] != NotFound);
122  }
123 
125  uint32_t left() const {return fix[0];}
126 
128  uint32_t right() const {return fix[1];}
129 
131  uint32_t otherFace(uint32_t f) const {
132  if (f == fix[0])
133  return fix[1];
134  else if (f == fix[1])
135  return fix[0];
136  return NotFound;
137  }
138 
140  void assign(uint32_t s, uint32_t t) {
141  assert(s != t);
142  if (s < t) {
143  vix[0] = s;
144  vix[1] = t;
145  } else {
146  vix[0] = t;
147  vix[1] = s;
148  }
149  }
150 
152  uint32_t degree() const {
153  uint32_t n(0);
154  n += (fix[0] != NotFound);
155  n += (fix[1] != NotFound);
156  return n;
157  }
158 
160  bool operator< (const DcEdge & e) const {
161  if (source() < e.source())
162  return true;
163  else if (source() > e.source())
164  return false;
165  else
166  return target() < e.target();
167  }
168 
170  bool operator== (const DcEdge & e) const {
171  return (source() == e.source()) and (target() == e.target());
172  }
173 
175  uint32_t appendFace(uint32_t f) {
176  for (int k=0; k<2; ++k) {
177  assert(fix[k] != f);
178  if (fix[k] == NotFound) {
179  fix[k] = f;
180  return k;
181  }
182  }
183  return NotFound;
184  }
185 
187  void assignFaces(uint32_t f1, uint32_t f2) {
188  assert(f1 != f2);
189  fix[0] = f1;
190  fix[1] = f2;
191  }
192 
194  bool replaceFace(uint32_t k1, uint32_t k2) {
195  if (fix[0] == k1) {
196  fix[0] = k2;
197  return true;
198  } else if (fix[1] == k1) {
199  fix[1] = k2;
200  return true;
201  }
202  return false;
203  }
204 
206  bool replaceFace(uint32_t fr, uint32_t fl, uint32_t k2) {
207  if (fix[0] == fr or fix[0] == fl) {
208  fix[0] = k2;
209  return true;
210  } else if (fix[1] == fr or fix[1] == fl) {
211  fix[1] = k2;
212  return true;
213  }
214  return false;
215  }
216 
218  struct Hasher
219  {
220  size_t operator() (const DcEdge *pe) const {
221  size_t seed = 0;
222  boost::hash_combine(seed, pe->source());
223  boost::hash_combine(seed, pe->target());
224  return seed;
225  }
226  };
227 
229  struct PtrEqual
230  {
231  bool operator() (const DcEdge *pa, const DcEdge *pb) const {
232  if (sizeof(char*) == 8) {
233  union {uint32_t u32[2]; uint64_t u64;} a = {{pa->source(), pa->target()}};
234  union {uint32_t u32[2]; uint64_t u64;} b = {{pb->source(), pb->target()}};
235  return (a.u64 == b.u64);
236  } else {
237  return ((pa->source() == pb->source()) and (pa->target() == pb->target()));
238  }
239  }
240  };
241 
243  struct PtrLess
244  {
245  bool operator() (const DcEdge *pa, const DcEdge *pb) const {
246  return (*pa < *pb);
247  }
248  };
249 
250 private:
251 
253  uint32_t vix[2];
254 
256  uint32_t fix[2];
257 
259  int32_t flags;
260 };
261 
262 typedef boost::unordered_set<DcEdge*, DcEdge::Hasher,
263  DcEdge::PtrEqual> DcEdgeHash;
264 typedef DcEdgeHash::iterator DcEdgeItr;
265 
266 #endif // DCEDGE_H
Edge is part of a constraint.
Definition: dcedge.h:44
Compares two edges for equality with respect to vertex indices.
Definition: dcedge.h:229
uint32_t appendFace(uint32_t f)
append face to neighbor set
Definition: dcedge.h:175
Edge is on a surface intersection.
Definition: dcedge.h:47
Edge should never be split.
Definition: dcedge.h:46
bool connects(uint32_t s, uint32_t t) const
check for equality
Definition: dcedge.h:109
uint32_t nfaces() const
number of defined face neighbors
Definition: dcedge.h:120
void topoId(int id)
embed topo edge id in high flag bits
Definition: dcedge.h:86
uint32_t right() const
access left neighbor face
Definition: dcedge.h:128
int getFlags() const
access flags
Definition: dcedge.h:78
uint32_t source() const
access source vertex
Definition: dcedge.h:103
bool valid() const
check whether edge is defined
Definition: dcedge.h:97
Flags
Definition: dcedge.h:43
bool replaceFace(uint32_t k1, uint32_t k2)
replace face index k1 with k2
Definition: dcedge.h:194
void assignFaces(uint32_t f1, uint32_t f2)
assign neighbor face indices
Definition: dcedge.h:187
bool canFlip() const
check whether edge is allowed to flip
Definition: dcedge.h:91
uint32_t vix[2]
source and target vertex indices, src &lt; trg
Definition: dcedge.h:253
int32_t flags
bitmap for various edge properties
Definition: dcedge.h:259
bool operator==(const DcEdge &e) const
define equality
Definition: dcedge.h:170
Computes hash value from vertex indices.
Definition: dcedge.h:218
void invalidate()
mark as invalid
Definition: dcedge.h:100
void assign(uint32_t s, uint32_t t)
set source and target vertices
Definition: dcedge.h:140
void setFlag(int f)
set flag
Definition: dcedge.h:68
DcEdge()
create undefined edge
Definition: dcedge.h:51
bool checkFlag(int f) const
test flag
Definition: dcedge.h:63
uint32_t otherFace(uint32_t f) const
face opposed to face f
Definition: dcedge.h:131
uint32_t left() const
access left neighbor face
Definition: dcedge.h:125
int topoId() const
return topo edge id embedded in high bits
Definition: dcedge.h:81
uint32_t fix[2]
left and right faces
Definition: dcedge.h:256
const uint32_t * faces() const
access neighbor face indices
Definition: dcedge.h:117
bool operator<(const DcEdge &e) const
define sort order
Definition: dcedge.h:160
Butterfly edge for Delaunay algorithms.
Definition: dcedge.h:39
Feature edge, should not be flipped.
Definition: dcedge.h:45
DcEdge(uint32_t s, uint32_t t)
create edge with source and target vertex only
Definition: dcedge.h:57
uint32_t degree() const
number of faces present
Definition: dcedge.h:152
bool replaceFace(uint32_t fr, uint32_t fl, uint32_t k2)
replace face index fr or fl with k2
Definition: dcedge.h:206
Establish ordering between two edges with respect to vertex indices.
Definition: dcedge.h:243
void unsetFlag(int f)
unset flag
Definition: dcedge.h:73
Normal, free edge.
Definition: dcedge.h:43
uint32_t target() const
access target vertex
Definition: dcedge.h:106
Generated on Thu Sep 29 2022 03:03:14 for libsurf by   doxygen 1.8.5