gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
PViewOptions.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 "GmshMessage.h"
9 #include "GmshDefines.h"
10 #include "PViewOptions.h"
11 #include "mathEvaluator.h"
12 
13 PViewOptions::PViewOptions() : genRaiseEvaluator(nullptr)
14 {
17  currentTime = 0.;
18 }
19 
21 {
23 }
24 
26 
28 {
29  if(!_reference) _reference = new PViewOptions();
30  return _reference;
31 }
32 
33 double PViewOptions::getScaleValue(int iso, int numIso, double min, double max)
34 {
35  if(numIso == 1) return (min + max) / 2.;
36 
37  if(scaleType == Linear) {
38  // treat min/max separately to avoid numerical errors (important
39  // not to miss first/last discrete iso on piece-wise constant
40  // datasets)
41  if(iso == 0)
42  return min;
43  else if(iso == numIso - 1)
44  return max;
45  else
46  return min + iso * (max - min) / (numIso - 1.);
47  }
48  else if(scaleType == Logarithmic) {
49  // should translate scale instead, with smallest val an option!
50  if(min <= 0.) return 0;
51  return pow(10.,
52  log10(min) + iso * (log10(max) - log10(min)) / (numIso - 1.));
53  }
54  else if(scaleType == DoubleLogarithmic) {
55  if(min <= 0.) return 0;
56  double iso2 = iso / 2.;
57  double numIso2 = numIso / 2.;
58  return pow(10.,
59  log10(min) + iso2 * (log10(max) - log10(min)) / (numIso2 - 1.));
60  }
61  return 0.;
62 }
63 
64 int PViewOptions::getScaleIndex(double val, int numIso, double min, double max,
65  bool forceLinear)
66 {
67  if(min == max) return numIso / 2;
68 
69  if(forceLinear || scaleType == Linear) {
70  return (int)((val - min) * (numIso - 1) / (max - min));
71  }
72  else if(scaleType == Logarithmic) {
73  if(min <= 0.) return 0;
74  return (int)((log10(val) - log10(min)) * (numIso - 1) /
75  (log10(max) - log10(min)));
76  }
77  else if(scaleType == DoubleLogarithmic) {
78  // FIXME
79  if(min <= 0.) return 0;
80  return (int)((log10(val) - log10(min)) * (numIso - 1) /
81  (log10(max) - log10(min)));
82  }
83  return 0;
84 }
85 
86 unsigned int PViewOptions::getColor(double val, double min, double max,
87  bool forceLinear, int numColors)
88 {
89  if(colorTable.size == 1) return colorTable.table[0];
90 
91  if(numColors <= 0) { // use full colormap
92  int index = getScaleIndex(val, colorTable.size, min, max, forceLinear);
93  if(index < 0)
94  index = 0;
95  else if(index > colorTable.size - 1)
96  index = colorTable.size - 1;
97  return colorTable.table[index];
98  }
99  else {
100  // the maximum should belong to the last interval: so use
101  // numColors + 1 and correct afterwards
102  int index = getScaleIndex(val, numColors + 1, min, max, forceLinear);
103  if(index > numColors - 1) index = numColors - 1;
104  return getColor(index, numColors);
105  }
106 }
107 
108 unsigned int PViewOptions::getColor(int i, int nb)
109 {
110  int index = (nb == 1) ?
111  colorTable.size / 2 :
112  (int)(i / (double)(nb - 1) * (colorTable.size - 1) + 0.5);
113  if(index < 0)
114  index = 0;
115  else if(index > colorTable.size - 1)
116  index = colorTable.size - 1;
117  return colorTable.table[index];
118 }
119 
121 {
122  const char *names[] = {"x", "y", "z", "v0", "v1", "v2", "v3",
123  "v4", "v5", "v6", "v7", "v8", "s", "t"};
124  std::size_t numVariables = sizeof(names) / sizeof(names[0]);
125  std::vector<std::string> expressions(3), variables(numVariables);
126  expressions[0] = genRaiseX;
127  expressions[1] = genRaiseY;
128  expressions[2] = genRaiseZ;
129  for(std::size_t i = 0; i < numVariables; i++) variables[i] = names[i];
130 
132  genRaiseEvaluator = new mathEvaluator(expressions, variables);
133  if(expressions.empty()) {
134  delete genRaiseEvaluator;
135  genRaiseEvaluator = nullptr;
136  }
137 }
138 
140 {
141  switch(type) {
142  case TYPE_PNT: return !drawPoints;
143  case TYPE_LIN: return !drawLines;
144  case TYPE_TRI: return !drawTriangles;
145  case TYPE_QUA: return !drawQuadrangles;
146  case TYPE_POLYG: return false;
147  case TYPE_TET: return !drawTetrahedra;
148  case TYPE_HEX: return !drawHexahedra;
149  case TYPE_PRI: return !drawPrisms;
150  case TYPE_PYR: return !drawPyramids;
151  case TYPE_TRIH: return !drawTrihedra;
152  case TYPE_POLYH: return false;
153  default: return true;
154  }
155 }
PViewOptions::colorTable
GmshColorTable colorTable
Definition: PViewOptions.h:70
PViewOptions::drawTriangles
int drawTriangles
Definition: PViewOptions.h:64
PViewOptions::genRaiseZ
std::string genRaiseZ
Definition: PViewOptions.h:76
ColorTable_Recompute
void ColorTable_Recompute(GmshColorTable *ct)
Definition: ColorTable.cpp:724
mathEvaluator
Definition: mathEvaluator.h:37
mathEvaluator.h
TYPE_LIN
#define TYPE_LIN
Definition: GmshDefines.h:65
PViewOptions::_reference
static PViewOptions * _reference
Definition: PViewOptions.h:94
PViewOptions::skipElement
bool skipElement(int type)
Definition: PViewOptions.cpp:139
TYPE_PNT
#define TYPE_PNT
Definition: GmshDefines.h:64
TYPE_TRI
#define TYPE_TRI
Definition: GmshDefines.h:66
PViewOptions::currentTime
double currentTime
Definition: PViewOptions.h:62
GmshMessage.h
TYPE_PRI
#define TYPE_PRI
Definition: GmshDefines.h:70
ColorTable_InitParam
void ColorTable_InitParam(int number, GmshColorTable *ct)
Definition: ColorTable.cpp:22
PViewOptions::drawTrihedra
int drawTrihedra
Definition: PViewOptions.h:65
PViewOptions::createGeneralRaise
void createGeneralRaise()
Definition: PViewOptions.cpp:120
PViewOptions::drawQuadrangles
int drawQuadrangles
Definition: PViewOptions.h:64
PViewOptions::genRaiseEvaluator
mathEvaluator * genRaiseEvaluator
Definition: PViewOptions.h:77
PViewOptions::drawTetrahedra
int drawTetrahedra
Definition: PViewOptions.h:65
PViewOptions::drawLines
int drawLines
Definition: PViewOptions.h:64
PViewOptions::PViewOptions
PViewOptions()
Definition: PViewOptions.cpp:13
PViewOptions.h
PViewOptions::~PViewOptions
~PViewOptions()
Definition: PViewOptions.cpp:20
GmshDefines.h
PViewOptions::drawHexahedra
int drawHexahedra
Definition: PViewOptions.h:65
PViewOptions::genRaiseY
std::string genRaiseY
Definition: PViewOptions.h:76
PViewOptions::genRaiseX
std::string genRaiseX
Definition: PViewOptions.h:76
TYPE_PYR
#define TYPE_PYR
Definition: GmshDefines.h:69
PViewOptions::scaleType
int scaleType
Definition: PViewOptions.h:59
PViewOptions::type
int type
Definition: PViewOptions.h:40
PViewOptions::reference
static PViewOptions * reference()
Definition: PViewOptions.cpp:27
PViewOptions::Linear
@ Linear
Definition: PViewOptions.h:38
TYPE_QUA
#define TYPE_QUA
Definition: GmshDefines.h:67
TYPE_POLYG
#define TYPE_POLYG
Definition: GmshDefines.h:72
PViewOptions::getScaleIndex
int getScaleIndex(double val, int numIso, double min, double max, bool forceLinear=false)
Definition: PViewOptions.cpp:64
PViewOptions::drawPoints
int drawPoints
Definition: PViewOptions.h:64
PViewOptions
Definition: PViewOptions.h:16
PViewOptions::drawPyramids
int drawPyramids
Definition: PViewOptions.h:65
TYPE_HEX
#define TYPE_HEX
Definition: GmshDefines.h:71
TYPE_TET
#define TYPE_TET
Definition: GmshDefines.h:68
GmshColorTable::size
int size
Definition: ColorTable.h:18
PViewOptions::getScaleValue
double getScaleValue(int iso, int numIso, double min, double max)
Definition: PViewOptions.cpp:33
GmshColorTable::table
unsigned int table[COLORTABLE_NBMAX_COLOR]
Definition: ColorTable.h:17
TYPE_TRIH
#define TYPE_TRIH
Definition: GmshDefines.h:76
PViewOptions::Logarithmic
@ Logarithmic
Definition: PViewOptions.h:38
PViewOptions::drawPrisms
int drawPrisms
Definition: PViewOptions.h:65
PViewOptions::getColor
unsigned int getColor(double val, double min, double max, bool forceLinear=false, int numColors=-1)
Definition: PViewOptions.cpp:86
TYPE_POLYH
#define TYPE_POLYH
Definition: GmshDefines.h:73
PViewOptions::DoubleLogarithmic
@ DoubleLogarithmic
Definition: PViewOptions.h:38