Skip to content

Commit

Permalink
Version 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
tzanio committed Jan 29, 2017
1 parent 75de1ff commit 4fc853f
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 31 deletions.
14 changes: 12 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@
http://glvis.org


Version 3.2, released on June 30, 2016
======================================
Version 3.3, released on Jan 28, 2017
=====================================

- Added the ability to change the axis labels displayed with the coordinate
cross in the lower left corner. They can be set with the new 'axis_labels'
socket command, for example: sol_sock << "axis_labels 'u' 'v' 'w'\n";

- With the corresponding version of MFEM, GLVis now supports gz-compressed
files and socket streams.

Version 3.2, released on Jun 30, 2016
=====================================

- Added support for secure socket connections based on the GnuTLS library
through MFEM. This option may be useful in multi-user environment to prevent
Expand Down
70 changes: 56 additions & 14 deletions glvis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ int ScriptReadSolution(istream &scr, Mesh **mp, GridFunction **sp)
// read the mesh
scr >> ws >> word; // mesh filename (can't contain spaces)
{
ifstream imesh(word.c_str());
named_ifgzstream imesh(word.c_str());
if (!imesh)
{
cout << "Can not open mesh file: " << word << endl;
Expand All @@ -523,7 +523,7 @@ int ScriptReadSolution(istream &scr, Mesh **mp, GridFunction **sp)
// read the solution (GridFunction)
scr >> ws >> word;
{
ifstream isol(word.c_str());
ifgzstream isol(word.c_str());
if (!isol)
{
cout << "Can not open solution file: " << word << endl;
Expand Down Expand Up @@ -581,7 +581,7 @@ int ScriptReadDisplMesh(istream &scr, Mesh **mp, GridFunction **sp)
cout << "Script: mesh: " << flush;
scr >> ws >> word;
{
ifstream imesh(word.c_str());
named_ifgzstream imesh(word.c_str());
if (!imesh)
{
cout << "Can not open mesh file: " << word << endl;
Expand Down Expand Up @@ -1387,7 +1387,12 @@ int main (int argc, char *argv[])
#endif
while (1)
{
while (server.accept(*isock) < 0);
while (server.accept(*isock) < 0)
{
#ifdef GLVIS_DEBUG
cout << "GLVis: server.accept(...) failed." << endl;
#endif
}

*isock >> data_type >> ws;

Expand All @@ -1408,7 +1413,38 @@ int main (int argc, char *argv[])
cout << "new connection: parallel " << nproc << ' ' << proc
<< endl;
#endif
input_streams.SetSize(nproc);
if (np == 0)
{
if (nproc <= 0)
{
cout << "Invalid number of processors: " << nproc << endl;
mfem_error();
}
input_streams.SetSize(nproc);
input_streams = NULL;
}
else
{
if (nproc != input_streams.Size())
{
cout << "Unexpected number of processors: " << nproc
<< ", expected: " << input_streams.Size() << endl;
mfem_error();
}
}
if (0 > proc || proc >= nproc)
{
cout << "Invalid processor rank: " << proc
<< ", number of processors: " << nproc << endl;
mfem_error();
}
if (input_streams[proc])
{
cout << "Second connection attempt from processor rank: "
<< proc << endl;
mfem_error();
}

input_streams[proc] = isock;
#ifndef MFEM_USE_GNUTLS
isock = new socketstream;
Expand All @@ -1422,8 +1458,19 @@ int main (int argc, char *argv[])
break;
}
// read next available socket stream
while (server.accept(*isock) < 0);
while (server.accept(*isock) < 0)
{
#ifdef GLVIS_DEBUG
cout << "GLVis: server.accept(...) failed." << endl;
#endif
}
*isock >> data_type >> ws; // "parallel"
if (data_type != "parallel")
{
cout << "Expected keyword \"parallel\", got \"" << data_type
<< '"' << endl;
mfem_error();
}
}
while (1);
}
Expand Down Expand Up @@ -1702,9 +1749,8 @@ void ReadSerial()

if (is_gf || (input & 4) || (input & 8))
{
ifstream solin;
// get the solution from file
solin.open(sol_file);
ifgzstream solin(sol_file);
if (!solin)
{
cerr << "Can not open solution file " << sol_file << ". Exit.\n";
Expand Down Expand Up @@ -1867,12 +1913,11 @@ int ReadParMeshAndGridFunction(int np, const char *mesh_prefix,
Array<Mesh *> mesh_array;

mesh_array.SetSize(np);
ifstream meshfile;
for (int p = 0; p < np; p++)
{
ostringstream fname;
fname << mesh_prefix << '.' << setfill('0') << setw(pad_digits) << p;
meshfile.open(fname.str().c_str());
named_ifgzstream meshfile(fname.str().c_str());
if (!meshfile)
{
cerr << "Can not open mesh file: " << fname.str().c_str()
Expand All @@ -1896,19 +1941,17 @@ int ReadParMeshAndGridFunction(int np, const char *mesh_prefix,
mesh_array[p]->GetBdrElement(i)->SetAttribute(p+1);
}
}
meshfile.close();
}
*mesh_p = new Mesh(mesh_array, np);

if (sol_prefix && sol_p)
{
Array<GridFunction *> gf_array(np);
ifstream solfile;
for (int p = 0; p < np; p++)
{
ostringstream fname;
fname << sol_prefix << '.' << setfill('0') << setw(pad_digits) << p;
solfile.open(fname.str().c_str());
ifgzstream solfile(fname.str().c_str());
if (!solfile)
{
cerr << "Can not open solution file " << fname.str().c_str()
Expand All @@ -1926,7 +1969,6 @@ int ReadParMeshAndGridFunction(int np, const char *mesh_prefix,
return 2;
}
gf_array[p] = new GridFunction(mesh_array[p], solfile);
solfile.close();
}
*sol_p = new GridFunction(*mesh_p, gf_array, np);

Expand Down
59 changes: 59 additions & 0 deletions lib/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,23 @@ int GLVisCommand::PlotCaption(const char *caption)
return 0;
}

int GLVisCommand::AxisLabels(const char *a_x, const char *a_y, const char *a_z)
{
if (lock() < 0)
{
return -1;
}
command = AXIS_LABELS;
axis_label_x = a_x;
axis_label_y = a_y;
axis_label_z = a_z;
if (signal() < 0)
{
return -2;
}
return 0;
}

int GLVisCommand::Pause()
{
if (lock() < 0)
Expand Down Expand Up @@ -523,6 +540,16 @@ int GLVisCommand::Execute()
break;
}

case AXIS_LABELS:
{
cout << "Command: axis_labels: '" << axis_label_x << "' '"
<< axis_label_y << "' '" << axis_label_z << "'" << endl;
(*vs)->SetAxisLabels(axis_label_x.c_str(), axis_label_y.c_str(),
axis_label_z.c_str());
MyExpose();
break;
}

case PAUSE:
{
cout << "Command: pause: ";
Expand Down Expand Up @@ -985,6 +1012,38 @@ void *communication_thread::execute(void *p)
goto comm_terminate;
}
}
else if (_this->ident == "axis_labels")
{
char c;
string label_x, label_y, label_z;

*_this->is[0] >> ws >> c; // read the opening char
// use the opening char as termination as well
getline(*_this->is[0], label_x, c);
*_this->is[0] >> ws >> c;
getline(*_this->is[0], label_y, c);
*_this->is[0] >> ws >> c;
getline(*_this->is[0], label_z, c);

// all processors sent the command
for (int i = 1; i < _this->is.Size(); i++)
{
*_this->is[i] >> ws >> _this->ident; // 'axis_label'
*_this->is[i] >> ws >> c;
getline(*_this->is[i], _this->ident, c);
*_this->is[i] >> ws >> c;
getline(*_this->is[i], _this->ident, c);
*_this->is[i] >> ws >> c;
getline(*_this->is[i], _this->ident, c);
}

if (glvis_command->AxisLabels(label_x.c_str(),
label_y.c_str(),
label_z.c_str()))
{
goto comm_terminate;
}
}
else if (_this->ident == "pause")
{
// all processors sent the command
Expand Down
7 changes: 6 additions & 1 deletion lib/threads.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class GLVisCommand
CAMERA = 15,
AUTOPAUSE = 16,
WINDOW_GEOMETRY = 17,
PLOT_CAPTION = 18
PLOT_CAPTION = 18,
AXIS_LABELS = 19
};

// command to be executed
Expand All @@ -66,6 +67,9 @@ class GLVisCommand
int window_w, window_h;
std::string window_title;
std::string plot_caption;
std::string axis_label_x;
std::string axis_label_y;
std::string axis_label_z;
double view_ang_theta, view_ang_phi;
double zoom_factor;
int subdiv_tot, subdiv_bdr;
Expand Down Expand Up @@ -105,6 +109,7 @@ class GLVisCommand
int WindowGeometry(int x, int y, int w, int h);
int WindowTitle(const char *title);
int PlotCaption(const char *caption);
int AxisLabels(const char *a_x, const char *a_y, const char *a_z);
int Pause();
int ViewAngles(double theta, double phi);
int Zoom(double factor);
Expand Down
29 changes: 19 additions & 10 deletions lib/vsdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,29 +636,28 @@ void VisualizationSceneScalarData::DrawCoordinateCross()
glListBase (fontbase);
#endif

const char *a_labels[] = {"x", "y", "z"};
glRasterPos3d (lenx, 0.0f, 0.0f);
if (print) { gl2psText(a_labels[0],"Times",8); }
if (print) { gl2psText(a_label_x.c_str(),"Times",8); }
#ifndef GLVIS_USE_FREETYPE
glCallLists(1, GL_UNSIGNED_BYTE, a_labels[0]);
glCallLists(a_label_x.length(), GL_UNSIGNED_BYTE, a_label_x.c_str());
#else
DrawBitmapText(a_labels[0]);
DrawBitmapText(a_label_x.c_str());
#endif

glRasterPos3d (0.0f, leny, 0.0f);
if (print) { gl2psText(a_labels[1],"Times",8); }
if (print) { gl2psText(a_label_y.c_str(),"Times",8); }
#ifndef GLVIS_USE_FREETYPE
glCallLists(1, GL_UNSIGNED_BYTE, a_labels[1]);
glCallLists(a_label_y.length(), GL_UNSIGNED_BYTE, a_label_y.c_str());
#else
DrawBitmapText(a_labels[1]);
DrawBitmapText(a_label_y.c_str());
#endif

glRasterPos3d (0.0f, 0.0f, lenz);
if (print) { gl2psText(a_labels[2],"Times",8); }
if (print) { gl2psText(a_label_z.c_str(),"Times",8); }
#ifndef GLVIS_USE_FREETYPE
glCallLists(1, GL_UNSIGNED_BYTE, a_labels[2]);
glCallLists(a_label_z.length(), GL_UNSIGNED_BYTE, a_label_z.c_str());
#else
DrawBitmapText(a_labels[2]);
DrawBitmapText(a_label_z.c_str());
#endif

#ifndef GLVIS_USE_FREETYPE
Expand Down Expand Up @@ -1182,6 +1181,7 @@ void VisualizationSceneScalarData::SetAutoscale(int _autoscale)

VisualizationSceneScalarData::VisualizationSceneScalarData(
Mesh & m, Vector & s)
: a_label_x("x"), a_label_y("y"), a_label_z("z")
{
mesh = &m;
sol = &s;
Expand Down Expand Up @@ -1344,6 +1344,15 @@ void VisualizationSceneScalarData::SetValueRange(double min, double max)
UpdateValueRange(true);
}

void VisualizationSceneScalarData::SetAxisLabels(const char * a_x,
const char * a_y,
const char * a_z)
{
a_label_x = a_x;
a_label_y = a_y;
a_label_z = a_z;
}

void VisualizationSceneScalarData::PrepareAxes()
{
Set_Black_Material();
Expand Down
7 changes: 6 additions & 1 deletion lib/vsdata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class VisualizationSceneScalarData : public VisualizationScene

double minv, maxv;

std::string a_label_x, a_label_y, a_label_z;

int scaling, colorbar, drawaxes, axeslist;
int auto_ref_max, auto_ref_max_surf_elem;

Expand Down Expand Up @@ -120,7 +122,8 @@ class VisualizationSceneScalarData : public VisualizationScene
/// Shrink factor with respect to the element (material) attributes centers
double shrinkmat;

VisualizationSceneScalarData() {}
VisualizationSceneScalarData()
: a_label_x("x"), a_label_y("y"), a_label_z("z") {}
VisualizationSceneScalarData (Mesh & m, Vector & s);

virtual ~VisualizationSceneScalarData();
Expand Down Expand Up @@ -220,6 +223,8 @@ class VisualizationSceneScalarData : public VisualizationScene
colorbar = (colorbar ? empty+1 : !empty);
}

void SetAxisLabels(const char * a_x, const char * a_y, const char * a_z);

void PrepareAxes();
void ToggleDrawAxes()
{
Expand Down
2 changes: 1 addition & 1 deletion lib/vssolution3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1783,7 +1783,7 @@ void VisualizationSceneSolution3d::PrepareLines()

void VisualizationSceneSolution3d::PrepareLines2()
{
int i, j, k, fn, fo, di;
int i, j, k, fn, fo, di = 0;
double bbox_diam;

glNewList (linelist, GL_COMPILE);
Expand Down
Loading

0 comments on commit 4fc853f

Please sign in to comment.