| 42 | } |
| 43 | |
| 44 | Expected<void> PointsProjector::findProjections( std::vector<MR::PointsProjectionResult>& results, |
| 45 | const std::vector<Vector3f>& points, const FindProjectionOnPointsSettings& settings ) const |
| 46 | { |
| 47 | if ( !data_ ) |
| 48 | return unexpected( "No reference point cloud is set" ); |
| 49 | |
| 50 | const auto totalSize = points.size(); |
| 51 | const auto bufferSize = maxBufferSize( getCudaSafeMemoryLimit(), totalSize, sizeof( float3 ) + sizeof( PointsProjectionResult ) ); |
| 52 | |
| 53 | DynamicArray<float3> cudaPoints; |
| 54 | CUDA_LOGE_RETURN_UNEXPECTED( cudaPoints.resize( bufferSize ) ); |
| 55 | |
| 56 | DynamicArray<PointsProjectionResult> cudaResult; |
| 57 | CUDA_LOGE_RETURN_UNEXPECTED( cudaResult.resize( bufferSize ) ); |
| 58 | |
| 59 | results.resize( totalSize ); |
| 60 | |
| 61 | DynamicArray<uint64_t> cudaValid; |
| 62 | if ( settings.valid ) |
| 63 | { |
| 64 | assert( points.size() <= settings.valid->size() ); |
| 65 | CUDA_LOGE_RETURN_UNEXPECTED( cudaValid.fromVector( settings.valid->bits() ) ); |
| 66 | } |
| 67 | |
| 68 | const auto cudaXf = settings.xf ? fromXf( *settings.xf ) : Matrix4{}; |
| 69 | |
| 70 | if ( !reportProgress( settings.cb, 0.60f ) ) |
| 71 | return unexpectedOperationCanceled(); |
| 72 | |
| 73 | const auto cb1 = subprogress( settings.cb, 0.60f, 1.00f ); |
| 74 | const auto iterCount = chunkCount( totalSize, bufferSize ); |
| 75 | size_t iterIndex = 0; |
| 76 | |
| 77 | for ( const auto [offset, size] : splitByChunks( totalSize, bufferSize ) ) |
| 78 | { |
| 79 | const auto cb2 = subprogress( cb1, iterIndex++, iterCount ); |
| 80 | |
| 81 | CUDA_LOGE_RETURN_UNEXPECTED( cudaPoints.copyFrom( points.data() + offset, size ) ); |
| 82 | |
| 83 | findProjectionOnPointsKernel( cudaResult.data(), data_->data(), cudaPoints.data(), settings.valid ? cudaValid.data() : nullptr, cudaXf, settings.upDistLimitSq, settings.loDistLimitSq, settings.skipSameIndex, size, offset ); |
| 84 | CUDA_LOGE_RETURN_UNEXPECTED( cudaGetLastError() ); |
| 85 | if ( !reportProgress( cb2, 0.33f ) ) |
| 86 | return unexpectedOperationCanceled(); |
| 87 | |
| 88 | CUDA_LOGE_RETURN_UNEXPECTED( cudaResult.copyTo( results.data() + offset, size ) ); |
| 89 | if ( !reportProgress( cb2, 1.00f ) ) |
| 90 | return unexpectedOperationCanceled(); |
| 91 | } |
| 92 | |
| 93 | return {}; |
| 94 | } |
| 95 | |
| 96 | size_t PointsProjector::projectionsHeapBytes( size_t numProjections ) const |
| 97 | { |
no test coverage detected