gmsh-TingyuanDoc
0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
CutSphere.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 <string.h>
7
#include "GmshConfig.h"
8
#include "
CutSphere.h
"
9
#include "
Context.h
"
10
11
#if defined(HAVE_OPENGL)
12
#include "
drawContext.h
"
13
#endif
14
15
StringXNumber
CutSphereOptions_Number
[] = {
16
{
GMSH_FULLRC
,
"Xc"
,
GMSH_CutSpherePlugin::callbackX
, 0.},
17
{
GMSH_FULLRC
,
"Yc"
,
GMSH_CutSpherePlugin::callbackY
, 0.},
18
{
GMSH_FULLRC
,
"Zc"
,
GMSH_CutSpherePlugin::callbackZ
, 0.},
19
{
GMSH_FULLRC
,
"R"
,
GMSH_CutSpherePlugin::callbackR
, 0.25},
20
{
GMSH_FULLRC
,
"ExtractVolume"
,
GMSH_CutSpherePlugin::callbackVol
, 0.},
21
{
GMSH_FULLRC
,
"RecurLevel"
,
GMSH_CutSpherePlugin::callbackRecur
, 3},
22
{
GMSH_FULLRC
,
"TargetError"
,
GMSH_CutSpherePlugin::callbackTarget
, 1e-4},
23
{
GMSH_FULLRC
,
"View"
,
nullptr
, -1.}};
24
25
extern
"C"
{
26
GMSH_Plugin
*
GMSH_RegisterCutSpherePlugin
()
27
{
28
return
new
GMSH_CutSpherePlugin
();
29
}
30
}
31
32
void
GMSH_CutSpherePlugin::draw
(
void
*context)
33
{
34
#if defined(HAVE_OPENGL)
35
GLint mode[2];
36
glGetIntegerv(GL_POLYGON_MODE, mode);
37
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
38
glColor4ubv((GLubyte *)&
CTX::instance
()->color.
fg
);
39
glLineWidth((
float
)
CTX::instance
()->lineWidth);
40
drawContext
*ctx = (
drawContext
*)context;
41
ctx->
drawSphere
(
42
CutSphereOptions_Number
[3].def,
CutSphereOptions_Number
[0].def,
43
CutSphereOptions_Number
[1].def,
CutSphereOptions_Number
[2].def, 40, 40, 1);
44
glPolygonMode(GL_FRONT_AND_BACK, mode[1]);
45
#endif
46
}
47
48
double
GMSH_CutSpherePlugin::callback
(
int
num,
int
action,
double
value,
49
double
*opt,
double
step,
double
min,
50
double
max)
51
{
52
switch
(action) {
// configure the input field
53
case
1:
return
step;
54
case
2:
return
min;
55
case
3:
return
max;
56
default
:
break
;
57
}
58
*opt = value;
59
GMSH_Plugin::setDrawFunction
(
draw
);
60
return
0.;
61
}
62
63
double
GMSH_CutSpherePlugin::callbackX
(
int
num,
int
action,
double
value)
64
{
65
return
callback
(num, action, value, &
CutSphereOptions_Number
[0].def,
66
CTX::instance
()->lc / 100., -2 *
CTX::instance
()->lc,
67
2 *
CTX::instance
()->lc);
68
}
69
70
double
GMSH_CutSpherePlugin::callbackY
(
int
num,
int
action,
double
value)
71
{
72
return
callback
(num, action, value, &
CutSphereOptions_Number
[1].def,
73
CTX::instance
()->lc / 100., -2 *
CTX::instance
()->lc,
74
2 *
CTX::instance
()->lc);
75
}
76
77
double
GMSH_CutSpherePlugin::callbackZ
(
int
num,
int
action,
double
value)
78
{
79
return
callback
(num, action, value, &
CutSphereOptions_Number
[2].def,
80
CTX::instance
()->lc / 100., -2 *
CTX::instance
()->lc,
81
2 *
CTX::instance
()->lc);
82
}
83
84
double
GMSH_CutSpherePlugin::callbackR
(
int
num,
int
action,
double
value)
85
{
86
return
callback
(num, action, value, &
CutSphereOptions_Number
[3].def,
87
CTX::instance
()->lc / 100., 0., 2 *
CTX::instance
()->lc);
88
}
89
90
double
GMSH_CutSpherePlugin::callbackVol
(
int
num,
int
action,
double
value)
91
{
92
return
callback
(num, action, value, &
CutSphereOptions_Number
[4].def, 1., -1.,
93
1.);
94
}
95
96
double
GMSH_CutSpherePlugin::callbackRecur
(
int
num,
int
action,
double
value)
97
{
98
return
callback
(num, action, value, &
CutSphereOptions_Number
[5].def, 1, 0,
99
10);
100
}
101
102
double
GMSH_CutSpherePlugin::callbackTarget
(
int
num,
int
action,
double
value)
103
{
104
return
callback
(num, action, value, &
CutSphereOptions_Number
[6].def, 0.01, 0.,
105
1.);
106
}
107
108
std::string
GMSH_CutSpherePlugin::getHelp
()
const
109
{
110
return
"Plugin(CutSphere) cuts the view `View' with the "
111
"sphere (X-`Xc')^2 + (Y-`Yc')^2 + (Z-`Zc')^2 = `R'^2.\n\n"
112
"If `ExtractVolume' is nonzero, the plugin extracts "
113
"the elements inside (if `ExtractVolume' < 0) or "
114
"outside (if `ExtractVolume' > 0) the sphere.\n\n"
115
"If `View' < 0, the plugin is run on the current view.\n\n"
116
"Plugin(CutSphere) creates one new list-based view."
;
117
}
118
119
int
GMSH_CutSpherePlugin::getNbOptions
()
const
120
{
121
return
sizeof
(
CutSphereOptions_Number
) /
sizeof
(
StringXNumber
);
122
}
123
124
StringXNumber
*
GMSH_CutSpherePlugin::getOption
(
int
iopt)
125
{
126
return
&
CutSphereOptions_Number
[iopt];
127
}
128
129
double
GMSH_CutSpherePlugin::levelset
(
double
x,
double
y,
double
z
,
130
double
val)
const
131
{
132
double
a =
CutSphereOptions_Number
[0].
def
;
133
double
b =
CutSphereOptions_Number
[1].
def
;
134
double
c
=
CutSphereOptions_Number
[2].
def
;
135
double
r =
CutSphereOptions_Number
[3].
def
;
136
return
(x - a) * (x - a) + (y - b) * (y - b) + (
z
-
c
) * (
z
-
c
) - r * r;
137
}
138
139
PView
*
GMSH_CutSpherePlugin::execute
(
PView
*v)
140
{
141
int
iView = (int)
CutSphereOptions_Number
[7].def;
142
_ref
[0] =
CutSphereOptions_Number
[0].
def
;
143
_ref
[1] =
CutSphereOptions_Number
[1].
def
;
144
_ref
[2] =
CutSphereOptions_Number
[2].
def
;
145
_extractVolume
= (int)
CutSphereOptions_Number
[4].def;
146
_recurLevel
= (int)
CutSphereOptions_Number
[5].def;
147
_targetError
=
CutSphereOptions_Number
[6].
def
;
148
149
_valueIndependent
= 1;
150
_valueView
= -1;
151
_valueTimeStep
= -1;
152
_orientation
=
GMSH_LevelsetPlugin::SPHERE
;
153
154
PView
*v1 =
getView
(iView, v);
155
if
(!v1)
return
v;
156
157
return
GMSH_LevelsetPlugin::execute
(v1);
158
}
PView
Definition:
PView.h:27
GMSH_CutSpherePlugin
Definition:
CutSphere.h:15
CutSphere.h
GMSH_Plugin
Definition:
Plugin.h:26
StringXNumber::def
double def
Definition:
Options.h:922
c
static double c(int i, int j, fullMatrix< double > &CA, const std::vector< SPoint3 > &P, const std::vector< SPoint3 > &Q)
Definition:
discreteFrechetDistance.cpp:15
GMSH_Plugin::draw
static void(* draw)(void *)
Definition:
Plugin.h:77
StringXNumber
Definition:
Options.h:918
GMSH_CutSpherePlugin::callbackZ
static double callbackZ(int, int, double)
Definition:
CutSphere.cpp:77
GMSH_CutSpherePlugin::callbackR
static double callbackR(int, int, double)
Definition:
CutSphere.cpp:84
GMSH_LevelsetPlugin::_valueView
int _valueView
Definition:
Levelset.h:24
GMSH_LevelsetPlugin::_extractVolume
int _extractVolume
Definition:
Levelset.h:25
GMSH_LevelsetPlugin::_ref
double _ref[3]
Definition:
Levelset.h:23
GMSH_CutSpherePlugin::getHelp
std::string getHelp() const
Definition:
CutSphere.cpp:108
CTX::fg
unsigned int fg
Definition:
Context.h:358
GMSH_LevelsetPlugin::_valueTimeStep
int _valueTimeStep
Definition:
Levelset.h:24
CTX::instance
static CTX * instance()
Definition:
Context.cpp:122
GMSH_CutSpherePlugin::callbackY
static double callbackY(int, int, double)
Definition:
CutSphere.cpp:70
GMSH_FULLRC
#define GMSH_FULLRC
Definition:
Options.h:20
GMSH_LevelsetPlugin::execute
virtual PView * execute(PView *)
Definition:
Levelset.cpp:537
GMSH_CutSpherePlugin::callbackRecur
static double callbackRecur(int, int, double)
Definition:
CutSphere.cpp:96
CutSphereOptions_Number
StringXNumber CutSphereOptions_Number[]
Definition:
CutSphere.cpp:15
drawContext
Definition:
drawContext.h:120
GMSH_CutSpherePlugin::execute
PView * execute(PView *)
Definition:
CutSphere.cpp:139
GMSH_LevelsetPlugin::_orientation
ORIENTATION _orientation
Definition:
Levelset.h:27
GMSH_CutSpherePlugin::getOption
StringXNumber * getOption(int iopt)
Definition:
CutSphere.cpp:124
GMSH_LevelsetPlugin::_recurLevel
int _recurLevel
Definition:
Levelset.h:24
GMSH_CutSpherePlugin::callbackTarget
static double callbackTarget(int, int, double)
Definition:
CutSphere.cpp:102
Context.h
z
const double z
Definition:
GaussQuadratureQuad.cpp:56
GMSH_Plugin::setDrawFunction
static void setDrawFunction(void(*fct)(void *))
Definition:
Plugin.cpp:21
GMSH_LevelsetPlugin::SPHERE
@ SPHERE
Definition:
Levelset.h:26
GMSH_PostPlugin::getView
virtual PView * getView(int index, PView *view)
Definition:
Plugin.cpp:81
GMSH_LevelsetPlugin::_valueIndependent
int _valueIndependent
Definition:
Levelset.h:24
GMSH_CutSpherePlugin::callbackX
static double callbackX(int, int, double)
Definition:
CutSphere.cpp:63
GMSH_CutSpherePlugin::getNbOptions
int getNbOptions() const
Definition:
CutSphere.cpp:119
GMSH_CutSpherePlugin::levelset
double levelset(double x, double y, double z, double val) const
Definition:
CutSphere.cpp:129
GMSH_RegisterCutSpherePlugin
GMSH_Plugin * GMSH_RegisterCutSpherePlugin()
Definition:
CutSphere.cpp:26
drawContext::drawSphere
void drawSphere(double R, double x, double y, double z, int n1, int n2, int light)
Definition:
drawGlyph.cpp:390
GMSH_CutSpherePlugin::callbackVol
static double callbackVol(int, int, double)
Definition:
CutSphere.cpp:90
GMSH_CutSpherePlugin::callback
static double callback(int num, int action, double value, double *opt, double step, double min, double max)
Definition:
CutSphere.cpp:48
GMSH_LevelsetPlugin::_targetError
double _targetError
Definition:
Levelset.h:23
drawContext.h
src
plugin
CutSphere.cpp
Generated by
1.8.18