gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
SmoothData.h
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #ifndef SMOOTH_DATA_H
7 #define SMOOTH_DATA_H
8 
9 #include <set>
10 #include <vector>
11 #include <string>
12 
13 // Basic coordinate-based floating point data averager
14 
15 struct xyzv {
16  double x, y, z, *vals;
17  int nbvals;
19  // Added by Trevor Strickler for scaling last element layer in quadtri
20  // boundary layer to make better quality interfaces
21  double scaleValue;
23  static double eps;
24  xyzv(double xx, double yy, double zz)
25  : x(xx), y(yy), z(zz), vals(nullptr), nbvals(0), nboccurrences(0),
26  scaleValue(1.0), scale_numvals(0)
27  {
28  }
30  {
31  if(vals) delete[] vals;
32  }
33  // these are needed for set<> operations since the default copy constructor
34  // won't allocate *vals
35  xyzv(const xyzv &other);
36  xyzv &operator=(const xyzv &other);
37  void update(int n, double *v);
38  void scale_update(double scale_val);
39 };
40 
41 struct lessthanxyzv {
42  bool operator()(const xyzv &p2, const xyzv &p1) const
43  {
44  if(p1.x - p2.x > xyzv::eps) return true;
45  if(p1.x - p2.x < -xyzv::eps) return false;
46  if(p1.y - p2.y > xyzv::eps) return true;
47  if(p1.y - p2.y < -xyzv::eps) return false;
48  if(p1.z - p2.z > xyzv::eps) return true;
49  return false;
50  }
51 };
52 
53 class smooth_data {
54 private:
55  std::set<xyzv, lessthanxyzv> c;
56 
57 public:
58  typedef std::set<xyzv, lessthanxyzv>::iterator iter;
59  iter begin() { return c.begin(); }
60  iter end() { return c.end(); }
62  void add(double x, double y, double z, int n, double *vals);
63  bool get(double x, double y, double z, int n, double *vals) const;
64  void add_scale(double x, double y, double z, double scale_val);
65  bool get_scale(double x, double y, double z, double *scale_val) const;
66  void normalize();
67  bool exportview(const std::string &filename) const;
68 };
69 
70 // Normal smoother with threshold (saves memory by storing normals as
71 // chars and coordinates as floats)
72 
73 struct nnb {
74  char nx, ny, nz;
75  unsigned char nb;
76 };
77 
78 struct xyzn {
79  float x, y, z;
80  std::vector<nnb> n;
81  static float eps;
82  xyzn(float xx, float yy, float zz) : x(xx), y(yy), z(zz) {}
83  ~xyzn() {}
84  float angle(int i, char n0, char n1, char n2);
85  void update(char n0, char n1, char n2, float tol);
86 };
87 
88 struct lessthanxyzn {
89  bool operator()(const xyzn &p2, const xyzn &p1) const
90  {
91  if(p1.x - p2.x > xyzn::eps) return true;
92  if(p1.x - p2.x < -xyzn::eps) return false;
93  if(p1.y - p2.y > xyzn::eps) return true;
94  if(p1.y - p2.y < -xyzn::eps) return false;
95  if(p1.z - p2.z > xyzn::eps) return true;
96  return false;
97  }
98 };
99 
101 private:
102  float tol;
103  std::set<xyzn, lessthanxyzn> c;
104 
105 public:
106  smooth_normals(double angle) : tol((float)angle) {}
107  void add(double x, double y, double z, double nx, double ny, double nz);
108  bool get(double x, double y, double z, double &nx, double &ny, double &nz) const;
109 };
110 
111 #endif
xyzv::update
void update(int n, double *v)
Definition: SmoothData.cpp:50
xyzn::angle
float angle(int i, char n0, char n1, char n2)
Definition: SmoothData.cpp:166
smooth_normals::tol
float tol
Definition: SmoothData.h:102
smooth_data::iter
std::set< xyzv, lessthanxyzv >::iterator iter
Definition: SmoothData.h:58
lessthanxyzn
Definition: SmoothData.h:88
xyzv::scale_numvals
int scale_numvals
Definition: SmoothData.h:22
xyzn::~xyzn
~xyzn()
Definition: SmoothData.h:83
smooth_normals::smooth_normals
smooth_normals(double angle)
Definition: SmoothData.h:106
angle
double angle(const SVector3 &a, const SVector3 &b)
Definition: SVector3.h:157
nnb
Definition: SmoothData.h:73
xyzv::xyzv
xyzv(double xx, double yy, double zz)
Definition: SmoothData.h:24
smooth_data::get
bool get(double x, double y, double z, int n, double *vals) const
Definition: SmoothData.cpp:112
smooth_data::add
void add(double x, double y, double z, int n, double *vals)
Definition: SmoothData.cpp:79
xyzv::operator=
xyzv & operator=(const xyzv &other)
Definition: SmoothData.cpp:32
smooth_normals
Definition: SmoothData.h:100
xyzn::y
float y
Definition: SmoothData.h:79
smooth_normals::add
void add(double x, double y, double z, double nx, double ny, double nz)
Definition: SmoothData.cpp:215
xyzv::vals
double * vals
Definition: SmoothData.h:16
xyzv
Definition: SmoothData.h:15
xyzn::update
void update(char n0, char n1, char n2, float tol)
Definition: SmoothData.cpp:184
nnb::nz
char nz
Definition: SmoothData.h:74
xyzn::z
float z
Definition: SmoothData.h:79
xyzv::y
double y
Definition: SmoothData.h:16
xyzn::x
float x
Definition: SmoothData.h:79
nnb::nx
char nx
Definition: SmoothData.h:74
smooth_normals::c
std::set< xyzn, lessthanxyzn > c
Definition: SmoothData.h:103
xyzn::xyzn
xyzn(float xx, float yy, float zz)
Definition: SmoothData.h:82
smooth_data
Definition: SmoothData.h:53
nnb::nb
unsigned char nb
Definition: SmoothData.h:75
smooth_data::smooth_data
smooth_data()
Definition: SmoothData.h:61
smooth_data::add_scale
void add_scale(double x, double y, double z, double scale_val)
Definition: SmoothData.cpp:96
xyzn::n
std::vector< nnb > n
Definition: SmoothData.h:80
smooth_data::normalize
void normalize()
Definition: SmoothData.cpp:129
xyzv::x
double x
Definition: SmoothData.h:16
smooth_data::end
iter end()
Definition: SmoothData.h:60
smooth_data::begin
iter begin()
Definition: SmoothData.h:59
xyzv::~xyzv
~xyzv()
Definition: SmoothData.h:29
smooth_data::c
std::set< xyzv, lessthanxyzv > c
Definition: SmoothData.h:55
xyzv::z
double z
Definition: SmoothData.h:16
smooth_normals::get
bool get(double x, double y, double z, double &nx, double &ny, double &nz) const
Definition: SmoothData.cpp:234
xyzn
Definition: SmoothData.h:78
z
const double z
Definition: GaussQuadratureQuad.cpp:56
lessthanxyzv::operator()
bool operator()(const xyzv &p2, const xyzv &p1) const
Definition: SmoothData.h:42
xyzv::scaleValue
double scaleValue
Definition: SmoothData.h:21
xyzn::eps
static float eps
Definition: SmoothData.h:81
smooth_data::exportview
bool exportview(const std::string &filename) const
Definition: SmoothData.cpp:138
xyzv::eps
static double eps
Definition: SmoothData.h:23
smooth_data::get_scale
bool get_scale(double x, double y, double z, double *scale_val) const
Definition: SmoothData.cpp:121
xyzv::scale_update
void scale_update(double scale_val)
Definition: SmoothData.cpp:67
lessthanxyzv
Definition: SmoothData.h:41
xyzv::nboccurrences
int nboccurrences
Definition: SmoothData.h:18
lessthanxyzn::operator()
bool operator()(const xyzn &p2, const xyzn &p1) const
Definition: SmoothData.h:89
nnb::ny
char ny
Definition: SmoothData.h:74
xyzv::nbvals
int nbvals
Definition: SmoothData.h:17