Skip to content

Commit 2406eff

Browse files
BotellaApanquez
authored andcommitted
perf(RegularGrid): faster initialization
1 parent 2568487 commit 2406eff

File tree

3 files changed

+129
-14
lines changed

3 files changed

+129
-14
lines changed

src/geode/mesh/builder/regular_grid_solid_builder.cpp

Lines changed: 80 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,92 @@ namespace geode
4848
{
4949
set_grid_dimensions(
5050
std::move( cells_number ), std::move( cells_length ) );
51+
const auto nb_u = grid_.nb_cells_in_direction( 0 );
52+
const auto nb_v = grid_.nb_cells_in_direction( 1 );
53+
const auto nb_w = grid_.nb_cells_in_direction( 2 );
5154
grid_.vertex_attribute_manager().resize(
52-
grid_.nb_vertices_in_direction( 0 )
53-
* grid_.nb_vertices_in_direction( 1 )
54-
* grid_.nb_vertices_in_direction( 2 ) );
55+
( nb_u + 1 ) * ( nb_v + 1 ) * ( nb_w + 1 ) );
5556
grid_.polyhedron_attribute_manager().resize( grid_.nb_cells() );
56-
for( const auto p : Range{ grid_.nb_polyhedra() } )
57+
for( const auto w : Range{ nb_w } )
5758
{
58-
for( const auto v : LRange{ 8 } )
59+
for( const auto v : Range{ nb_v } )
5960
{
60-
associate_polyhedron_vertex_to_vertex(
61-
{ p, v }, grid_.polyhedron_vertex( { p, v } ) );
61+
for( const auto u : Range{ nb_u } )
62+
{
63+
const auto cell = u + v * nb_u + w * nb_u * nb_v;
64+
const auto vertex =
65+
u + v * ( nb_u + 1 ) + w * ( nb_u + 1 ) * ( nb_v + 1 );
66+
associate_polyhedron_vertex_to_vertex(
67+
{ cell, 0 }, vertex );
68+
}
6269
}
6370
}
71+
// Last Face U
72+
for( const auto w : Range{ nb_w } )
73+
{
74+
for( const auto v : Range{ nb_v } )
75+
{
76+
const auto cell = ( nb_u - 1 ) + v * nb_u + w * nb_u * nb_v;
77+
const auto vertex =
78+
nb_u + v * ( nb_u + 1 ) + w * ( nb_u + 1 ) * ( nb_v + 1 );
79+
associate_polyhedron_vertex_to_vertex( { cell, 1 }, vertex );
80+
}
81+
}
82+
// Last Face V
83+
for( const auto w : Range{ nb_w } )
84+
{
85+
for( const auto u : Range{ nb_u } )
86+
{
87+
const auto cell = u + ( nb_v - 1 ) * nb_u + w * nb_u * nb_v;
88+
const auto vertex =
89+
u + nb_v * ( nb_u + 1 ) + w * ( nb_u + 1 ) * ( nb_v + 1 );
90+
associate_polyhedron_vertex_to_vertex( { cell, 2 }, vertex );
91+
}
92+
}
93+
// Last Face W
94+
for( const auto v : Range{ nb_v } )
95+
{
96+
for( const auto u : Range{ nb_u } )
97+
{
98+
const auto cell = u + v * nb_u + ( nb_w - 1 ) * nb_u * nb_v;
99+
const auto vertex =
100+
u + v * ( nb_u + 1 ) + nb_w * ( nb_u + 1 ) * ( nb_v + 1 );
101+
associate_polyhedron_vertex_to_vertex( { cell, 4 }, vertex );
102+
}
103+
}
104+
// Last Line U-V
105+
for( const auto w : Range{ nb_w } )
106+
{
107+
const auto cell =
108+
( nb_u - 1 ) + ( nb_v - 1 ) * nb_u + w * nb_u * nb_v;
109+
const auto vertex =
110+
nb_u + nb_v * ( nb_u + 1 ) + w * ( nb_u + 1 ) * ( nb_v + 1 );
111+
associate_polyhedron_vertex_to_vertex( { cell, 3 }, vertex );
112+
}
113+
// Last Line U-W
114+
for( const auto v : Range{ nb_v } )
115+
{
116+
const auto cell =
117+
( nb_u - 1 ) + v * nb_u + ( nb_w - 1 ) * nb_u * nb_v;
118+
const auto vertex =
119+
nb_u + v * ( nb_u + 1 ) + nb_w * ( nb_u + 1 ) * ( nb_v + 1 );
120+
associate_polyhedron_vertex_to_vertex( { cell, 5 }, vertex );
121+
}
122+
// Last Line V-W
123+
for( const auto u : Range{ nb_u } )
124+
{
125+
const auto cell =
126+
u + ( nb_v - 1 ) * nb_u + ( nb_w - 1 ) * nb_u * nb_v;
127+
const auto vertex =
128+
u + nb_v * ( nb_u + 1 ) + nb_w * ( nb_u + 1 ) * ( nb_v + 1 );
129+
associate_polyhedron_vertex_to_vertex( { cell, 6 }, vertex );
130+
}
131+
// Last Corner U-V-W
132+
const auto cell =
133+
( nb_u - 1 ) + ( nb_v - 1 ) * nb_u + ( nb_w - 1 ) * nb_u * nb_v;
134+
const auto vertex =
135+
nb_u + nb_v * ( nb_u + 1 ) + nb_w * ( nb_u + 1 ) * ( nb_v + 1 );
136+
associate_polyhedron_vertex_to_vertex( { cell, 7 }, vertex );
64137
update_origin( origin );
65138
}
66139

src/geode/mesh/builder/regular_grid_surface_builder.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,37 @@ namespace geode
5050
{
5151
set_grid_dimensions(
5252
std::move( cells_number ), std::move( cells_length ) );
53-
grid_.vertex_attribute_manager().resize(
54-
grid_.nb_vertices_in_direction( 0 )
55-
* grid_.nb_vertices_in_direction( 1 ) );
53+
const auto nb_u = grid_.nb_cells_in_direction( 0 );
54+
const auto nb_v = grid_.nb_cells_in_direction( 1 );
55+
grid_.vertex_attribute_manager().resize( ( nb_u + 1 ) * ( nb_v + 1 ) );
5656
grid_.polygon_attribute_manager().resize( grid_.nb_cells() );
57-
for( const auto p : Range{ grid_.nb_polygons() } )
57+
for( const auto v : Range{ nb_v } )
5858
{
59-
for( const auto v : LRange{ 4 } )
59+
for( const auto u : Range{ nb_u } )
6060
{
61-
associate_polygon_vertex_to_vertex(
62-
{ p, v }, grid_.polygon_vertex( { p, v } ) );
61+
const auto cell = u + v * nb_u;
62+
const auto vertex = u + v * ( nb_u + 1 );
63+
associate_polygon_vertex_to_vertex( { cell, 0 }, vertex );
6364
}
6465
}
66+
// Last Line U
67+
for( const auto v : Range{ nb_v } )
68+
{
69+
const auto cell = ( nb_u - 1 ) + v * nb_u;
70+
const auto vertex = nb_u + v * ( nb_u + 1 );
71+
associate_polygon_vertex_to_vertex( { cell, 1 }, vertex );
72+
}
73+
// Last Line V
74+
for( const auto u : Range{ nb_u } )
75+
{
76+
const auto cell = u + ( nb_v - 1 ) * nb_u;
77+
const auto vertex = u + nb_v * ( nb_u + 1 );
78+
associate_polygon_vertex_to_vertex( { cell, 2 }, vertex );
79+
}
80+
// Last Corner U-V
81+
const auto cell = ( nb_u - 1 ) + ( nb_v - 1 ) * nb_u;
82+
const auto vertex = nb_u + nb_v * ( nb_u + 1 );
83+
associate_polygon_vertex_to_vertex( { cell, 3 }, vertex );
6584
update_origin( origin );
6685
}
6786

tests/mesh/test-regular-grid.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,28 @@ void test_adjacencies2D()
408408
}
409409
}
410410

411+
void test_around_vertex( const geode::RegularGrid3D& grid )
412+
{
413+
for( const auto v : geode::Range{ grid.nb_vertices() } )
414+
{
415+
const auto vertex = grid.vertex_indices( v );
416+
geode::index_t nb_polyhedra{ 8 };
417+
for( const auto d : geode::LRange{ 3 } )
418+
{
419+
if( vertex[d] == 0
420+
|| vertex[d] == grid.nb_vertices_in_direction( d ) - 1 )
421+
{
422+
nb_polyhedra /= 2;
423+
}
424+
}
425+
const auto nb_polyhedra_around =
426+
grid.polyhedra_around_vertex( v ).size();
427+
OPENGEODE_EXCEPTION( nb_polyhedra_around == nb_polyhedra,
428+
"[Test] Wrong number of polyhedra around vertex ", v, "(",
429+
nb_polyhedra_around, "/", nb_polyhedra, ")" );
430+
}
431+
}
432+
411433
void test()
412434
{
413435
geode::OpenGeodeMesh::initialize();
@@ -419,6 +441,7 @@ void test()
419441
test_vertex_number( *grid );
420442
test_vertex_index( *grid );
421443
test_vertex_on_border( *grid );
444+
test_around_vertex( *grid );
422445
test_cell_geometry( *grid );
423446
test_cell_query( *grid );
424447
test_boundary_box( *grid );

0 commit comments

Comments
 (0)