gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
MFace.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 MFACE_H
7 #define MFACE_H
8 
9 #include <functional>
10 #include <vector>
11 #include "MVertex.h"
12 #include "MEdge.h"
13 #include "SVector3.h"
14 #include "GmshMessage.h"
15 #include "GmshDefines.h"
16 
17 template <class t> class fullMatrix;
18 
19 // A mesh face.
20 class MFace {
21 private:
22  std::vector<MVertex *> _v;
23  std::vector<char> _si; // sorted indices
24 
25 public:
26  MFace() {}
27  MFace(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3 = nullptr);
28  MFace(const std::vector<MVertex *> &v);
29  std::size_t getNumVertices() const { return _v.size(); }
30  MVertex *getVertex(std::size_t i) const { return _v[i]; }
31  MVertex *getSortedVertex(std::size_t i) const
32  {
33  return _v[std::size_t(_si[i])];
34  }
35  MEdge getEdge(std::size_t i) const
36  {
37  return MEdge(getVertex(i), getVertex((i + 1) % getNumVertices()));
38  }
39  void getOrientationFlagForFace(std::vector<int> &faceOrientationFlag);
40  bool computeCorrespondence(const MFace &, int &, bool &) const;
41 
42  void getOrderedVertices(std::vector<MVertex *> &verts) const
43  {
44  for(std::size_t i = 0; i < getNumVertices(); i++)
45  verts.push_back(getSortedVertex(i));
46  }
47  void getOrderedVertices(const MVertex **const verts) const
48  {
49  for(std::size_t i = 0; i < getNumVertices(); i++) {
50  verts[i] = getSortedVertex(i);
51  }
52  }
53  double approximateArea() const;
54  SVector3 normal() const;
55  SVector3 tangent(int num) const
56  {
57  SVector3 t0(_v[1]->x() - _v[0]->x(), _v[1]->y() - _v[0]->y(),
58  _v[1]->z() - _v[0]->z());
59  t0.normalize();
60  if(!num) return t0;
61  SVector3 n = normal();
62  SVector3 t1 = crossprod(n, t0);
63  return t1;
64  }
66  {
67  SPoint3 p(0., 0., 0.);
68  std::size_t n = getNumVertices();
69  for(std::size_t i = 0; i < n; i++) {
70  const MVertex *v = getVertex(i);
71  p[0] += v->x();
72  p[1] += v->y();
73  p[2] += v->z();
74  }
75  p[0] /= static_cast<double>(n);
76  p[1] /= static_cast<double>(n);
77  p[2] /= static_cast<double>(n);
78  return p;
79  }
80  SPoint3 interpolate(const double &u, const double &v) const
81  {
82  SPoint3 p(0.0, 0.0, 0.0);
83  std::size_t n = getNumVertices();
84  if(n == 3) {
85  const double ff[3] = {1.0 - u - v, u, v};
86  for(std::size_t i = 0; i < n; i++) {
87  MVertex *v = getVertex(i);
88  p[0] += v->x() * ff[i];
89  p[1] += v->y() * ff[i];
90  p[2] += v->z() * ff[i];
91  }
92  }
93  else if(n == 4) {
94  const double ff[4] = {(1 - u) * (1. - v), (1 + u) * (1. - v),
95  (1 + u) * (1. + v), (1 - u) * (1. + v)};
96  for(std::size_t i = 0; i < n; i++) {
97  MVertex *v = getVertex(i);
98  p[0] += v->x() * ff[i] * 0.25;
99  p[1] += v->y() * ff[i] * 0.25;
100  p[2] += v->z() * ff[i] * 0.25;
101  }
102  }
103  else
104  Msg::Error(
105  "Cannot interpolate inside a polygonal MFace with more than 4 edges");
106  return p;
107  }
108 };
109 
110 inline bool operator==(const MFace &f1, const MFace &f2)
111 {
112  if(f1.getNumVertices() != f2.getNumVertices()) return false;
113  for(std::size_t i = 0; i < f1.getNumVertices(); i++)
114  if(f1.getSortedVertex(i) != f2.getSortedVertex(i)) return false;
115  return true;
116 }
117 
118 inline bool operator!=(const MFace &f1, const MFace &f2)
119 {
120  if(f1.getNumVertices() != f2.getNumVertices()) return true;
121  for(std::size_t i = 0; i < f1.getNumVertices(); i++)
122  if(f1.getSortedVertex(i) != f2.getSortedVertex(i)) return true;
123  return false;
124 }
125 
126 struct MFaceEqual : public std::binary_function<MFace, MFace, bool> {
127  bool operator()(const MFace &f1, const MFace &f2) const { return (f1 == f2); }
128 };
129 
130 struct MFaceLessThan : public std::binary_function<MFace, MFace, bool> {
131  bool operator()(const MFace &f1, const MFace &f2) const
132  {
133  if(f1.getNumVertices() != f2.getNumVertices())
134  return f1.getNumVertices() < f2.getNumVertices();
135  for(std::size_t i = 0; i < f1.getNumVertices(); i++) {
136  if(f1.getSortedVertex(i)->getNum() < f2.getSortedVertex(i)->getNum())
137  return true;
138  if(f1.getSortedVertex(i)->getNum() > f2.getSortedVertex(i)->getNum())
139  return false;
140  }
141  return false;
142  }
143 };
144 
145 class MFaceN {
146 private:
147  int _type;
148  int _order;
149  std::vector<MVertex *> _v;
150 
151 public:
152  MFaceN() {}
153  MFaceN(int type, int order, const std::vector<MVertex *> &v);
154 
155  int getPolynomialOrder() const { return _order; }
156  int getType() const { return _type; }
157  bool isTriangular() const { return _type == TYPE_TRI; }
158  std::size_t getNumVertices() const { return (int)_v.size(); }
159  int getNumCorners() const { return isTriangular() ? 3 : 4; }
160  int getNumVerticesOnBoundary() const { return getNumCorners() * _order; }
161 
162  MVertex *getVertex(std::size_t i) const { return _v[i]; }
163  const std::vector<MVertex *> &getVertices() const { return _v; }
164 
165  MEdgeN getHighOrderEdge(int num, int sign) const;
166  MFace getFace() const;
167 
168  SPoint3 pnt(double u, double v) const;
169  SVector3 tangent(double u, double v, int num) const;
170  SVector3 normal(double u, double v) const;
171  void frame(double u, double v, SVector3 &t0, SVector3 &t1, SVector3 &n) const;
172  void frame(double u, double v, SPoint3 &p, SVector3 &t0, SVector3 &t1,
173  SVector3 &n) const;
174 
175  void repositionInnerVertices(const fullMatrix<double> *) const;
176 };
177 
178 #endif
crossprod
SVector3 crossprod(const SVector3 &a, const SVector3 &b)
Definition: SVector3.h:150
MFaceN::getNumCorners
int getNumCorners() const
Definition: MFace.h:159
MEdge
Definition: MEdge.h:14
MFaceEqual::operator()
bool operator()(const MFace &f1, const MFace &f2) const
Definition: MFace.h:127
MFaceN::isTriangular
bool isTriangular() const
Definition: MFace.h:157
MFaceEqual
Definition: MFace.h:126
MFace::_si
std::vector< char > _si
Definition: MFace.h:23
MVertex
Definition: MVertex.h:24
MFace::barycenter
SPoint3 barycenter() const
Definition: MFace.h:65
MFace::tangent
SVector3 tangent(int num) const
Definition: MFace.h:55
MFaceN::_type
int _type
Definition: MFace.h:147
MFace::MFace
MFace()
Definition: MFace.h:26
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
MVertex::z
double z() const
Definition: MVertex.h:62
SPoint3
Definition: SPoint3.h:14
MVertex::getNum
std::size_t getNum() const
Definition: MVertex.h:86
MFace::getEdge
MEdge getEdge(std::size_t i) const
Definition: MFace.h:35
MFace::normal
SVector3 normal() const
Definition: MFace.cpp:204
SVector3
Definition: SVector3.h:16
TYPE_TRI
#define TYPE_TRI
Definition: GmshDefines.h:66
MFace::getSortedVertex
MVertex * getSortedVertex(std::size_t i) const
Definition: MFace.h:31
SVector3.h
GmshMessage.h
MFaceN::getNumVertices
std::size_t getNumVertices() const
Definition: MFace.h:158
operator!=
bool operator!=(const MFace &f1, const MFace &f2)
Definition: MFace.h:118
MFaceN::pnt
SPoint3 pnt(double u, double v) const
Definition: MFace.cpp:273
MFaceN::_order
int _order
Definition: MFace.h:148
MFaceN::MFaceN
MFaceN()
Definition: MFace.h:152
MFaceN::tangent
SVector3 tangent(double u, double v, int num) const
Definition: MFace.cpp:290
MFace::interpolate
SPoint3 interpolate(const double &u, const double &v) const
Definition: MFace.h:80
fullMatrix
Definition: MElement.h:27
MFace
Definition: MFace.h:20
MFace::_v
std::vector< MVertex * > _v
Definition: MFace.h:22
MVertex.h
MFaceN::getPolynomialOrder
int getPolynomialOrder() const
Definition: MFace.h:155
MFace::getVertex
MVertex * getVertex(std::size_t i) const
Definition: MFace.h:30
GmshDefines.h
MFaceN::getVertices
const std::vector< MVertex * > & getVertices() const
Definition: MFace.h:163
MFaceN::normal
SVector3 normal(double u, double v) const
Definition: MFace.cpp:309
MFaceN::getType
int getType() const
Definition: MFace.h:156
MFaceN::getVertex
MVertex * getVertex(std::size_t i) const
Definition: MFace.h:162
MFaceN::_v
std::vector< MVertex * > _v
Definition: MFace.h:149
MFaceN::getHighOrderEdge
MEdgeN getHighOrderEdge(int num, int sign) const
Definition: MFace.cpp:241
MFace::getOrderedVertices
void getOrderedVertices(std::vector< MVertex * > &verts) const
Definition: MFace.h:42
MFaceLessThan::operator()
bool operator()(const MFace &f1, const MFace &f2) const
Definition: MFace.h:131
MFaceN::frame
void frame(double u, double v, SVector3 &t0, SVector3 &t1, SVector3 &n) const
Definition: MFace.cpp:332
MFaceN::repositionInnerVertices
void repositionInnerVertices(const fullMatrix< double > *) const
Definition: MFace.cpp:385
MEdge.h
MEdgeN
Definition: MEdge.h:136
z
const double z
Definition: GaussQuadratureQuad.cpp:56
MFaceN
Definition: MFace.h:145
MFace::approximateArea
double approximateArea() const
Definition: MFace.cpp:195
operator==
bool operator==(const MFace &f1, const MFace &f2)
Definition: MFace.h:110
MFaceN::getNumVerticesOnBoundary
int getNumVerticesOnBoundary() const
Definition: MFace.h:160
MFace::getOrientationFlagForFace
void getOrientationFlagForFace(std::vector< int > &faceOrientationFlag)
Definition: MFace.cpp:84
MFaceLessThan
Definition: MFace.h:130
MFace::getNumVertices
std::size_t getNumVertices() const
Definition: MFace.h:29
MFaceN::getFace
MFace getFace() const
Definition: MFace.cpp:265
MFace::getOrderedVertices
void getOrderedVertices(const MVertex **const verts) const
Definition: MFace.h:47
MVertex::y
double y() const
Definition: MVertex.h:61
MFace::computeCorrespondence
bool computeCorrespondence(const MFace &, int &, bool &) const
Definition: MFace.cpp:212
MVertex::x
double x() const
Definition: MVertex.h:60
SVector3::normalize
double normalize()
Definition: SVector3.h:38