gmsh-TingyuanDoc
0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
ShowNeighborElements.cpp
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
#include "
ShowNeighborElements.h
"
7
#include "
GModel.h
"
8
#include "
MElement.h
"
9
#include "
MVertex.h
"
10
#include "
Options.h
"
11
#include "
Context.h
"
12
#include "
GmshDefines.h
"
13
14
#if defined(HAVE_OPENGL)
15
#include "
drawContext.h
"
16
#endif
17
18
StringXNumber
ShowNeighborElementsOptions_Number
[] = {
19
{
GMSH_FULLRC
,
"NumLayers"
,
nullptr
, 1},
20
{
GMSH_FULLRC
,
"Element1"
,
nullptr
, 0},
21
{
GMSH_FULLRC
,
"Element2"
,
nullptr
, 0},
22
{
GMSH_FULLRC
,
"Element3"
,
nullptr
, 0},
23
{
GMSH_FULLRC
,
"Element4"
,
nullptr
, 0},
24
{
GMSH_FULLRC
,
"Element5"
,
nullptr
, 0}};
25
26
extern
"C"
{
27
GMSH_Plugin
*
GMSH_RegisterShowNeighborElementsPlugin
()
28
{
29
return
new
GMSH_ShowNeighborElementsPlugin
();
30
}
31
}
32
33
int
GMSH_ShowNeighborElementsPlugin::getNbOptions
()
const
34
{
35
return
sizeof
(
ShowNeighborElementsOptions_Number
) /
sizeof
(
StringXNumber
);
36
}
37
38
StringXNumber
*
GMSH_ShowNeighborElementsPlugin::getOption
(
int
iopt)
39
{
40
return
&
ShowNeighborElementsOptions_Number
[iopt];
41
}
42
std::string
GMSH_ShowNeighborElementsPlugin::getHelp
()
const
43
{
44
return
"Plugin(ShowNeighborElements) sets visible some elements "
45
"and a layer of elements around them, the other being set invisible."
;
46
}
47
48
PView
*
GMSH_ShowNeighborElementsPlugin::execute
(
PView
*v)
49
{
50
GModel
*m =
GModel::current
();
51
52
_nLayers
=
static_cast<
int
>
(
ShowNeighborElementsOptions_Number
[0].
def
);
53
_nel1
=
static_cast<
int
>
(
ShowNeighborElementsOptions_Number
[1].
def
);
54
_nel2
=
static_cast<
int
>
(
ShowNeighborElementsOptions_Number
[2].
def
);
55
_nel3
=
static_cast<
int
>
(
ShowNeighborElementsOptions_Number
[3].
def
);
56
_nel4
=
static_cast<
int
>
(
ShowNeighborElementsOptions_Number
[4].
def
);
57
_nel5
=
static_cast<
int
>
(
ShowNeighborElementsOptions_Number
[5].
def
);
58
59
for
(
auto
it = m->
firstFace
(); it != m->
lastFace
(); it++) {
60
GFace
*
f
= *it;
61
_init
(
f
);
62
_showLayers
(
f
,
_nLayers
);
63
}
64
65
for
(
auto
it = m->
firstRegion
(); it != m->
lastRegion
(); it++) {
66
GRegion
*r = *it;
67
_init
(r);
68
_showLayers
(r,
_nLayers
);
69
}
70
71
#if defined(HAVE_OPENGL)
72
CTX::instance
()->
mesh
.
changed
=
ENT_ALL
;
73
drawContext::global
()->
draw
();
74
#endif
75
76
return
nullptr
;
77
}
78
79
void
GMSH_ShowNeighborElementsPlugin::_init
(
GEntity
*ent)
80
{
81
_vert2elem
.clear();
82
for
(
unsigned
i = 0; i < ent->
getNumMeshElements
(); ++i) {
83
MElement
*el = ent->
getMeshElement
(i);
84
if
(el->
getNum
() ==
_nel1
|| el->
getNum
() ==
_nel2
||
85
el->
getNum
() ==
_nel3
|| el->
getNum
() ==
_nel4
||
86
el->
getNum
() ==
_nel5
) {
87
el->
setVisibility
(
true
);
88
for
(std::size_t k = 0; k < el->
getNumVertices
();
89
++k) {
// TODO only corner vertices?
90
_vertices
.insert(el->
getVertex
(k));
91
}
92
}
93
else
{
94
el->
setVisibility
(
false
);
95
for
(std::size_t k = 0; k < el->
getNumVertices
();
96
++k) {
// TODO only corner vertices?
97
_vert2elem
.insert(std::make_pair(el->
getVertex
(k), el));
98
}
99
}
100
}
101
}
102
103
void
GMSH_ShowNeighborElementsPlugin::_showLayers
(
GEntity
*ent,
int
nLayer)
104
{
105
if
(
_vertices
.empty() || nLayer < 1)
return
;
106
107
std::set<MVertex *> &vert =
_vertices
;
108
std::map<MElement *, int> el2cnt;
109
110
for
(
auto
it = vert.begin(); it != vert.end(); ++it) {
111
MVertex
*v = *it;
112
auto
ite =
_vert2elem
.lower_bound(v);
113
auto
itstop =
_vert2elem
.upper_bound(v);
114
for
(; ite != itstop; ++ite) {
115
MElement
*el = ite->second;
116
if
(el2cnt.find(el) == el2cnt.end()) el2cnt[el] = 0;
117
++el2cnt[el];
118
}
119
}
120
121
for
(
auto
it2 = el2cnt.begin(); it2 != el2cnt.end(); ++it2) {
122
if
(it2->second && it2->second > 3 - nLayer) {
123
it2->first->
setVisibility
(
true
);
124
}
125
}
126
}
MElement::getNum
virtual std::size_t getNum() const
Definition:
MElement.h:68
PView
Definition:
PView.h:27
GMSH_ShowNeighborElementsPlugin::_vert2elem
std::multimap< MVertex *, MElement * > _vert2elem
Definition:
ShowNeighborElements.h:22
GMSH_ShowNeighborElementsPlugin::getOption
StringXNumber * getOption(int)
Definition:
ShowNeighborElements.cpp:38
GMSH_ShowNeighborElementsPlugin::_nel4
std::size_t _nel4
Definition:
ShowNeighborElements.h:21
GMSH_ShowNeighborElementsPlugin::_vertices
std::set< MVertex * > _vertices
Definition:
ShowNeighborElements.h:23
GFace
Definition:
GFace.h:33
GMSH_Plugin
Definition:
Plugin.h:26
StringXNumber::def
double def
Definition:
Options.h:922
MVertex
Definition:
MVertex.h:24
GMSH_ShowNeighborElementsPlugin::_init
void _init(GEntity *)
Definition:
ShowNeighborElements.cpp:79
LegendrePolynomials::f
void f(int n, double u, double *val)
Definition:
orthogonalBasis.cpp:77
StringXNumber
Definition:
Options.h:918
GMSH_ShowNeighborElementsPlugin::_nel3
std::size_t _nel3
Definition:
ShowNeighborElements.h:21
GEntity
Definition:
GEntity.h:31
MElement::getNumVertices
virtual std::size_t getNumVertices() const =0
drawContext::global
static drawContextGlobal * global()
Definition:
drawContext.cpp:85
drawContextGlobal::draw
virtual void draw(bool rateLimited=true)
Definition:
drawContext.h:97
CTX::instance
static CTX * instance()
Definition:
Context.cpp:122
MElement::getVertex
virtual const MVertex * getVertex(int num) const =0
GModel::lastFace
fiter lastFace()
Definition:
GModel.h:359
GMSH_ShowNeighborElementsPlugin::_nLayers
int _nLayers
Definition:
ShowNeighborElements.h:20
ShowNeighborElementsOptions_Number
StringXNumber ShowNeighborElementsOptions_Number[]
Definition:
ShowNeighborElements.cpp:18
GMSH_ShowNeighborElementsPlugin
Definition:
ShowNeighborElements.h:18
GEntity::getNumMeshElements
virtual std::size_t getNumMeshElements() const
Definition:
GEntity.h:348
MVertex.h
GMSH_ShowNeighborElementsPlugin::_nel2
std::size_t _nel2
Definition:
ShowNeighborElements.h:21
GMSH_FULLRC
#define GMSH_FULLRC
Definition:
Options.h:20
GModel
Definition:
GModel.h:44
GModel::firstFace
fiter firstFace()
Definition:
GModel.h:355
GmshDefines.h
CTX::mesh
contextMeshOptions mesh
Definition:
Context.h:313
MElement
Definition:
MElement.h:30
GRegion
Definition:
GRegion.h:28
GMSH_ShowNeighborElementsPlugin::_nel1
std::size_t _nel1
Definition:
ShowNeighborElements.h:21
contextMeshOptions::changed
int changed
Definition:
Context.h:82
GMSH_ShowNeighborElementsPlugin::getNbOptions
int getNbOptions() const
Definition:
ShowNeighborElements.cpp:33
GModel::firstRegion
riter firstRegion()
Definition:
GModel.h:354
GModel::lastRegion
riter lastRegion()
Definition:
GModel.h:358
ENT_ALL
#define ENT_ALL
Definition:
GmshDefines.h:235
Context.h
GEntity::getMeshElement
virtual MElement * getMeshElement(std::size_t index) const
Definition:
GEntity.h:363
ShowNeighborElements.h
GMSH_ShowNeighborElementsPlugin::_showLayers
void _showLayers(GEntity *, int nLayer)
Definition:
ShowNeighborElements.cpp:103
GMSH_ShowNeighborElementsPlugin::getHelp
std::string getHelp() const
Definition:
ShowNeighborElements.cpp:42
MElement.h
GMSH_ShowNeighborElementsPlugin::_nel5
std::size_t _nel5
Definition:
ShowNeighborElements.h:21
Options.h
MElement::setVisibility
virtual void setVisibility(char val)
Definition:
MElement.h:97
GModel.h
GMSH_ShowNeighborElementsPlugin::execute
PView * execute(PView *)
Definition:
ShowNeighborElements.cpp:48
GModel::current
static GModel * current(int index=-1)
Definition:
GModel.cpp:136
GMSH_RegisterShowNeighborElementsPlugin
GMSH_Plugin * GMSH_RegisterShowNeighborElementsPlugin()
Definition:
ShowNeighborElements.cpp:27
drawContext.h
src
plugin
ShowNeighborElements.cpp
Generated by
1.8.18