| 59 | } |
| 60 | |
| 61 | MR::Mesh fromFV( const pybind11::buffer& faces, const pybind11::buffer& verts, const MR::MeshBuilder::BuildSettings & settings, bool duplicateNonManifoldVertices ) |
| 62 | { |
| 63 | pybind11::buffer_info infoFaces = faces.request(); |
| 64 | pybind11::buffer_info infoVerts = verts.request(); |
| 65 | if ( infoFaces.ndim != 2 || infoFaces.shape[1] != 3 ) |
| 66 | throw std::runtime_error( "shape of input python vector 'faces' should be (n,3)" ); |
| 67 | if ( infoVerts.ndim != 2 || infoVerts.shape[1] != 3 ) |
| 68 | throw std::runtime_error( "shape of input python vector 'verts' should be (n,3)" ); |
| 69 | |
| 70 | // faces to topology part |
| 71 | auto strideF0 = infoFaces.strides[0] / infoFaces.itemsize; |
| 72 | auto strideF1 = infoFaces.strides[1] / infoFaces.itemsize; |
| 73 | MR::Triangulation t; |
| 74 | |
| 75 | auto fillTris = [&] ( const auto* data ) |
| 76 | { |
| 77 | t.reserve( infoFaces.shape[0] ); |
| 78 | for ( auto i = 0; i < infoFaces.shape[0]; i++ ) |
| 79 | { |
| 80 | auto ind = strideF0 * i; |
| 81 | t.push_back( { |
| 82 | MR::VertId( int( data[ind] ) ), |
| 83 | MR::VertId( int( data[ind + strideF1] ) ), |
| 84 | MR::VertId( int( data[ind + strideF1 * 2] ) ) |
| 85 | } ); |
| 86 | } |
| 87 | }; |
| 88 | if ( infoFaces.itemsize == sizeof( int32_t ) ) |
| 89 | { |
| 90 | int* data = reinterpret_cast< int32_t* >( infoFaces.ptr ); |
| 91 | fillTris( data ); |
| 92 | } |
| 93 | else if ( infoFaces.itemsize == sizeof( int64_t ) ) |
| 94 | { |
| 95 | int64_t* data = reinterpret_cast< int64_t* >( infoFaces.ptr ); |
| 96 | fillTris( data ); |
| 97 | } |
| 98 | else |
| 99 | throw std::runtime_error( "dtype of input python vector 'faces' should be int32 or int64" ); |
| 100 | |
| 101 | // verts to points part |
| 102 | MR::VertCoords points; |
| 103 | points.vec_ = fromNumpyArrayInfo( infoVerts ); |
| 104 | if ( duplicateNonManifoldVertices ) |
| 105 | return MR::Mesh::fromTrianglesDuplicatingNonManifoldVertices( std::move( points ), t, nullptr, settings ); |
| 106 | else |
| 107 | return MR::Mesh::fromTriangles( std::move( points ), t, settings ); |
| 108 | } |
| 109 | |
| 110 | MR::Mesh fromUVPoints( const pybind11::buffer& xArray, const pybind11::buffer& yArray, const pybind11::buffer& zArray ) |
| 111 | { |
nothing calls this directly
no test coverage detected