Skip to content

Commit dc73e79

Browse files
authored
Merge pull request #340 from GLVis/time-series-js
Proper stream parsing in glvis-js
2 parents 86f9c88 + 7b90519 commit dc73e79

16 files changed

Lines changed: 569 additions & 597 deletions

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ Unlike previous GLVis releases, this version requires a C++17 compiler.
5252
- Color palettes defined in an external file can now also be specified in
5353
scripts and streams using the keyword 'palette_file'.
5454

55+
- Generalized and unified processing of stream commands for glvis-js to support
56+
all commands.
57+
58+
5559
Version 4.4 released on May 1, 2025
5660
===================================
5761

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ if (NOT EMSCRIPTEN)
258258
endif (GLVIS_USE_EGL)
259259

260260
# Find CGL
261-
if (GLVIS_USE_CGL)
261+
if (GLVIS_USE_CGL AND NOT EMSCRIPTEN)
262262
list(APPEND _glvis_compile_defs "GLVIS_USE_CGL")
263-
endif (GLVIS_USE_CGL)
263+
endif (GLVIS_USE_CGL AND NOT EMSCRIPTEN)
264264

265265
# Find threading library
266266
find_package(Threads REQUIRED)

lib/aux_js.cpp

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -42,47 +42,29 @@ namespace js
4242
using namespace mfem;
4343

4444
/// Display a new stream
45-
void display(std::stringstream & commands, const int w, const int h)
45+
void display(StreamCollection streams, const int w, const int h)
4646
{
4747
// reset antialiasing
4848
if (win.wnd)
4949
{
5050
win.wnd->getRenderer().setAntialiasing(0);
5151
}
5252

53-
std::string word, keys;
54-
double minv = 0.0, maxv = 0.0;
55-
while (commands >> word)
56-
{
57-
if (word == "keys")
58-
{
59-
std::cout << "parsing 'keys'" << std::endl;
60-
commands >> keys;
61-
}
62-
else if (word == "valuerange")
63-
{
64-
std::cout << "parsing 'valuerange'" << std::endl;
65-
commands >> minv >> maxv;
66-
}
67-
else
68-
{
69-
std::cout << "unknown command '" << word << "'" << std::endl;
70-
}
71-
}
72-
7353
win.window_title = "glvis";
7454
win.window_x = 0.;
7555
win.window_y = 0.;
7656
win.window_w = w;
7757
win.window_h = h;
7858

79-
if (!win.GLVisInitVis({})) { return; }
59+
if (!win.GLVisInitVis(std::move(streams))) { return; }
8060

81-
CallKeySequence(keys.c_str());
82-
83-
if (minv || maxv)
61+
while (win.comm_thread->process_one())
8462
{
85-
win.vs->SetValueRange(minv, maxv);
63+
if (win.glvis_command->Execute() < 0)
64+
{
65+
// GLVisCommand signalled exit!
66+
break;
67+
}
8668
}
8769

8870
SendExposeEvent();
@@ -96,61 +78,48 @@ void display(std::stringstream & commands, const int w, const int h)
9678
// each string in streams must start with `parallel <nproc> <rank>'
9779
//
9880
using StringArray = std::vector<std::string>;
99-
void processParallelStreams(DataState & state,
100-
const StringArray & streams,
101-
std::stringstream * commands = nullptr)
81+
StreamCollection processParallelStreams(DataState & state,
82+
const StringArray & streams)
10283
{
10384
// std::cerr << "got " << streams.size() << " streams" << std::endl;
104-
// HACK: match unique_ptr<istream> interface for ReadStreams:
105-
std::vector<std::stringstream> sstreams(streams.size());
10685
StreamCollection istreams(streams.size());
10786
for (int i = 0; i < streams.size(); ++i)
10887
{
109-
sstreams[i] = std::stringstream(streams[i]);
88+
istreams[i] = std::unique_ptr<std::istream>(new std::stringstream(streams[i]));
11089
// pull off the first list
11190
std::string word;
11291
int nproc, rank;
113-
sstreams[i] >> word >> nproc >> rank;
114-
// std::cerr << "packing " << rank+1 << "/" << nproc << std::endl;
115-
istreams[i] = std::unique_ptr<std::istream>(&sstreams[i]);
92+
*istreams[i] >> word >> nproc >> rank;
11693
}
11794

11895
StreamReader reader(state);
11996
reader.ReadStreams(istreams);
12097

121-
if (commands)
122-
{
123-
commands->seekg(istreams[0]->tellg());
124-
}
125-
126-
// HACK: don't let unique_ptr free the data
127-
for (int i = 0; i < streams.size(); ++i)
128-
{
129-
istreams[i].release();
130-
}
131-
13298
last_stream_nproc = streams.size();
99+
100+
return istreams;
133101
}
134102

135103
void displayParallelStreams(const StringArray & streams, const int w,
136104
const int h)
137105
{
138-
std::stringstream commands(streams[0]);
139-
processParallelStreams(win.data_state, streams, &commands);
106+
StreamCollection sc = processParallelStreams(win.data_state, streams);
140107

141-
display(commands, w, h);
108+
display(std::move(sc), w, h);
142109
}
143110

144111
void displayStream(const std::string & stream, const int w, const int h)
145112
{
146-
std::stringstream ss(stream);
113+
std::unique_ptr<std::istream> ss(new std::istringstream(stream));
147114
std::string data_type;
148-
ss >> data_type;
115+
*ss >> data_type;
149116

150117
StreamReader reader(win.data_state);
151-
reader.ReadStream(ss, data_type);
118+
reader.ReadStream(*ss, data_type);
152119

153-
display(ss, w, h);
120+
StreamCollection sc;
121+
sc.emplace_back(std::move(ss));
122+
display(std::move(sc), w, h);
154123
}
155124

156125
//

lib/aux_vis.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,6 @@ void InitIdleFuncs()
523523
}
524524
}
525525

526-
#ifndef __EMSCRIPTEN__
527526
bool CommunicationIdleFunc()
528527
{
529528
int status = glvis_command->Execute();
@@ -539,12 +538,11 @@ bool CommunicationIdleFunc()
539538
}
540539
return false;
541540
}
542-
#endif
543541

544542
bool MainIdleFunc()
545543
{
546544
bool sleep = true;
547-
#ifndef __EMSCRIPTEN__
545+
548546
if (glvis_command && visualize == 1
549547
&& !(IdleFuncs.Size() > 0 && use_idle))
550548
{
@@ -567,24 +565,8 @@ bool MainIdleFunc()
567565
sleep = false;
568566
}
569567
use_idle = !use_idle;
570-
#else
571-
if (IdleFuncs.Size() > 0)
572-
{
573-
LastIdleFunc = (LastIdleFunc + 1) % IdleFuncs.Size();
574-
if (IdleFuncs[LastIdleFunc])
575-
{
576-
(*IdleFuncs[LastIdleFunc])();
577-
}
578-
// Continue executing idle functions
579-
sleep = false;
580-
}
581-
#endif
568+
582569
return sleep;
583-
LastIdleFunc = (LastIdleFunc + 1) % IdleFuncs.Size();
584-
if (IdleFuncs[LastIdleFunc])
585-
{
586-
(*IdleFuncs[LastIdleFunc])();
587-
}
588570
}
589571

590572
void AddIdleFunc(void (*Func)(void))
@@ -1376,9 +1358,7 @@ void ThreadsPauseFunc(SDL_Keymod state)
13761358
{
13771359
if (state & KMOD_CTRL)
13781360
{
1379-
#ifndef __EMSCRIPTEN__
13801361
glvis_command->ToggleAutopause();
1381-
#endif
13821362
}
13831363
else
13841364
{

lib/sdl/sdl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,10 @@ void SdlWindow::signalLoop()
436436
lock_guard<mutex> evt_guard{event_mutex};
437437
call_idle_func = true;
438438
}
439-
events_available.notify_all();
439+
if (is_multithreaded)
440+
{
441+
events_available.notify_all();
442+
}
440443
}
441444

442445
void SdlWindow::getWindowSize(int& w, int& h) const

0 commit comments

Comments
 (0)