libsurf
Programmer's Documentation

dcface.h (r6227/r5731)
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_DCFACE_H
16 #define SURF_DCFACE_H
17 
18 #include "dcedge.h"
19 #include <genua/morton.h>
20 #include <genua/point.h>
21 #include <vector>
22 #include <iostream>
23 
36 class DcFace
37 {
38 public:
39 
40  enum SplitConfig { NoSplit = 0,
41  SplitEdge0 = 1,
42  SplitEdge1 = 2,
43  SplitEdge2 = 4,
44  QuadSplit = 7
45  };
46 
48  DcFace() {
49  vix[0] = vix[1] = vix[2] = NotFound;
50  }
51 
53  explicit DcFace(uint a, uint b, uint c) {
54  assign(a, b, c);
55  }
56 
58  explicit DcFace(const uint vip[]) {
59  assign(vip[0], vip[1], vip[2]);
60  }
61 
63  bool valid() const {return vix[0] != NotFound;}
64 
66  void invalidate() {vix[0] = NotFound;}
67 
69  const uint *vertices() const {return vix;}
70 
72  void copyVertices(uint v[]) const {
73  v[0] = vix[0]; v[1] = vix[1]; v[2] = vix[2];
74  }
75 
77  uint opposedVertex(uint s, uint t) const {
78  for (int k=0; k<3; ++k) {
79  uint a = vix[k];
80  uint b = vix[(k+1)%3];
81  uint c = vix[(k+2)%3];
82  if (s == a and t == b)
83  return c;
84  if (s == b and t == a)
85  return c;
86  }
87  return NotFound;
88  }
89 
91  Real cosApexAngle(const PointList3d &pts, uint a) const {
92  const Vct3 &pa = pts[a];
93  for (int k=0; k<3; ++k) {
94  if (a == vix[k]) {
95  uint b = vix[(k+1)%3];
96  uint c = vix[(k+2)%3];
97  return cosarg( pts[b]-pa, pts[c]-pa );
98  }
99  }
100  return 1.0;
101  }
102 
104  uint find(uint v) const {
105  for (int k=0; k<3; ++k) {
106  if (vix[k] == v)
107  return k;
108  }
109  return NotFound;
110  }
111 
113  DcEdge edge(uint k) const {
114  assert(k < 3);
115  return DcEdge( vix[k], vix[(k+1)%3] );
116  }
117 
119  uint esource(uint k) const {
120  assert(k < 3);
121  return vix[k];
122  }
123 
125  uint etarget(uint k) const {
126  assert(k < 3);
127  const int map[3] = {1, 2, 0};
128  return vix[map[k]];
129  }
130 
132  uint findEdge(uint s, uint t) {
133  for (int k=0; k<3; ++k) {
134  uint a = vix[k];
135  uint b = vix[(k+1)%3];
136  if (b < a)
137  std::swap(a,b);
138  if (a == s and b == t)
139  return k;
140  }
141  return NotFound;
142  }
143 
145  size_t zcode(const PointList<2> & vtx, Real qoffset, Real qscale) const {
146  assert(valid());
147 
148  // note : profile - could be vectorized if necessary (SSE2)
149  const Vct2 & p1( vtx[vix[0]] );
150  const Vct2 & p2( vtx[vix[1]] );
151  const Vct2 & p3( vtx[vix[2]] );
152  const Real third(1.0 / 3.0);
153  const int nbits( sizeof(size_t)*4 );
154  Real uc = (p1[0] + p2[0] + p3[0])*third;
155  Real vc = (p1[1] + p2[1] + p3[1])*third;
156  size_t a( (uc - qoffset)*qscale );
157  size_t b( (vc - qoffset)*qscale );
158  return interleave_bits<size_t, nbits>(a, b);
159  }
160 
161 private:
162 
164  void assign(uint a, uint b, uint c) {
165  if (a < b and a < c) {
166  vix[0] = a;
167  vix[1] = b;
168  vix[2] = c;
169  } else if (b < a and b < c) {
170  vix[0] = b;
171  vix[1] = c;
172  vix[2] = a;
173  } else {
174  vix[0] = c;
175  vix[1] = a;
176  vix[2] = b;
177  }
178  }
179 
180 private:
181 
183  uint vix[3];
184 
185  // padding (found detrimental)
186  // uint pad;
187 };
188 
189 typedef std::vector<DcFace> DcFaceArray;
190 
191 inline std::ostream & operator<<( std::ostream &os, const DcFace & f )
192 {
193  const uint *vf = f.vertices();
194  os << '[' << vf[0] << ' ' << vf[1] << ' ' << vf[2] << ']';
195  return os;
196 }
197 
198 #endif // DCFACE_H
uint opposedVertex(uint s, uint t) const
return vertex opposing edge vertices s, t, or NotFound
Definition: dcface.h:77
uint findEdge(uint s, uint t)
find edge (s,t)
Definition: dcface.h:132
size_t zcode(const PointList< 2 > &vtx, Real qoffset, Real qscale) const
determine Morton code (or z-code) from vertex array and quantization
Definition: dcface.h:145
DcFace()
create undefined face
Definition: dcface.h:48
Real cosApexAngle(const PointList3d &pts, uint a) const
determine cosine of angle at node a
Definition: dcface.h:91
void assign(uint a, uint b, uint c)
set vertex indices
Definition: dcface.h:164
All edges split.
Definition: dcface.h:44
DcFace(const uint vip[])
define face
Definition: dcface.h:58
SplitConfig
Definition: dcface.h:40
uint find(uint v) const
check whether face contains v
Definition: dcface.h:104
No split performed.
Definition: dcface.h:40
DcEdge edge(uint k) const
compute edge k
Definition: dcface.h:113
uint vix[3]
three vertices
Definition: dcface.h:183
void invalidate()
make invalid
Definition: dcface.h:66
bool valid() const
check whether edge is defined
Definition: dcface.h:63
Second edge (v[1],v[2]) split.
Definition: dcface.h:42
Face in a plane Delaunay triangulation.
Definition: dcface.h:36
Third edge (v[2],v[0]) split.
Definition: dcface.h:43
void copyVertices(uint v[]) const
copy vertices
Definition: dcface.h:72
uint esource(uint k) const
return source vertex of edge k
Definition: dcface.h:119
const uint * vertices() const
access vertices
Definition: dcface.h:69
Butterfly edge for Delaunay algorithms.
Definition: dcedge.h:39
uint etarget(uint k) const
return target vertex of edge k
Definition: dcface.h:125
DcFace(uint a, uint b, uint c)
define face
Definition: dcface.h:53
First edge (v[0],v[1]) split.
Definition: dcface.h:41
Generated on Wed Jan 19 2022 03:03:15 for libsurf by   doxygen 1.8.5