Skip to content

Commit 4f8e54d

Browse files
authored
Merge pull request #924 from Geode-solutions/feat/cut_along_solid_facets
Feat/cut along solid facets
2 parents 4399b8f + 0749021 commit 4f8e54d

File tree

11 files changed

+553
-194
lines changed

11 files changed

+553
-194
lines changed

include/geode/mesh/core/detail/facet_storage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ namespace geode
115115
for( const auto e :
116116
Range{ facet_attribute_manager_.nb_elements() } )
117117
{
118-
to_delete[e] = !counter_->value( e );
118+
to_delete[e] = counter_->value( e ) == 0;
119119
}
120120
return delete_facets( to_delete );
121121
}

include/geode/mesh/core/grid.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,27 @@ namespace geode
170170
IMPLEMENTATION_MEMBER( impl_ );
171171
};
172172
ALIAS_2D_AND_3D( Grid );
173+
174+
namespace detail
175+
{
176+
static constexpr std::array< std::array< geode::local_index_t, 2 >, 12 >
177+
CELL_EDGE_VERTICES_3D{ { { 0, 1 }, { 0, 2 }, { 2, 3 }, { 1, 3 },
178+
{ 4, 5 }, { 4, 6 }, { 6, 7 }, { 5, 7 }, { 0, 4 }, { 1, 5 },
179+
{ 2, 6 }, { 3, 7 } } };
180+
181+
static constexpr std::array< std::array< geode::local_index_t, 4 >, 6 >
182+
CELL_FACET_VERTICES_3D{ { { 0, 4, 6, 2 }, { 1, 5, 7, 3 },
183+
{ 0, 4, 5, 1 }, { 2, 3, 7, 6 }, { 0, 1, 3, 2 },
184+
{ 4, 6, 7, 5 } } };
185+
186+
static constexpr std::array< std::array< geode::local_index_t, 3 >, 8 >
187+
CELL_EDGES_AROUND_VERTEX_3D{ { { 0, 1, 8 }, { 0, 3, 9 },
188+
{ 1, 2, 10 }, { 2, 3, 11 }, { 4, 5, 8 }, { 4, 7, 9 },
189+
{ 5, 6, 10 }, { 6, 7, 11 } } };
190+
191+
static constexpr std::array< std::array< geode::local_index_t, 3 >, 8 >
192+
CELL_FACETS_AROUND_VERTEX_3D{ { { 0, 2, 4 }, { 1, 2, 4 },
193+
{ 0, 3, 4 }, { 1, 3, 4 }, { 0, 2, 5 }, { 1, 2, 5 }, { 0, 3, 5 },
194+
{ 1, 3, 5 } } };
195+
} // namespace detail
173196
} // namespace geode
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2019 - 2024 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 <geode/basic/mapping.h>
27+
28+
#include <geode/mesh/common.h>
29+
30+
namespace geode
31+
{
32+
using ElementsMapping = GenericMapping< index_t, index_t >;
33+
34+
struct MeshesElementsMapping
35+
{
36+
ElementsMapping vertices;
37+
ElementsMapping edges;
38+
ElementsMapping polygons;
39+
ElementsMapping polyhedra;
40+
};
41+
} // namespace geode
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2019 - 2024 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 <absl/types/span.h>
27+
28+
#include <geode/basic/pimpl.h>
29+
30+
#include <geode/mesh/common.h>
31+
#include <geode/mesh/core/meshes_mapping.h>
32+
33+
namespace geode
34+
{
35+
FORWARD_DECLARATION_DIMENSION_CLASS( SolidMesh );
36+
FORWARD_DECLARATION_DIMENSION_CLASS( SolidMeshBuilder );
37+
ALIAS_3D( SolidMesh );
38+
ALIAS_3D( SolidMeshBuilder );
39+
} // namespace geode
40+
41+
namespace geode
42+
{
43+
namespace detail
44+
{
45+
class opengeode_mesh_api CutAlongSolidFacets
46+
{
47+
public:
48+
CutAlongSolidFacets(
49+
const SolidMesh3D& mesh, SolidMeshBuilder3D& builder );
50+
~CutAlongSolidFacets();
51+
52+
/*
53+
* Cuts the solid along given facets, and returns the mapping on
54+
* vertices and facets.
55+
*/
56+
MeshesElementsMapping cut_solid_along_facets(
57+
absl::Span< const PolyhedronFacet > facets_list );
58+
59+
private:
60+
IMPLEMENTATION_MEMBER( impl_ );
61+
};
62+
} // namespace detail
63+
} // namespace geode

include/geode/model/helpers/detail/cut_along_internal_surfaces.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ namespace geode
4343
class opengeode_model_api CutAlongInternalSurfaces
4444
{
4545
public:
46-
CutAlongInternalSurfaces( BRep& model );
4746
CutAlongInternalSurfaces( const BRep& model, BRepBuilder& builder );
4847
~CutAlongInternalSurfaces();
4948

src/geode/mesh/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ add_geode_library(
117117
"helpers/detail/component_identifier.cpp"
118118
"helpers/detail/create_mesh.cpp"
119119
"helpers/detail/curve_merger.cpp"
120+
"helpers/detail/cut_along_solid_facets.cpp"
120121
"helpers/detail/debug.cpp"
121122
"helpers/detail/element_identifier.cpp"
122123
"helpers/detail/solid_merger.cpp"
@@ -298,6 +299,7 @@ add_geode_library(
298299
"core/detail/geode_elements.h"
299300
"core/detail/vertex_cycle.h"
300301
"helpers/detail/curve_merger.h"
302+
"helpers/detail/cut_along_solid_facets.h"
301303
"helpers/detail/component_identifier.h"
302304
"helpers/detail/create_mesh.h"
303305
"helpers/detail/debug.h"

src/geode/mesh/builder/solid_mesh_builder.cpp

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -293,49 +293,49 @@ namespace
293293
}
294294
const auto position_it =
295295
absl::c_find( facet_vertices, polyhedron_vertex );
296-
if( position_it != facet_vertices.end() )
296+
if( position_it == facet_vertices.end() )
297297
{
298-
geode::PolyhedronFacetVertices facet_vertices_id;
299-
facet_vertices_id.reserve( nb_facet_vertices );
300-
for( const auto& v : facet_vertices )
301-
{
302-
facet_vertices_id.emplace_back(
303-
solid.polyhedron_vertex( v ) );
304-
}
298+
continue;
299+
}
300+
geode::PolyhedronFacetVertices facet_vertices_id;
301+
facet_vertices_id.reserve( nb_facet_vertices );
302+
for( const auto& v : facet_vertices )
303+
{
304+
facet_vertices_id.emplace_back( solid.polyhedron_vertex( v ) );
305+
}
305306

306-
const auto position = static_cast< geode::index_t >(
307-
std::distance( facet_vertices.begin(), position_it ) );
307+
const auto position = static_cast< geode::index_t >(
308+
std::distance( facet_vertices.begin(), position_it ) );
308309

309-
if( solid.are_facets_enabled() )
310+
if( solid.are_facets_enabled() )
311+
{
312+
auto facets = builder.facets_builder();
313+
facets.update_facet_vertex(
314+
facet_vertices_id, position, new_vertex_id );
315+
}
316+
317+
if( solid.are_edges_enabled() )
318+
{
319+
auto edges = builder.edges_builder();
320+
const auto next =
321+
position + 1 == nb_facet_vertices ? 0 : position + 1;
322+
std::array< geode::index_t, 2 > next_edge_vertices{
323+
facet_vertices_id[position], facet_vertices_id[next]
324+
};
325+
if( next_edge_vertices[0] < next_edge_vertices[1] )
310326
{
311-
auto facets = builder.facets_builder();
312-
facets.update_facet_vertex(
313-
facet_vertices_id, position, new_vertex_id );
327+
edges.update_edge_vertex(
328+
next_edge_vertices, 0, new_vertex_id );
314329
}
315-
316-
if( solid.are_edges_enabled() )
330+
const auto prev =
331+
position == 0 ? nb_facet_vertices - 1 : position - 1;
332+
std::array< geode::index_t, 2 > previous_edge_vertices{
333+
facet_vertices_id[prev], facet_vertices_id[position]
334+
};
335+
if( previous_edge_vertices[0] < previous_edge_vertices[1] )
317336
{
318-
auto edges = builder.edges_builder();
319-
const auto next =
320-
position + 1 == nb_facet_vertices ? 0 : position + 1;
321-
std::array< geode::index_t, 2 > next_edge_vertices{
322-
facet_vertices_id[position], facet_vertices_id[next]
323-
};
324-
if( next_edge_vertices[0] < next_edge_vertices[1] )
325-
{
326-
edges.update_edge_vertex(
327-
next_edge_vertices, 0, new_vertex_id );
328-
}
329-
const auto prev =
330-
position == 0 ? nb_facet_vertices - 1 : position - 1;
331-
std::array< geode::index_t, 2 > previous_edge_vertices{
332-
facet_vertices_id[prev], facet_vertices_id[position]
333-
};
334-
if( previous_edge_vertices[0] < previous_edge_vertices[1] )
335-
{
336-
edges.update_edge_vertex(
337-
previous_edge_vertices, 1, new_vertex_id );
338-
}
337+
edges.update_edge_vertex(
338+
previous_edge_vertices, 1, new_vertex_id );
339339
}
340340
}
341341
}

src/geode/mesh/core/solid_mesh.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,7 @@ namespace geode
11461146
}
11471147
return result;
11481148
}
1149+
11491150
template < index_t dimension >
11501151
absl::optional< index_t > SolidMesh< dimension >::polyhedron_around_edge(
11511152
const std::array< index_t, 2 >& vertices ) const

0 commit comments

Comments
 (0)