Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions bindings/python/src/model/representation/io/brep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
#include <geode/model/representation/core/brep.hpp>
#include <geode/model/representation/io/brep_input.hpp>
#include <geode/model/representation/io/brep_output.hpp>
#include <geode/model/representation/io/brep_time_series_input.hpp>

namespace geode
{
void define_brep_io( pybind11::module& module )

Check warning on line 34 in bindings/python/src/model/representation/io/brep.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

bindings/python/src/model/representation/io/brep.cpp:34:10 [misc-use-internal-linkage]

function 'define_brep_io' can be made static or moved into an anonymous namespace to enforce internal linkage
{
module.def( "save_brep", &save_brep );
module.def( "load_brep", &load_brep );
Expand All @@ -38,7 +39,13 @@
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
77 changes: 77 additions & 0 deletions include/geode/model/representation/io/brep_time_series_input.hpp
Original file line number Diff line number Diff line change
@@ -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 <string_view>

#include <geode/basic/factory.hpp>
#include <geode/basic/input.hpp>

#include <geode/model/common.hpp>

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
2 changes: 2 additions & 0 deletions src/geode/model/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
122 changes: 122 additions & 0 deletions src/geode/model/representation/io/brep_time_series_input.cpp
Original file line number Diff line number Diff line change
@@ -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 <geode/model/representation/io/brep_time_series_input.hpp>

#include <string_view>

#include <absl/container/flat_hash_set.h>

#include <geode/basic/attribute_manager.hpp>
#include <geode/basic/detail/geode_input_impl.hpp>
#include <geode/basic/io.hpp>
#include <geode/basic/logger.hpp>
#include <geode/basic/timer.hpp>

#include <geode/mesh/core/solid_mesh.hpp>

#include <geode/model/mixin/core/block.hpp>
#include <geode/model/representation/core/brep.hpp>

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
Loading