def test_io(polyhedral_solid, filename): mesh.save_polyhedral_solid3D(polyhedral_solid, filename) new_polyhedral_solid = mesh.load_polyhedral_solid3D(filename) if new_polyhedral_solid.nb_vertices() != 8: raise ValueError( "[Test] Reloaded PolyhedralSolid should have 8 vertices") if new_polyhedral_solid.nb_facets() != 11: raise ValueError( "[Test] Reloaded PolyhedralSolid should have 11 facets") if new_polyhedral_solid.nb_edges() != 15: raise ValueError( "[Test] Reloaded PolyhedralSolid should have 15 edges") if new_polyhedral_solid.nb_polyhedra() != 3: raise ValueError( "[Test] Reloaded PolyhedralSolid should have 3 polyhedra") if new_polyhedral_solid.polyhedron_facet(mesh.PolyhedronFacet( 1, 0)) != polyhedral_solid.polyhedron_facet( mesh.PolyhedronFacet(1, 0)): raise ValueError( "[Test] Reloaded PolyhedralSolid has wrong polyhedron facet index") attribute = new_polyhedral_solid.facet_attribute_manager( ).find_attribute_uint("test") for f in range(new_polyhedral_solid.nb_facets()): if attribute.value(f) != f: raise ValueError( "[Test] Reloaded PolyhedralSolid has wrong attributes on its facets" )
def test_normals(): polyhedral_solid = mesh.PolyhedralSolid3D.create() builder = mesh.PolyhedralSolidBuilder3D.create(polyhedral_solid) o = 0.0 a = 0.6 b = 2.4 c = 1.8 builder.create_point(geom.Point3D([o, b, -c])) builder.create_point(geom.Point3D([o, o, o])) builder.create_point(geom.Point3D([a, o, o])) builder.create_point(geom.Point3D([a, b, o])) builder.create_point(geom.Point3D([o, b, o])) builder.create_point(geom.Point3D([o, b, c])) builder.create_polyhedron( [0, 1, 2, 3, 4], [[1, 2, 0], [1, 2, 3, 4], [2, 3, 0], [3, 4, 0], [4, 1, 0]]) builder.create_polyhedron( [5, 1, 4, 3, 2], [[1, 2, 0], [1, 2, 3, 4], [2, 3, 0], [3, 4, 0], [4, 1, 0]]) answer_facet_normal = geom.Point3D([0, 0, 1]) if polyhedral_solid.polyhedron_facet_normal(mesh.PolyhedronFacet( 0, 1)) != answer_facet_normal: raise ValueError( "[Test] PolyhedralSolid polyhedron_facet_normal is not correct (0, 1)" ) if polyhedral_solid.polyhedron_facet_normal(mesh.PolyhedronFacet( 1, 1)) != answer_facet_normal * -1.: raise ValueError( "[Test] PolyhedralSolid polyhedron_facet_normal is not correct )1, 1)" )
def test_delete_vertex(polyhedral_solid, builder): to_delete = [False] * polyhedral_solid.nb_vertices() to_delete[0] = True builder.delete_vertices(to_delete) if polyhedral_solid.nb_vertices() != 7: raise ValueError("[Test] PolyhedralSolid should have 7 vertices") answer = geom.Point3D([2.1, 9.4, 6.7]) if polyhedral_solid.point(0) != answer: raise ValueError( "[Test] PolyhedralSolid vertex coordinates are not correct") if polyhedral_solid.nb_polyhedra() != 2: raise ValueError("[Test] PolyhedralSolid should have 2 polyhedra") if polyhedral_solid.polyhedron_adjacent(mesh.PolyhedronFacet(1, 3)) != 0: raise ValueError( "[Test] PolyhedralSolid adjacent index is not correct") if polyhedral_solid.nb_facets() != 7: raise ValueError("[Test] PolyhedralSolid should have 7 facets") if polyhedral_solid.nb_edges() != 9: raise ValueError("[Test] PolyhedralSolid should have 9 edges") attribute = polyhedral_solid.edge_attribute_manager().find_attribute_uint( "test") if attribute.value(0) != 8: raise ValueError( "[Test] Wrong value for attribute on edge 0 after vertex deletion") if attribute.value(1) != 7: raise ValueError( "[Test] Wrong value for attribute on edge 1 after vertex deletion")
def test_barycenters(): polyhedral_solid = mesh.PolyhedralSolid3D.create() builder = mesh.PolyhedralSolidBuilder3D.create(polyhedral_solid) o = 0.0 a = 0.6 b = 2.4 c = 1.8 builder.create_point(geom.Point3D([o, o, o])) builder.create_point(geom.Point3D([a, o, o])) builder.create_point(geom.Point3D([o, o, c])) builder.create_point(geom.Point3D([o, b, o])) builder.create_point(geom.Point3D([a, b, o])) builder.create_point(geom.Point3D([o, b, c])) builder.create_polyhedron( [0, 1, 2, 3, 4, 5], [[0, 1, 2], [0, 1, 4, 3], [1, 2, 5, 4], [0, 3, 5, 2], [3, 4, 5]]) answer_facet_barycenter = geom.Point3D([a / 3., 0, c / 3.]) if polyhedral_solid.facet_barycenter( polyhedral_solid.polyhedron_facet_vertices( mesh.PolyhedronFacet(0, 0))) != answer_facet_barycenter: raise ValueError( "[Test] PolyhedralSolid facet_barycenter is not correct") answer_polyhedron_barycenter = geom.Point3D([a / 3., 0.5 * b, c / 3.]) if polyhedral_solid.polyhedron_barycenter( 0) != answer_polyhedron_barycenter: raise ValueError( "[Test] PolyhedralSolid polyhedron barycenter is not correct")
def test_set_polyhedron_vertex(polyhedral_solid, builder): facet_id = polyhedral_solid.polyhedron_facet(mesh.PolyhedronFacet(0, 1)) builder.set_polyhedron_vertex(mesh.PolyhedronVertex(0, 2), 1) builder.delete_isolated_facets() if polyhedral_solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 2)) != 1: raise ValueError( "[Test] PolyhedronVertex after set_polyhedron_vertex is wrong") if polyhedral_solid.polyhedron_facet_vertex( mesh.PolyhedronFacetVertex(mesh.PolyhedronFacet(0, 1), 1)) != 1: raise ValueError( "[Test] PolyhedronFacetVertex after set_polyhedron_vertex is wrong" ) if polyhedral_solid.polyhedron_facet(mesh.PolyhedronFacet(0, 1)) != facet_id: raise ValueError( "[Test] Polyhedron facet id after set_polyhedron_vertex is wrong")
def test_delete_vertex(solid, builder): to_delete = [False] * solid.nb_vertices() to_delete[0] = True builder.delete_vertices(to_delete) if solid.nb_vertices() != 5: raise ValueError("[Test] TetrahedralSolid should have 5 vertices") answer = geom.Point3D([2.1, 9.4, 6.7]) if solid.point(0) != answer: raise ValueError( "[Test] TetrahedralSolid vertex coordinates are not correct") if solid.nb_polyhedra() != 2: raise ValueError("[Test] TetrahedralSolid should have 2 tetrahedra") if solid.polyhedron_adjacent(mesh.PolyhedronFacet(1, 3)) != 0: raise ValueError( "[Test] TetrahedralSolid adjacent index is not correct") if solid.nb_facets() != 7: raise ValueError("[Test] PolyhedralSolid should have 7 facets") if solid.nb_edges() != 9: raise ValueError("[Test] PolyhedralSolid should have 9 edges")
def test_polyhedron_adjacencies(polyhedral_solid, builder): builder.compute_polyhedron_adjacencies() if polyhedral_solid.polyhedron_adjacent(mesh.PolyhedronFacet(0, 0)): raise ValueError( "[Test] PolyhedralSolid adjacent index is not correct") if polyhedral_solid.polyhedron_adjacent(mesh.PolyhedronFacet(0, 1)) != 1: raise ValueError( "[Test] PolyhedralSolid adjacent index is not correct") if polyhedral_solid.polyhedron_adjacent(mesh.PolyhedronFacet(0, 2)): raise ValueError( "[Test] PolyhedralSolid adjacent index is not correct") if polyhedral_solid.polyhedron_adjacent(mesh.PolyhedronFacet(1, 0)) != 2: raise ValueError( "[Test] PolyhedralSolid adjacent index is not correct") if polyhedral_solid.polyhedron_adjacent(mesh.PolyhedronFacet(1, 3)) != 0: raise ValueError( "[Test] PolyhedralSolid adjacent index is not correct") if polyhedral_solid.polyhedron_adjacent(mesh.PolyhedronFacet(2, 3)) != 1: raise ValueError( "[Test] PolyhedralSolid adjacent index is not correct") if len(polyhedral_solid.polyhedra_around_vertex(4)) != 3: raise ValueError( "[Test] PolyhedralSolid should have 3 polyhedra around this vertex" ) if len(polyhedral_solid.polyhedron_facets_on_border(0)) != 4: raise ValueError( "[Test] First polyhedron of PolyhedralSolid should have 4 facets on order" ) edge_id = polyhedral_solid.edges().edge_from_vertices([5, 4]) if edge_id != 8: raise ValueError("[Test] Wrong edge index from vertices") if len(polyhedral_solid.polyhedra_around_edge([5, 4])) != 3: raise ValueError( "[Test] PolyhedralSolid should have 3 polyhedra around this edge") facet_id = polyhedral_solid.facets().facet_from_vertices( polyhedral_solid.polyhedron_facet_vertices(mesh.PolyhedronFacet(1, 0))) polyhedra = polyhedral_solid.polyhedra_from_facet( polyhedral_solid.facets().facet_vertices(facet_id)) if len(polyhedra) != 2: raise ValueError("[Test] Wrong number of polyhedra from facet") if not 1 in polyhedra: raise ValueError("[Test] Polyhedra from facet should contain 1") if not 2 in polyhedra: raise ValueError("[Test] Polyhedra from facet should contain 2")
def test_polyhedron_adjacencies(solid, builder): builder.compute_polyhedron_adjacencies() if solid.polyhedron_adjacent(mesh.PolyhedronFacet(0, 0)) != 1: raise ValueError( "[Test] TetrahedralSolid adjacent index is not correct") if solid.polyhedron_adjacent(mesh.PolyhedronFacet(0, 1)): raise ValueError( "[Test] TetrahedralSolid adjacent index is not correct") if solid.polyhedron_adjacent(mesh.PolyhedronFacet(1, 3)) != 0: raise ValueError( "[Test] TetrahedralSolid adjacent index is not correct") if solid.polyhedron_adjacent_facet(mesh.PolyhedronFacet( 0, 0)) != mesh.PolyhedronFacet(1, 3): raise ValueError( "[Test] TetrahedralSolid adjacent index is not correct") if solid.polyhedron_adjacent(mesh.PolyhedronFacet(2, 3)) != 1: raise ValueError( "[Test] TetrahedralSolid adjacent index is not correct") if solid.polyhedron_adjacent(mesh.PolyhedronFacet(2, 0)): raise ValueError( "[Test] TetrahedralSolid adjacent index is not correct")
def test_permutation(solid, builder): builder.permute_vertices([4, 2, 1, 5, 0, 3]) if solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 0)) != 4: raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 1)) != 2: raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 2)) != 1: raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 3)) != 5: raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(1, 0)) != 2: raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(1, 1)) != 1: raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(1, 2)) != 5: raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(1, 3)) != 0: raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(2, 0)) != 2: raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(2, 1)) != 0: raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(2, 2)) != 5: raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(2, 3)) != 3: raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute") builder.permute_polyhedra([2, 0, 1]) if solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 0)) != 2: raise ValueError( "[Test] Wrong PolyhedronVertex after polyhedron permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 1)) != 0: raise ValueError( "[Test] Wrong PolyhedronVertex after polyhedron permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 2)) != 5: raise ValueError( "[Test] Wrong PolyhedronVertex after polyhedron permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 3)) != 3: raise ValueError( "[Test] Wrong PolyhedronVertex after polyhedron permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(1, 0)) != 4: raise ValueError( "[Test] Wrong PolyhedronVertex after polyhedron permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(1, 1)) != 2: raise ValueError( "[Test] Wrong PolyhedronVertex after polyhedron permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(1, 2)) != 1: raise ValueError( "[Test] Wrong PolyhedronVertex after polyhedron permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(1, 3)) != 5: raise ValueError( "[Test] Wrong PolyhedronVertex after polyhedron permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(2, 0)) != 2: raise ValueError( "[Test] Wrong PolyhedronVertex after polyhedron permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(2, 1)) != 1: raise ValueError( "[Test] Wrong PolyhedronVertex after polyhedron permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(2, 2)) != 5: raise ValueError( "[Test] Wrong PolyhedronVertex after polyhedron permute") if solid.polyhedron_vertex(mesh.PolyhedronVertex(2, 3)) != 0: raise ValueError( "[Test] Wrong PolyhedronVertex after polyhedron permute") if solid.polyhedron_adjacent(mesh.PolyhedronFacet(0, 2)): raise ValueError("[Test] Wrong Adjacency after polyhedron permute") if solid.polyhedron_adjacent(mesh.PolyhedronFacet(2, 3)) != 1: raise ValueError("[Test] Wrong Adjacency after polyhedron permute") if solid.polyhedron_adjacent(mesh.PolyhedronFacet(0, 3)) != 2: raise ValueError("[Test] Wrong Adjacency after polyhedron permute") if solid.polyhedron_adjacent(mesh.PolyhedronFacet(1, 0)) != 2: raise ValueError("[Test] Wrong Adjacency after polyhedron permute") polyhedra_5 = solid.polyhedra_around_vertex(5) if len(polyhedra_5) != 3: raise ValueError("[Test] Wrong polyhedra_5 after polyhedron permute") if polyhedra_5[0].polyhedron_id != 0: raise ValueError("[Test] Wrong polyhedra_5 after polyhedron permute") if polyhedra_5[0].vertex_id != 2: raise ValueError("[Test] Wrong polyhedra_5 after polyhedron permute") if polyhedra_5[1].polyhedron_id != 2: raise ValueError("[Test] Wrong polyhedra_5 after polyhedron permute") if polyhedra_5[1].vertex_id != 2: raise ValueError("[Test] Wrong polyhedra_5 after polyhedron permute") if polyhedra_5[2].polyhedron_id != 1: raise ValueError("[Test] Wrong polyhedra_5 after polyhedron permute") if polyhedra_5[2].vertex_id != 3: raise ValueError("[Test] Wrong polyhedra_5 after polyhedron permute")