| 14 | { |
| 15 | |
| 16 | Expected<DistanceMap> computeDistanceMap( const MR::Mesh& mesh, const MR::MeshToDistanceMapParams& params, ProgressCallback cb /*= {}*/, std::vector<MR::MeshTriPoint>* outSamples /*= nullptr */ ) |
| 17 | { |
| 18 | MR_TIMER; |
| 19 | |
| 20 | if ( params.resolution.x <= 0 || params.resolution.y <= 0 ) |
| 21 | return {}; |
| 22 | |
| 23 | DistanceMap distMap( params.resolution.x, params.resolution.y ); |
| 24 | |
| 25 | // precomputed some values |
| 26 | MR::IntersectionPrecomputes<double> prec( Vector3d( params.direction ) ); |
| 27 | |
| 28 | auto ori = params.orgPoint; |
| 29 | float shift = 0.f; |
| 30 | if ( params.allowNegativeValues ) |
| 31 | { |
| 32 | AffineXf3f xf( Matrix3f( params.xRange.normalized(), params.yRange.normalized(), params.direction.normalized() ), Vector3f() ); |
| 33 | Box3f box = mesh.computeBoundingBox( &xf ); |
| 34 | shift = dot( params.direction, ori - box.min ); |
| 35 | if ( shift > 0.f ) |
| 36 | { |
| 37 | ori -= params.direction * shift; |
| 38 | } |
| 39 | else |
| 40 | { |
| 41 | shift = 0.0f; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | if ( !reportProgress( cb, 0.1f ) ) |
| 46 | return unexpectedOperationCanceled(); |
| 47 | |
| 48 | const AABBTree& tree = mesh.getAABBTree(); |
| 49 | const auto& nodes = tree.nodes(); |
| 50 | const auto& meshPoints = mesh.points; |
| 51 | const auto tris = mesh.topology.getTriangulation(); |
| 52 | |
| 53 | DynamicArray<float3> cudaMeshPoints; |
| 54 | CUDA_LOGE_RETURN_UNEXPECTED( cudaMeshPoints.fromVector( meshPoints.vec_ ) ); |
| 55 | |
| 56 | DynamicArray<Node3> cudaNodes; |
| 57 | CUDA_LOGE_RETURN_UNEXPECTED( cudaNodes.fromVector( nodes.vec_ ) ); |
| 58 | |
| 59 | DynamicArray<FaceToThreeVerts> cudaFaces; |
| 60 | CUDA_LOGE_RETURN_UNEXPECTED( cudaFaces.fromVector( tris.vec_ ) ); |
| 61 | |
| 62 | MeshToDistanceMapParams cudaParams { |
| 63 | .xRange = { params.xRange.x, params.xRange.y, params.xRange.z }, |
| 64 | .yRange = { params.yRange.x, params.yRange.y, params.yRange.z }, |
| 65 | .direction = { params.direction.x, params.direction.y, params.direction.z }, |
| 66 | .orgPoint = { ori.x, ori.y, ori.z }, |
| 67 | .resolution = { params.resolution.x, params.resolution.y }, |
| 68 | .minValue = params.minValue, |
| 69 | .maxValue = params.maxValue, |
| 70 | .useDistanceLimits = params.useDistanceLimits, |
| 71 | .allowNegativeValues = params.allowNegativeValues, |
| 72 | }; |
| 73 |
nothing calls this directly
no test coverage detected