| 378 | } |
| 379 | |
| 380 | void test_io( const geode::PolyhedralSolid3D& polyhedral_solid, |
| 381 | const std::string& filename ) |
| 382 | { |
| 383 | geode::save_polyhedral_solid( polyhedral_solid, filename ); |
| 384 | const auto reloaded = geode::load_polyhedral_solid< 3 >( filename ); |
| 385 | geode_unused( reloaded ); |
| 386 | const auto new_polyhedral_solid = geode::load_polyhedral_solid< 3 >( |
| 387 | geode::OpenGeodePolyhedralSolid3D::impl_name_static(), filename ); |
| 388 | |
| 389 | geode::OpenGeodeMeshException::test( |
| 390 | new_polyhedral_solid->nb_vertices() == 8, |
| 391 | "Reloaded PolyhedralSolid should have 8 vertices" ); |
| 392 | for( const auto vertex_id : geode::Range{ polyhedral_solid.nb_vertices() } ) |
| 393 | { |
| 394 | geode::OpenGeodeMeshException::test( |
| 395 | polyhedral_solid.point( vertex_id ) |
| 396 | .inexact_equal( new_polyhedral_solid->point( vertex_id ) ), |
| 397 | "Wrong reloaded mesh point coordinates." ); |
| 398 | } |
| 399 | geode::OpenGeodeMeshException::test( |
| 400 | new_polyhedral_solid->facets().nb_facets() == 11, |
| 401 | "Reloaded PolyhedralSolid should have 11 facets" ); |
| 402 | geode::OpenGeodeMeshException::test( |
| 403 | new_polyhedral_solid->edges().nb_edges() == 15, |
| 404 | "Reloaded PolyhedralSolid should have 15 edges" ); |
| 405 | geode::OpenGeodeMeshException::test( |
| 406 | new_polyhedral_solid->nb_polyhedra() == 3, |
| 407 | "Reloaded PolyhedralSolid should have 3 polyhedra" ); |
| 408 | geode::OpenGeodeMeshException::test( |
| 409 | new_polyhedral_solid->facets().facet_from_vertices( |
| 410 | new_polyhedral_solid->polyhedron_facet_vertices( { 1, 0 } ) ) |
| 411 | == polyhedral_solid.facets().facet_from_vertices( |
| 412 | polyhedral_solid.polyhedron_facet_vertices( { 1, 0 } ) ), |
| 413 | "Reloaded PolyhedralSolid has wrong polyhedron facet index" ); |
| 414 | auto attribute = new_polyhedral_solid->facets() |
| 415 | .facet_attribute_manager() |
| 416 | .find_attribute< geode::index_t >( "test" ); |
| 417 | for( auto f : geode::Range{ new_polyhedral_solid->facets().nb_facets() } ) |
| 418 | { |
| 419 | geode::OpenGeodeMeshException::test( attribute->value( f ) == f, |
| 420 | "Reloaded PolyhedralSolid has " |
| 421 | "wrong attributes on its facets" ); |
| 422 | } |
| 423 | auto manager = new_polyhedral_solid->texture_manager(); |
| 424 | auto texture_names = manager.texture_names(); |
| 425 | geode::OpenGeodeMeshException::test( texture_names.size() == 1, |
| 426 | "Reloaded PolyhedralSolid has wrong number of textures" ); |
| 427 | geode::OpenGeodeMeshException::test( texture_names[0] == "texture", |
| 428 | "Reloaded PolyhedralSolid has wrong texture name" ); |
| 429 | } |
| 430 | |
| 431 | void test_backward_io( const std::string& filename ) |
| 432 | { |
no test coverage detected