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

Function polyline2FromNP

source/mrmeshnumpy/MRPythonNumpyExposing.cpp:273–310  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

271}
272
273MR::Polyline2 polyline2FromNP( const pybind11::buffer& points )
274{
275 pybind11::buffer_info infoPoints = points.request();
276 if ( infoPoints.ndim != 2 || infoPoints.shape[1] != 2 )
277 throw std::runtime_error( "shape of input python vector 'points' should be (n,2)" );
278
279 // verts to points part
280 MR::Contour2f inputContour;
281
282 auto stride0 = infoPoints.strides[0] / infoPoints.itemsize;
283 auto stride1 = infoPoints.strides[1] / infoPoints.itemsize;
284 inputContour.resize( infoPoints.shape[0] );
285 auto fillPoints = [&] ( const auto* data )
286 {
287 for ( auto i = 0; i < infoPoints.shape[0]; i++ )
288 {
289 auto ind = stride0 * i;
290 inputContour[i] = MR::Vector2f( float( data[ind] ), float( data[ind + stride1] ) );
291 }
292 };
293 if ( infoPoints.format == pybind11::format_descriptor<double>::format() )
294 {
295 double* data = reinterpret_cast< double* >( infoPoints.ptr );
296 fillPoints( data );
297 }
298 else if ( infoPoints.format == pybind11::format_descriptor<float>::format() )
299 {
300 float* data = reinterpret_cast< float* >( infoPoints.ptr );
301 fillPoints( data );
302 }
303 else
304 throw std::runtime_error( "dtype of input python vector should be float32 or float64" );
305
306 MR::Polyline2 res;
307 res.addFromPoints( inputContour.data(), inputContour.size() );
308
309 return res;
310}
311
312// returns numpy array shapes [num faces,3] which represents vertices of mesh valid faces
313pybind11::array_t<int> getNumpyFaces( const MR::MeshTopology& topology )

Callers

nothing calls this directly

Calls 5

addFromPointsMethod · 0.80
requestMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected