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

Function fromNumpyArrayInfo

source/mrmeshnumpy/MRPythonNumpyExposing.cpp:20–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18} )
19
20std::vector<MR::Vector3f> fromNumpyArrayInfo( const pybind11::buffer_info& bufInfo )
21{
22 std::vector<MR::Vector3f> vec;
23 auto stride0 = bufInfo.strides[0] / bufInfo.itemsize;
24 auto stride1 = bufInfo.strides[1] / bufInfo.itemsize;
25 vec.resize( bufInfo.shape[0] );
26 auto fillData = [&] ( const auto* data )
27 {
28 for ( auto i = 0; i < bufInfo.shape[0]; i++ )
29 {
30 auto ind = stride0 * i;
31 vec[i] = MR::Vector3f(
32 float( data[ind] ),
33 float( data[ind + stride1] ),
34 float( data[ind + stride1 * 2] ) );
35 }
36 };
37 if ( bufInfo.format == pybind11::format_descriptor<double>::format() )
38 {
39 double* data = reinterpret_cast< double* >( bufInfo.ptr );
40 fillData( data );
41 }
42 else if ( bufInfo.format == pybind11::format_descriptor<float>::format() )
43 {
44 float* data = reinterpret_cast< float* >( bufInfo.ptr );
45 fillData( data );
46 }
47 else
48 throw std::runtime_error( "dtype of input python vector should be float32 or float64" );
49 return vec;
50}
51
52std::vector<MR::Vector3f> fromNumpyArray( const pybind11::buffer& coords )
53{

Callers 3

fromNumpyArrayFunction · 0.85
fromFVFunction · 0.85
pointCloudFromNPFunction · 0.85

Calls 1

resizeMethod · 0.45

Tested by

no test coverage detected