| 228 | } |
| 229 | |
| 230 | Expected<void> FastWindingNumber::calcFromGridWithDistances( std::vector<float>& res, const Vector3i& dims, const AffineXf3f& gridToMeshXf, const DistanceToMeshOptions& options, const ProgressCallback& cb ) |
| 231 | { |
| 232 | MR_TIMER; |
| 233 | if ( auto maybe = prepareData_( subprogress( cb, 0.0, 0.5f ) ); !maybe ) |
| 234 | return unexpected( std::move( maybe.error() ) ); |
| 235 | |
| 236 | const auto getCudaMatrix = [] ( const AffineXf3f& xf ) |
| 237 | { |
| 238 | Matrix4 res; |
| 239 | res.x.x = xf.A.x.x; res.x.y = xf.A.x.y; res.x.z = xf.A.x.z; |
| 240 | res.y.x = xf.A.y.x; res.y.y = xf.A.y.y; res.y.z = xf.A.y.z; |
| 241 | res.z.x = xf.A.z.x; res.z.y = xf.A.z.y; res.z.z = xf.A.z.z; |
| 242 | res.b.x = xf.b.x; res.b.y = xf.b.y; res.b.z = xf.b.z; |
| 243 | res.isIdentity = false; |
| 244 | return res; |
| 245 | }; |
| 246 | const Matrix4 cudaGridToMeshXf = ( gridToMeshXf == AffineXf3f{} ) ? Matrix4{} : getCudaMatrix( gridToMeshXf ); |
| 247 | |
| 248 | const auto totalSize = (size_t)dims.x * dims.y * dims.z; |
| 249 | const auto bufferSize = maxBufferSizeAlignedByBlock( getCudaSafeMemoryLimit(), dims, sizeof( float ) ); |
| 250 | |
| 251 | DynamicArrayF cudaResult; |
| 252 | CUDA_LOGE_RETURN_UNEXPECTED( cudaResult.resize( bufferSize ) ); |
| 253 | if ( !reportProgress( cb, 0.6f ) ) |
| 254 | return unexpectedOperationCanceled(); |
| 255 | |
| 256 | const auto cb1 = subprogress( cb, 0.60f, 1.00f ); |
| 257 | const auto iterCount = chunkCount( totalSize, bufferSize ); |
| 258 | size_t iterIndex = 0; |
| 259 | |
| 260 | for ( const auto [offset, size] : splitByChunks( totalSize, bufferSize ) ) |
| 261 | { |
| 262 | const auto cb2 = subprogress( cb1, iterIndex++, iterCount ); |
| 263 | |
| 264 | signedDistance( |
| 265 | int3 { dims.x, dims.y, dims.z }, |
| 266 | cudaGridToMeshXf, |
| 267 | data_->toData(), |
| 268 | cudaResult.data(), |
| 269 | size, |
| 270 | offset, |
| 271 | options |
| 272 | ); |
| 273 | CUDA_LOGE_RETURN_UNEXPECTED( cudaGetLastError() ); |
| 274 | if ( !reportProgress( cb2, 0.25f ) ) |
| 275 | return unexpectedOperationCanceled(); |
| 276 | |
| 277 | CUDA_LOGE_RETURN_UNEXPECTED( cudaResult.copyTo( res.data() + offset, size ) ); |
| 278 | if ( !reportProgress( cb2, 1.00f ) ) |
| 279 | return unexpectedOperationCanceled(); |
| 280 | } |
| 281 | |
| 282 | return {}; |
| 283 | } |
| 284 | |
| 285 | Expected<void> FastWindingNumber::calcFromGridByParts( GridByPartsFunc resFunc, const Vector3i& dims, const AffineXf3f& gridToMeshXf, float beta, int layerOverlap, const ProgressCallback& cb ) |
| 286 | { |
nothing calls this directly
no test coverage detected