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
13 changes: 13 additions & 0 deletions include/geode/basic/assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ namespace geode
using OpenGeodeException::OpenGeodeException;
};

class OpenGeodeResultException : public OpenGeodeException
{
public:
using OpenGeodeException::OpenGeodeException;
};

void opengeode_basic_api geode_assertion_failed( std::string_view condition,
std::string_view message,
std::string_view file,
Expand Down Expand Up @@ -144,5 +150,12 @@ namespace geode
__VA_ARGS__ \
}

#define OPENGEODE_RESULT_EXCEPTION( condition, ... ) \
if( ABSL_PREDICT_FALSE( !( condition ) ) ) \
throw geode::OpenGeodeResultException \
{ \
__VA_ARGS__ \
}

#define OPENGEODE_RESEARCH( condition, ... ) \
OPENGEODE_EXCEPTION( condition, __VA_ARGS__ )
41 changes: 41 additions & 0 deletions include/geode/model/helpers/detail/surface_mesh_validity_fix.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2019 - 2025 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 <geode/model/common.hpp>

namespace geode
{
FORWARD_DECLARATION_DIMENSION_CLASS( Surface );
} // namespace geode

namespace geode
{
namespace detail
{
template < typename Model >
void repair_non_manifold_vertices(
Model& model, const Surface< Model::dim >& surface );
} // namespace detail
} // namespace geode
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#pragma once

#include <async++.h>

#include <geode/model/representation/builder/detail/filter.hpp>
#include <geode/model/representation/builder/detail/register.hpp>
#include <geode/model/representation/builder/section_builder.hpp>
Expand Down
5 changes: 5 additions & 0 deletions src/geode/basic/assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ namespace geode
Logger::critical( "OpenGeodeDataException: ", exception.what(),
"\n", exception.stack_trace() );
}
catch( const OpenGeodeResultException& exception )
{
Logger::critical( "OpenGeodeResultException: ", exception.what(),
"\n", exception.stack_trace() );
}
catch( const OpenGeodeException& exception )
{
Logger::critical( "OpenGeodeException: ", exception.what(), "\n",
Expand Down
7 changes: 2 additions & 5 deletions src/geode/geometry/basic_objects/segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,9 @@ namespace geode
GenericSegment< PointType, dimension >::direction() const
{
Vector< dimension > direction{ vertices_[0], vertices_[1] };
if( direction.length() < GLOBAL_EPSILON )
{
DEBUG( direction.length() );
}
OPENGEODE_EXCEPTION( direction.length() > GLOBAL_EPSILON,
"[Segment::direction] Segment length too small" );
"[Segment::direction] Segment length too small (",
direction.length(), ")" );
return direction;
}
template < typename PointType, index_t dimension >
Expand Down
2 changes: 2 additions & 0 deletions src/geode/model/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ add_geode_library(
"helpers/detail/mappings_merger.cpp"
"helpers/detail/split_along_surface_mesh_borders.cpp"
"helpers/detail/split_along_block_mesh_borders.cpp"
"helpers/detail/surface_mesh_validity_fix.cpp"
"mixin/builder/blocks_builder.cpp"
"mixin/builder/block_collections_builder.cpp"
"mixin/builder/component_registry_builder.cpp"
Expand Down Expand Up @@ -172,6 +173,7 @@ add_geode_library(
"helpers/detail/mappings_merger.hpp"
"helpers/detail/split_along_surface_mesh_borders.hpp"
"helpers/detail/split_along_block_mesh_borders.hpp"
"helpers/detail/surface_mesh_validity_fix.hpp"
"mixin/core/detail/components_storage.hpp"
"mixin/core/detail/count_relationships.hpp"
"mixin/core/detail/mesh_storage.hpp"
Expand Down
115 changes: 115 additions & 0 deletions src/geode/model/helpers/detail/surface_mesh_validity_fix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright (c) 2019 - 2025 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/helpers/detail/surface_mesh_validity_fix.hpp>

#include <absl/container/flat_hash_map.h>

#include <geode/basic/uuid.hpp>

#include <geode/geometry/point.hpp>

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

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

namespace geode
{
namespace detail
{
template < typename Model >
void repair_non_manifold_vertices(
Model& model, const Surface< Model::dim >& surface )
{
const auto& mesh = surface.mesh();
typename Model::Builder model_builder{ model };
auto mesh_builder =
model_builder.surface_mesh_builder( surface.id() );
absl::FixedArray< PolygonsAroundVertex > polygons_around_vertices(
mesh.nb_vertices() );
for( const auto p : Range{ mesh.nb_polygons() } )
{
for( const auto v : LRange{ mesh.nb_polygon_vertices( p ) } )
{
polygons_around_vertices[mesh.polygon_vertex( { p, v } )]
.emplace_back( p, v );
}
}
absl::flat_hash_map< index_t, std::vector< index_t > > mappings;
for( const auto v : Range{ mesh.nb_vertices() } )
{
auto polygons_around = mesh.polygons_around_vertex( v );
const auto& polygon_vertices = polygons_around_vertices[v];
auto nb_polygons_around = polygons_around.size();
if( nb_polygons_around == polygon_vertices.size() )
{
continue;
}
std::vector< index_t > new_values;
PolygonsAroundVertex total_polygons;
while( nb_polygons_around != polygon_vertices.size() )
{
for( auto&& polygon : polygons_around )
{
total_polygons.emplace_back( std::move( polygon ) );
}
const auto new_vertex_id =
mesh_builder->create_point( mesh.point( v ) );
mesh_builder->replace_vertex( v, new_vertex_id );
for( const auto& polygon_vertex : polygon_vertices )
{
if( absl::c_find( total_polygons, polygon_vertex )
== total_polygons.end() )
{
mesh_builder->associate_polygon_vertex_to_vertex(
polygon_vertex, v );
break;
}
}
new_values.push_back( new_vertex_id );
polygons_around = mesh.polygons_around_vertex( v );
nb_polygons_around += polygons_around.size();
}
mappings.try_emplace( v, std::move( new_values ) );
}
for( const auto& [old_vertex, new_vertices] : mappings )
{
const auto unique_vertex = model.unique_vertex(
{ surface.component_id(), old_vertex } );
for( const auto new_vertex : new_vertices )
{
model_builder.set_unique_vertex(
{ surface.component_id(), new_vertex }, unique_vertex );
}
}
}

template void opengeode_model_api
repair_non_manifold_vertices< Section >(
Section&, const Surface2D& );
template void opengeode_model_api repair_non_manifold_vertices< BRep >(
BRep&, const Surface3D& );
} // namespace detail
} // namespace geode
9 changes: 9 additions & 0 deletions tests/basic/test-assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ void test_exception()
{
geode::geode_lippincott();
}

try
{
throw geode::OpenGeodeResultException{ "Bad ", "result" };
}
catch( ... )
{
geode::geode_lippincott();
}
}

void test()
Expand Down