| 50 | } |
| 51 | |
| 52 | void PointsToMeshProjector::findProjections( |
| 53 | std::vector<MR::MeshProjectionResult>& res, const std::vector<Vector3f>& points, const AffineXf3f* objXf, const AffineXf3f* refObjXf, float upDistLimitSq, float loDistLimitSq ) |
| 54 | { |
| 55 | MR_TIMER; |
| 56 | if ( !mesh_ ) |
| 57 | { |
| 58 | assert( false ); |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | CUDA_EXEC( cudaSetDevice( 0 ) ); |
| 63 | |
| 64 | const auto getCudaMatrix = [] ( const AffineXf3f& xf ) |
| 65 | { |
| 66 | Matrix4 res; |
| 67 | res.x.x = xf.A.x.x; res.x.y = xf.A.x.y; res.x.z = xf.A.x.z; |
| 68 | res.y.x = xf.A.y.x; res.y.y = xf.A.y.y; res.y.z = xf.A.y.z; |
| 69 | res.z.x = xf.A.z.x; res.z.y = xf.A.z.y; res.z.z = xf.A.z.z; |
| 70 | res.b.x = xf.b.x; res.b.y = xf.b.y; res.b.z = xf.b.z; |
| 71 | res.isIdentity = false; |
| 72 | return res; |
| 73 | }; |
| 74 | |
| 75 | const AffineXf3f* notRigidRefXf{ nullptr }; |
| 76 | if ( refObjXf && !isRigid( refObjXf->A ) ) |
| 77 | notRigidRefXf = refObjXf; |
| 78 | |
| 79 | AffineXf3f xf; |
| 80 | const AffineXf3f* xfPtr{ nullptr }; |
| 81 | if ( notRigidRefXf || !refObjXf ) |
| 82 | xfPtr = objXf; |
| 83 | else |
| 84 | { |
| 85 | xf = refObjXf->inverse(); |
| 86 | if ( objXf ) |
| 87 | xf = xf * ( *objXf ); |
| 88 | xfPtr = &xf; |
| 89 | } |
| 90 | |
| 91 | Matrix4 cudaRefXf; |
| 92 | Matrix4 cudaXf; |
| 93 | if ( notRigidRefXf ) |
| 94 | cudaRefXf = getCudaMatrix( *notRigidRefXf ); |
| 95 | if ( xfPtr ) |
| 96 | cudaXf = getCudaMatrix( *xfPtr ); |
| 97 | |
| 98 | const auto totalSize = points.size(); |
| 99 | const auto bufferSize = maxBufferSize( getCudaSafeMemoryLimit(), totalSize, sizeof( float3 ) + sizeof( MeshProjectionResult ) ); |
| 100 | |
| 101 | DynamicArray<float3> cudaPoints; |
| 102 | cudaPoints.resize( bufferSize ); |
| 103 | |
| 104 | DynamicArray<MeshProjectionResult> cudaResult; |
| 105 | cudaResult.resize( bufferSize ); |
| 106 | res.resize( totalSize ); |
| 107 | |
| 108 | for ( const auto [offset, size] : splitByChunks( totalSize, bufferSize ) ) |
| 109 | { |
nothing calls this directly
no test coverage detected