From 93fb39bc95a8823c5b18cea37836e0345e200014 Mon Sep 17 00:00:00 2001 From: BenPinet Date: Tue, 6 Oct 2026 13:38:31 +0200 Subject: [PATCH 1/2] feat(BrepTimeSeries): add time series import factory --- .../src/model/representation/io/brep.cpp | 7 + .../io/brep_time_series_input.hpp | 77 +++++++++++ src/geode/model/CMakeLists.txt | 2 + .../io/brep_time_series_input.cpp | 122 ++++++++++++++++++ 4 files changed, 208 insertions(+) create mode 100644 include/geode/model/representation/io/brep_time_series_input.hpp create mode 100644 src/geode/model/representation/io/brep_time_series_input.cpp diff --git a/bindings/python/src/model/representation/io/brep.cpp b/bindings/python/src/model/representation/io/brep.cpp index 69a41e89d..cfcf23f55 100644 --- a/bindings/python/src/model/representation/io/brep.cpp +++ b/bindings/python/src/model/representation/io/brep.cpp @@ -27,6 +27,7 @@ #include #include #include +#include namespace geode { @@ -38,7 +39,13 @@ namespace geode module.def( "is_brep_loadable", &is_brep_loadable ); module.def( "is_brep_saveable", &is_brep_saveable ); module.def( "brep_additional_files", &brep_additional_files ); + module.def( "load_brep_time_series", &load_brep_time_series ); + module.def( "is_brep_time_series_loadable", + &is_brep_time_series_loadable ); + module.def( "brep_time_series_additional_files", + &brep_time_series_additional_files ); PYTHON_FACTORY_CLASS( BRepInputFactory ); PYTHON_FACTORY_CLASS( BRepOutputFactory ); + PYTHON_FACTORY_CLASS( BRepTimeSeriesInputFactory ); } } // namespace geode diff --git a/include/geode/model/representation/io/brep_time_series_input.hpp b/include/geode/model/representation/io/brep_time_series_input.hpp new file mode 100644 index 000000000..3338572b0 --- /dev/null +++ b/include/geode/model/representation/io/brep_time_series_input.hpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2019 - 2026 Geode-solutions + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#pragma once + +#include + +#include +#include + +#include + +namespace geode +{ + class BRep; +} // namespace geode + +namespace geode +{ + /*! + * API function for loading time series onto an existing + * BoundaryRepresentation. + * Each series is stored on the Block meshes (vertex and polyhedron + * attribute managers) as time step attributes (see + * AttributeManager::create_time_step_attribute). + * The adequate loader is called depending on the filename extension. + * @param[in] brep BRep receiving the time series. + * @param[in] filename Path to the file to load. + */ + void opengeode_model_api load_brep_time_series( + BRep& brep, std::string_view filename ); + + class opengeode_model_api BRepTimeSeriesInput : public IOFile + { + public: + [[nodiscard]] virtual AdditionalFiles additional_files() const = 0; + + [[nodiscard]] virtual Percentage is_loadable() const = 0; + + virtual void read( BRep& brep ) = 0; + + protected: + explicit BRepTimeSeriesInput( std::string_view filename ) + : IOFile{ filename } + { + } + }; + + [[nodiscard]] AdditionalFiles opengeode_model_api + brep_time_series_additional_files( std::string_view filename ); + + [[nodiscard]] Percentage opengeode_model_api is_brep_time_series_loadable( + std::string_view filename ); + + using BRepTimeSeriesInputFactory = + Factory< std::string, BRepTimeSeriesInput, std::string_view >; +} // namespace geode diff --git a/src/geode/model/CMakeLists.txt b/src/geode/model/CMakeLists.txt index 2fa21d036..73381542a 100644 --- a/src/geode/model/CMakeLists.txt +++ b/src/geode/model/CMakeLists.txt @@ -96,6 +96,7 @@ add_geode_library( "representation/core/brep.cpp" "representation/core/section.cpp" "representation/io/brep_input.cpp" + "representation/io/brep_time_series_input.cpp" "representation/io/section_input.cpp" "representation/io/brep_output.cpp" "representation/io/section_output.cpp" @@ -171,6 +172,7 @@ add_geode_library( "representation/core/section.hpp" "representation/core/mapping.hpp" "representation/io/brep_input.hpp" + "representation/io/brep_time_series_input.hpp" "representation/io/section_input.hpp" "representation/io/brep_output.hpp" "representation/io/section_output.hpp" diff --git a/src/geode/model/representation/io/brep_time_series_input.cpp b/src/geode/model/representation/io/brep_time_series_input.cpp new file mode 100644 index 000000000..d66b0a151 --- /dev/null +++ b/src/geode/model/representation/io/brep_time_series_input.cpp @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2019 - 2026 Geode-solutions + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + + +#include + +#include + +#include + +#include +#include +#include +#include +#include + +#include + +#include +#include + +namespace +{ + void add_time_series( const geode::AttributeManager& manager, + absl::flat_hash_set< std::string >& names, + absl::flat_hash_set< double >& times ) + { + for( auto& name : manager.time_series_names() ) + { + for( const auto& step : manager.time_steps( name ) ) + { + times.insert( step.time ); + } + names.insert( std::move( name ) ); + } + } + + void log_time_series( const geode::BRep& brep ) + { + absl::flat_hash_set< std::string > names; + absl::flat_hash_set< double > times; + for( const auto& block : brep.blocks() ) + { + const auto& mesh = block.mesh(); + add_time_series( mesh.vertex_attribute_manager(), names, times ); + add_time_series( + mesh.polyhedron_attribute_manager(), names, times ); + } + geode::Logger::info( "BRep has: ", names.size(), " time series, ", + times.size(), " time steps" ); + } +} // namespace + +namespace geode +{ + void load_brep_time_series( BRep& brep, std::string_view filename ) + { + constexpr auto TYPE = "BRep time series"; + try + { + const Timer timer; + auto input = detail::geode_object_input_reader< + BRepTimeSeriesInputFactory >( filename ); + input->read( brep ); + Logger::info( + TYPE, " loaded from ", filename, " in ", timer.duration() ); + log_time_series( brep ); + } + catch( const OpenGeodeException& e ) + { + Logger::error( e.what() ); + print_available_extensions< BRepTimeSeriesInputFactory >( TYPE ); + throw OpenGeodeModelException{ nullptr, + OpenGeodeException::TYPE::data, + "Cannot load BRep time series from file: ", filename }; + } + } + + AdditionalFiles brep_time_series_additional_files( + std::string_view filename ) + { + const auto input = + detail::geode_object_input_reader< BRepTimeSeriesInputFactory >( + filename ); + return input->additional_files(); + } + + Percentage is_brep_time_series_loadable( std::string_view filename ) + { + try + { + const auto input = + detail::geode_object_input_reader< BRepTimeSeriesInputFactory >( + filename ); + return input->is_loadable(); + } + catch( ... ) + { + return Percentage{ 0 }; + } + } +} // namespace geode From d1b93fa3f92cfb884e9ed9e58a4d547988cd028f Mon Sep 17 00:00:00 2001 From: BenPinet <126688250+BenPinet@users.noreply.github.com> Date: Tue, 6 Oct 2026 12:26:30 +0000 Subject: [PATCH 2/2] Apply prepare changes --- bindings/python/src/model/representation/io/brep.cpp | 4 ++-- .../model/representation/io/brep_time_series_input.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bindings/python/src/model/representation/io/brep.cpp b/bindings/python/src/model/representation/io/brep.cpp index cfcf23f55..afc8862dc 100644 --- a/bindings/python/src/model/representation/io/brep.cpp +++ b/bindings/python/src/model/representation/io/brep.cpp @@ -40,8 +40,8 @@ namespace geode module.def( "is_brep_saveable", &is_brep_saveable ); module.def( "brep_additional_files", &brep_additional_files ); module.def( "load_brep_time_series", &load_brep_time_series ); - module.def( "is_brep_time_series_loadable", - &is_brep_time_series_loadable ); + module.def( + "is_brep_time_series_loadable", &is_brep_time_series_loadable ); module.def( "brep_time_series_additional_files", &brep_time_series_additional_files ); PYTHON_FACTORY_CLASS( BRepInputFactory ); diff --git a/src/geode/model/representation/io/brep_time_series_input.cpp b/src/geode/model/representation/io/brep_time_series_input.cpp index d66b0a151..713711cf1 100644 --- a/src/geode/model/representation/io/brep_time_series_input.cpp +++ b/src/geode/model/representation/io/brep_time_series_input.cpp @@ -21,7 +21,6 @@ * */ - #include #include @@ -79,8 +78,9 @@ namespace geode try { const Timer timer; - auto input = detail::geode_object_input_reader< - BRepTimeSeriesInputFactory >( filename ); + auto input = + detail::geode_object_input_reader< BRepTimeSeriesInputFactory >( + filename ); input->read( brep ); Logger::info( TYPE, " loaded from ", filename, " in ", timer.duration() );