diff --git a/libsrc/include/nginterface.h b/libsrc/include/nginterface.h index 4ded8217..93c0fd52 100644 --- a/libsrc/include/nginterface.h +++ b/libsrc/include/nginterface.h @@ -307,6 +307,9 @@ extern "C" { struct Ng_SolutionData { 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 int components; // relevant (double) components in solution vector int dist; // # doubles per entry alignment! diff --git a/libsrc/visualization/mvdraw.cpp b/libsrc/visualization/mvdraw.cpp index 89aa6cff..bcb25b71 100644 --- a/libsrc/visualization/mvdraw.cpp +++ b/libsrc/visualization/mvdraw.cpp @@ -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; @@ -622,9 +622,8 @@ namespace netgen else 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); - // glCallLists (GLsizei(strlen (buf)), GL_UNSIGNED_BYTE, buf); double x = minx + i * (maxx-minx) / 4; x -= 0.5*char_width * n; // center text glRasterPos3d (x, 0.7,-5); @@ -632,6 +631,34 @@ namespace netgen 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 (); glEnable (GL_DEPTH_TEST); } diff --git a/libsrc/visualization/mvdraw.hpp b/libsrc/visualization/mvdraw.hpp index 79830b95..76d610ea 100644 --- a/libsrc/visualization/mvdraw.hpp +++ b/libsrc/visualization/mvdraw.hpp @@ -69,7 +69,8 @@ namespace netgen { backcolor = col; } 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 DrawMarker(); NGGUI_API void DrawNetgenLogo (); diff --git a/libsrc/visualization/visualpkg.cpp b/libsrc/visualization/visualpkg.cpp index 42670769..d855ca40 100644 --- a/libsrc/visualization/visualpkg.cpp +++ b/libsrc/visualization/visualpkg.cpp @@ -83,7 +83,7 @@ namespace netgen if ( (strlen (vssolution.soldata[i]->name.c_str()) == size_t(pointpos-1)) && (strncmp (vssolution.soldata[i]->name.c_str(), scalname, pointpos-1) == 0) ) { - vssolution.scalfunction = i; + vssolution.SetScalfunction(i); vssolution.scalcomp = atoi (scalname + pointpos); if ( vssolution.scalcomp > vssolution.soldata[i]->components ) vssolution.scalcomp = 1; @@ -98,7 +98,7 @@ namespace netgen scalname = Tcl_GetVar (interp, "::visoptions.scalfunction", TCL_GLOBAL_ONLY); } 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) vssolution.fieldlines_vecfunction = i; diff --git a/libsrc/visualization/vssolution.cpp b/libsrc/visualization/vssolution.cpp index 78541f9b..1520c3e6 100644 --- a/libsrc/visualization/vssolution.cpp +++ b/libsrc/visualization/vssolution.cpp @@ -628,7 +628,8 @@ namespace netgen glPopMatrix(); glDisable(GL_CLIP_PLANE0); - DrawColorBar (minval, maxval, logscale, lineartexture); + DrawColorBar (minval, maxval, logscale, lineartexture, number_format, unit); + DrawTitle (title); if (vispar.drawcoordinatecross) DrawCoordinateCross (); @@ -5017,6 +5018,9 @@ void Impl_Ng_SetSolutionData (Ng_SolutionData * soldata) // vss->name = new char[strlen (soldata->name)+1]; // strcpy (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->components = soldata->components; vss->dist = soldata->dist; diff --git a/libsrc/visualization/vssolution.hpp b/libsrc/visualization/vssolution.hpp index e9a406be..c7c4fd1f 100644 --- a/libsrc/visualization/vssolution.hpp +++ b/libsrc/visualization/vssolution.hpp @@ -98,6 +98,11 @@ class NGGUI_API VisualSceneSolution : public VisualScene int timetimestamp; double minval, maxval; + int scalfunction, vecfunction; + string number_format = "%8.3e"; + string unit = ""; + string title = ""; + NgLock *lock; @@ -137,6 +142,9 @@ public: ~SolData (); string name; + string number_format = "%8.3e"; + string unit = ""; + string title = ""; double * data; int components; int dist; @@ -159,7 +167,7 @@ public: int usetexture; // 0..no, 1..1D texture (standard), 2..2D-texture (complex) int clipsolution; // 0..no, 1..scal, 2..vec - int scalfunction, scalcomp, vecfunction; + int scalcomp; int gridsize; double xoffset, yoffset; @@ -348,6 +356,19 @@ public: Tcl_Interp * interp, 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 void Broadcast ();