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