gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
drawGraph2d.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 <algorithm>
7 #include "drawContext.h"
8 #include "PView.h"
9 #include "PViewOptions.h"
10 #include "PViewData.h"
11 #include "gl2ps.h"
12 #include "Context.h"
13 #include "Numeric.h"
14 
15 int drawContext::fix2dCoordinates(double *x, double *y)
16 {
17  int ret =
18  (*x > 99999 && *y > 99999) ? 3 : (*y > 99999) ? 2 : (*x > 99999) ? 1 : 0;
19 
20  if(*x < 0) // measure from right border
21  *x = viewport[2] + *x;
22  else if(*x > 99999) // by convention, x-centered
23  *x = viewport[2] / 2;
24 
25  if(*y < 0) // measure from bottom border
26  *y = -(*y);
27  else if(*y > 99999) // by convention, y-centered
28  *y = viewport[3] / 2.;
29  else
30  *y = viewport[3] - *y;
31  return ret;
32 }
33 
35 {
36  for(std::size_t i = 0; i < PView::list.size(); i++) {
37  PViewData *data = PView::list[i]->getData();
38  PViewOptions *opt = PView::list[i]->getOptions();
39  if(opt->visible && opt->drawStrings && isVisible(PView::list[i])) {
41  glPushName(5);
42  glPushName(PView::list[i]->getIndex());
43  }
44  glColor4ubv((GLubyte *)&opt->color.text2d);
45  for(int j = 0; j < data->getNumStrings2D(); j++) {
46  double x, y, style;
47  std::string str;
48  data->getString2D(j, opt->timeStep, str, x, y, style);
49  fix2dCoordinates(&x, &y);
50  drawString(str, x, y, 0., style);
51  }
53  glPopName();
54  glPopName();
55  }
56  }
57  }
58 }
59 
60 static bool getGraphData(PView *p, std::vector<double> &x, double &xmin,
61  double &xmax, std::vector<std::vector<double> > &y,
62  double &ymin, double &ymax)
63 {
64  PViewData *data = p->getData(true); // use adaptive data if available
65  PViewOptions *opt = p->getOptions();
66 
67  if(data->hasMultipleMeshes()) return false; // cannot handle multi-mesh
68 
69  int numy = 0;
70  if(opt->type == PViewOptions::Plot2D ||
72  numy = 1;
73  }
74  else if(opt->type == PViewOptions::Plot2DTime) {
75  numy = 0;
76  for(int ent = 0; ent < data->getNumEntities(0); ent++) {
77  if(data->skipEntity(0, ent)) continue;
78  for(int ele = 0; ele < data->getNumElements(0, ent); ele++) {
79  if(data->skipElement(0, ent, ele, true)) continue;
80  if(opt->skipElement(data->getType(0, ent, ele))) continue;
81  if(data->getDimension(0, ent, ele) >= 2) continue;
82  numy++;
83  }
84  }
85  }
86 
87  if(!numy) return false;
88  y.resize(numy);
89 
90  bool space = (opt->type == PViewOptions::Plot2D ||
92 
93  int which2d = 0;
94  if(opt->type == PViewOptions::Plot2D) {
95  SBoundingBox3d bbox = p->getData()->getBoundingBox();
96  SPoint3 min = bbox.min();
97  SPoint3 max = bbox.max();
98  if(fabs(max.y() - min.y()) > fabs(max.x() - min.x()) &&
99  fabs(max.y() - min.y()) > fabs(max.z() - min.z()))
100  which2d = 1;
101  else if(fabs(max.z() - min.z()) > fabs(max.x() - min.x()) &&
102  fabs(max.z() - min.z()) > fabs(max.y() - min.y()))
103  which2d = 2;
104  }
105 
106  SPoint3 p0(0., 0., 0.);
107 
108  numy = 0;
109  for(int ent = 0; ent < data->getNumEntities(0); ent++) {
110  if(data->skipEntity(0, ent)) continue;
111  for(int ele = 0; ele < data->getNumElements(0, ent); ele++) {
112  if(data->skipElement(0, ent, ele, true)) continue;
113  if(opt->skipElement(data->getType(0, ent, ele))) continue;
114  if(data->getDimension(0, ent, ele) >= 2) continue;
115  int numNodes = data->getNumNodes(0, ent, ele);
116  // reorder the nodes for high order line elements
117  std::vector<int> reorder(numNodes);
118  if(numNodes < 3) {
119  for(int j = 0; j < numNodes; j++) reorder[j] = j;
120  }
121  else {
122  reorder[0] = 0;
123  reorder[numNodes - 1] = 1;
124  for(int j = 1; j < numNodes - 1; j++) reorder[j] = 1 + j;
125  }
126  for(int ts = space ? opt->timeStep : 0; ts < opt->timeStep + 1; ts++) {
127  if(!data->hasTimeStep(ts)) continue;
128  int numComp = data->getNumComponents(ts, ent, ele);
129  for(int j = 0; j < numNodes; j++) {
130  double val[9], xyz[3];
131  data->getNode(ts, ent, ele, reorder[j], xyz[0], xyz[1], xyz[2]);
132  for(int k = 0; k < numComp; k++)
133  data->getValue(ts, ent, ele, reorder[j], k, val[k]);
134  double vy = ComputeScalarRep(numComp, val);
135 
136  if(opt->type == PViewOptions::Plot2D) {
137  x.push_back(xyz[which2d]);
138  y[0].push_back(vy);
139  }
140  else if(opt->type == PViewOptions::Plot2DSpace) {
141  // compute curvilinear coordinate
142  if(x.empty()) {
143  p0 = SPoint3(xyz[0], xyz[1], xyz[2]);
144  x.push_back(ComputeScalarRep(3, xyz));
145  }
146  else {
147  SPoint3 p1(xyz[0], xyz[1], xyz[2]);
148  x.push_back(x.back() + p0.distance(p1));
149  p0 = p1;
150  }
151  y[0].push_back(vy);
152  }
153  else {
154  if(!numy) x.push_back(data->getTime(ts));
155  y[numy].push_back(vy);
156  }
157  }
158  }
159  numy++;
160  }
161  }
162 
163  if(x.empty()) return false;
164 
166  std::vector<double> x2;
167  std::vector<std::vector<double> > y2(y.size());
168  for(std::size_t i = 0; i < x.size(); i++) {
169  if(x[i] >= opt->customAbscissaMin && x[i] <= opt->customAbscissaMax) {
170  x2.push_back(x[i]);
171  for(std::size_t j = 0; j < y2.size(); j++) y2[j].push_back(y[j][i]);
172  }
173  }
174  x = x2;
175  y = y2;
176  }
177 
178  if(space) {
179  xmin = xmax = x[0];
180  for(std::size_t i = 1; i < x.size(); i++) {
181  xmin = std::min(xmin, x[i]);
182  xmax = std::max(xmax, x[i]);
183  }
184  }
185  else {
186  xmin = data->getTime(0);
187  xmax = data->getTime(data->getNumTimeSteps() - 1);
188  }
189 
191  for(std::size_t i = 0; i < y.size(); i++)
192  for(std::size_t j = 0; j < y[i].size(); j++) y[i][j] = log10(y[i][j]);
193 
194  ymin = VAL_INF;
195  ymax = -VAL_INF;
196  for(std::size_t i = 0; i < y.size(); i++) {
197  for(std::size_t j = 0; j < y[i].size(); j++) {
198  ymin = std::min(ymin, y[i][j]);
199  ymax = std::max(ymax, y[i][j]);
200  }
201  }
202 
203  return true;
204 }
205 
206 static void drawGraphAxes(drawContext *ctx, PView *p, double xleft, double ytop,
207  double width, double height, double xmin, double xmax,
208  double tic, int overlay, bool inModelCoordinates)
209 {
210  PViewData *data = p->getData();
211  PViewOptions *opt = p->getOptions();
212 
213  if(!opt->axes) return;
214 
215  if(overlay > 2) return;
216 
217  if(width <= 0 || height <= 0) return;
218 
219  if(!overlay && !inModelCoordinates) {
220  int alpha = CTX::instance()->unpackAlpha(opt->color.background2d);
221  if(alpha != 0) {
222  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
223  glEnable(GL_BLEND);
224  glColor4ubv((GLubyte *)&opt->color.background2d);
225  glBegin(GL_QUADS);
226  glVertex2d(xleft, ytop);
227  glVertex2d(xleft + width, ytop);
228  glVertex2d(xleft + width, ytop - height);
229  glVertex2d(xleft, ytop - height);
230  glEnd();
231  glDisable(GL_BLEND);
232  }
233  }
234 
235  // total font height
236  double font_h = drawContext::global()->getStringHeight() ?
238  1;
239  // height above ref. point
240  double font_a = font_h - drawContext::global()->getStringDescent();
241 
242  if(inModelCoordinates) {
243  double ss = ctx->pixel_equiv_x / ctx->s[0];
244  font_h *= ss;
245  font_a *= ss;
246  }
247 
248  double ps = CTX::instance()->pointSize * ctx->highResolutionPixelFactor();
249 
250  glPointSize((float)ps);
251  gl2psPointSize((float)(CTX::instance()->pointSize *
253 
254  glLineWidth((float)CTX::instance()->lineWidth);
255  gl2psLineWidth((float)(CTX::instance()->lineWidth *
257 
258  glColor4ubv((GLubyte *)&opt->color.axes);
259 
260  // bare axes
261  if(!overlay) {
262  glBegin(GL_LINE_STRIP);
263  glVertex2d(xleft, ytop);
264  glVertex2d(xleft, ytop - height);
265  glVertex2d(xleft + width, ytop - height);
266  if(opt->axes > 1) {
267  glVertex2d(xleft + width, ytop);
268  glVertex2d(xleft, ytop);
269  }
270  glEnd();
271  }
272 
273  // y label
274  std::string label = data->getName();
275  if(opt->type == PViewOptions::Plot2D ||
277  int nt = data->getNumTimeSteps();
278  if((opt->showTime == 1 && nt > 1) || opt->showTime == 2) {
279  char tmp[256];
280  sprintf(tmp, opt->format.c_str(), data->getTime(opt->timeStep));
281  label += std::string(" (") + tmp + ")";
282  }
283  else if((opt->showTime == 3 && nt > 1) || opt->showTime == 4) {
284  char tmp[256];
285  sprintf(tmp, "%d", opt->timeStep);
286  label += std::string(" (") + tmp + ")";
287  }
288  }
289  if(opt->scaleType == PViewOptions::Logarithmic) label = "Log10 " + label;
290  ctx->drawString(label, xleft + (overlay ? width : 0), ytop + font_h + tic, 0,
291  CTX::instance()->glFontTitle,
292  CTX::instance()->glFontEnumTitle,
293  CTX::instance()->glFontSizeTitle, 1);
294 
295  // x label
296  label = opt->axesLabel[0];
297  ctx->drawString(
298  label, xleft + width / 2,
299  ytop - height - 2 * font_h - 2 * tic - overlay * (font_h + tic), 0,
300  CTX::instance()->glFontTitle, CTX::instance()->glFontEnumTitle,
301  CTX::instance()->glFontSizeTitle, 1);
302 
303  // y tics and horizontal grid
304  if(opt->nbIso > 0) {
305  int nb = opt->nbIso;
306  if(opt->showScale && (opt->nbIso * font_h > height))
307  nb = (int)floor(height / font_h);
308  double dy = height / (double)nb;
309  double dv = (opt->tmpMax - opt->tmpMin) / (double)nb;
310  for(int i = 0; i < nb + 1; i++) {
311  glBegin(GL_LINES);
312  glVertex2d(xleft, ytop - i * dy);
313  glVertex2d(xleft + tic, ytop - i * dy);
314  if(opt->axes > 1) {
315  glVertex2d(xleft + width - tic, ytop - i * dy);
316  glVertex2d(xleft + width, ytop - i * dy);
317  }
318  glEnd();
319  if(opt->axes > 2 && i != 0 && i != nb) {
320  glEnable(GL_LINE_STIPPLE);
321  glLineStipple(1, 0x1111);
323  gl2psLineWidth((float)(1. * CTX::instance()->print.epsLineWidthFactor));
324  glBegin(GL_LINES);
325  glVertex2d(xleft, ytop - i * dy);
326  glVertex2d(xleft + width, ytop - i * dy);
327  glEnd();
328  glDisable(GL_LINE_STIPPLE);
330  gl2psLineWidth((float)(CTX::instance()->lineWidth *
332  }
333  if(opt->showScale) {
334  char tmp[256];
335  sprintf(tmp, opt->format.c_str(),
336  (i == nb) ? opt->tmpMin : (opt->tmpMax - i * dv));
337  if(!overlay) {
338  ctx->drawStringRight(tmp, xleft - 2 * tic,
339  ytop - i * dy - font_a / 3., 0.);
340  }
341  else {
342  ctx->drawString(tmp, xleft + width + 2 * tic,
343  ytop - i * dy - font_a / 3., 0.);
344  }
345  }
346  }
347  }
348 
349  // x tics and vertical grid
350  if(opt->axesTics[0] > 0) {
351  int nb = opt->axesTics[0];
352  char tmp[256];
353  sprintf(tmp, opt->axesFormat[0].c_str(), -M_PI * 1.e4);
354  double ww = drawContext::global()->getStringWidth(tmp);
355  if(inModelCoordinates) ww *= ctx->pixel_equiv_x / ctx->s[0];
356  if((nb - 1) * ww > width) nb = (int)(width / ww) + 1;
357  if(nb == 1) nb++;
358 
359  double dx = width / (double)(nb - 1);
360  double ybot = ytop - height;
361 
362  for(int i = 0; i < nb; i++) {
363  glBegin(GL_LINES);
364  glVertex2d(xleft + i * dx, ybot);
365  glVertex2d(xleft + i * dx, ybot + tic);
366  if(opt->axes > 1) {
367  glVertex2d(xleft + i * dx, ytop);
368  glVertex2d(xleft + i * dx, ytop - tic);
369  }
370  glEnd();
371  if(opt->axes > 2 && i != 0 && i != nb - 1) {
372  glEnable(GL_LINE_STIPPLE);
373  glLineStipple(1, 0x1111);
375  gl2psLineWidth((float)(1. * CTX::instance()->print.epsLineWidthFactor));
376  glBegin(GL_LINES);
377  glVertex2d(xleft + i * dx, ytop);
378  glVertex2d(xleft + i * dx, ybot);
379  glEnd();
380  glDisable(GL_LINE_STIPPLE);
382  gl2psLineWidth((float)(CTX::instance()->lineWidth *
384  }
385  if(opt->showScale) {
386  char tmp[256];
387  if(nb == 1)
388  sprintf(tmp, opt->axesFormat[0].c_str(), xmin);
389  else
390  sprintf(tmp, opt->axesFormat[0].c_str(),
391  xmin + i * (xmax - xmin) / (double)(nb - 1));
392  ctx->drawStringCenter(tmp, xleft + i * dx,
393  ybot - font_h - tic - overlay * (font_h + tic),
394  0.);
395  }
396  }
397  }
398 }
399 
400 static std::map<SPoint2, unsigned int> tags;
401 static std::map<unsigned int, SPoint2> tags_rev;
402 
403 static unsigned int getTagForGraph2dDataPoint(const SPoint2 &p)
404 {
405  auto it = tags.find(p);
406  if(it != tags.end()) return it->second;
407  int t = tags.size();
408  tags[p] = t;
409  tags_rev[t] = p;
410  return t;
411 }
412 
413 SPoint2 getGraph2dDataPointForTag(unsigned int tag) { return tags_rev[tag]; }
414 
415 static void addGraphPoint(drawContext *ctx, PView *p, double xleft, double ytop,
416  double width, double height, double x, double y,
417  double xmin, double xmax, double ymin, double ymax,
418  bool numeric, bool singlePoint,
419  bool inModelCoordinates)
420 {
421  PViewOptions *opt = p->getOptions();
422 
423  double px = xleft;
424  if(xmin != xmax) px += (x - xmin) / (xmax - xmin) * width;
425 
426  if(opt->saturateValues) {
427  if(y > ymax)
428  y = ymax;
429  else if(y < ymin)
430  y = ymin;
431  }
432 
433  double ybot = ytop - height;
434  double py = ybot;
435  if(ymax != ymin) py += (y - ymin) / (ymax - ymin) * height;
436 
437  if(y >= ymin && y <= ymax) {
438  unsigned int col = opt->getColor(y, ymin, ymax, true);
439  glColor4ubv((GLubyte *)&col);
440 
441  if(singlePoint && ctx->render_mode == drawContext::GMSH_SELECT) {
442  glPushName(4);
443  glPushName(getTagForGraph2dDataPoint(SPoint2(x, y)));
444  }
445 
446  if(numeric) {
447  double offset = 3;
448  if(inModelCoordinates) offset *= ctx->pixel_equiv_x / ctx->s[0];
449  char label[256];
450  sprintf(label, opt->format.c_str(), y);
451  ctx->drawString(label, px + offset, py + offset, 0.);
452  }
453  else if(singlePoint && (opt->pointType == 1 || opt->pointType == 3)) {
454  double ps = CTX::instance()->pointSize * ctx->highResolutionPixelFactor();
455  if(inModelCoordinates)
456  ctx->drawSphere(ps, px, py, 0, opt->light);
457  else
458  ctx->drawSphere(ps, px, py, 0, 10, 10, opt->light);
459  }
460  else {
461  if(singlePoint) glBegin(GL_POINTS);
462  glVertex2d(px, py);
463  if(singlePoint) glEnd();
464  }
465 
466  if(singlePoint && ctx->render_mode == drawContext::GMSH_SELECT) {
467  glPopName();
468  glPopName();
469  }
470  }
471 }
472 
473 static void drawGraphCurves(drawContext *ctx, PView *p, double xleft,
474  double ytop, double width, double height,
475  std::vector<double> &x, double xmin, double xmax,
476  std::vector<std::vector<double> > &y,
477  bool inModelCoordinates)
478 {
479  if(width <= 0 || height <= 0) return;
480 
481  PViewOptions *opt = p->getOptions();
482 
483  double ps = CTX::instance()->pointSize * ctx->highResolutionPixelFactor();
484 
485  glPointSize((float)ps);
487  (float)(opt->pointSize * CTX::instance()->print.epsPointSizeFactor));
488 
489  glLineWidth((float)opt->lineWidth);
491  (float)(opt->lineWidth * CTX::instance()->print.epsLineWidthFactor));
492 
495  for(std::size_t i = 0; i < y.size(); i++) {
496  if(opt->useStipple) {
497  glEnable(GL_LINE_STIPPLE);
498  glLineStipple(opt->stipple[i % 10][0], opt->stipple[i % 10][1]);
500  }
501  glBegin(GL_LINE_STRIP);
502  for(std::size_t j = 0; j < x.size(); j++)
503  addGraphPoint(ctx, p, xleft, ytop, width, height, x[j], y[i][j], xmin,
504  xmax, opt->tmpMin, opt->tmpMax, false, false,
505  inModelCoordinates);
506  glEnd();
507  if(opt->useStipple) {
508  glDisable(GL_LINE_STIPPLE);
510  }
511  }
512  }
513 
514  if(opt->intervalsType == PViewOptions::Iso ||
517  for(std::size_t i = 0; i < y.size(); i++)
518  for(std::size_t j = 0; j < x.size(); j++)
519  addGraphPoint(ctx, p, xleft, ytop, width, height, x[j], y[i][j], xmin,
520  xmax, opt->tmpMin, opt->tmpMax, false, true,
521  inModelCoordinates);
522  }
523 
525  for(std::size_t i = 0; i < y.size(); i++)
526  for(std::size_t j = 0; j < x.size(); j++)
527  addGraphPoint(ctx, p, xleft, ytop, width, height, x[j], y[i][j], xmin,
528  xmax, opt->tmpMin, opt->tmpMax, true, true,
529  inModelCoordinates);
530  }
531 }
532 
533 static void drawGraph(drawContext *ctx, PView *p, double xleft, double ytop,
534  double width, double height, double tic, int overlay = 0,
535  bool inModelCoordinates = false)
536 {
537  std::vector<double> x;
538  std::vector<std::vector<double> > y;
539  double xmin, xmax, ymin, ymax;
540  if(!getGraphData(p, x, xmin, xmax, y, ymin, ymax)) return;
541 
542  PViewData *data = p->getData(true); // use adaptive data if available
543  PViewOptions *opt = p->getOptions();
544  if(opt->rangeType == PViewOptions::Custom) {
545  opt->tmpMin = opt->customMin;
546  opt->tmpMax = opt->customMax;
547  }
548  else if(opt->rangeType == PViewOptions::PerTimeStep) {
549  opt->tmpMin = data->getMin(opt->timeStep);
550  opt->tmpMax = data->getMax(opt->timeStep);
551  }
552  else if(opt->abscissaRangeType == PViewOptions::Custom) {
553  // FIXME: should also compute min/max for reduced abscissa range over all
554  // steps
555  opt->tmpMin = ymin;
556  opt->tmpMax = ymax;
557  }
558  else {
559  opt->tmpMin = data->getMin();
560  opt->tmpMax = data->getMax();
561  }
562 
564  opt->tmpMin = log10(opt->tmpMin);
565  opt->tmpMax = log10(opt->tmpMax);
566  }
567 
568  drawGraphAxes(ctx, p, xleft, ytop, width, height, xmin, xmax, tic, overlay,
569  inModelCoordinates);
570  drawGraphCurves(ctx, p, xleft, ytop, width, height, x, xmin, xmax, y,
571  inModelCoordinates);
572 }
573 
574 void drawContext::drawGraph2d(bool inModelCoordinates)
575 {
576  std::vector<PView *> graphs;
577  for(std::size_t i = 0; i < PView::list.size(); i++) {
578  PViewData *data = PView::list[i]->getData();
579  PViewOptions *opt = PView::list[i]->getOptions();
580  if(!data->getDirty() && opt->visible && opt->type != PViewOptions::Plot3D &&
582  graphs.push_back(PView::list[i]);
583  }
584  if(graphs.empty()) return;
585 
586  drawContext::global()->setFont(CTX::instance()->glFontEnum,
587  CTX::instance()->glFontSize);
588  double tic = 5; // size of tic marks and interline
589  double mx = 25, my = 5; // x- and y-margin
590  double xsep = 0., ysep = drawContext::global()->getStringHeight() + tic;
591  char label[1024];
592  for(std::size_t i = 0; i < graphs.size(); i++) {
593  PViewOptions *opt = graphs[i]->getOptions();
594  sprintf(label, opt->format.c_str(), -M_PI * 1.e4);
595  xsep = std::max(xsep, drawContext::global()->getStringWidth(label));
596  }
597  xsep += tic;
598 
599  if(inModelCoordinates) {
600  double ss = pixel_equiv_x / s[0];
601  tic *= ss;
602  mx *= ss;
603  my *= ss;
604  xsep *= ss;
605  ysep *= ss;
606  }
607 
608  // +------------------winw-------------------+
609  // | my+3*ysep |
610  // |mx+xsep+---w---+mx+2*xsep+---w---+mx+xsep|
611  // | | | | | |
612  // | h | | | |
613  // | | | | | |
614  // | +-------+ +-------+ |
615  // winh my+5*ysep |
616  // | +-------+ +-------+ |
617  // | | | | | |
618  // | h | | | |
619  // | | | | | |
620  // | +-------+ +-------+ |
621  // | my+4*ysep |
622  // +-----------------------------------------+
623 
624  int overlay[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
625  double winw = viewport[2] - viewport[0];
626  double winh = viewport[3] - viewport[1];
627  for(std::size_t i = 0; i < graphs.size(); i++) {
628  double x = viewport[0] + mx + xsep;
629  double y = viewport[1] + my + 3 * ysep;
630  PView *p = graphs[i];
631  PViewOptions *opt = graphs[i]->getOptions();
632  if(opt->autoPosition == 0 && !inModelCoordinates) { // manual
633  double x = opt->position[0], y = opt->position[1];
634  int center = fix2dCoordinates(&x, &y);
635  drawGraph(this, p, x - (center & 1 ? opt->size[0] / 2. : 0),
636  y + (center & 2 ? opt->size[1] / 2. : 0), opt->size[0],
637  opt->size[1], tic);
638  }
639  else if(opt->autoPosition == 1 && !inModelCoordinates) { // automatic
640  if(graphs.size() == 1) {
641  double w = winw - 2 * mx - 2 * xsep;
642  double h = winh - 2 * my - 7 * ysep;
643  drawGraph(this, p, x, viewport[3] - y, w, h, tic);
644  }
645  else if(graphs.size() == 2) {
646  double w = winw - 2 * mx - 2 * xsep;
647  double h = (winh - 3 * my - 12 * ysep) / 2.;
648  if(i == 1) y += (h + my + 5 * ysep);
649  drawGraph(this, p, x, viewport[3] - y, w, h, tic);
650  }
651  else {
652  double w = (winw - 3 * mx - 4 * xsep) / 2.;
653  double h = (winh - 3 * my - 12 * ysep) / 2.;
654  if(i == 1 || i == 3) x += (w + mx + 2 * xsep);
655  if(i == 2 || i == 3) y += (h + 5 * ysep);
656  drawGraph(this, p, x, viewport[3] - y, w, h, tic);
657  }
658  }
659  else if(opt->autoPosition >= 2 && opt->autoPosition <= 11 &&
660  !inModelCoordinates) {
661  // top left (2), top right (3), bottom left (4), bottom right (5), top
662  // half (6), bottom half (7), left half (8), right half (9), full (10),
663  // top third (11)
664  int a = opt->autoPosition;
665  double w, h;
666  if(a <= 5 || a == 8 || a == 9)
667  w = (winw - 3 * mx - 4 * xsep) / 2.;
668  else
669  w = winw - 2 * mx - 2 * xsep;
670  if(a <= 5 || a == 6 || a == 7)
671  h = (winh - 3 * my - 12 * ysep) / 2.;
672  else if(a == 11)
673  h = (winh - 3 * my - 12 * ysep) / 3.;
674  else
675  h = winh - 2 * my - 7 * ysep;
676  if(a == 3 || a == 5 || a == 9) x += (w + mx + 2 * xsep);
677  if(a == 4 || a == 5 || a == 7) y += (h + my + 5 * ysep);
678  drawGraph(this, p, x, viewport[3] - y, w, h, tic,
679  overlay[opt->autoPosition]);
680  if(opt->axes)
681  overlay[opt->autoPosition] += (opt->axesLabel[0].size() ? 2 : 1);
682  }
683  else if(opt->autoPosition == 12 &&
684  inModelCoordinates) { // in model coordinates
685  drawGraph(this, p, opt->position[0], opt->position[1] + opt->size[1],
686  opt->size[0], opt->size[1], tic, 0, true);
687  }
688  }
689 }
drawContext::fix2dCoordinates
int fix2dCoordinates(double *x, double *y)
Definition: drawGraph2d.cpp:15
PViewOptions::timeStep
int timeStep
Definition: PViewOptions.h:61
gl2ps.h
PViewOptions::lineWidth
double lineWidth
Definition: PViewOptions.h:69
drawContext::highResolutionPixelFactor
double highResolutionPixelFactor()
Definition: drawContext.cpp:73
tags
static std::map< SPoint2, unsigned int > tags
Definition: drawGraph2d.cpp:400
PView
Definition: PView.h:27
PViewOptions::Plot2DSpace
@ Plot2DSpace
Definition: PViewOptions.h:18
gl2psEnable
GL2PSDLL_API GLint gl2psEnable(GLint mode)
Definition: gl2ps.cpp:6476
getGraphData
static bool getGraphData(PView *p, std::vector< double > &x, double &xmin, double &xmax, std::vector< std::vector< double > > &y, double &ymin, double &ymax)
Definition: drawGraph2d.cpp:60
PViewData::skipElement
virtual bool skipElement(int step, int ent, int ele, bool checkVisibility=false, int samplingRate=1)
Definition: PViewData.cpp:90
tags_rev
static std::map< unsigned int, SPoint2 > tags_rev
Definition: drawGraph2d.cpp:401
PViewData::getNumStrings2D
virtual int getNumStrings2D()
Definition: PViewData.h:186
SPoint2
Definition: SPoint2.h:12
PViewData::getNumTimeSteps
virtual int getNumTimeSteps()=0
drawContext::drawStringCenter
void drawStringCenter(const std::string &s, double x, double y, double z, int line_num=0)
Definition: drawGlyph.cpp:147
PViewOptions::skipElement
bool skipElement(int type)
Definition: PViewOptions.cpp:139
PViewData::getNode
virtual int getNode(int step, int ent, int ele, int nod, double &x, double &y, double &z)
Definition: PViewData.h:141
PViewOptions::tmpMax
double tmpMax
Definition: PViewOptions.h:47
drawContext::drawText2d
void drawText2d()
Definition: drawGraph2d.cpp:34
drawContext::drawString
void drawString(const std::string &s, double x, double y, double z, const std::string &font_name, int font_enum, int font_size, int align, int line_num=0)
Definition: drawGlyph.cpp:16
CTX::epsPointSizeFactor
double epsPointSizeFactor
Definition: Context.h:341
SPoint3
Definition: SPoint3.h:14
PViewData::getValue
virtual void getValue(int step, int ent, int ele, int idx, double &val)
Definition: PViewData.h:159
PViewOptions::text2d
unsigned int text2d
Definition: PViewOptions.h:89
SBoundingBox3d::min
SPoint3 min() const
Definition: SBoundingBox3d.h:90
PViewOptions::useStipple
int useStipple
Definition: PViewOptions.h:71
PViewOptions::color
struct PViewOptions::@32 color
PViewOptions::stipple
int stipple[10][2]
Definition: PViewOptions.h:71
VAL_INF
#define VAL_INF
Definition: PViewData.h:16
PViewOptions::size
double size[2]
Definition: PViewOptions.h:41
drawContextGlobal::setFont
virtual void setFont(int fontid, int fontsize)
Definition: drawContext.h:104
CTX::epsLineWidthFactor
double epsLineWidthFactor
Definition: Context.h:341
PView.h
PViewOptions::axesTics
double axesTics[3]
Definition: PViewOptions.h:44
PViewOptions::showScale
int showScale
Definition: PViewOptions.h:58
PViewData::hasMultipleMeshes
virtual bool hasMultipleMeshes()
Definition: PViewData.h:216
PViewData::getNumEntities
virtual int getNumEntities(int step=-1)
Definition: PViewData.h:127
PViewData.h
gl2psPointSize
GL2PSDLL_API GLint gl2psPointSize(GLfloat value)
Definition: gl2ps.cpp:6537
PViewOptions::nbIso
int nbIso
Definition: PViewOptions.h:54
PViewOptions::Iso
@ Iso
Definition: PViewOptions.h:19
drawContext::global
static drawContextGlobal * global()
Definition: drawContext.cpp:85
PViewOptions::abscissaRangeType
int abscissaRangeType
Definition: PViewOptions.h:59
drawGraphAxes
static void drawGraphAxes(drawContext *ctx, PView *p, double xleft, double ytop, double width, double height, double xmin, double xmax, double tic, int overlay, bool inModelCoordinates)
Definition: drawGraph2d.cpp:206
PViewOptions::customMax
double customMax
Definition: PViewOptions.h:47
drawContext::s
double s[3]
Definition: drawContext.h:135
getTagForGraph2dDataPoint
static unsigned int getTagForGraph2dDataPoint(const SPoint2 &p)
Definition: drawGraph2d.cpp:403
PViewData::getDirty
virtual bool getDirty()
Definition: PViewData.h:62
CTX::instance
static CTX * instance()
Definition: Context.cpp:122
PViewOptions::Numeric
@ Numeric
Definition: PViewOptions.h:19
drawContext::GMSH_SELECT
@ GMSH_SELECT
Definition: drawContext.h:145
SPoint3::x
double x(void) const
Definition: SPoint3.h:125
PViewOptions::customAbscissaMax
double customAbscissaMax
Definition: PViewOptions.h:48
PViewData::getDimension
virtual int getDimension(int step, int ent, int ele)
Definition: PViewData.h:134
PViewOptions::pointType
int pointType
Definition: PViewOptions.h:68
addGraphPoint
static void addGraphPoint(drawContext *ctx, PView *p, double xleft, double ytop, double width, double height, double x, double y, double xmin, double xmax, double ymin, double ymax, bool numeric, bool singlePoint, bool inModelCoordinates)
Definition: drawGraph2d.cpp:415
PViewData::getTime
virtual double getTime(int step)
Definition: PViewData.h:94
PViewData::getMax
virtual double getMax(int step=-1, bool onlyVisible=false, int tensorRep=0, int forceNumComponents=0, int componentMap[9]=nullptr)=0
PViewData::getType
virtual int getType(int step, int ent, int ele)
Definition: PViewData.h:183
drawContext::drawStringRight
void drawStringRight(const std::string &s, double x, double y, double z, int line_num=0)
Definition: drawGlyph.cpp:154
drawGraph
static void drawGraph(drawContext *ctx, PView *p, double xleft, double ytop, double width, double height, double tic, int overlay=0, bool inModelCoordinates=false)
Definition: drawGraph2d.cpp:533
drawContext::isVisible
bool isVisible(GModel *m)
Definition: drawContext.h:202
PViewData::getBoundingBox
virtual SBoundingBox3d getBoundingBox(int step=-1)=0
drawGraphCurves
static void drawGraphCurves(drawContext *ctx, PView *p, double xleft, double ytop, double width, double height, std::vector< double > &x, double xmin, double xmax, std::vector< std::vector< double > > &y, bool inModelCoordinates)
Definition: drawGraph2d.cpp:473
Numeric.h
PViewData::hasTimeStep
virtual bool hasTimeStep(int step)
Definition: PViewData.h:211
PView::getData
PViewData * getData(bool useAdaptiveIfAvailable=false)
Definition: PView.cpp:233
PViewOptions::rangeType
int rangeType
Definition: PViewOptions.h:59
PViewOptions::background2d
unsigned int background2d
Definition: PViewOptions.h:89
PViewOptions::intervalsType
int intervalsType
Definition: PViewOptions.h:54
PViewOptions.h
PViewOptions::saturateValues
int saturateValues
Definition: PViewOptions.h:57
PViewOptions::format
std::string format
Definition: PViewOptions.h:42
PViewData::getNumNodes
virtual int getNumNodes(int step, int ent, int ele)
Definition: PViewData.h:137
SPoint3::y
double y(void) const
Definition: SPoint3.h:127
drawContext::render_mode
int render_mode
Definition: drawContext.h:146
drawContext
Definition: drawContext.h:120
drawContextGlobal::getStringDescent
virtual int getStringDescent()
Definition: drawContext.h:107
GL2PS_LINE_STIPPLE
#define GL2PS_LINE_STIPPLE
Definition: gl2ps.h:149
PViewOptions::Plot2D
@ Plot2D
Definition: PViewOptions.h:18
getGraph2dDataPointForTag
SPoint2 getGraph2dDataPointForTag(unsigned int tag)
Definition: drawGraph2d.cpp:413
PViewOptions::customMin
double customMin
Definition: PViewOptions.h:47
PViewOptions::showTime
int showTime
Definition: PViewOptions.h:58
CTX::print
struct CTX::@2 print
PViewData
Definition: PViewData.h:29
PViewOptions::scaleType
int scaleType
Definition: PViewOptions.h:59
drawContextGlobal::getStringHeight
virtual int getStringHeight()
Definition: drawContext.h:106
PViewOptions::Plot2DTime
@ Plot2DTime
Definition: PViewOptions.h:18
CTX::unpackAlpha
int unpackAlpha(unsigned int X)
Definition: Context.cpp:160
PViewOptions::type
int type
Definition: PViewOptions.h:40
SPoint3::distance
double distance(const SPoint3 &p) const
Definition: SPoint3.h:176
drawContextGlobal::getStringWidth
virtual double getStringWidth(const char *str)
Definition: drawContext.h:105
PViewOptions::PerTimeStep
@ PerTimeStep
Definition: PViewOptions.h:37
gl2psDisable
GL2PSDLL_API GLint gl2psDisable(GLint mode)
Definition: gl2ps.cpp:6512
Context.h
PViewOptions::autoPosition
int autoPosition
Definition: PViewOptions.h:40
PViewOptions::Discrete
@ Discrete
Definition: PViewOptions.h:19
PViewData::getNumComponents
virtual int getNumComponents(int step, int ent, int ele)
Definition: PViewData.h:152
PViewOptions::axesFormat
std::string axesFormat[3]
Definition: PViewOptions.h:45
PViewOptions::customAbscissaMin
double customAbscissaMin
Definition: PViewOptions.h:48
drawContext::viewport
int viewport[4]
Definition: drawContext.h:137
PViewOptions
Definition: PViewOptions.h:16
PView::getOptions
PViewOptions * getOptions()
Definition: PView.h:81
gl2psLineWidth
GL2PSDLL_API GLint gl2psLineWidth(GLfloat value)
Definition: gl2ps.cpp:6567
PViewOptions::axes
int axes
Definition: PViewOptions.h:43
PViewOptions::Continuous
@ Continuous
Definition: PViewOptions.h:19
SPoint3::z
double z(void) const
Definition: SPoint3.h:129
PViewData::getMin
virtual double getMin(int step=-1, bool onlyVisible=false, int tensorRep=0, int forceNumComponents=0, int componentMap[9]=nullptr)=0
PViewData::getNumElements
virtual int getNumElements(int step=-1, int ent=-1)
Definition: PViewData.h:131
drawContext::pixel_equiv_x
double pixel_equiv_x
Definition: drawContext.h:141
PViewOptions::Logarithmic
@ Logarithmic
Definition: PViewOptions.h:38
PViewData::getName
virtual std::string getName()
Definition: PViewData.h:70
drawContext::drawGraph2d
void drawGraph2d(bool inModelCoordinates)
Definition: drawGraph2d.cpp:574
PViewOptions::tmpMin
double tmpMin
Definition: PViewOptions.h:47
PViewOptions::Custom
@ Custom
Definition: PViewOptions.h:37
PViewOptions::position
double position[2]
Definition: PViewOptions.h:41
PViewData::getString2D
virtual void getString2D(int i, int step, std::string &str, double &x, double &y, double &style)
Definition: PViewData.h:190
CTX::pointSize
double pointSize
Definition: Context.h:271
PView::list
static std::vector< PView * > list
Definition: PView.h:112
SBoundingBox3d::max
SPoint3 max() const
Definition: SBoundingBox3d.h:91
PViewOptions::drawStrings
int drawStrings
Definition: PViewOptions.h:63
PViewOptions::pointSize
double pointSize
Definition: PViewOptions.h:69
PViewOptions::axesLabel
std::string axesLabel[3]
Definition: PViewOptions.h:45
PViewOptions::getColor
unsigned int getColor(double val, double min, double max, bool forceLinear=false, int numColors=-1)
Definition: PViewOptions.cpp:86
PViewOptions::light
int light
Definition: PViewOptions.h:55
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
ComputeScalarRep
double ComputeScalarRep(int numComp, double *val, int tensorRep)
Definition: Numeric.cpp:506
PViewOptions::visible
int visible
Definition: PViewOptions.h:54
PViewData::skipEntity
virtual bool skipEntity(int step, int ent)
Definition: PViewData.h:206
PViewOptions::Plot3D
@ Plot3D
Definition: PViewOptions.h:18
drawContext.h