gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
MEdge.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 MEDGE_H
7 #define MEDGE_H
8 
9 #include "MVertex.h"
10 #include "SVector3.h"
11 #include <iostream>
12 
13 // A mesh edge.
14 class MEdge {
15 private:
16  MVertex *_v[2];
17  char _si[2]; // sorted indices
18 
19 public:
21  {
22  _v[0] = _v[1] = nullptr;
23  _si[0] = _si[1] = 0;
24  }
25  MEdge(MVertex *v0, MVertex *v1)
26  {
27  _v[0] = v0;
28  _v[1] = v1;
29  if(_v[1]->getNum() < _v[0]->getNum()) {
30  _si[0] = 1;
31  _si[1] = 0;
32  }
33  else {
34  _si[0] = 0;
35  _si[1] = 1;
36  }
37  }
38  std::size_t getNumVertices() const { return 2; }
39  MVertex *getVertex(std::size_t i) const { return _v[i]; }
40  MVertex *getSortedVertex(std::size_t i) const { return _v[int(_si[i])]; }
41  MVertex *getMinVertex() const { return _v[int(_si[0])]; }
42  MVertex *getMaxVertex() const { return _v[int(_si[1])]; }
43 
45  {
46  if(other.getVertex(0) == _v[0] && other.getVertex(1) == _v[1])
47  return 1;
48  else if(other.getVertex(0) == _v[1] && other.getVertex(1) == _v[0])
49  return -1;
50  return 0;
51  }
52 
53  bool alignWith(MEdge &other)
54  {
55  int orientation = computeCorrespondence(other);
56  if(!orientation) return false;
57  if(orientation == -1) {
58  std::swap(_v[0], _v[1]);
59  std::swap(_si[0], _si[1]);
60  }
61  return true;
62  }
63 
65  {
66  return SVector3(_v[1]->x() - _v[0]->x(), _v[1]->y() - _v[0]->y(),
67  _v[1]->z() - _v[0]->z());
68  }
69  SVector3 tangent() const
70  {
71  SVector3 t(_v[1]->x() - _v[0]->x(), _v[1]->y() - _v[0]->y(),
72  _v[1]->z() - _v[0]->z());
73  t.normalize();
74  return t;
75  }
76  double length() const
77  {
78  SVector3 t(_v[1]->x() - _v[0]->x(), _v[1]->y() - _v[0]->y(),
79  _v[1]->z() - _v[0]->z());
80  return t.norm();
81  }
82  SVector3 normal() const
83  {
84  // this computes one of the normals to the edge
85  SVector3 t = tangent(), ex(0., 0., 0.);
86  if(t[0] == 0.)
87  ex[0] = 1.;
88  else if(t[1] == 0.)
89  ex[1] = 1.;
90  else
91  ex[2] = 1.;
92  SVector3 n = crossprod(t, ex);
93  n.normalize();
94  return n;
95  }
96  SPoint3 barycenter() const { return interpolate(0.5); }
97  SPoint3 interpolate(const double &t) const
98  {
99  return SPoint3(t * _v[1]->x() + (1. - t) * _v[0]->x(),
100  t * _v[1]->y() + (1. - t) * _v[0]->y(),
101  t * _v[1]->z() + (1. - t) * _v[0]->z());
102  }
103  bool isInside(MVertex *v) const;
104 };
105 
106 inline bool operator==(const MEdge &e1, const MEdge &e2)
107 {
108  return (e1.getMinVertex() == e2.getMinVertex() &&
109  e1.getMaxVertex() == e2.getMaxVertex());
110 }
111 
112 inline bool operator!=(const MEdge &e1, const MEdge &e2)
113 {
114  return (e1.getMinVertex() != e2.getMinVertex() ||
115  e1.getMaxVertex() != e2.getMaxVertex());
116 }
117 
118 struct MEdgeEqual {
119  bool operator()(const MEdge &e1, const MEdge &e2) const { return (e1 == e2); }
120 };
121 
123  bool operator()(const MEdge &e1, const MEdge &e2) const
124  {
125  if(e1.getMinVertex()->getNum() < e2.getMinVertex()->getNum()) return true;
126  if(e1.getMinVertex()->getNum() > e2.getMinVertex()->getNum()) return false;
127  if(e1.getMaxVertex()->getNum() < e2.getMaxVertex()->getNum()) return true;
128  return false;
129  }
130 };
131 
132 // assume a set of MEdge, give consecutive list of vertices
133 bool SortEdgeConsecutive(const std::vector<MEdge> &,
134  std::vector<std::vector<MVertex *> > &vs);
135 
136 class MEdgeN {
137 private:
138  std::vector<MVertex *> _v;
139 
140 public:
141  MEdgeN() {}
142  MEdgeN(const std::vector<MVertex *> &v);
143  std::size_t getNumVertices() const { return _v.size(); }
144  MVertex *getVertex(std::size_t i) const { return _v[i]; }
145  const std::vector<MVertex *> &getVertices() const { return _v; }
146  int getPolynomialOrder() const { return (int)(getNumVertices() - 1); }
147 
148  MEdge getEdge() const;
149 
150  SPoint3 pnt(double u) const;
151  SVector3 tangent(double u) const;
152 
153  double interpolate(const double val[], double u, int stride = 1) const;
154 };
155 
156 #endif
MEdge::MEdge
MEdge()
Definition: MEdge.h:20
crossprod
SVector3 crossprod(const SVector3 &a, const SVector3 &b)
Definition: SVector3.h:150
MEdge::getSortedVertex
MVertex * getSortedVertex(std::size_t i) const
Definition: MEdge.h:40
MEdgeN::interpolate
double interpolate(const double val[], double u, int stride=1) const
Definition: MEdge.cpp:198
MEdge
Definition: MEdge.h:14
std::swap
void swap(picojson::value &x, picojson::value &y)
Definition: picojson.h:1136
MEdge::getMaxVertex
MVertex * getMaxVertex() const
Definition: MEdge.h:42
MEdgeN::getPolynomialOrder
int getPolynomialOrder() const
Definition: MEdge.h:146
MEdgeN::getVertices
const std::vector< MVertex * > & getVertices() const
Definition: MEdge.h:145
MVertex
Definition: MVertex.h:24
SPoint3
Definition: SPoint3.h:14
MVertex::getNum
std::size_t getNum() const
Definition: MVertex.h:86
MEdgeEqual::operator()
bool operator()(const MEdge &e1, const MEdge &e2) const
Definition: MEdge.h:119
SVector3
Definition: SVector3.h:16
SVector3.h
MEdge::tangent
SVector3 tangent() const
Definition: MEdge.h:69
MEdgeLessThan
Definition: MEdge.h:122
operator!=
bool operator!=(const MEdge &e1, const MEdge &e2)
Definition: MEdge.h:112
MEdgeN::MEdgeN
MEdgeN()
Definition: MEdge.h:141
MEdgeN::getNumVertices
std::size_t getNumVertices() const
Definition: MEdge.h:143
MEdgeN::_v
std::vector< MVertex * > _v
Definition: MEdge.h:138
MEdge::getVertex
MVertex * getVertex(std::size_t i) const
Definition: MEdge.h:39
MVertex.h
MEdge::barycenter
SPoint3 barycenter() const
Definition: MEdge.h:96
MEdge::getMinVertex
MVertex * getMinVertex() const
Definition: MEdge.h:41
SVector3::norm
double norm() const
Definition: SVector3.h:33
operator==
bool operator==(const MEdge &e1, const MEdge &e2)
Definition: MEdge.h:106
MEdge::scaledTangent
SVector3 scaledTangent() const
Definition: MEdge.h:64
MEdge::interpolate
SPoint3 interpolate(const double &t) const
Definition: MEdge.h:97
MEdgeN::pnt
SPoint3 pnt(double u) const
Definition: MEdge.cpp:164
MEdge::alignWith
bool alignWith(MEdge &other)
Definition: MEdge.h:53
MEdgeN
Definition: MEdge.h:136
MEdgeN::tangent
SVector3 tangent(double u) const
Definition: MEdge.cpp:181
z
const double z
Definition: GaussQuadratureQuad.cpp:56
MEdge::_si
char _si[2]
Definition: MEdge.h:17
MEdgeN::getVertex
MVertex * getVertex(std::size_t i) const
Definition: MEdge.h:144
MEdge::length
double length() const
Definition: MEdge.h:76
SortEdgeConsecutive
bool SortEdgeConsecutive(const std::vector< MEdge > &, std::vector< std::vector< MVertex * > > &vs)
Definition: MEdge.cpp:68
MEdge::computeCorrespondence
int computeCorrespondence(MEdge &other)
Definition: MEdge.h:44
MEdgeEqual
Definition: MEdge.h:118
MEdge::MEdge
MEdge(MVertex *v0, MVertex *v1)
Definition: MEdge.h:25
MEdgeLessThan::operator()
bool operator()(const MEdge &e1, const MEdge &e2) const
Definition: MEdge.h:123
MEdgeN::getEdge
MEdge getEdge() const
Definition: MEdge.cpp:162
MEdge::getNumVertices
std::size_t getNumVertices() const
Definition: MEdge.h:38
MEdge::_v
MVertex * _v[2]
Definition: MEdge.h:16
MEdge::isInside
bool isInside(MVertex *v) const
Definition: MEdge.cpp:16
SVector3::normalize
double normalize()
Definition: SVector3.h:38
MEdge::normal
SVector3 normal() const
Definition: MEdge.h:82