Skip to content

Commit d724d46

Browse files
authored
Merge pull request #157 from Geode-solutions/fix/externalize_functions_to_compute_expected_nb_cmvs
fix(BlocksTopology): Externalized function to compute the expected nu…
2 parents ad975af + 277dca3 commit d724d46

File tree

4 files changed

+310
-168
lines changed

4 files changed

+310
-168
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2019 - 2025 Geode-solutions
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*
22+
*/
23+
24+
#pragma once
25+
26+
#include <optional>
27+
28+
#include <geode/model/mixin/core/vertex_identifier.hpp>
29+
30+
#include <geode/inspector/common.hpp>
31+
32+
namespace geode
33+
{
34+
class BRep;
35+
} // namespace geode
36+
37+
namespace geode
38+
{
39+
namespace internal
40+
{
41+
struct VertexCMVsByComponent
42+
{
43+
std::vector< ComponentMeshVertex > block_cmvs;
44+
std::vector< ComponentMeshVertex > surface_cmvs;
45+
std::vector< ComponentMeshVertex > line_cmvs;
46+
std::vector< ComponentMeshVertex > corner_cmvs;
47+
};
48+
49+
VertexCMVsByComponent vertex_cmvs_by_component(
50+
const BRep& brep, index_t unique_vertex_id );
51+
52+
index_t nb_expected_block_cmvs( const BRep& brep,
53+
index_t unique_vertex_id,
54+
const geode::uuid& block_uuid,
55+
const VertexCMVsByComponent& unique_vertex_cmvs );
56+
57+
std::optional< std::string > wrong_nb_expected_block_cmvs(
58+
const BRep& brep,
59+
index_t unique_vertex_id,
60+
const geode::uuid& block_uuid,
61+
const VertexCMVsByComponent& unique_vertex_cmvs );
62+
} // namespace internal
63+
} // namespace geode

src/geode/inspector/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ add_geode_library(
6868
"topology/section_corners_topology.cpp"
6969
"topology/section_lines_topology.cpp"
7070
"topology/section_surfaces_topology.cpp"
71+
"topology/internal/expected_nb_cmvs.cpp"
7172
"topology/internal/topology_helpers.cpp"
7273
"section_inspector.cpp"
7374
"brep_inspector.cpp"
@@ -131,6 +132,7 @@ add_geode_library(
131132
"topology/section_corners_topology.hpp"
132133
"topology/section_lines_topology.hpp"
133134
"topology/section_surfaces_topology.hpp"
135+
"topology/internal/expected_nb_cmvs.hpp"
134136
"topology/internal/topology_helpers.hpp"
135137
PUBLIC_DEPENDENCIES
136138
OpenGeode::basic

src/geode/inspector/topology/brep_blocks_topology.cpp

Lines changed: 7 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include <geode/model/mixin/core/surface.hpp>
5151
#include <geode/model/representation/core/brep.hpp>
5252

53+
#include <geode/inspector/topology/internal/expected_nb_cmvs.hpp>
5354
#include <geode/inspector/topology/internal/topology_helpers.hpp>
5455

5556
namespace
@@ -128,22 +129,6 @@ namespace
128129
return false;
129130
}
130131

131-
template < typename Condition >
132-
geode::index_t count_cmvs(
133-
absl::Span< const geode::ComponentMeshVertex > cmvs,
134-
const Condition& condition )
135-
{
136-
geode::index_t counter{ 0 };
137-
for( const auto& cmv : cmvs )
138-
{
139-
if( condition( cmv ) )
140-
{
141-
counter++;
142-
}
143-
}
144-
return counter;
145-
}
146-
147132
void create_graph( const geode::BRep& brep,
148133
geode::GenericMapping< geode::uuid, geode::index_t >&
149134
surface_uuids_to_graph_edges,
@@ -566,8 +551,7 @@ namespace geode
566551
}
567552
return absl::StrCat( "Unique vertex with index ", unique_vertex_index,
568553
" is part of two blocks, but not of a surface boundary to the "
569-
"two "
570-
"blocks, nor of a line boundary to one of the blocks incident "
554+
"two blocks, nor of a line boundary to one of the blocks incident "
571555
"surfaces." );
572556
}
573557

@@ -577,159 +561,14 @@ namespace geode
577561
{
578562
const auto block_uuids = internal::components_uuids(
579563
brep_, unique_vertex_index, Block3D::component_type_static() );
580-
581-
std::vector< ComponentMeshVertex > block_cmvs;
582-
std::vector< ComponentMeshVertex > surface_cmvs;
583-
std::vector< ComponentMeshVertex > line_cmvs;
584-
std::vector< ComponentMeshVertex > corner_cmvs;
585-
for( const auto& cmv :
586-
brep_.component_mesh_vertices( unique_vertex_index ) )
587-
{
588-
if( cmv.component_id.type() == Block3D::component_type_static() )
589-
{
590-
block_cmvs.push_back( cmv );
591-
}
592-
if( cmv.component_id.type() == Surface3D::component_type_static() )
593-
{
594-
surface_cmvs.push_back( cmv );
595-
}
596-
if( cmv.component_id.type() == Line3D::component_type_static() )
597-
{
598-
line_cmvs.push_back( cmv );
599-
}
600-
if( cmv.component_id.type() == Corner3D::component_type_static() )
601-
{
602-
corner_cmvs.push_back( cmv );
603-
}
604-
}
564+
const auto component_cmvs =
565+
internal::vertex_cmvs_by_component( brep_, unique_vertex_index );
605566
for( const auto& block_uuid : block_uuids )
606567
{
607-
const auto nb_block_cmvs =
608-
count_cmvs( block_cmvs, [&block_uuid]( const auto& cmv ) {
609-
return cmv.component_id.id() == block_uuid;
610-
} );
611-
612-
const auto nb_internal_surface_cmvs = count_cmvs(
613-
surface_cmvs, [&block_uuid, this]( const auto& cmv ) {
614-
return this->brep_.is_internal(
615-
brep_.surface( cmv.component_id.id() ),
616-
brep_.block( block_uuid ) );
617-
} );
618-
619-
const auto nb_boundary_surface_cmvs = count_cmvs(
620-
surface_cmvs, [&block_uuid, this]( const auto& cmv ) {
621-
return this->brep_.is_boundary(
622-
brep_.surface( cmv.component_id.id() ),
623-
brep_.block( block_uuid ) );
624-
} );
625-
const auto nb_boundary_line_cmvs =
626-
count_cmvs( line_cmvs, [&block_uuid, this]( const auto& cmv ) {
627-
for( const auto& block_boundary :
628-
this->brep_.boundaries( brep_.block( block_uuid ) ) )
629-
{
630-
for( const auto& surface_boundary :
631-
this->brep_.boundaries( block_boundary ) )
632-
{
633-
if( surface_boundary.id() == cmv.component_id.id() )
634-
{
635-
return true;
636-
}
637-
}
638-
for( const auto& surface_internal :
639-
this->brep_.internal_lines( block_boundary ) )
640-
{
641-
if( surface_internal.id() == cmv.component_id.id() )
642-
{
643-
return true;
644-
}
645-
}
646-
}
647-
return false;
648-
} );
649-
const auto nb_free_line_cmvs =
650-
count_cmvs( line_cmvs, [this]( const auto& cmv ) {
651-
return this->brep_.nb_incidences( cmv.component_id.id() )
652-
== 1
653-
&& this->brep_.nb_embedding_surfaces(
654-
brep_.line( cmv.component_id.id() ) )
655-
== 0;
656-
} );
657-
if( corner_cmvs.size() == 1 && nb_internal_surface_cmvs == 0 )
658-
{
659-
if( nb_boundary_line_cmvs == 1 )
660-
{
661-
if( nb_block_cmvs != 1 )
662-
{
663-
return absl::StrCat( "Unique vertex with index ",
664-
unique_vertex_index, " is part of block ",
665-
block_uuid.string(),
666-
" and exactly one corner and one line but "
667-
"has ",
668-
nb_block_cmvs,
669-
" block component mesh vertices (should be "
670-
"1)." );
671-
}
672-
continue;
673-
}
674-
675-
const auto predicted_nb_block_cmvs = nb_boundary_surface_cmvs
676-
+ corner_cmvs.size()
677-
- nb_boundary_line_cmvs;
678-
if( nb_block_cmvs != predicted_nb_block_cmvs )
679-
{
680-
return absl::StrCat( "Unique vertex with index ",
681-
unique_vertex_index, " is part of the block ",
682-
block_uuid.string(),
683-
", and of a corner, and of no internal line, ",
684-
"and of ", nb_boundary_surface_cmvs,
685-
" boundary surface(s), and of ", nb_boundary_line_cmvs,
686-
" line(s) on block boundaries, with ", nb_block_cmvs,
687-
" block component mesh vertices (should be ",
688-
predicted_nb_block_cmvs, ")." );
689-
}
690-
continue;
691-
}
692-
693-
if( nb_internal_surface_cmvs == 0 )
568+
if( auto error_message = internal::wrong_nb_expected_block_cmvs(
569+
brep_, unique_vertex_index, block_uuid, component_cmvs ) )
694570
{
695-
const auto predicted_nb_block_cmvs =
696-
nb_boundary_line_cmvs == 0 ? 1
697-
: nb_boundary_surface_cmvs / 2;
698-
if( nb_block_cmvs != predicted_nb_block_cmvs )
699-
{
700-
return absl::StrCat( "Unique vertex with index ",
701-
unique_vertex_index, " is part of the block ",
702-
block_uuid.string(),
703-
" and none of its internal surfaces but has ",
704-
nb_block_cmvs,
705-
" block component mesh vertices (should be ",
706-
predicted_nb_block_cmvs, ")." );
707-
}
708-
continue;
709-
}
710-
auto predicted_nb_block_cmvs =
711-
nb_internal_surface_cmvs < nb_free_line_cmvs + 1
712-
? static_cast< index_t >( 1 )
713-
: nb_internal_surface_cmvs - nb_free_line_cmvs;
714-
if( nb_internal_surface_cmvs - nb_free_line_cmvs == 1 )
715-
{
716-
predicted_nb_block_cmvs++;
717-
}
718-
if( nb_boundary_surface_cmvs > 1 && corner_cmvs.empty() )
719-
{
720-
predicted_nb_block_cmvs += ( nb_boundary_surface_cmvs - 2 ) / 2;
721-
}
722-
if( nb_block_cmvs != predicted_nb_block_cmvs )
723-
{
724-
return absl::StrCat( "Unique vertex with index ",
725-
unique_vertex_index, " is part of the block ",
726-
block_uuid.string(), ", has ", nb_internal_surface_cmvs,
727-
" internal surface(s) component mesh vertices (CMVs), "
728-
"has ",
729-
nb_boundary_surface_cmvs,
730-
" boundary surface(s) CMVs, and has ", nb_free_line_cmvs,
731-
" free line(s) CMVs, with ", nb_block_cmvs,
732-
" block CMVs (should be ", predicted_nb_block_cmvs, ")." );
571+
return error_message;
733572
}
734573
}
735574
return std::nullopt;

0 commit comments

Comments
 (0)