Skip to content
Open
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
98 changes: 60 additions & 38 deletions src/geode/mesh/core/surface_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,44 @@
"edge" );
}

template < geode::index_t dimension >
bool not_same_orientation( const geode::SurfaceMesh< dimension >& mesh,
const geode::PolygonEdge& current_edge,

Check warning on line 112 in src/geode/mesh/core/surface_mesh.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/mesh/core/surface_mesh.cpp:112:9 [bugprone-easily-swappable-parameters]

2 adjacent parameters of 'not_same_orientation' of similar type ('const geode::PolygonEdge &') are easily swapped by mistake
const geode::PolygonEdge& adj_edge )
{
const auto cur_v0 = mesh.polygon_edge_vertex( current_edge, 0 );
const auto cur_v1 = mesh.polygon_edge_vertex( current_edge, 1 );
const auto adj_v0 = mesh.polygon_edge_vertex( adj_edge, 0 );
const auto adj_v1 = mesh.polygon_edge_vertex( adj_edge, 1 );
return cur_v0 == adj_v0 && cur_v1 == adj_v1;
}

template < geode::index_t dimension >
std::optional< geode::PolygonVertex > next_polygon_vertex_around(
const geode::SurfaceMesh< dimension >& mesh,
const geode::PolygonVertex& cur_polygon_vertex,
bool& vertex_is_next )
{
const auto exit_vertex =
vertex_is_next ? cur_polygon_vertex
: mesh.previous_polygon_vertex( cur_polygon_vertex );
const geode::PolygonEdge exit_edge{ exit_vertex };
const auto adj_edge = mesh.polygon_adjacent_edge( exit_edge );
if( !adj_edge )
{
return std::nullopt;
}
if( not_same_orientation( mesh, exit_edge, adj_edge.value() ) )
{
vertex_is_next = !vertex_is_next;
}
return vertex_is_next ? geode::PolygonVertex{ mesh.next_polygon_vertex(
geode::PolygonVertex{ adj_edge.value() } ) }
: geode::PolygonVertex{ adj_edge.value() };
}

template < geode::index_t dimension >
geode::internal::PolygonsAroundVertexImpl compute_polygons_around_vertex(

Check warning on line 147 in src/geode/mesh/core/surface_mesh.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/mesh/core/surface_mesh.cpp:147:47 [readability-function-cognitive-complexity]

function 'compute_polygons_around_vertex' has cognitive complexity of 11 (threshold 10)
const geode::SurfaceMesh< dimension >& mesh,
const geode::index_t& vertex_id,
const std::optional< geode::PolygonVertex >& first_polygon )
Expand All @@ -125,7 +161,8 @@
constexpr geode::index_t MAX_SAFETY_COUNT{ 1000 };
geode::internal::PolygonsAroundVertexImpl result;
auto cur_polygon_vertex = first_polygon;
bool vertex_is_next{ false };
do

Check warning on line 165 in src/geode/mesh/core/surface_mesh.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/mesh/core/surface_mesh.cpp:165:9 [cppcoreguidelines-avoid-do-while]

avoid do-while loops
{
OPENGEODE_ASSERT(
mesh.polygon_vertex( cur_polygon_vertex.value() ) == vertex_id,
Expand All @@ -134,18 +171,11 @@
vertex_id, " / ", cur_polygon_vertex->string(), " ",
mesh.polygon_vertex( cur_polygon_vertex.value() ) );
result.polygons.push_back( cur_polygon_vertex.value() );
const auto prev_vertex =
mesh.previous_polygon_vertex( cur_polygon_vertex.value() );
auto adj_edge =
mesh.polygon_adjacent_edge( geode::PolygonEdge{ prev_vertex } );
safety_count++;
if( adj_edge )
{
cur_polygon_vertex = geode::PolygonVertex{ adj_edge.value() };
}
else
cur_polygon_vertex = next_polygon_vertex_around(
mesh, cur_polygon_vertex.value(), vertex_is_next );
if( !cur_polygon_vertex )
{
cur_polygon_vertex = std::nullopt;
break;
}
} while( cur_polygon_vertex != first_polygon
Expand All @@ -154,35 +184,27 @@
result.vertex_is_on_border = cur_polygon_vertex != first_polygon;
if( result.vertex_is_on_border )
{
auto adj_edge = mesh.polygon_adjacent_edge(
geode::PolygonEdge{ first_polygon.value() } );
if( adj_edge )
{
cur_polygon_vertex = geode::PolygonVertex{ adj_edge.value() };
}
else
{
cur_polygon_vertex = std::nullopt;
}
while( cur_polygon_vertex && safety_count < MAX_SAFETY_COUNT )
vertex_is_next = true;
cur_polygon_vertex = next_polygon_vertex_around(
mesh, first_polygon.value(), vertex_is_next );
}
else
{
cur_polygon_vertex = std::nullopt;
}
while( cur_polygon_vertex && safety_count < MAX_SAFETY_COUNT )
{
OPENGEODE_ASSERT(
mesh.polygon_vertex( cur_polygon_vertex.value() ) == vertex_id,
"[SurfaceMesh::polygons_around_vertex] Wrong polygon "
"around vertex" );
result.polygons.push_back( cur_polygon_vertex.value() );
safety_count++;
cur_polygon_vertex = next_polygon_vertex_around(
mesh, cur_polygon_vertex.value(), vertex_is_next );
if( !cur_polygon_vertex )
{
const geode::PolygonVertex next_vertex{ mesh.next_polygon_edge(
geode::PolygonEdge{ cur_polygon_vertex.value() } ) };
OPENGEODE_ASSERT(
mesh.polygon_vertex( next_vertex ) == vertex_id,
"[SurfaceMesh::polygons_around_vertex] Wrong polygon "
"around vertex" );
result.polygons.push_back( next_vertex );
safety_count++;
adj_edge = mesh.polygon_adjacent_edge(
geode::PolygonEdge{ next_vertex } );
if( adj_edge )
{
cur_polygon_vertex =
geode::PolygonVertex{ adj_edge.value() };
continue;
}
cur_polygon_vertex = std::nullopt;
break;
}
}
OPENGEODE_EXCEPTION( safety_count < MAX_SAFETY_COUNT,
Expand Down Expand Up @@ -215,13 +237,13 @@
{
archive.ext(
*this, Growable< Archive, PolygonVertex >{
{ []( Archive& a, PolygonVertex& polygon_vertex ) {

Check warning on line 240 in src/geode/mesh/core/surface_mesh.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/mesh/core/surface_mesh.cpp:240:39 [readability-identifier-length]

parameter name 'a' is too short, expected at least 3 characters
a.value4b( polygon_vertex.polygon_id );
index_t value{ NO_ID };
a.value4b( value );
polygon_vertex.vertex_id = value;
},
[]( Archive& a, PolygonVertex& polygon_vertex ) {

Check warning on line 246 in src/geode/mesh/core/surface_mesh.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/mesh/core/surface_mesh.cpp:246:41 [readability-identifier-length]

parameter name 'a' is too short, expected at least 3 characters
a.value4b( polygon_vertex.polygon_id );
a.value1b( polygon_vertex.vertex_id );
} } } );
Expand All @@ -232,13 +254,13 @@
{
archive.ext(
*this, Growable< Archive, PolygonEdge >{
{ []( Archive& a, PolygonEdge& polygon_edge ) {

Check warning on line 257 in src/geode/mesh/core/surface_mesh.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/mesh/core/surface_mesh.cpp:257:39 [readability-identifier-length]

parameter name 'a' is too short, expected at least 3 characters
a.value4b( polygon_edge.polygon_id );
index_t value{ NO_ID };
a.value4b( value );
polygon_edge.edge_id = value;
},
[]( Archive& a, PolygonEdge& polygon_edge ) {

Check warning on line 263 in src/geode/mesh/core/surface_mesh.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/mesh/core/surface_mesh.cpp:263:41 [readability-identifier-length]

parameter name 'a' is too short, expected at least 3 characters
a.value4b( polygon_edge.polygon_id );
a.value1b( polygon_edge.edge_id );
} } } );
Expand All @@ -254,7 +276,7 @@
"polygons_around_vertex";

public:
Impl( SurfaceMesh& surface )

Check warning on line 279 in src/geode/mesh/core/surface_mesh.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/mesh/core/surface_mesh.cpp:279:9 [google-explicit-constructor]

single-argument constructors must be marked explicit to avoid unintentional implicit conversions
: polygon_around_vertex_( surface.vertex_attribute_manager()
.template find_or_create_attribute< VariableAttribute,
PolygonVertex >( "polygon_around_vertex",
Expand Down Expand Up @@ -415,7 +437,7 @@
{
archive.ext( *this,
Growable< Archive, Impl >{
{ []( Archive& a, Impl& impl ) {

Check warning on line 440 in src/geode/mesh/core/surface_mesh.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/mesh/core/surface_mesh.cpp:440:36 [readability-identifier-length]

parameter name 'a' is too short, expected at least 3 characters
a.object( impl.polygon_attribute_manager_ );
a.ext( impl.polygon_around_vertex_,
bitsery::ext::StdSmartPtr{} );
Expand All @@ -435,7 +457,7 @@
.interpolable,
false } );
},
[]( Archive& a, Impl& impl ) {

Check warning on line 460 in src/geode/mesh/core/surface_mesh.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/mesh/core/surface_mesh.cpp:460:38 [readability-identifier-length]

parameter name 'a' is too short, expected at least 3 characters
a.object( impl.polygon_attribute_manager_ );
a.ext( impl.polygon_around_vertex_,
bitsery::ext::StdSmartPtr{} );
Expand Down
11 changes: 10 additions & 1 deletion src/geode/mesh/helpers/detail/surface_merger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <absl/container/flat_hash_set.h>

#include <geode/basic/algorithm.hpp>
#include <geode/basic/logger.hpp>
#include <geode/basic/pimpl_impl.hpp>

#include <geode/mesh/builder/surface_mesh_builder.hpp>
Expand Down Expand Up @@ -131,7 +132,15 @@ namespace geode
void clean_surface( SurfaceMeshMerger< dimension >& merger )
{
separate_surfaces( merger );
repair_polygon_orientations( merger.mesh(), merger.builder() );
try
{
repair_polygon_orientations(
merger.mesh(), merger.builder() );
}
catch( const OpenGeodeException& e )
{
Logger::warn( e.what() );
}
}

void create_polygons( SurfaceMeshMerger< dimension >& merger )
Expand Down
7 changes: 7 additions & 0 deletions src/geode/mesh/helpers/repair_polygon_orientations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ namespace
}
return get_bad_oriented_polygons();
}
catch( geode::OpenGeodeDataException& e )
{
const auto msg = absl::StrCat( "Surface ",
mesh_.name().value_or( mesh_.id().string() ), ": ",
e.what() );
throw geode::OpenGeodeDataException( msg );
}
catch( geode::OpenGeodeException& e )
{
const auto msg = absl::StrCat( "Surface ",
Expand Down
Binary file added tests/data/moebius_strip.og_tsf3d
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/mesh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,9 @@ add_geode_test(
${PROJECT_NAME}::geometry
${PROJECT_NAME}::mesh
)
add_geode_test(
SOURCE "test-moebius-strip.cpp"
DEPENDENCIES
${PROJECT_NAME}::basic
${PROJECT_NAME}::mesh
)
105 changes: 105 additions & 0 deletions tests/mesh/test-moebius-strip.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* 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/tests/common.hpp>

#include <geode/basic/assert.hpp>
#include <geode/basic/logger.hpp>

#include <geode/mesh/core/surface_mesh.hpp>
#include <geode/mesh/core/triangulated_surface.hpp>
#include <geode/mesh/io/triangulated_surface_input.hpp>

void test_polygons_around_vertex()
{
const auto moebius_strip = geode::load_triangulated_surface< 3 >(
absl::StrCat( geode::DATA_PATH, "moebius_strip.og_tsf3d" ) );

const geode::index_t vertex_id_0{ 0 };
const auto polygons_around_0 =
moebius_strip->polygons_around_vertex( vertex_id_0 );
OPENGEODE_EXCEPTION( polygons_around_0.size() == 2,
"[Test] Wrong computation of polygons around vertex 0 : should be 2 "
"polygons, get ",
polygons_around_0.size() );
OPENGEODE_EXCEPTION( polygons_around_0[0].polygon_id == 159
&& polygons_around_0[0].vertex_id == 2,
"[TEST] Wrong polygons around vertex 0" );
OPENGEODE_EXCEPTION( polygons_around_0[1].polygon_id == 0
&& polygons_around_0[1].vertex_id == 0,
"[TEST] Wrong polygons around vertex 0" );

const geode::index_t vertex_id_1{ 1 };
const auto polygons_around_1 =
moebius_strip->polygons_around_vertex( vertex_id_1 );
OPENGEODE_EXCEPTION( polygons_around_1.size() == 6,
"[Test] Wrong computation of polygons around vertex 1 : should be 6 "
"polygons, get ",
polygons_around_1.size() );
OPENGEODE_EXCEPTION( polygons_around_1[0].polygon_id == 159
&& polygons_around_1[0].vertex_id == 1,
"[TEST] Wrong polygons around vertex 1" );
OPENGEODE_EXCEPTION( polygons_around_1[1].polygon_id == 158
&& polygons_around_1[1].vertex_id == 1,
"[TEST] Wrong polygons around vertex 1" );
OPENGEODE_EXCEPTION( polygons_around_1[2].polygon_id == 157
&& polygons_around_1[2].vertex_id == 2,
"[TEST] Wrong polygons around vertex 1" );
OPENGEODE_EXCEPTION( polygons_around_1[3].polygon_id == 2
&& polygons_around_1[3].vertex_id == 0,
"[TEST] Wrong polygons around vertex 1" );
OPENGEODE_EXCEPTION( polygons_around_1[4].polygon_id == 1
&& polygons_around_1[4].vertex_id == 0,
"[TEST] Wrong polygons around vertex 1" );
OPENGEODE_EXCEPTION( polygons_around_1[5].polygon_id == 0
&& polygons_around_1[5].vertex_id == 2,
"[TEST] Wrong polygons around vertex 1" );

const geode::index_t vertex_id_99{ 99 };
const auto polygons_around_99 =
moebius_strip->polygons_around_vertex( vertex_id_99 );
OPENGEODE_EXCEPTION( polygons_around_99.size() == 4,
"[Test] Wrong computation of polygons around vertex 99 : should be 4 "
"polygons, get ",
polygons_around_99.size() );
OPENGEODE_EXCEPTION( polygons_around_99[0].polygon_id == 153
&& polygons_around_99[0].vertex_id == 1,
"[TEST] Wrong polygons around vertex 99" );
OPENGEODE_EXCEPTION( polygons_around_99[1].polygon_id == 152
&& polygons_around_99[1].vertex_id == 1,
"[TEST] Wrong polygons around vertex 99" );
OPENGEODE_EXCEPTION( polygons_around_99[2].polygon_id == 6
&& polygons_around_99[2].vertex_id == 2,
"[TEST] Wrong polygons around vertex 99" );
OPENGEODE_EXCEPTION( polygons_around_99[3].polygon_id == 7
&& polygons_around_99[3].vertex_id == 0,
"[TEST] Wrong polygons around vertex 99" );
}

void test()
{
geode::OpenGeodeMeshLibrary::initialize();
geode::Logger::set_level( geode::Logger::LEVEL::info );
test_polygons_around_vertex();
}

OPENGEODE_TEST( "moebius-strip" )
Loading