MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / fromFV

Function fromFV

source/mrmeshnumpy/MRPythonNumpyExposing.cpp:61–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59}
60
61MR::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
110MR::Mesh fromUVPoints( const pybind11::buffer& xArray, const pybind11::buffer& yArray, const pybind11::buffer& zArray )
111{

Callers

nothing calls this directly

Calls 6

fromNumpyArrayInfoFunction · 0.85
fromTrianglesFunction · 0.85
push_backMethod · 0.80
requestMethod · 0.45
reserveMethod · 0.45

Tested by

no test coverage detected