Skip to content

Commit 57e5110

Browse files
committed
Add optional support for VSG run-time visualization
1 parent 0ff9b59 commit 57e5110

7 files changed

Lines changed: 596 additions & 421 deletions

File tree

CMakeLists.txt

Lines changed: 74 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ endif()
109109

110110
option(HYDROCHRONO_ENABLE_TESTS "Enable tests" ON)
111111
option(HYDROCHRONO_ENABLE_IRRLICHT "Enable irrlicht visualization library" OFF)
112+
option(HYDROCHRONO_ENABLE_VSG "Enable VSG visualization library" OFF)
112113
option(HYDROCHRONO_ENABLE_DEMOS "Enable demo executables" OFF)
113114
option(HYDROCHRONO_ENABLE_YAML_RUNNER "Enable YAML-based CLI runner" OFF)
114115
option(HYDROCHRONO_ENABLE_USER_DOC "User's documentation" OFF)
@@ -205,7 +206,7 @@ endif()
205206
find_package(Chrono
206207
CONFIG REQUIRED
207208
COMPONENTS Parsers
208-
OPTIONAL_COMPONENTS Irrlicht)
209+
OPTIONAL_COMPONENTS Irrlicht VSG)
209210

210211
message(STATUS "----\n")
211212

@@ -244,16 +245,30 @@ if(HYDROCHRONO_ENABLE_IRRLICHT AND NOT TARGET Chrono::Chrono_irrlicht)
244245
message(FATAL_ERROR "HYDROCHRONO_ENABLE_IRRLICHT is ON but Chrono::Chrono_irrlicht target not found. Ensure Chrono was built with Irrlicht support.")
245246
endif()
246247

248+
# Enable VSG support if requested and available
249+
if(HYDROCHRONO_ENABLE_VSG AND NOT TARGET Chrono::Chrono_vsg)
250+
message(FATAL_ERROR "HYDROCHRONO_ENABLE_VSG is ON but Chrono::Chrono_vsg target not found. Ensure Chrono was built with VSG support.")
251+
endif()
252+
247253
# If on a Windows platform, copy the Chrono DLLs to the binary directory
248254
add_CHRONO_DLLS_copy_command()
249255

250256
# Copy selected Chrono data directories to the HydroChrono data directory
251257
if(EXISTS "${CHRONO_DATA_DIR}")
258+
if(EXISTS "${CHRONO_DATA_DIR}/colormaps")
259+
file(COPY ${CHRONO_DATA_DIR}/colormaps DESTINATION ${HC_BUILD_DATA}/chrono)
260+
endif()
261+
252262
if(EXISTS "${CHRONO_DATA_DIR}/skybox")
253263
file(COPY ${CHRONO_DATA_DIR}/skybox DESTINATION ${HC_BUILD_DATA}/chrono)
254264
endif()
255-
if(EXISTS "${CHRONO_DATA_DIR}/colormaps")
256-
file(COPY ${CHRONO_DATA_DIR}/colormaps DESTINATION ${HC_BUILD_DATA}/chrono)
265+
266+
if(EXISTS "${CHRONO_DATA_DIR}/vsg")
267+
file(COPY ${CHRONO_DATA_DIR}/vsg DESTINATION ${HC_BUILD_DATA}/chrono)
268+
endif()
269+
270+
if(EXISTS "${CHRONO_DATA_DIR}/logo_chrono_alpha.png")
271+
file(COPY ${CHRONO_DATA_DIR}/logo_chrono_alpha.png DESTINATION ${HC_BUILD_DATA}/chrono)
257272
endif()
258273
endif()
259274

@@ -277,6 +292,12 @@ else()
277292
set(HC_HAS_IRRLICHT "#undef HYDROCHRONO_HAVE_IRRLICHT")
278293
endif()
279294

295+
if(HYDROCHRONO_ENABLE_VSG)
296+
set(HC_HAS_VSG "#define HYDROCHRONO_HAVE_VSG")
297+
else()
298+
set(HC_HAS_VSG "#undef HYDROCHRONO_HAVE_VSG")
299+
endif()
300+
280301
# For BUILD tree
281302
set(HC_DATA_DIR "#define HC_DATA_DIR \"${HC_BUILD_DATA}\"")
282303
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in
@@ -293,43 +314,23 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in
293314
# ------- Core Library Target ---------------------------------------------------
294315
# ===============================================================================
295316

296-
# Helper function to configure common HydroChrono target properties
297-
# Now uses modern Chrono imported targets (Chrono ≥ v9.1.0)
298-
function(configure_hydro_target tgt)
299-
target_compile_features(${tgt} PUBLIC ${HC_CXX_STANDARD})
300-
301-
list(APPEND HC_INCLUDES_BUILD ${PROJECT_SOURCE_DIR}/include)
302-
list(APPEND HC_INCLUDES_BUILD ${PROJECT_BINARY_DIR})
303-
target_include_directories(${tgt}
304-
PUBLIC
305-
"$<BUILD_INTERFACE:${HC_INCLUDES_BUILD}>"
306-
"$<INSTALL_INTERFACE:include>"
307-
)
308-
309-
# Enable position-independent code for static library linking
310-
set_target_properties(${tgt} PROPERTIES POSITION_INDEPENDENT_CODE ON)
311-
312-
# Link to modern Chrono imported targets - these automatically propagate
313-
# include paths, compile flags, and link dependencies
314-
target_link_libraries(${tgt}
315-
PUBLIC
316-
Chrono::Chrono_core
317-
# Conditionally link Irrlicht component if enabled
318-
$<$<BOOL:${HYDROCHRONO_ENABLE_IRRLICHT}>:Chrono::Chrono_irrlicht>
319-
)
320-
endfunction()
317+
list(APPEND HC_INCLUDES_BUILD ${PROJECT_SOURCE_DIR}/include)
318+
list(APPEND HC_INCLUDES_BUILD ${PROJECT_BINARY_DIR})
321319

322320
# Helper function to configure test environment (Windows DLL paths, etc.)
323321
function(configure_test_environment)
324322
# Set up DLL search paths for Windows testing
325323
set(CHRONO_DLL_DIR "${Chrono_DIR}/../bin/Release")
324+
326325
# Always include our build output bin directories for all common configs
327326
set(HC_BIN_DIRS "${CMAKE_BINARY_DIR}/bin/Release;${CMAKE_BINARY_DIR}/bin/RelWithDebInfo;${CMAKE_BINARY_DIR}/bin/MinSizeRel;${CMAKE_BINARY_DIR}/bin/Debug")
327+
328328
# Include HDF5 bin if available to stabilize test runtime on clean systems
329329
set(HDF5_DLL_DIR "")
330330
if(DEFINED HDF5_ROOT AND EXISTS "${HDF5_ROOT}/bin")
331331
set(HDF5_DLL_DIR "${HDF5_ROOT}/bin")
332332
endif()
333+
333334
# Derive Irrlicht DLL dir from Irrlicht_ROOT provided by user config
334335
set(IRRLICHT_DLL_DIR "")
335336
if(DEFINED Irrlicht_ROOT AND EXISTS "${Irrlicht_ROOT}/bin/Win64-VisualStudio")
@@ -353,7 +354,7 @@ function(configure_test_environment)
353354
endfunction()
354355

355356
# -- Main HydroChrono Library --
356-
set(HYDROCHRONO_SOURCES
357+
set(HC_SOURCES
357358
src/h5fileinfo.cpp
358359
src/chloadaddedmass.cpp
359360
src/hydro_forces.cpp
@@ -369,7 +370,7 @@ set(HYDROCHRONO_SOURCES
369370
src/simulation_exporter.cpp
370371
)
371372

372-
set(HYDROCHRONO_HEADERS
373+
set(HC_HEADERS
373374
${PROJECT_BINARY_DIR}/hydroc/config.h
374375
${PROJECT_BINARY_DIR}/hydroc/version.h
375376
include/hydroc/h5_writer.h
@@ -380,8 +381,16 @@ set(HYDROCHRONO_HEADERS
380381
)
381382

382383
# Create the library target and configure it
383-
add_library(HydroChrono ${HYDROCHRONO_SOURCES} ${HYDROCHRONO_HEADERS})
384-
configure_hydro_target(HydroChrono)
384+
add_library(HydroChrono ${HC_SOURCES} ${HC_HEADERS})
385+
386+
target_compile_features(HydroChrono PUBLIC ${HC_CXX_STANDARD})
387+
target_include_directories(HydroChrono
388+
PUBLIC
389+
"$<BUILD_INTERFACE:${HC_INCLUDES_BUILD}>"
390+
"$<INSTALL_INTERFACE:include>"
391+
)
392+
set_target_properties(HydroChrono PROPERTIES POSITION_INDEPENDENT_CODE ON)
393+
target_link_libraries(HydroChrono PUBLIC Chrono::Chrono_core)
385394

386395
# Add OpenMP
387396
target_link_libraries(HydroChrono PUBLIC OpenMP::OpenMP_CXX)
@@ -433,7 +442,39 @@ target_compile_definitions(HydroChrono
433442
)
434443

435444
# ===============================================================================
436-
# ------- Auxiliary Targets (GUI, Tests, Demos) ---------------------------------
445+
# ------- Visualization library -------------------------------------------------
446+
# ===============================================================================
447+
448+
set(HCGUI_HEADERS
449+
include/hydroc/gui/guihelper.h
450+
src/gui/guihelper_impl.h
451+
)
452+
453+
set(HCGUI_SOURCES
454+
src/gui/guihelper.cpp
455+
src/gui/guihelperIRR.cpp
456+
src/gui/guihelperVSG.cpp
457+
)
458+
459+
add_library(HydroChronoGUI ${HCGUI_SOURCES} ${HCGUI_HEADERS})
460+
461+
target_compile_features(HydroChronoGUI PUBLIC ${HC_CXX_STANDARD})
462+
target_include_directories(HydroChronoGUI
463+
PUBLIC
464+
"$<BUILD_INTERFACE:${HC_INCLUDES_BUILD}>"
465+
"$<INSTALL_INTERFACE:include>"
466+
)
467+
set_target_properties(HydroChronoGUI PROPERTIES POSITION_INDEPENDENT_CODE ON)
468+
target_link_libraries(HydroChronoGUI
469+
PUBLIC
470+
Chrono::Chrono_core
471+
# Conditionally link Irrlicht and VSG components if enabled
472+
$<$<BOOL:${HYDROCHRONO_ENABLE_IRRLICHT}>:Chrono::Chrono_irrlicht>
473+
$<$<BOOL:${HYDROCHRONO_ENABLE_VSG}>:Chrono::Chrono_vsg>
474+
)
475+
476+
# ===============================================================================
477+
# ------- Auxiliary Targets (app, tests, demos) ---------------------------------
437478
# ===============================================================================
438479

439480
# YAML-driven CLI app
@@ -443,10 +484,6 @@ else()
443484
message(STATUS "YAML runner disabled - not creating run_hydrochrono target")
444485
endif()
445486

446-
# Separate library for Irrlicht visualization helpers
447-
add_library(HydroChronoGUI src/gui/guihelper.cpp)
448-
configure_hydro_target(HydroChronoGUI)
449-
450487
# Demos
451488
if(HYDROCHRONO_ENABLE_DEMOS)
452489
add_subdirectory(demos)

cmake/config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
// If HydroChrono was built with Irrlicht support, define HYDROCHRONO_HAVE_IRRLICHT
1313
@HC_HAS_IRRLICHT@
1414

15+
// If HydroChrono was built with VSG support, define HYDROCHRONO_HAVE_VSG
16+
@HC_HAS_VSG@
17+
1518
// Path to HydroChrono data directory
1619
@HC_DATA_DIR@
1720

include/hydroc/gui/guihelper.h

Lines changed: 56 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,76 @@
11
#pragma once
22

3-
43
#include <memory>
54

65
namespace chrono {
7-
class ChSystem;
6+
class ChSystem;
87
}
98

10-
11-
129
namespace hydroc {
13-
namespace gui {
14-
15-
16-
struct UI {
17-
18-
UI()
19-
{
20-
}
21-
virtual ~UI() {}
22-
23-
24-
UI(const UI&) = delete;
25-
UI& operator = (const UI&) = delete;
26-
27-
/**@brief Initialize the system
28-
*
29-
* Should be called after the given ChSystem is fully initialized
30-
* The best is to call it just before the simulation loop that call IsRunning
31-
*
32-
*/
33-
virtual void Init(chrono::ChSystem*, const char* title);
34-
35-
/**@brief Set Camera position and direction
36-
*
37-
*/
38-
virtual void SetCamera(double x, double y, double z, double dirx, double diry, double dirz);
39-
40-
/**@brief To call during simulation loop
41-
*
42-
*/
43-
virtual bool IsRunning(double timestep);
44-
45-
/**@brief return the internal system.
46-
*
47-
* Should be called after init.
48-
*/
49-
chrono::ChSystem* GetSystem() const {return pSystem; }
50-
51-
bool simulationStarted = true;
52-
53-
protected:
54-
55-
chrono::ChSystem* pSystem = nullptr; // Do not manage the memory
56-
10+
namespace gui {
11+
12+
/// HydroChrono User Interface.
13+
class UI {
14+
public:
15+
UI();
16+
virtual ~UI() {}
17+
18+
UI(const UI&) = delete;
19+
UI& operator=(const UI&) = delete;
20+
21+
/**@brief Initialize the system
22+
*
23+
* Should be called after the given ChSystem is fully initialized
24+
* The best is to call it just before the simulation loop that call IsRunning
25+
*
26+
*/
27+
virtual void Init(chrono::ChSystem*, const char* title);
28+
29+
/**@brief Set Camera position and direction
30+
*
31+
*/
32+
virtual void SetCamera(double x, double y, double z, double dirx, double diry, double dirz);
33+
34+
/**@brief To call during simulation loop
35+
*
36+
*/
37+
virtual bool IsRunning(double timestep);
38+
39+
/**@brief return the internal system.
40+
*
41+
* Should be called after init.
42+
*/
43+
chrono::ChSystem* GetSystem() const { return pSystem; }
44+
45+
bool simulationStarted = true;
46+
47+
protected:
48+
chrono::ChSystem* pSystem; // Do not manage the memory
5749
};
5850

51+
// -----------------------------------------------------------------------------
5952

6053
class GUIImpl;
6154

55+
/// HydroChrono Graphical User Interface.
56+
class GUI : public UI {
57+
public:
58+
GUI();
59+
GUI(const GUI&) = delete;
60+
GUI& operator=(const GUI&) = delete;
6261

63-
struct GUI: public UI {
62+
void Init(chrono::ChSystem*, const char* title) override;
63+
void SetCamera(double x, double y, double z, double dirx, double diry, double dirz) override;
64+
bool IsRunning(double timestep) override;
6465

65-
GUI();
66-
GUI(const GUI&) = delete;
67-
GUI& operator = (const GUI&) = delete;
68-
69-
void Init(chrono::ChSystem*, const char* title) override;
70-
void SetCamera(double x, double y, double z, double dirx, double diry, double dirz) override;
71-
bool IsRunning(double timestep) override;
72-
73-
private:
74-
std::shared_ptr<hydroc::gui::GUIImpl> pImpl;
66+
private:
67+
std::shared_ptr<hydroc::gui::GUIImpl> pImpl;
7568
};
7669

77-
7870
/**@brief Factory to create UI or GUI
79-
*
80-
*/
71+
*
72+
*/
8173
std::shared_ptr<hydroc::gui::UI> CreateUI(bool visualizationOn = true);
8274

83-
84-
} // end namespace gui
85-
} // end namespace hydroc
86-
87-
88-
89-
90-
75+
} // end namespace gui
76+
} // end namespace hydroc

0 commit comments

Comments
 (0)