mirror of
https://github.com/NGSolve/netgen.git
synced 2025-01-24 03:40:34 +05:00
Colorbar features
- title above - unit at the end - allow user-defined number formatting
This commit is contained in:
parent
9443929806
commit
838450b7a8
@ -307,6 +307,9 @@ extern "C" {
|
|||||||
struct Ng_SolutionData
|
struct Ng_SolutionData
|
||||||
{
|
{
|
||||||
std::string name; // name of gridfunction
|
std::string name; // name of gridfunction
|
||||||
|
std::string title = ""; // name of gridfunction ( printed on top of window )
|
||||||
|
std::string number_format = "%.3e"; // printf-style string to format colormap values
|
||||||
|
std::string unit = ""; // string to append to last number in colormap (ASCII only)
|
||||||
double * data; // solution values
|
double * data; // solution values
|
||||||
int components; // relevant (double) components in solution vector
|
int components; // relevant (double) components in solution vector
|
||||||
int dist; // # doubles per entry alignment!
|
int dist; // # doubles per entry alignment!
|
||||||
|
@ -566,7 +566,7 @@ namespace netgen
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void VisualScene :: DrawColorBar (double minval, double maxval, int logscale, bool linear)
|
void VisualScene :: DrawColorBar (double minval, double maxval, int logscale, bool linear, string format, string unit)
|
||||||
{
|
{
|
||||||
if (!vispar.drawcolorbar) return;
|
if (!vispar.drawcolorbar) return;
|
||||||
|
|
||||||
@ -622,9 +622,8 @@ namespace netgen
|
|||||||
else
|
else
|
||||||
val = minval + i * (maxval-minval) / 4;
|
val = minval + i * (maxval-minval) / 4;
|
||||||
|
|
||||||
snprintf (buf, buf_size, "%8.3e", val);
|
snprintf (buf, buf_size, format.c_str(), val);
|
||||||
auto n = strlen(buf);
|
auto n = strlen(buf);
|
||||||
// glCallLists (GLsizei(strlen (buf)), GL_UNSIGNED_BYTE, buf);
|
|
||||||
double x = minx + i * (maxx-minx) / 4;
|
double x = minx + i * (maxx-minx) / 4;
|
||||||
x -= 0.5*char_width * n; // center text
|
x -= 0.5*char_width * n; // center text
|
||||||
glRasterPos3d (x, 0.7,-5);
|
glRasterPos3d (x, 0.7,-5);
|
||||||
@ -632,6 +631,34 @@ namespace netgen
|
|||||||
MyOpenGLText (buf);
|
MyOpenGLText (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(unit != "")
|
||||||
|
MyOpenGLText (unit.c_str());
|
||||||
|
|
||||||
|
glPopAttrib ();
|
||||||
|
glEnable (GL_DEPTH_TEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VisualScene :: DrawTitle (string title)
|
||||||
|
{
|
||||||
|
if(title=="")
|
||||||
|
return;
|
||||||
|
glDisable (GL_LIGHTING);
|
||||||
|
glDisable (GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
glEnable (GL_COLOR_MATERIAL);
|
||||||
|
GLfloat textcol[3] = { GLfloat(1 - backcolor),
|
||||||
|
GLfloat(1 - backcolor),
|
||||||
|
GLfloat(1 - backcolor) };
|
||||||
|
glColor3fv (textcol);
|
||||||
|
|
||||||
|
glPushAttrib (GL_LIST_BIT);
|
||||||
|
|
||||||
|
GLint viewport[4];
|
||||||
|
glGetIntegerv (GL_VIEWPORT, viewport);
|
||||||
|
double char_width = 2.0*MyOpenGLTextWidth()/(viewport[3]);
|
||||||
|
double x = -0.5*char_width * title.size(); // center text
|
||||||
|
glRasterPos3d (x, 0.82,-5);
|
||||||
|
MyOpenGLText (title.c_str());
|
||||||
glPopAttrib ();
|
glPopAttrib ();
|
||||||
glEnable (GL_DEPTH_TEST);
|
glEnable (GL_DEPTH_TEST);
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,8 @@ namespace netgen
|
|||||||
{ backcolor = col; }
|
{ backcolor = col; }
|
||||||
|
|
||||||
NGGUI_API void CreateTexture (int ncols, int linear, double alpha, int typ);
|
NGGUI_API void CreateTexture (int ncols, int linear, double alpha, int typ);
|
||||||
NGGUI_API void DrawColorBar (double minval, double maxval, int logscale = 0, bool linear = 1);
|
NGGUI_API void DrawColorBar (double minval, double maxval, int logscale = 0, bool linear = 1, string format="%8.3e", string unit="");
|
||||||
|
NGGUI_API void DrawTitle (string title);
|
||||||
NGGUI_API void DrawCoordinateCross ();
|
NGGUI_API void DrawCoordinateCross ();
|
||||||
NGGUI_API void DrawMarker();
|
NGGUI_API void DrawMarker();
|
||||||
NGGUI_API void DrawNetgenLogo ();
|
NGGUI_API void DrawNetgenLogo ();
|
||||||
|
@ -83,7 +83,7 @@ namespace netgen
|
|||||||
if ( (strlen (vssolution.soldata[i]->name.c_str()) == size_t(pointpos-1)) &&
|
if ( (strlen (vssolution.soldata[i]->name.c_str()) == size_t(pointpos-1)) &&
|
||||||
(strncmp (vssolution.soldata[i]->name.c_str(), scalname, pointpos-1) == 0) )
|
(strncmp (vssolution.soldata[i]->name.c_str(), scalname, pointpos-1) == 0) )
|
||||||
{
|
{
|
||||||
vssolution.scalfunction = i;
|
vssolution.SetScalfunction(i);
|
||||||
vssolution.scalcomp = atoi (scalname + pointpos);
|
vssolution.scalcomp = atoi (scalname + pointpos);
|
||||||
if ( vssolution.scalcomp > vssolution.soldata[i]->components )
|
if ( vssolution.scalcomp > vssolution.soldata[i]->components )
|
||||||
vssolution.scalcomp = 1;
|
vssolution.scalcomp = 1;
|
||||||
@ -98,7 +98,7 @@ namespace netgen
|
|||||||
scalname = Tcl_GetVar (interp, "::visoptions.scalfunction", TCL_GLOBAL_ONLY);
|
scalname = Tcl_GetVar (interp, "::visoptions.scalfunction", TCL_GLOBAL_ONLY);
|
||||||
}
|
}
|
||||||
if (strcmp (vssolution.soldata[i]->name.c_str(), vecname) == 0)
|
if (strcmp (vssolution.soldata[i]->name.c_str(), vecname) == 0)
|
||||||
vssolution.vecfunction = i;
|
vssolution.SetVecfunction(i);
|
||||||
|
|
||||||
if (strcmp (vssolution.soldata[i]->name.c_str(), fieldlines_vecname) == 0)
|
if (strcmp (vssolution.soldata[i]->name.c_str(), fieldlines_vecname) == 0)
|
||||||
vssolution.fieldlines_vecfunction = i;
|
vssolution.fieldlines_vecfunction = i;
|
||||||
|
@ -628,7 +628,8 @@ namespace netgen
|
|||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
glDisable(GL_CLIP_PLANE0);
|
glDisable(GL_CLIP_PLANE0);
|
||||||
DrawColorBar (minval, maxval, logscale, lineartexture);
|
DrawColorBar (minval, maxval, logscale, lineartexture, number_format, unit);
|
||||||
|
DrawTitle (title);
|
||||||
|
|
||||||
if (vispar.drawcoordinatecross)
|
if (vispar.drawcoordinatecross)
|
||||||
DrawCoordinateCross ();
|
DrawCoordinateCross ();
|
||||||
@ -5017,6 +5018,9 @@ void Impl_Ng_SetSolutionData (Ng_SolutionData * soldata)
|
|||||||
// vss->name = new char[strlen (soldata->name)+1];
|
// vss->name = new char[strlen (soldata->name)+1];
|
||||||
// strcpy (vss->name, soldata->name);
|
// strcpy (vss->name, soldata->name);
|
||||||
vss->name = soldata->name;
|
vss->name = soldata->name;
|
||||||
|
vss->title = soldata->title;
|
||||||
|
vss->number_format = soldata->number_format;
|
||||||
|
vss->unit = soldata->unit;
|
||||||
vss->data = soldata->data;
|
vss->data = soldata->data;
|
||||||
vss->components = soldata->components;
|
vss->components = soldata->components;
|
||||||
vss->dist = soldata->dist;
|
vss->dist = soldata->dist;
|
||||||
|
@ -98,6 +98,11 @@ class NGGUI_API VisualSceneSolution : public VisualScene
|
|||||||
int timetimestamp;
|
int timetimestamp;
|
||||||
double minval, maxval;
|
double minval, maxval;
|
||||||
|
|
||||||
|
int scalfunction, vecfunction;
|
||||||
|
string number_format = "%8.3e";
|
||||||
|
string unit = "";
|
||||||
|
string title = "";
|
||||||
|
|
||||||
NgLock *lock;
|
NgLock *lock;
|
||||||
|
|
||||||
|
|
||||||
@ -137,6 +142,9 @@ public:
|
|||||||
~SolData ();
|
~SolData ();
|
||||||
|
|
||||||
string name;
|
string name;
|
||||||
|
string number_format = "%8.3e";
|
||||||
|
string unit = "";
|
||||||
|
string title = "";
|
||||||
double * data;
|
double * data;
|
||||||
int components;
|
int components;
|
||||||
int dist;
|
int dist;
|
||||||
@ -159,7 +167,7 @@ public:
|
|||||||
|
|
||||||
int usetexture; // 0..no, 1..1D texture (standard), 2..2D-texture (complex)
|
int usetexture; // 0..no, 1..1D texture (standard), 2..2D-texture (complex)
|
||||||
int clipsolution; // 0..no, 1..scal, 2..vec
|
int clipsolution; // 0..no, 1..scal, 2..vec
|
||||||
int scalfunction, scalcomp, vecfunction;
|
int scalcomp;
|
||||||
int gridsize;
|
int gridsize;
|
||||||
double xoffset, yoffset;
|
double xoffset, yoffset;
|
||||||
|
|
||||||
@ -348,6 +356,19 @@ public:
|
|||||||
Tcl_Interp * interp,
|
Tcl_Interp * interp,
|
||||||
int argc, const char *argv[]);
|
int argc, const char *argv[]);
|
||||||
|
|
||||||
|
void SetScalfunction( int i ) {
|
||||||
|
scalfunction = i;
|
||||||
|
title = soldata[i]->title;
|
||||||
|
number_format = soldata[i]->number_format;
|
||||||
|
unit = soldata[i]->unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetVecfunction( int i ) {
|
||||||
|
vecfunction = i;
|
||||||
|
title = soldata[i]->title;
|
||||||
|
number_format = soldata[i]->number_format;
|
||||||
|
unit = soldata[i]->unit;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef PARALLELGL
|
#ifdef PARALLELGL
|
||||||
void Broadcast ();
|
void Broadcast ();
|
||||||
|
Loading…
Reference in New Issue
Block a user