Skip to content

Commit bb6cfad

Browse files
committed
fix(RegularGrid): Fixed issue on grid origin initialization on old grids.
1 parent 68c768d commit bb6cfad

File tree

9 files changed

+68
-18
lines changed

9 files changed

+68
-18
lines changed

include/geode/basic/mapping.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ namespace geode
3232
{
3333
template < typename T1,
3434
typename T2,
35-
template < typename >
36-
class StorageType >
35+
template < typename > class StorageType >
3736
class MappingBase
3837
{
3938
public:
@@ -200,7 +199,7 @@ namespace geode
200199
{
201200
if( this->has_mapping_input( in ) )
202201
{
203-
if( absl::c_contains( this->in2out_mapping().at( in ), out ) )
202+
if( absl::c_contains( this->in2out( in ), out ) )
204203
{
205204
return;
206205
}

src/geode/mesh/core/grid.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <absl/container/inlined_vector.h>
2727

2828
#include <geode/basic/bitsery_archive.hpp>
29+
#include <geode/basic/logger.hpp>
2930
#include <geode/basic/pimpl_impl.hpp>
3031

3132
#include <geode/geometry/bounding_box.hpp>
@@ -53,6 +54,7 @@ namespace geode
5354
Impl()
5455
{
5556
cells_length_.fill( 1 );
57+
set_base_origin();
5658
set_base_grid_directions();
5759
}
5860

@@ -429,10 +431,12 @@ namespace geode
429431
{ []( Archive& a, Impl& impl ) {
430432
a.container4b( impl.deprecated_cells_number_ );
431433
a.container8b( impl.cells_length_ );
434+
impl.set_base_origin();
432435
impl.set_base_grid_directions();
433436
},
434437
[]( Archive& a, Impl& impl ) {
435438
a.container8b( impl.cells_length_ );
439+
impl.set_base_origin();
436440
impl.set_base_grid_directions();
437441
},
438442
[]( Archive& a, Impl& impl ) {
@@ -441,6 +445,11 @@ namespace geode
441445
} } } );
442446
}
443447

448+
void set_base_origin()
449+
{
450+
set_grid_origin( Point< dimension >{} );
451+
}
452+
444453
void set_base_grid_directions()
445454
{
446455
std::array< Vector< dimension >, dimension > directions;
@@ -524,8 +533,8 @@ namespace geode
524533
}
525534

526535
template < index_t dimension >
527-
auto Grid< dimension >::cell_vertices(
528-
const CellIndices& cell_id ) const -> CellVertices
536+
auto Grid< dimension >::cell_vertices( const CellIndices& cell_id ) const
537+
-> CellVertices
529538
{
530539
return impl_->cell_vertices( cell_id );
531540
}
@@ -572,15 +581,15 @@ namespace geode
572581
}
573582

574583
template < index_t dimension >
575-
auto Grid< dimension >::cells(
576-
const Point< dimension >& query ) const -> CellsAroundVertex
584+
auto Grid< dimension >::cells( const Point< dimension >& query ) const
585+
-> CellsAroundVertex
577586
{
578587
return impl_->cells( *this, query );
579588
}
580589

581590
template < index_t dimension >
582-
auto Grid< dimension >::cells_around(
583-
VertexIndices vertex_indices ) const -> CellsAroundVertex
591+
auto Grid< dimension >::cells_around( VertexIndices vertex_indices ) const
592+
-> CellsAroundVertex
584593
{
585594
return impl_->cells_around( *this, vertex_indices );
586595
}

src/geode/mesh/core/regular_grid_solid.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ namespace geode
9494
a.ext( grid, bitsery::ext::BaseClass< SolidMesh< 3 > >{} );
9595
a.ext( grid, bitsery::ext::BaseClass< Grid< 3 > >{} );
9696
GridBuilder3D builder{ grid };
97-
builder.set_grid_origin( grid.point( 0 ) );
97+
builder.set_grid_origin( grid.grid_point( { 0, 0, 0 } ) );
9898
},
9999
[]( Archive& a, RegularGrid< 3 >& grid ) {
100100
a.ext(

src/geode/mesh/core/regular_grid_surface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ namespace geode
9595
grid, bitsery::ext::BaseClass< SurfaceMesh< 2 > >{} );
9696
a.ext( grid, bitsery::ext::BaseClass< Grid< 2 > >{} );
9797
GridBuilder2D builder{ grid };
98-
builder.set_grid_origin( grid.point( 0 ) );
98+
builder.set_grid_origin( grid.grid_point( { 0, 0 } ) );
9999
},
100100
[]( Archive& a, RegularGrid< 2 >& grid ) {
101101
a.ext( grid,

src/geode/mesh/helpers/convert_solid_mesh.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,17 @@ namespace
310310
std::vector< double > lambdas;
311311
cell_vertices.reserve( 8 );
312312
lambdas.reserve( 8 );
313+
geode::Point3D position{ { 0., 0., 0. } };
313314
for( const auto& vertex_indices :
314315
grid.cell_vertices( cell_indices ) )
315316
{
316317
cell_vertices.push_back( grid.vertex_index( vertex_indices ) );
317318
lambdas.push_back( 0.125 );
319+
position += grid.grid_point( vertex_indices ) * 0.125;
318320
}
319321
solid_attribute_manager.interpolate_attribute_value(
320322
{ cell_vertices, lambdas }, counter );
323+
builder.set_point( counter, position );
321324
counter++;
322325
}
323326
}

src/geode/mesh/helpers/convert_surface_mesh.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ namespace
149149
cell_mesh_vertices[3], additional_vertex_id } );
150150
created_triangles[2] = builder.create_triangle( { cell_mesh_vertices[3],
151151
cell_mesh_vertices[2], additional_vertex_id } );
152-
created_triangles[4] = builder.create_triangle( { cell_mesh_vertices[2],
152+
created_triangles[3] = builder.create_triangle( { cell_mesh_vertices[2],
153153
cell_mesh_vertices[0], additional_vertex_id } );
154154
return created_triangles;
155155
}
@@ -210,14 +210,14 @@ namespace
210210
for( const auto cell_index : geode::Indices{ cells_to_densify } )
211211
{
212212
const auto cell_indices =
213-
grid.cell_indices( cells_to_densify[cell_index] );
213+
grid.cell_indices( cells_to_densify.at( cell_index ) );
214214
const auto additional_vertex_id =
215215
grid.nb_grid_vertices() + cell_index;
216216
for( const auto triangle_id : create_triangles_from_cross_pattern(
217217
builder, grid, cell_indices, additional_vertex_id ) )
218218
{
219219
old2new_mapping.map(
220-
cells_to_densify[cell_index], triangle_id );
220+
cells_to_densify.at( cell_index ), triangle_id );
221221
}
222222
}
223223
builder.compute_polygon_adjacencies();
@@ -232,14 +232,14 @@ namespace
232232
{
233233
builder.create_vertices(
234234
grid.nb_grid_vertices() + cells_to_densify.size() );
235+
auto& surface_attribute_manager = surface.vertex_attribute_manager();
236+
geode::internal::copy_attributes(
237+
grid.grid_vertex_attribute_manager(), surface_attribute_manager );
235238
for( const auto vertex_id : geode::Range{ grid.nb_grid_vertices() } )
236239
{
237240
builder.set_point( vertex_id,
238241
grid.grid_point( grid.vertex_indices( vertex_id ) ) );
239242
}
240-
auto& surface_attribute_manager = surface.vertex_attribute_manager();
241-
geode::internal::copy_attributes(
242-
grid.grid_vertex_attribute_manager(), surface_attribute_manager );
243243
geode::index_t counter{ grid.nb_grid_vertices() };
244244
for( const auto cell_id : cells_to_densify )
245245
{
@@ -249,14 +249,17 @@ namespace
249249
std::vector< double > lambdas;
250250
cell_vertices.reserve( 4 );
251251
lambdas.reserve( 4 );
252+
geode::Point2D position{ { 0., 0. } };
252253
for( const auto& vertex_indices :
253254
grid.cell_vertices( cell_indices ) )
254255
{
255256
cell_vertices.push_back( grid.vertex_index( vertex_indices ) );
256257
lambdas.push_back( 0.25 );
258+
position += grid.grid_point( vertex_indices ) * 0.25;
257259
}
258260
surface_attribute_manager.interpolate_attribute_value(
259261
{ cell_vertices, lambdas }, counter );
262+
builder.set_point( counter, position );
260263
counter++;
261264
}
262265
}
243 KB
Binary file not shown.
157 KB
Binary file not shown.

tests/mesh/test-convert-surface.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,20 @@
2424
#include <geode/tests/common.hpp>
2525

2626
#include <geode/basic/assert.hpp>
27+
#include <geode/basic/attribute_manager.hpp>
2728
#include <geode/basic/logger.hpp>
2829

2930
#include <geode/geometry/point.hpp>
3031
#include <geode/geometry/vector.hpp>
3132

33+
#include <geode/mesh/builder/regular_grid_surface_builder.hpp>
3234
#include <geode/mesh/builder/surface_mesh_builder.hpp>
3335
#include <geode/mesh/core/light_regular_grid.hpp>
3436
#include <geode/mesh/core/polygonal_surface.hpp>
37+
#include <geode/mesh/core/regular_grid_surface.hpp>
3538
#include <geode/mesh/core/triangulated_surface.hpp>
3639
#include <geode/mesh/io/polygonal_surface_output.hpp>
40+
#include <geode/mesh/io/regular_grid_input.hpp>
3741
#include <geode/mesh/io/triangulated_surface_input.hpp>
3842

3943
#include <geode/mesh/helpers/convert_surface_mesh.hpp>
@@ -78,9 +82,9 @@ void convert_grid_to_surface()
7882
{
7983
geode::LightRegularGrid2D grid{ geode::Point2D{ { 1, 2 } }, { 5, 6 },
8084
{ 1, 1 } };
81-
const std::array< geode::index_t, 4 > cells_to_densify{ 5, 11, 12, 13 };
8285
const auto converted_grid2d =
8386
geode::convert_grid_into_triangulated_surface( grid );
87+
const std::array< geode::index_t, 4 > cells_to_densify{ 5, 11, 12, 13 };
8488
const auto converted_grid2d_densified =
8589
geode::convert_grid_into_densified_triangulated_surface(
8690
grid, cells_to_densify );
@@ -92,6 +96,37 @@ void convert_grid_to_surface()
9296
== grid.nb_cells() * 2 + 2 * cells_to_densify.size(),
9397
"[Test] Number of polygons in TriangulatedSurface2D from grid is not "
9498
"correct." );
99+
100+
geode::Logger::debug( "Triangulated surface from created RegularGrid" );
101+
auto mesh_grid = geode::RegularGrid2D::create();
102+
auto builder = geode::RegularGridBuilder2D::create( *mesh_grid );
103+
builder->initialize_grid( geode::Point2D{ { 1, 1.5 } }, { 5, 5 }, 5 );
104+
const auto tri_surf_from_mesh_grid_1 =
105+
geode::convert_surface_mesh_into_triangulated_surface( *mesh_grid );
106+
const auto tri_surf_from_mesh_grid_2 =
107+
geode::convert_grid_into_triangulated_surface( *mesh_grid );
108+
109+
geode::Logger::debug( "Triangulated surface from old RegularGrid" );
110+
const auto old_regular_grid = geode::load_regular_grid< 2 >(
111+
absl::StrCat( geode::DATA_PATH, "old_regular_grid.og_rgd2d" ) );
112+
const auto old_regular_grid_surface =
113+
geode::convert_grid_into_triangulated_surface( *old_regular_grid );
114+
auto test_attribute =
115+
old_regular_grid_surface->vertex_attribute_manager()
116+
.find_or_create_attribute< geode::VariableAttribute,
117+
geode::Point2D >( "test", geode::Point2D{ { 0., 0. } } );
118+
auto pt_attribute = old_regular_grid_surface->vertex_attribute_manager()
119+
.find_attribute< geode::Point2D >( "points" );
120+
const auto old_regular_grid_surface2 =
121+
geode::convert_surface_mesh_into_triangulated_surface(
122+
*old_regular_grid )
123+
.value();
124+
auto test_attribute2 =
125+
old_regular_grid_surface2->vertex_attribute_manager()
126+
.find_or_create_attribute< geode::VariableAttribute,
127+
geode::Point2D >( "test", geode::Point2D{ { 0., 0. } } );
128+
auto pt_attribute2 = old_regular_grid_surface2->vertex_attribute_manager()
129+
.find_attribute< geode::Point2D >( "points" );
95130
}
96131

97132
void triangulate_surface()
@@ -118,6 +153,7 @@ void triangulate_surface()
118153
void test()
119154
{
120155
geode::OpenGeodeMeshLibrary::initialize();
156+
geode::Logger::set_level( geode::Logger::LEVEL::debug );
121157
convert_surface_dimension();
122158
convert_grid_to_surface();
123159
triangulate_surface();

0 commit comments

Comments
 (0)