gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
Probe.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 "Probe.h"
8 #include "Context.h"
9 #include "OctreePost.h"
10 
11 #if defined(HAVE_OPENGL)
12 #include "drawContext.h"
13 #endif
14 
16 
21  {GMSH_FULLRC, "View", nullptr, -1.},
22 };
23 
24 extern "C" {
26 }
27 
28 void GMSH_ProbePlugin::draw(void *context)
29 {
30 #if defined(HAVE_OPENGL)
31  int num = (int)ProbeOptions_Number[3].def;
32  if(num < 0) num = iview;
33  if(num >= 0 && num < (int)PView::list.size()) {
34  double x = ProbeOptions_Number[0].def;
35  double y = ProbeOptions_Number[1].def;
36  double z = ProbeOptions_Number[2].def;
37  drawContext *ctx = (drawContext *)context;
38  glColor4ubv((GLubyte *)&CTX::instance()->color.fg);
39  glLineWidth((float)CTX::instance()->lineWidth);
40  SBoundingBox3d bb = PView::list[num]->getData()->getBoundingBox();
41  if(x >= bb.min().x() && x <= bb.max().x() && y >= bb.min().y() &&
42  y <= bb.max().y() && z >= bb.min().z() && z <= bb.max().z()) {
43  // we're inside the bounding box: draw a large cross
44  glBegin(GL_LINES);
45  glVertex3d(bb.min().x(), y, z);
46  glVertex3d(bb.max().x(), y, z);
47  glVertex3d(x, bb.min().y(), z);
48  glVertex3d(x, bb.max().y(), z);
49  glVertex3d(x, y, bb.min().z());
50  glVertex3d(x, y, bb.max().z());
51  glEnd();
52  }
53  else {
54  // draw 10-pixel marker
55  double d = 10 * ctx->pixel_equiv_x / ctx->s[0];
56  glBegin(GL_LINES);
57  glVertex3d(x - d, y, z);
58  glVertex3d(x + d, y, z);
59  glVertex3d(x, y - d, z);
60  glVertex3d(x, y + d, z);
61  glVertex3d(x, y, z - d);
62  glVertex3d(x, y, z + d);
63  glEnd();
64  }
65  ctx->drawSphere(CTX::instance()->pointSize, x, y, z, 1);
66  }
67 #endif
68 }
69 
70 double GMSH_ProbePlugin::callback(int num, int action, double value,
71  double *opt)
72 {
73  if(action > 0) iview = num;
74  switch(action) { // configure the input field
75  case 1: return CTX::instance()->lc / 100.;
76  case 2: return -2 * CTX::instance()->lc;
77  case 3: return 2 * CTX::instance()->lc;
78  default: break;
79  }
80  *opt = value;
82  return 0.;
83 }
84 
85 double GMSH_ProbePlugin::callbackX(int num, int action, double value)
86 {
87  return callback(num, action, value, &ProbeOptions_Number[0].def);
88 }
89 
90 double GMSH_ProbePlugin::callbackY(int num, int action, double value)
91 {
92  return callback(num, action, value, &ProbeOptions_Number[1].def);
93 }
94 
95 double GMSH_ProbePlugin::callbackZ(int num, int action, double value)
96 {
97  return callback(num, action, value, &ProbeOptions_Number[2].def);
98 }
99 
100 std::string GMSH_ProbePlugin::getHelp() const
101 {
102  return "Plugin(Probe) gets the value of the view `View' at "
103  "the point (`X',`Y',`Z').\n\n"
104  "If `View' < 0, the plugin is run on the current view.\n\n"
105  "Plugin(Probe) creates one new view.";
106 }
107 
109 {
110  return sizeof(ProbeOptions_Number) / sizeof(StringXNumber);
111 }
112 
114 {
115  return &ProbeOptions_Number[iopt];
116 }
117 
119 {
120  double x = ProbeOptions_Number[0].def;
121  double y = ProbeOptions_Number[1].def;
122  double z = ProbeOptions_Number[2].def;
123  int iView = (int)ProbeOptions_Number[3].def;
124 
125  PView *v1 = getView(iView, v);
126  if(!v1) return v;
127 
128  PView *v2 = new PView();
129  PViewDataList *data2 = getDataList(v2);
130 
131  int numSteps = v1->getData()->getNumTimeSteps();
132  double *val = new double[9 * numSteps];
133 
134  OctreePost o(v1);
135 
136  if(o.searchScalar(x, y, z, val)) {
137  data2->SP.push_back(x);
138  data2->SP.push_back(y);
139  data2->SP.push_back(z);
140  for(int i = 0; i < numSteps; i++) data2->SP.push_back(val[i]);
141  data2->NbSP++;
142  }
143 
144  if(o.searchVector(x, y, z, val)) {
145  data2->VP.push_back(x);
146  data2->VP.push_back(y);
147  data2->VP.push_back(z);
148  for(int i = 0; i < numSteps; i++) {
149  for(int j = 0; j < 3; j++) data2->VP.push_back(val[3 * i + j]);
150  }
151  data2->NbVP++;
152  }
153 
154  if(o.searchTensor(x, y, z, val)) {
155  data2->TP.push_back(x);
156  data2->TP.push_back(y);
157  data2->TP.push_back(z);
158  for(int i = 0; i < numSteps; i++) {
159  for(int j = 0; j < 9; j++) data2->TP.push_back(val[9 * i + j]);
160  }
161  data2->NbTP++;
162  }
163 
164  delete[] val;
165 
166  for(int i = 0; i < numSteps; i++) {
167  double time = v1->getData()->getTime(i);
168  data2->Time.push_back(time);
169  }
170  data2->setName(v1->getData()->getName() + "_Probe");
171  data2->setFileName(v1->getData()->getName() + "_Probe.pos");
172  data2->finalize();
173 
174  return v2;
175 }
GMSH_ProbePlugin::callbackZ
static double callbackZ(int, int, double)
Definition: Probe.cpp:95
PView
Definition: PView.h:27
OctreePost::searchScalar
bool searchScalar(double x, double y, double z, double *values, int step=-1, double *size=nullptr, int qn=0, double *qx=nullptr, double *qy=nullptr, double *qz=nullptr, bool grad=false, int dim=-1)
Definition: OctreePost.cpp:578
GMSH_ProbePlugin::callbackY
static double callbackY(int, int, double)
Definition: Probe.cpp:90
ProbeOptions_Number
StringXNumber ProbeOptions_Number[]
Definition: Probe.cpp:17
GMSH_Plugin
Definition: Plugin.h:26
StringXNumber::def
double def
Definition: Options.h:922
PViewData::getNumTimeSteps
virtual int getNumTimeSteps()=0
PViewDataList::NbTP
int NbTP
Definition: PViewDataList.h:26
OctreePost.h
PViewDataList
Definition: PViewDataList.h:17
GMSH_Plugin::draw
static void(* draw)(void *)
Definition: Plugin.h:77
PViewDataList::NbSP
int NbSP
Definition: PViewDataList.h:26
StringXNumber
Definition: Options.h:918
SBoundingBox3d::min
SPoint3 min() const
Definition: SBoundingBox3d.h:90
OctreePost
Definition: BoundaryLayers.cpp:23
GMSH_RegisterProbePlugin
GMSH_Plugin * GMSH_RegisterProbePlugin()
Definition: Probe.cpp:25
PViewData::setFileName
virtual void setFileName(const std::string &val)
Definition: PViewData.h:75
GMSH_ProbePlugin::getOption
StringXNumber * getOption(int iopt)
Definition: Probe.cpp:113
drawContext::s
double s[3]
Definition: drawContext.h:135
CTX::fg
unsigned int fg
Definition: Context.h:358
CTX::instance
static CTX * instance()
Definition: Context.cpp:122
SPoint3::x
double x(void) const
Definition: SPoint3.h:125
PViewDataList::TP
std::vector< double > TP
Definition: PViewDataList.h:27
Probe.h
PViewData::getTime
virtual double getTime(int step)
Definition: PViewData.h:94
PViewDataList::VP
std::vector< double > VP
Definition: PViewDataList.h:27
PViewDataList::SP
std::vector< double > SP
Definition: PViewDataList.h:27
CTX::lc
double lc
Definition: Context.h:234
GMSH_FULLRC
#define GMSH_FULLRC
Definition: Options.h:20
PView::getData
PViewData * getData(bool useAdaptiveIfAvailable=false)
Definition: PView.cpp:233
SPoint3::y
double y(void) const
Definition: SPoint3.h:127
drawContext
Definition: drawContext.h:120
PViewDataList::finalize
bool finalize(bool computeMinMax=true, const std::string &interpolationScheme="")
Definition: PViewDataList.cpp:81
PViewData::setName
virtual void setName(const std::string &val)
Definition: PViewData.h:71
GMSH_ProbePlugin::getHelp
std::string getHelp() const
Definition: Probe.cpp:100
PViewDataList::NbVP
int NbVP
Definition: PViewDataList.h:26
GMSH_ProbePlugin::getNbOptions
int getNbOptions() const
Definition: Probe.cpp:108
GMSH_ProbePlugin::callback
static double callback(int num, int action, double value, double *opt)
Definition: Probe.cpp:70
Context.h
OctreePost::searchVector
bool searchVector(double x, double y, double z, double *values, int step=-1, double *size=nullptr, int qn=0, double *qx=nullptr, double *qy=nullptr, double *qz=nullptr, bool grad=false, int dim=-1)
Definition: OctreePost.cpp:634
GMSH_ProbePlugin::iview
static int iview
Definition: Probe.h:18
z
const double z
Definition: GaussQuadratureQuad.cpp:56
GMSH_ProbePlugin::execute
PView * execute(PView *)
Definition: Probe.cpp:118
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
PViewDataList::Time
std::vector< double > Time
Definition: PViewDataList.h:25
SPoint3::z
double z(void) const
Definition: SPoint3.h:129
drawContext::pixel_equiv_x
double pixel_equiv_x
Definition: drawContext.h:141
PViewData::getName
virtual std::string getName()
Definition: PViewData.h:70
GMSH_ProbePlugin::callbackX
static double callbackX(int, int, double)
Definition: Probe.cpp:85
PView::list
static std::vector< PView * > list
Definition: PView.h:112
SBoundingBox3d::max
SPoint3 max() const
Definition: SBoundingBox3d.h:91
GMSH_ProbePlugin
Definition: Probe.h:15
SBoundingBox3d
Definition: SBoundingBox3d.h:21
drawContext::drawSphere
void drawSphere(double R, double x, double y, double z, int n1, int n2, int light)
Definition: drawGlyph.cpp:390
GMSH_PostPlugin::getDataList
virtual PViewDataList * getDataList(PView *view, bool showError=true)
Definition: Plugin.cpp:107
OctreePost::searchTensor
bool searchTensor(double x, double y, double z, double *values, int step=-1, double *size=nullptr, int qn=0, double *qx=nullptr, double *qy=nullptr, double *qz=nullptr, bool grad=false, int dim=-1)
Definition: OctreePost.cpp:690
drawContext.h