Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
6c00bda
Move background setting to MyExpose
publixsubfan Jan 19, 2021
a1c18c4
Move antialiasing to aux_vis
publixsubfan Jan 20, 2021
dd9b278
Create GLVisWindow class, move font handling stuff into it
publixsubfan Jan 20, 2021
403282f
Moving more methods to GLVisWindow class
publixsubfan Jan 27, 2021
a392026
Move idle func handling into GLVisWindow
publixsubfan Jan 27, 2021
d40b414
Add mouse events, model spinning stuff to GLVisWindow
publixsubfan Jan 28, 2021
9ff3eeb
Move MSAA, screenshot controls into GLVisWindow, add wrapper for memb…
publixsubfan Jan 28, 2021
1dfc47a
Move screenshot implementation to new file
publixsubfan Jan 28, 2021
e3cc12a
Move some window control functions to GLVisWindow
publixsubfan Jan 28, 2021
e7b9806
Move more scene transformation methods into GLVisWindow
publixsubfan Jan 28, 2021
93c95f8
Fix a segfault with font ptr in VisualizationScene
publixsubfan Jan 28, 2021
d836dde
Remove GetUseTexture/SetUseTexture functions, move into aux_js
publixsubfan Jan 29, 2021
69072c1
Move thread control functions into GLVisWindow
publixsubfan Jan 29, 2021
84815a3
Remove some global dependencies from glvis.cpp
publixsubfan Feb 3, 2021
2707c46
Remove references to global glvis_command instance
publixsubfan May 12, 2021
e369884
Move command, vis scene construction into GLVisWindow; pass local GLV…
publixsubfan Feb 4, 2021
dfe6aca
JS-related build fixes
publixsubfan Feb 4, 2021
7c4b7a0
Remove global vsdata dependence from Plane class
publixsubfan Feb 10, 2021
15a2a74
Start moving over some key events to member functions
publixsubfan Feb 10, 2021
eb59307
Add support for stackable events, improve handling of scene view resets
publixsubfan Feb 11, 2021
a8dcb86
Add support for conditionally-updatable event handlers
publixsubfan Feb 11, 2021
ca18aa2
Make all vssolution3d event handlers member functions
publixsubfan Feb 11, 2021
664b7f1
Make vssolution event handlers member functions
publixsubfan Feb 11, 2021
bfb252c
Make vsvector event handlers member functions
publixsubfan Feb 11, 2021
8100b38
Convert last of vsdata event handlers
publixsubfan Feb 11, 2021
4b6f7b7
Remove SdlWindow reference from vsdata
publixsubfan Feb 11, 2021
2e9032d
Fix for printing
publixsubfan Feb 11, 2021
24485b3
Cleanup globals from aux_vis
publixsubfan Feb 11, 2021
53e7370
Make TouchPinch a member of GLVisWindow
publixsubfan May 12, 2021
9990835
Run astyle
publixsubfan May 12, 2021
1e4c54e
Remove more globals
publixsubfan May 12, 2021
942c632
Remove global stream_state from desktop side code
publixsubfan May 12, 2021
4c97a29
Merge branch 'master' into glvis-window-dev
publixsubfan May 24, 2021
2bb63be
Remove unused variable
publixsubfan May 24, 2021
5e023b8
fix js build
Jun 1, 2021
51f67e8
fix some bugs & emscripten incompatibilities
Jun 5, 2021
44fd6d8
'fix' issue where the canvas size doubles on new vis; not sure why th…
Jun 13, 2021
c0de293
make style
tzanio Jun 16, 2021
9ba13ce
Fix for vsvector grid function initialization
publixsubfan Jun 16, 2021
31cc55b
Simplify GLVisCommand constructors
publixsubfan Jun 16, 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
262 changes: 69 additions & 193 deletions glvis.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ list(APPEND SOURCES
openglvis.cpp
palettes.cpp
sdl.cpp
sdl_screenshot.cpp
stream_reader.cpp
vsdata.cpp
vssolution.cpp
Expand Down
212 changes: 61 additions & 151 deletions lib/aux_js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ std::string plot_caption;
std::string extra_caption; // used in extern context
mfem::GeometryRefiner GLVisGeometryRefiner; // used in extern context

static VisualizationSceneScalarData * vs = nullptr;
StreamState stream_state;
static GLVisWindow * mainWindow = nullptr;
static VisualizationSceneScalarData * vssd = nullptr;
static bool keep_attr = false;

namespace js
{
Expand All @@ -33,12 +34,10 @@ bool startVisualization(const std::string input, const std::string data_type,
{
std::stringstream ss(input);

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

// reset antialiasing
GetAppWindow()->getRenderer().setAntialiasing(0);

std::string line;
double minv = 0.0, maxv = 0.0;
while (ss >> line)
Expand All @@ -64,150 +63,35 @@ bool startVisualization(const std::string input, const std::string data_type,
return false;
}

if (InitVisualization("glvis", 0, 0, w, h))
{
return false;
}

delete vs;
vs = nullptr;

double mesh_range = -1.0;
if (field_type == 0 || field_type == 2)
if (mainWindow == nullptr)
{
if (stream_state.grid_f)
try
{
stream_state.grid_f->GetNodalValues(stream_state.sol);
mainWindow = new GLVisWindow("glvis", 0, 0, w, h, false);
}
if (stream_state.mesh->SpaceDimension() == 2)
catch (std::runtime_error& ex)
{
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).
vs->palette.SetIndex(4);
}
cerr << "Initializing the visualization failed: " << endl
<< ex.what() << endl;
return false;
}
else if (stream_state.mesh->SpaceDimension() == 3)
catch (...)
{
VisualizationSceneSolution3d * vss;
vs = vss = new VisualizationSceneSolution3d(*stream_state.mesh,
stream_state.sol);
if (stream_state.grid_f)
{
vss->SetGridFunction(stream_state.grid_f.get());
}
if (field_type == 2)
{
if (stream_state.mesh->Dimension() == 3)
{
// Use the 'white' palette when visualizing a 3D volume mesh only
// vs->palette.SetIndex(4);
vs->palette.SetIndex(11);
vss->SetLightMatIdx(4);
}
else
{
// Use the 'bone' palette when visualizing a surface mesh only
// (the same as when visualizing a 2D mesh only)
vs->palette.SetIndex(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;
}
}
}
else if (field_type == 1)
{
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(std::move(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);
}
}

CallKeySequence(stream_state.keys.c_str());
double mesh_range = -1.0;
mainWindow->InitVisualization(field_type, std::move(stream_state), keep_attr);
vssd = dynamic_cast<VisualizationSceneScalarData*>(mainWindow->getScene());

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

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

Expand All @@ -227,14 +111,14 @@ int updateVisualization(std::string data_type, std::string stream)
new_state.ReadStream(ss, data_type);
double mesh_range = -1.0;

if (stream_state.SetNewMeshAndSolution(std::move(new_state), vs))
StreamState & stream_state = mainWindow->getStreamState();
if (stream_state.SetNewMeshAndSolution(std::move(new_state), vssd))
{
if (mesh_range > 0.0)
{
vs->SetValueRange(-mesh_range, mesh_range);
vssd->SetValueRange(-mesh_range, mesh_range);
}

SendExposeEvent();
mainWindow->SendExposeEvent();
return 0;
}
else
Expand All @@ -246,13 +130,13 @@ int updateVisualization(std::string data_type, std::string stream)

void iterVisualization()
{
GetAppWindow()->mainIter();
mainWindow->getSdl()->mainIter();
}

void setCanvasId(const std::string & id)
{
std::cout << "glvis: setting canvas id to " << id << std::endl;
GetAppWindow()->setCanvasId(id);
mainWindow->getSdl()->setCanvasId(id);
}

void disableKeyHandling()
Expand All @@ -274,7 +158,7 @@ void setKeyboardListeningElementId(const std::string & id)

void processKeys(const std::string & keys)
{
CallKeySequence(keys.c_str());
mainWindow->CallKeySequence(keys.c_str());
}

void processKey(int sym, bool ctrl=false, bool shift=false, bool alt=false)
Expand All @@ -283,7 +167,7 @@ void processKey(int sym, bool ctrl=false, bool shift=false, bool alt=false)
mod |= ctrl ? KMOD_CTRL : 0;
mod |= shift ? KMOD_SHIFT : 0;
mod |= alt ? KMOD_ALT : 0;
GetAppWindow()->callKeyDown(sym, mod);
mainWindow->getSdl()->callKeyDown(sym, mod);
}

void setupResizeEventCallback(const std::string & id)
Expand All @@ -306,10 +190,36 @@ void setupResizeEventCallback(const std::string & id)

std::string getHelpString()
{
VisualizationSceneScalarData* vss
= dynamic_cast<VisualizationSceneScalarData*>(GetVisualizationScene());
return vss->GetHelpString();
return vssd->GetHelpString();
}

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

int GetUseTexture()
{
return vssd->palette.GetSmoothSetting();
}

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

void SendExposeEvent()
{
mainWindow->SendExposeEvent();
}

} // namespace js

// Info on type conversion:
Expand All @@ -320,14 +230,14 @@ EMSCRIPTEN_BINDINGS(js_funcs)
em::function("startVisualization", &js::startVisualization);
em::function("updateVisualization", &js::updateVisualization);
em::function("iterVisualization", &js::iterVisualization);
em::function("sendExposeEvent", &SendExposeEvent);
em::function("sendExposeEvent", &js::SendExposeEvent);
em::function("disableKeyHanding", &js::disableKeyHandling);
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