Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
93c8ad0
Refactoring palettes.cpp to remove global state
publixsubfan Jan 19, 2021
6abe3c2
Move background setting to MyExpose
publixsubfan Jan 19, 2021
00fbe29
Move antialiasing to aux_vis
publixsubfan Jan 20, 2021
c8cfa0e
Create GLVisWindow class, move font handling stuff into it
publixsubfan Jan 20, 2021
aa2444c
Moving more methods to GLVisWindow class
publixsubfan Jan 27, 2021
a5f331a
Move idle func handling into GLVisWindow
publixsubfan Jan 27, 2021
da8381d
Add mouse events, model spinning stuff to GLVisWindow
publixsubfan Jan 28, 2021
f439f2b
Move MSAA, screenshot controls into GLVisWindow, add wrapper for memb…
publixsubfan Jan 28, 2021
24f7e4f
Move screenshot implementation to new file
publixsubfan Jan 28, 2021
6fb5ecd
Move some window control functions to GLVisWindow
publixsubfan Jan 28, 2021
da7e90a
Move more scene transformation methods into GLVisWindow
publixsubfan Jan 28, 2021
58f1aaf
Move geometry functions into an isolated header
publixsubfan Jan 28, 2021
7d81b66
Move some more color functions into PaletteState
publixsubfan Jan 28, 2021
303f4a1
Fix a segfault with font ptr in VisualizationScene
publixsubfan Jan 28, 2021
ae0c01c
Remove GetUseTexture/SetUseTexture functions, move into aux_js
publixsubfan Jan 29, 2021
159252d
Move thread control functions into GLVisWindow
publixsubfan Jan 29, 2021
019b0ab
Modularize stream reader methods
publixsubfan Feb 3, 2021
a5a8ca2
Deduplicate mesh/solution update code
publixsubfan Feb 3, 2021
33ee057
Remove some global dependencies from glvis.cpp
publixsubfan Feb 3, 2021
f9f8d69
Remove references to global glvis_command instance
publixsubfan Feb 4, 2021
ccf25c7
Move command, vis scene construction into GLVisWindow; pass local GLV…
publixsubfan Feb 4, 2021
dc54295
Merge branch 'master' into multithread-refactor-dev
publixsubfan Feb 4, 2021
d082219
JS-related build fixes
publixsubfan Feb 4, 2021
b069e32
Replace pthreads code with c++ standard library threads
publixsubfan Feb 4, 2021
84ea36e
Remove some more global references to stream_state
publixsubfan Feb 5, 2021
cdbcaf1
Remove global vsdata dependence from Plane class
publixsubfan Feb 10, 2021
5ee2857
Only init freetype once
publixsubfan Feb 10, 2021
4332822
Start moving over some key events to member functions
publixsubfan Feb 10, 2021
0ce1340
Add support for stackable events, improve handling of scene view resets
publixsubfan Feb 11, 2021
85688cf
Add support for conditionally-updatable event handlers
publixsubfan Feb 11, 2021
ba78536
Make all vssolution3d event handlers member functions
publixsubfan Feb 11, 2021
7408d75
Make vssolution event handlers member functions
publixsubfan Feb 11, 2021
83a2288
Make vsvector event handlers member functions
publixsubfan Feb 11, 2021
bdd2aa2
Convert last of vsdata event handlers
publixsubfan Feb 11, 2021
a97d444
Move resource types into gl/types.hpp
publixsubfan Feb 11, 2021
28b64a7
Remove SdlWindow reference from vsdata
publixsubfan Feb 11, 2021
7806bd6
Fix for printing
publixsubfan Feb 11, 2021
89ff3e5
Make GetColorFromVal a member function of PaletteState
publixsubfan Feb 11, 2021
ca8d5ea
Cleanup some globals from aux_vis
publixsubfan Feb 11, 2021
abdbdd0
Cleanup some more globals from aux_vis
publixsubfan Feb 11, 2021
2702600
Remove remaining references to global GLVisWindow
publixsubfan Feb 12, 2021
fa40052
Remove some comments
publixsubfan Feb 12, 2021
40d06eb
Remove last globals from aux_vis
publixsubfan Feb 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
532 changes: 167 additions & 365 deletions glvis.cpp

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ list(APPEND SOURCES
openglvis.cpp
palettes.cpp
sdl.cpp
sdl_screenshot.cpp
stream_reader.cpp
vsdata.cpp
vssolution.cpp
Expand All @@ -34,6 +35,7 @@ list(APPEND HEADERS
gl/types.hpp
aux_vis.hpp
font.hpp
geom_utils.hpp
logo.hpp
material.hpp
openglvis.hpp
Expand Down
231 changes: 50 additions & 181 deletions lib/aux_js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ std::string extra_caption; // used in extern context
mfem::GeometryRefiner GLVisGeometryRefiner; // used in extern context

static VisualizationSceneScalarData * vs = nullptr;
StreamState stream_state;
GLVisWindow * mainWindow = nullptr;

namespace js
{
Expand Down Expand Up @@ -56,10 +58,7 @@ bool startVisualization(const std::string input, const std::string data_type,
std::stringstream ss(input);

// 0 - scalar data, 1 - vector data, 2 - mesh only, (-1) - unknown
const int field_type = ReadStream(ss, data_type);

// reset antialiasing
GetAppWindow()->getRenderer().setAntialiasing(0);
const int field_type = stream_state.ReadStream(ss, data_type);

std::string line;
double minv = 0.0, maxv = 0.0;
Expand All @@ -86,149 +85,34 @@ bool startVisualization(const std::string input, const std::string data_type,
return false;
}

if (InitVisualization("glvis", 0, 0, w, h))
try
{
return false;
mainWindow = new GLVisWindow("glvis", 0, 0, w, h, false);
}

delete vs;
vs = nullptr;

double mesh_range = -1.0;
if (field_type == 0 || field_type == 2)
catch (std::runtime_error& ex)
{
if (stream_state.grid_f)
{
stream_state.grid_f->GetNodalValues(stream_state.sol);
}
if (stream_state.mesh->SpaceDimension() == 2)
{
VisualizationSceneSolution * vss;
if (stream_state.normals.Size() > 0)
{
vs = vss = new VisualizationSceneSolution(*stream_state.mesh, stream_state.sol,
&stream_state.normals);
}
else
{
vs = vss = new VisualizationSceneSolution(*stream_state.mesh, stream_state.sol);
}
if (stream_state.grid_f)
{
vss->SetGridFunction(*stream_state.grid_f);
}
if (field_type == 2)
{
vs->OrthogonalProjection = 1;
vs->SetLight(0);
vs->Zoom(1.8);
// Use the 'bone' palette when visualizing a 2D mesh only (otherwise
// the 'jet-like' palette is used in 2D, see vssolution.cpp).
paletteSet(4);
}
}
else if (stream_state.mesh->SpaceDimension() == 3)
{
VisualizationSceneSolution3d * vss;
vs = vss = new VisualizationSceneSolution3d(*stream_state.mesh,
stream_state.sol);
if (stream_state.grid_f)
{
vss->SetGridFunction(stream_state.grid_f);
}
if (field_type == 2)
{
if (stream_state.mesh->Dimension() == 3)
{
// Use the 'white' palette when visualizing a 3D volume mesh only
// paletteSet(4);
paletteSet(11);
vss->SetLightMatIdx(4);
}
else
{
// Use the 'bone' palette when visualizing a surface mesh only
// (the same as when visualizing a 2D mesh only)
paletteSet(4);
}
// Otherwise, the 'vivid' palette is used in 3D see vssolution3d.cpp

vss->ToggleDrawAxes();
vss->ToggleDrawMesh();
}
}
if (field_type == 2)
{
if (stream_state.grid_f)
{
mesh_range = stream_state.grid_f->Max() + 1.0;
}
else
{
mesh_range = stream_state.sol.Max() + 1.0;
}
}
cerr << "Initializing the visualization failed: " << endl
<< ex.what() << endl;
return false;
}
else if (field_type == 1)
catch(...)
{
if (stream_state.mesh->SpaceDimension() == 2)
{
if (stream_state.grid_f)
{
vs = new VisualizationSceneVector(*stream_state.grid_f);
}
else
{
vs = new VisualizationSceneVector(*stream_state.mesh, stream_state.solu,
stream_state.solv);
}
}
else if (stream_state.mesh->SpaceDimension() == 3)
{
if (stream_state.grid_f)
{
stream_state.grid_f = ProjectVectorFEGridFunction(stream_state.grid_f);
vs = new VisualizationSceneVector3d(*stream_state.grid_f);
}
else
{
vs = new VisualizationSceneVector3d(*stream_state.mesh, stream_state.solu,
stream_state.solv, stream_state.solw);
}
}
cerr << "Initializing the visualization failed - unknown error."
<< endl;
return false;
}

if (vs)
{
// increase the refinement factors if visualizing a GridFunction
if (stream_state.grid_f)
{
vs->AutoRefine();
vs->SetShading(2, true);
}
if (mesh_range > 0.0)
{
vs->SetValueRange(-mesh_range, mesh_range);
vs->SetAutoscale(0);
}
if (stream_state.mesh->SpaceDimension() == 2 && field_type == 2)
{
SetVisualizationScene(vs, 2);
}
else
{
SetVisualizationScene(vs, 3);
}
}
delete vs;
vs = nullptr;

CallKeySequence(stream_state.keys.c_str());
double mesh_range = -1.0;
mainWindow->InitVisualization(field_type, std::move(stream_state));

if (minv || maxv)
{
vs->SetValueRange(minv, maxv);
}

SendExposeEvent();
mainWindow->SendExposeEvent();
return true;
}

Expand All @@ -244,64 +128,26 @@ int updateVisualization(std::string data_type, std::string stream)
return 1;
}

StreamState new_state;
new_state.ReadStream(ss, data_type);


auto * new_m = new Mesh(ss, 1, 0, stream_state.fix_elem_orient);
auto * new_g = new GridFunction(new_m, ss);
double mesh_range = -1.0;

if (new_m->SpaceDimension() == stream_state.mesh->SpaceDimension() &&
new_g->VectorDim() == stream_state.grid_f->VectorDim())
if (stream_state.SetNewMeshAndSolution(std::move(new_state), vs))
{
if (new_m->SpaceDimension() == 2)
{
if (new_g->VectorDim() == 1)
{
VisualizationSceneSolution *vss =
dynamic_cast<VisualizationSceneSolution *>(vs);
new_g->GetNodalValues(stream_state.sol);
vss->NewMeshAndSolution(new_m, &stream_state.sol, new_g);
}
else
{
VisualizationSceneVector *vsv =
dynamic_cast<VisualizationSceneVector *>(vs);
vsv->NewMeshAndSolution(*new_g);
}
}
else
{
if (new_g->VectorDim() == 1)
{
VisualizationSceneSolution3d *vss =
dynamic_cast<VisualizationSceneSolution3d *>(vs);
new_g->GetNodalValues(stream_state.sol);
vss->NewMeshAndSolution(new_m, &stream_state.sol, new_g);
}
else
{
new_g = ProjectVectorFEGridFunction(new_g);
VisualizationSceneVector3d *vss =
dynamic_cast<VisualizationSceneVector3d *>(vs);
vss->NewMeshAndSolution(new_m, new_g);
}
}
if (mesh_range > 0.0)
{
vs->SetValueRange(-mesh_range, mesh_range);
}

delete stream_state.grid_f;
stream_state.grid_f = new_g;
delete stream_state.mesh;
stream_state.mesh = new_m;

SendExposeEvent();
mainWindow->SendExposeEvent();
return 0;
}
else
{
cout << "Stream: field type does not match!" << endl;
delete new_g;
delete new_m;
return 1;
}
}
Expand Down Expand Up @@ -358,6 +204,29 @@ std::string getHelpString()
= dynamic_cast<VisualizationSceneScalarData*>(GetVisualizationScene());
return vss->GetHelpString();
}

void ResizeWindow(int w, int h)
{
mainWindow->ResizeWindow(w, h);
}

int GetUseTexture()
{
return vs->GetPalette().GetSmoothSetting();
}

void SetUseTexture(int ut)
{
if (ut == 0)
{
vs->GetPalette().UseDiscrete();
}
else
{
vs->GetPalette().UseSmooth();
}
}

} // namespace js

namespace em = emscripten;
Expand All @@ -371,9 +240,9 @@ EMSCRIPTEN_BINDINGS(js_funcs)
em::function("enableKeyHandling", &js::enableKeyHandling);
em::function("setKeyboardListeningElementId",
js::setKeyboardListeningElementId);
em::function("getTextureMode", &GetUseTexture);
em::function("setTextureMode", &SetUseTexture);
em::function("resizeWindow", &ResizeWindow);
em::function("getTextureMode", &js::GetUseTexture);
em::function("setTextureMode", &js::SetUseTexture);
em::function("resizeWindow", &js::ResizeWindow);
em::function("setCanvasId", &js::setCanvasId);
em::function("setupResizeEventCallback", &js::setupResizeEventCallback);
em::function("getHelpString", &js::getHelpString);
Expand Down
Loading