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

Function simpleVolumeFrom3Darray

source/mrmeshnumpy/MRPythonNumpyVoxels.cpp:11–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9using namespace MR;
10
11MR::SimpleVolumeMinMax simpleVolumeFrom3Darray( const pybind11::buffer& voxelsArray )
12{
13 pybind11::buffer_info info = voxelsArray.request();
14 if ( info.ndim != 3 )
15 throw std::runtime_error( "shape of input python vector 'voxelsArray' should be (x,y,z)" );
16
17 MR::SimpleVolumeMinMax res;
18 res.dims = MR::Vector3i( int( info.shape[0] ), int( info.shape[1] ), int( info.shape[2] ) );
19 size_t countPoints = size_t( res.dims.x ) * res.dims.y * res.dims.z;
20 res.data.resize( countPoints );
21
22 auto strideX = info.strides[0] / info.itemsize;
23 auto strideY = info.strides[1] / info.itemsize;
24 auto strideZ = info.strides[2] / info.itemsize;
25
26 VolumeIndexer indexer( res.dims );
27 if ( info.format == pybind11::format_descriptor<double>::format() )
28 {
29 double* data = reinterpret_cast< double* >( info.ptr );
30 ParallelFor( 0_vox, indexer.endId(), [&] ( VoxelId i )
31 {
32 auto pos = indexer.toPos( i );
33 res.data[i] = float( data[size_t( pos.x ) * strideX + size_t( pos.y ) * strideY + size_t( pos.z ) * strideZ] );
34 } );
35 }
36 else if ( info.format == pybind11::format_descriptor<float>::format() )
37 {
38 float* data = reinterpret_cast< float* >( info.ptr );
39 ParallelFor( 0_vox, indexer.endId(), [&] ( VoxelId i )
40 {
41 auto pos = indexer.toPos( i );
42 res.data[i] = data[size_t( pos.x ) * strideX + size_t( pos.y ) * strideY + size_t( pos.z ) * strideZ];
43 } );
44 }
45 else
46 throw std::runtime_error( "dtype of input python vector should be float32 or float64" );
47
48 std::tie( res.min, res.max ) = MR::parallelMinMax( res.data );
49 return res;
50}
51
52pybind11::array_t<double> getNumpy3Darray( const MR::SimpleVolume& simpleVolume )
53{

Callers

nothing calls this directly

Calls 6

ParallelForFunction · 0.85
parallelMinMaxFunction · 0.85
requestMethod · 0.45
resizeMethod · 0.45
endIdMethod · 0.45
toPosMethod · 0.45

Tested by

no test coverage detected