Skip to content
Snippets Groups Projects
Commit 2ec6dfbb authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

use correct subset of colors when drawing points or arrows in "Filled Iso" mode

(Thanks to Charles Shahrokh GHAVAMIAN from www.necs.eu)
parent 201fc201
Branches
Tags
No related merge requests found
...@@ -323,7 +323,9 @@ static void addScalarPoint(PView *p, double xyz[NMAX][3], double val[NMAX][9], ...@@ -323,7 +323,9 @@ static void addScalarPoint(PView *p, double xyz[NMAX][3], double val[NMAX][9],
if(opt->SaturateValues) saturate(1, val, vmin, vmax, i0); if(opt->SaturateValues) saturate(1, val, vmin, vmax, i0);
if(val[i0][0] >= vmin && val[i0][0] <= vmax){ if(val[i0][0] >= vmin && val[i0][0] <= vmax){
unsigned int col = opt->getColor(val[i0][0], vmin, vmax); unsigned int col = opt->getColor(val[i0][0], vmin, vmax, false,
(opt->IntervalsType == PViewOptions::Discrete) ?
opt->NbIso : -1);
SVector3 n = getPointNormal(p, val[i0][0]); SVector3 n = getPointNormal(p, val[i0][0]);
p->va_points->add(&xyz[i0][0], &xyz[i0][1], &xyz[i0][2], &n, &col, 0, unique); p->va_points->add(&xyz[i0][0], &xyz[i0][1], &xyz[i0][2], &n, &col, 0, unique);
} }
...@@ -399,7 +401,7 @@ static void addScalarLine(PView *p, double xyz[NMAX][3], double val[NMAX][9], ...@@ -399,7 +401,7 @@ static void addScalarLine(PView *p, double xyz[NMAX][3], double val[NMAX][9],
double x2[2], y2[2], z2[2], v2[2]; double x2[2], y2[2], z2[2], v2[2];
int nb = CutLine(x, y, z, v, min, max, x2, y2, z2, v2); int nb = CutLine(x, y, z, v, min, max, x2, y2, z2, v2);
if(nb == 2){ if(nb == 2){
unsigned color = opt->getColor(k, opt->NbIso); unsigned int color = opt->getColor(k, opt->NbIso);
unsigned int col[2] = {color, color}; unsigned int col[2] = {color, color};
SVector3 n[2]; SVector3 n[2];
getLineNormal(p, x2, y2, z2, v2, n, true); getLineNormal(p, x2, y2, z2, v2, n, true);
...@@ -524,7 +526,7 @@ static void addScalarTriangle(PView *p, double xyz[NMAX][3], double val[NMAX][9] ...@@ -524,7 +526,7 @@ static void addScalarTriangle(PView *p, double xyz[NMAX][3], double val[NMAX][9]
double x2[10], y2[10], z2[10], v2[10]; double x2[10], y2[10], z2[10], v2[10];
int nb = CutTriangle(x, y, z, v, min, max, x2, y2, z2, v2); int nb = CutTriangle(x, y, z, v, min, max, x2, y2, z2, v2);
if(nb >= 3){ if(nb >= 3){
unsigned color = opt->getColor(k, opt->NbIso); unsigned int color = opt->getColor(k, opt->NbIso);
unsigned int col[3] = {color, color, color}; unsigned int col[3] = {color, color, color};
for(int j = 2; j < nb; j++){ for(int j = 2; j < nb; j++){
double x3[3] = {x2[0], x2[j - 1], x2[j]}; double x3[3] = {x2[0], x2[j - 1], x2[j]};
...@@ -868,7 +870,9 @@ static void addVectorElement(PView *p, int ient, int iele, int numNodes, ...@@ -868,7 +870,9 @@ static void addVectorElement(PView *p, int ient, int iele, int numNodes,
for(int i = 0; i < numNodes; i++){ for(int i = 0; i < numNodes; i++){
double v2 = ComputeScalarRep(numComp2, val2[i]); double v2 = ComputeScalarRep(numComp2, val2[i]);
if(v2 >= opt->ExternalMin && v2 <= opt->ExternalMax){ if(v2 >= opt->ExternalMin && v2 <= opt->ExternalMax){
unsigned int color = opt->getColor(v2, opt->ExternalMin, opt->ExternalMax); unsigned int color = opt->getColor(v2, opt->ExternalMin, opt->ExternalMax, false,
(opt->IntervalsType == PViewOptions::Discrete) ?
opt->NbIso : -1);
unsigned int col[2] = {color, color}; unsigned int col[2] = {color, color};
double dxyz[3][2]; double dxyz[3][2];
for(int j = 0; j < 3; j++){ for(int j = 0; j < 3; j++){
...@@ -899,7 +903,9 @@ static void addVectorElement(PView *p, int ient, int iele, int numNodes, ...@@ -899,7 +903,9 @@ static void addVectorElement(PView *p, int ient, int iele, int numNodes,
double v2 = ComputeScalarRep(numComp2, d2); double v2 = ComputeScalarRep(numComp2, d2);
if(v2 >= opt->ExternalMin * (1. - 1.e-15) && if(v2 >= opt->ExternalMin * (1. - 1.e-15) &&
v2 <= opt->ExternalMax * (1. + 1.e-15)){ v2 <= opt->ExternalMax * (1. + 1.e-15)){
unsigned int color = opt->getColor(v2, opt->ExternalMin, opt->ExternalMax); unsigned int color = opt->getColor(v2, opt->ExternalMin, opt->ExternalMax, false,
(opt->IntervalsType == PViewOptions::Discrete) ?
opt->NbIso : -1);
unsigned int col[2] = {color, color}; unsigned int col[2] = {color, color};
double dxyz[3][2]; double dxyz[3][2];
for(int i = 0; i < 3; i++){ for(int i = 0; i < 3; i++){
......
...@@ -46,6 +46,7 @@ double PViewOptions::getScaleValue(int iso, int numIso, double min, double max) ...@@ -46,6 +46,7 @@ double PViewOptions::getScaleValue(int iso, int numIso, double min, double max)
return 0.; return 0.;
} }
// return index between 0 and (numIso-1)
int PViewOptions::getScaleIndex(double val, int numIso, double min, double max, int PViewOptions::getScaleIndex(double val, int numIso, double min, double max,
bool forceLinear) bool forceLinear)
{ {
...@@ -68,11 +69,23 @@ int PViewOptions::getScaleIndex(double val, int numIso, double min, double max, ...@@ -68,11 +69,23 @@ int PViewOptions::getScaleIndex(double val, int numIso, double min, double max,
// val in [min, max] // val in [min, max]
unsigned int PViewOptions::getColor(double val, double min, double max, unsigned int PViewOptions::getColor(double val, double min, double max,
bool forceLinear) bool forceLinear, int numColors)
{ {
if(CT.size == 1) return CT.table[0]; if(CT.size == 1) return CT.table[0];
int index = getScaleIndex(val, CT.size, min, max, forceLinear);
return CT.table[index]; if(numColors <= 0){ // use full colormap
int index = getScaleIndex(val, CT.size, min, max, forceLinear);
if(index < 0) index = 0;
else if(index > CT.size - 1) index = CT.size - 1;
return CT.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);
}
} }
// i in [0, nb - 1] // i in [0, nb - 1]
...@@ -80,6 +93,8 @@ unsigned int PViewOptions::getColor(int i, int nb) ...@@ -80,6 +93,8 @@ unsigned int PViewOptions::getColor(int i, int nb)
{ {
int index = (nb == 1) ? CT.size / 2 : int index = (nb == 1) ? CT.size / 2 :
(int)(i / (double)(nb - 1) * (CT.size - 1) + 0.5); (int)(i / (double)(nb - 1) * (CT.size - 1) + 0.5);
if(index < 0) index = 0;
else if(index > CT.size - 1) index = CT.size - 1;
return CT.table[index]; return CT.table[index];
} }
......
...@@ -102,7 +102,8 @@ class PViewOptions { ...@@ -102,7 +102,8 @@ class PViewOptions {
int getScaleIndex(double val, int numIso, double min, double max, int getScaleIndex(double val, int numIso, double min, double max,
bool forceLinear=false); bool forceLinear=false);
unsigned int getColor(int i, int nb); unsigned int getColor(int i, int nb);
unsigned int getColor(double val, double min, double max, bool forceLinear=false); unsigned int getColor(double val, double min, double max,
bool forceLinear=false, int numColors=-1);
bool skipElement(int numEdges); bool skipElement(int numEdges);
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment