diff --git a/CMakeLists.txt b/CMakeLists.txt index a9f1ee7d..c1313e17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -328,6 +328,10 @@ message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}") add_subdirectory(lib) add_subdirectory(share) +if (GLVIS_BUILD_LIB_ONLY) + return() +endif() + if(NOT EMSCRIPTEN) # Setup the GLVis executable @@ -392,7 +396,6 @@ if(NOT EMSCRIPTEN) execute_process(COMMAND codesign --force --sign - ${CMAKE_INSTALL_PREFIX}/GLVis.app) ]] COMPONENT RUNTIME) endif(APPLE) - endif(NOT EMSCRIPTEN) if(ENABLE_TESTS) diff --git a/glvis.cpp b/glvis.cpp index c68418b2..633acdb0 100644 --- a/glvis.cpp +++ b/glvis.cpp @@ -11,7 +11,7 @@ // GLVis - an OpenGL visualization server based on the MFEM library -#include +// #include #include #include #include @@ -35,6 +35,7 @@ #endif #include +#include "lib/session.hpp" #include "lib/visual.hpp" #include "lib/window.hpp" #include "lib/script_controller.hpp" @@ -69,92 +70,6 @@ thread_local GeometryRefiner GLVisGeometryRefiner; void PrintSampleUsage(ostream &out); -class Session -{ - StreamCollection input_streams; - Window win; - std::thread handler; - -public: - Session(bool fix_elem_orient, - bool save_coloring, - string plot_caption, - bool headless) - { - win.data_state.fix_elem_orient = fix_elem_orient; - win.data_state.save_coloring = save_coloring; - win.plot_caption = plot_caption; - win.headless = headless; - } - - Session(Window other_win) - : win(std::move(other_win)) - { } - - ~Session() = default; - - Session(Session&& from) = default; - Session& operator= (Session&& from) = default; - - inline DataState& GetState() { return win.data_state; } - inline const DataState& GetState() const { return win.data_state; } - - void StartSession() - { - auto funcThread = [](Window w, StreamCollection is) - { - if (w.GLVisInitVis(std::move(is))) - { - w.GLVisStartVis(); - } - }; - handler = std::thread {funcThread, - std::move(win), std::move(input_streams)}; - handler.detach(); - } - - bool StartSavedSession(std::string stream_file) - { - unique_ptr ifs(new ifstream(stream_file)); - if (!(*ifs)) - { - cout << "Can not open stream file: " << stream_file << endl; - return false; - } - string data_type; - *ifs >> data_type >> ws; - StreamReader reader(win.data_state); - reader.ReadStream(*ifs, data_type); - input_streams.emplace_back(std::move(ifs)); - - StartSession(); - return true; - } - - int StartStreamSession(std::unique_ptr &&stream, - const std::string &data_type) - { - StreamReader reader(win.data_state); - int ierr = reader.ReadStream(*stream, data_type); - if (ierr) { return ierr; } - input_streams.emplace_back(std::move(stream)); - - StartSession(); - return 0; - } - - int StartStreamSession(StreamCollection &&streams) - { - StreamReader reader(win.data_state); - int ierr = reader.ReadStreams(streams); - if (ierr) { return ierr; } - input_streams = std::move(streams); - - StartSession(); - return 0; - } - -}; void GLVisServer(int portnum, bool save_stream, bool fix_elem_orient, bool save_coloring, string plot_caption, bool headless = false) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 0611ffb8..2583c134 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -32,7 +32,9 @@ list(APPEND SOURCES palettes_default.cpp palettes_base.cpp script_controller.cpp + session.cpp stream_reader.cpp + stream_session.cpp vsdata.cpp vssolution.cpp vssolution3d.cpp @@ -67,6 +69,7 @@ list(APPEND HEADERS palettes.hpp palettes_base.hpp script_controller.hpp + session.hpp stream_reader.hpp visual.hpp vsdata.hpp diff --git a/lib/session.cpp b/lib/session.cpp new file mode 100644 index 00000000..cbf51eeb --- /dev/null +++ b/lib/session.cpp @@ -0,0 +1,83 @@ +// Copyright (c) 2010-2026, Lawrence Livermore National Security, LLC. Produced +// at the Lawrence Livermore National Laboratory. All Rights reserved. See files +// LICENSE and NOTICE for details. LLNL-CODE-443271. +// +// This file is part of the GLVis visualization tool and library. For more +// information and source code availability see https://glvis.org. +// +// GLVis is free software; you can redistribute it and/or modify it under the +// terms of the BSD-3 license. We welcome feedback and contributions, see file +// CONTRIBUTING.md for details. + +#include "threads.hpp" // IWYU pragma: keep for GLVisCommand + +#include + +#include "session.hpp" + +void Session::StartSession() +{ + auto funcThread = [](Window w, StreamCollection is) + { + if (w.GLVisInitVis(std::move(is))) + { + w.GLVisStartVis(); + } + }; + handler = std::thread {funcThread, + std::move(win), std::move(input_streams)}; + handler.detach(); +} + +bool Session::StartSavedSession(std::string stream_file) +{ + std::unique_ptr ifs(new std::ifstream(stream_file)); + if (!(*ifs)) + { + std::cout << "Can not open stream file: " << stream_file << std::endl; + return false; + } + std::string data_type; + *ifs >> data_type >> std::ws; + StreamReader reader(win.data_state); + reader.ReadStream(*ifs, data_type); + input_streams.emplace_back(std::move(ifs)); + + StartSession(); + return true; +} + +int Session::StartStreamSession(std::unique_ptr &&stream, + const std::string &data_type) +{ + StreamReader reader(win.data_state); + int ierr = reader.ReadStream(*stream, data_type); + if (ierr) { return ierr; } + input_streams.emplace_back(std::move(stream)); + + StartSession(); + return 0; +} + +int Session::StartStreamSession(StreamCollection &&streams) +{ + StreamReader reader(win.data_state); + int ierr = reader.ReadStreams(streams); + if (ierr) { return ierr; } + input_streams = std::move(streams); + + StartSession(); + return 0; +} + +int Session::StartStreamSession(std::unique_ptr &&stream, + const std::string &data_type) +{ + StreamReader reader(win.data_state); + int ierr = reader.ReadStream(*stream, data_type); + if (ierr) { return ierr; } + input_streams.emplace_back(std::move(stream)); + + StartSession(); + return 0; +} diff --git a/lib/session.hpp b/lib/session.hpp new file mode 100644 index 00000000..6819116e --- /dev/null +++ b/lib/session.hpp @@ -0,0 +1,61 @@ +// Copyright (c) 2010-2026, Lawrence Livermore National Security, LLC. Produced +// at the Lawrence Livermore National Laboratory. All Rights reserved. See files +// LICENSE and NOTICE for details. LLNL-CODE-443271. +// +// This file is part of the GLVis visualization tool and library. For more +// information and source code availability see https://glvis.org. +// +// GLVis is free software; you can redistribute it and/or modify it under the +// terms of the BSD-3 license. We welcome feedback and contributions, see file +// CONTRIBUTING.md for details. +#pragma once + +#include "stream_reader.hpp" +#include "window.hpp" + +#include + +class Session +{ + StreamCollection input_streams; + Window win; + std::thread handler; + +public: + Session(bool fix_elem_orient, + bool save_coloring, + std::string plot_caption, + bool headless) + { + win.data_state.fix_elem_orient = fix_elem_orient; + win.data_state.save_coloring = save_coloring; + win.plot_caption = plot_caption; + win.headless = headless; + } + + Session(Window other_win): win(std::move(other_win)) { } + + ~Session() = default; + + Session(Session&& from) = default; + Session& operator= (Session&& from) = default; + + inline DataState& GetState() { return win.data_state; } + inline const DataState& GetState() const { return win.data_state; } + + void StartSession(); + + bool StartSavedSession(std::string stream_file); + + int StartStreamSession(std::unique_ptr &&stream, + const std::string &data_type); + + int StartStreamSession(std::unique_ptr &&stream, + const std::string &data_type); + + int StartStreamSession(StreamCollection &&streams); + + int StartSerialStreamSession(std::istream &stream, + const std::string &data_type); + +}; \ No newline at end of file diff --git a/lib/stream_session.cpp b/lib/stream_session.cpp new file mode 100644 index 00000000..0a2baf4d --- /dev/null +++ b/lib/stream_session.cpp @@ -0,0 +1,62 @@ +// Copyright (c) 2010-2026, Lawrence Livermore National Security, LLC. Produced +// at the Lawrence Livermore National Laboratory. All Rights reserved. See files +// LICENSE and NOTICE for details. LLNL-CODE-443271. +// +// This file is part of the GLVis visualization tool and library. For more +// information and source code availability see https://glvis.org. +// +// GLVis is free software; you can redistribute it and/or modify it under the +// terms of the BSD-3 license. We welcome feedback and contributions, see file +// CONTRIBUTING.md for details. + +#include "threads.hpp" // IWYU pragma: keep for GLVisCommand +#include "aux_vis.hpp" // SetUseHiDPI + +#include "session.hpp" + +#include + +extern thread_local mfem::GeometryRefiner GLVisGeometryRefiner; + +int GLVisStreamSession(const bool fix_elem_orient, + const bool save_coloring, + const bool headless, + const std::string &plot_caption, + const std::string &data_type, + StreamCollection &&streams) +{ + const int geom_ref_type = mfem::Quadrature1D::ClosedUniform; + const bool enable_hidpi = true; + + Window win; + + std::cout << std::endl + << " _/_/_/ _/ _/ _/ _/" << std::endl + << " _/ _/ _/ _/ _/_/_/" << std::endl + << " _/ _/_/ _/ _/ _/ _/ _/_/" << std::endl + << " _/ _/ _/ _/ _/ _/ _/_/" << std::endl + << " _/_/_/ _/_/_/_/ _/ _/ _/_/_/" << std::endl + << std::endl; + + SetUseHiDPI(enable_hidpi); + GLVisGeometryRefiner.SetType(geom_ref_type); + + GetMainThread(false); + + Session new_session(fix_elem_orient, save_coloring, plot_caption, headless); + if (streams.size() == 1 && data_type == "solution") + { + new_session.StartStreamSession(std::move(streams[0]), data_type); + } + else + { + new_session.StartStreamSession(std::move(streams)); + } + + std::vector current_sessions; + current_sessions.emplace_back(std::move(new_session)); + + MainThreadLoop(false, false); + + return EXIT_SUCCESS; +} diff --git a/lib/threads.cpp b/lib/threads.cpp index d6c4690d..1f30988c 100644 --- a/lib/threads.cpp +++ b/lib/threads.cpp @@ -1630,12 +1630,14 @@ void communication_thread::execute() } } - for (size_t i = 0; i < is.size(); i++) - { - socketstream *isock = dynamic_cast(is[i].get()); - if (isock) - { - isock->close(); - } - } + // avoid 'typeinfo for mfem::socketstream' rtti error + // until two stage compilation + // for (size_t i = 0; i < is.size(); i++) + // { + // socketstream *isock = dynamic_cast(is[i].get()); + // if (isock) + // { + // isock->close(); + // } + // } } diff --git a/makefile b/makefile index 2fe2e491..949c176e 100644 --- a/makefile +++ b/makefile @@ -276,7 +276,8 @@ ALL_SOURCE_FILES = \ lib/palettes_base.cpp lib/palettes.cpp lib/palettes_default.cpp \ lib/script_controller.cpp lib/stream_reader.cpp lib/threads.cpp \ lib/vsdata.cpp lib/vssolution.cpp lib/vssolution3d.cpp \ - lib/vsvector.cpp lib/vsvector3d.cpp lib/window.cpp + lib/vsvector.cpp lib/vsvector3d.cpp lib/window.cpp \ + lib/session.cpp lib/stream_session.cpp OBJC_SOURCE_FILES = $(if $(NOTMAC),,lib/sdl/sdl_mac.mm) DESKTOP_ONLY_SOURCE_FILES = \ lib/gl/renderer_ff.cpp lib/gl2ps.c lib/script_controller.cpp \ @@ -300,7 +301,7 @@ HEADER_FILES = \ lib/openglvis.hpp lib/palettes_base.hpp lib/palettes.hpp \ lib/script_controller.hpp lib/stream_reader.hpp lib/threads.hpp \ lib/visual.hpp lib/vsdata.hpp lib/vssolution.hpp lib/vssolution3d.hpp \ - lib/vsvector.hpp lib/vsvector3d.hpp lib/window.hpp + lib/vsvector.hpp lib/vsvector3d.hpp lib/window.hpp lib/session.hpp DESKTOP_SOURCE_FILES = $(COMMON_SOURCE_FILES) $(DESKTOP_ONLY_SOURCE_FILES) $(LOGO_FILE_CPP) WEB_SOURCE_FILES = $(COMMON_SOURCE_FILES) $(WEB_ONLY_SOURCE_FILES)