gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
CutPlane.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 "GmshConfig.h"
7 #include "CutPlane.h"
8 #include "Context.h"
9 #include "fullMatrix.h"
10 
11 #if defined(HAVE_OPENGL)
12 #include "drawContext.h"
13 #endif
14 
16 
22  {GMSH_FULLRC, "ExtractVolume", GMSH_CutPlanePlugin::callbackVol, 0},
24  {GMSH_FULLRC, "TargetError", GMSH_CutPlanePlugin::callbackTarget, 1e-4},
25  {GMSH_FULLRC, "View", nullptr, -1.}};
26 
27 extern "C" {
29 }
30 
31 void GMSH_CutPlanePlugin::draw(void *context)
32 {
33 #if defined(HAVE_OPENGL)
34  int num = (int)CutPlaneOptions_Number[7].def;
35  drawContext *ctx = (drawContext *)context;
36  if(num < 0) num = iview;
37  if(num >= 0 && num < (int)PView::list.size()) {
38  glColor4ubv((GLubyte *)&CTX::instance()->color.fg);
39  glLineWidth((float)CTX::instance()->lineWidth);
40  SBoundingBox3d bb = PView::list[num]->getData()->getBoundingBox();
42  bb.min().x(), bb.min().y(), bb.min().z(), bb.max().x(), bb.max().y(),
43  bb.max().z(), CutPlaneOptions_Number[0].def,
46  }
47 #endif
48 }
49 
50 double GMSH_CutPlanePlugin::callback(int num, int action, double value,
51  double *opt, double step, double min,
52  double max)
53 {
54  if(action > 0) iview = num;
55  switch(action) { // configure the input field
56  case 1: return step;
57  case 2: return min;
58  case 3: return max;
59  default: break;
60  }
61  *opt = value;
63  return 0.;
64 }
65 
66 double GMSH_CutPlanePlugin::callbackA(int num, int action, double value)
67 {
68  return callback(num, action, value, &CutPlaneOptions_Number[0].def, 0.01, -1,
69  1);
70 }
71 
72 double GMSH_CutPlanePlugin::callbackB(int num, int action, double value)
73 {
74  return callback(num, action, value, &CutPlaneOptions_Number[1].def, 0.01, -1,
75  1);
76 }
77 
78 double GMSH_CutPlanePlugin::callbackC(int num, int action, double value)
79 {
80  return callback(num, action, value, &CutPlaneOptions_Number[2].def, 0.01, -1,
81  1);
82 }
83 
84 double GMSH_CutPlanePlugin::callbackD(int num, int action, double value)
85 {
86  return callback(num, action, value, &CutPlaneOptions_Number[3].def,
87  CTX::instance()->lc / 200., -CTX::instance()->lc,
88  CTX::instance()->lc);
89 }
90 
91 double GMSH_CutPlanePlugin::callbackVol(int num, int action, double value)
92 {
93  return callback(num, action, value, &CutPlaneOptions_Number[4].def, 1., -1,
94  1);
95 }
96 
97 double GMSH_CutPlanePlugin::callbackRecur(int num, int action, double value)
98 {
99  return callback(num, action, value, &CutPlaneOptions_Number[5].def, 1, 0, 10);
100 }
101 
102 double GMSH_CutPlanePlugin::callbackTarget(int num, int action, double value)
103 {
104  return callback(num, action, value, &CutPlaneOptions_Number[6].def, 0.01, 0.,
105  1.);
106 }
107 
108 std::string GMSH_CutPlanePlugin::getHelp() const
109 {
110  return "Plugin(CutPlane) cuts the view `View' with "
111  "the plane `A'*X + `B'*Y + `C'*Z + `D' = 0.\n\n"
112  "If `ExtractVolume' is nonzero, the plugin extracts "
113  "the elements on one side of the plane (depending "
114  "on the sign of `ExtractVolume').\n\n"
115  "If `View' < 0, the plugin is run on the current view.\n\n"
116  "Plugin(CutPlane) creates one new list-based view.";
117 }
118 
120 {
121  return sizeof(CutPlaneOptions_Number) / sizeof(StringXNumber);
122 }
123 
125 {
126  return &CutPlaneOptions_Number[iopt];
127 }
128 
129 double GMSH_CutPlanePlugin::levelset(double x, double y, double z,
130  double val) const
131 {
132  return CutPlaneOptions_Number[0].def * x + CutPlaneOptions_Number[1].def * y +
134 }
135 
137  fullMatrix<double> *node_positions) const
138 {
139  const double l0 = levelset((*node_positions)(0, 0), (*node_positions)(0, 1),
140  (*node_positions)(0, 2), 1);
141  for(int i = 1; i < node_positions->size1(); i++)
142  if(levelset((*node_positions)(i, 0), (*node_positions)(i, 1),
143  (*node_positions)(i, 2), 1) *
144  l0 <
145  0)
146  return true;
147  return false;
148 }
149 
151 {
152  int iView = (int)CutPlaneOptions_Number[7].def;
156  _valueIndependent = 1;
157  _valueView = -1;
158  _valueTimeStep = -1;
161  _recurLevel = (int)CutPlaneOptions_Number[5].def;
163 
164  PView *v1 = getView(iView, v);
165  if(!v1) return v;
166 
167  return GMSH_LevelsetPlugin::execute(v1);
168 }
PView
Definition: PView.h:27
GMSH_Plugin
Definition: Plugin.h:26
GMSH_CutPlanePlugin::callbackRecur
static double callbackRecur(int, int, double)
Definition: CutPlane.cpp:97
StringXNumber::def
double def
Definition: Options.h:922
GMSH_Plugin::draw
static void(* draw)(void *)
Definition: Plugin.h:77
GMSH_CutPlanePlugin
Definition: CutPlane.h:15
StringXNumber
Definition: Options.h:918
GMSH_LevelsetPlugin::PLANE
@ PLANE
Definition: Levelset.h:26
GMSH_CutPlanePlugin::iview
static int iview
Definition: CutPlane.h:19
SBoundingBox3d::min
SPoint3 min() const
Definition: SBoundingBox3d.h:90
GMSH_CutPlanePlugin::callbackTarget
static double callbackTarget(int, int, double)
Definition: CutPlane.cpp:102
GMSH_LevelsetPlugin::_valueView
int _valueView
Definition: Levelset.h:24
GMSH_CutPlanePlugin::getHelp
std::string getHelp() const
Definition: CutPlane.cpp:108
GMSH_CutPlanePlugin::getOption
StringXNumber * getOption(int iopt)
Definition: CutPlane.cpp:124
GMSH_CutPlanePlugin::callbackB
static double callbackB(int, int, double)
Definition: CutPlane.cpp:72
GMSH_LevelsetPlugin::_extractVolume
int _extractVolume
Definition: Levelset.h:25
GMSH_LevelsetPlugin::_ref
double _ref[3]
Definition: Levelset.h:23
drawContext::drawPlaneInBoundingBox
void drawPlaneInBoundingBox(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax, double a, double b, double c, double d, int shade=0)
Definition: drawGlyph.cpp:824
CTX::fg
unsigned int fg
Definition: Context.h:358
GMSH_CutPlanePlugin::callback
static double callback(int num, int action, double value, double *opt, double step, double min, double max)
Definition: CutPlane.cpp:50
GMSH_LevelsetPlugin::_valueTimeStep
int _valueTimeStep
Definition: Levelset.h:24
CTX::instance
static CTX * instance()
Definition: Context.cpp:122
SPoint3::x
double x(void) const
Definition: SPoint3.h:125
fullMatrix< double >
CutPlane.h
GMSH_CutPlanePlugin::callbackC
static double callbackC(int, int, double)
Definition: CutPlane.cpp:78
GMSH_CutPlanePlugin::levelset
double levelset(double x, double y, double z, double val) const
Definition: CutPlane.cpp:129
GMSH_FULLRC
#define GMSH_FULLRC
Definition: Options.h:20
GMSH_LevelsetPlugin::execute
virtual PView * execute(PView *)
Definition: Levelset.cpp:537
GMSH_CutPlanePlugin::callbackA
static double callbackA(int, int, double)
Definition: CutPlane.cpp:66
GMSH_CutPlanePlugin::execute
PView * execute(PView *)
Definition: CutPlane.cpp:150
SPoint3::y
double y(void) const
Definition: SPoint3.h:127
drawContext
Definition: drawContext.h:120
GMSH_LevelsetPlugin::_orientation
ORIENTATION _orientation
Definition: Levelset.h:27
CutPlaneOptions_Number
StringXNumber CutPlaneOptions_Number[]
Definition: CutPlane.cpp:17
GMSH_LevelsetPlugin::_recurLevel
int _recurLevel
Definition: Levelset.h:24
GMSH_CutPlanePlugin::geometricalFilter
virtual bool geometricalFilter(fullMatrix< double > *) const
Definition: CutPlane.cpp:136
GMSH_CutPlanePlugin::callbackVol
static double callbackVol(int, int, double)
Definition: CutPlane.cpp:91
Context.h
fullMatrix::size1
int size1() const
Definition: fullMatrix.h:274
z
const double z
Definition: GaussQuadratureQuad.cpp:56
GMSH_Plugin::setDrawFunction
static void setDrawFunction(void(*fct)(void *))
Definition: Plugin.cpp:21
GMSH_PostPlugin::getView
virtual PView * getView(int index, PView *view)
Definition: Plugin.cpp:81
GMSH_LevelsetPlugin::_valueIndependent
int _valueIndependent
Definition: Levelset.h:24
SPoint3::z
double z(void) const
Definition: SPoint3.h:129
GMSH_CutPlanePlugin::callbackD
static double callbackD(int, int, double)
Definition: CutPlane.cpp:84
PView::list
static std::vector< PView * > list
Definition: PView.h:112
SBoundingBox3d::max
SPoint3 max() const
Definition: SBoundingBox3d.h:91
SBoundingBox3d
Definition: SBoundingBox3d.h:21
GMSH_CutPlanePlugin::getNbOptions
int getNbOptions() const
Definition: CutPlane.cpp:119
fullMatrix.h
GMSH_RegisterCutPlanePlugin
GMSH_Plugin * GMSH_RegisterCutPlanePlugin()
Definition: CutPlane.cpp:28
GMSH_LevelsetPlugin::_targetError
double _targetError
Definition: Levelset.h:23
drawContext.h