| 9 | using namespace MR; |
| 10 | |
| 11 | MR::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 | |
| 52 | pybind11::array_t<double> getNumpy3Darray( const MR::SimpleVolume& simpleVolume ) |
| 53 | { |
nothing calls this directly
no test coverage detected