MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / calcFromGrid

Method calcFromGrid

source/MRCuda/MRCudaFastWindingNumber.cpp:175–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

173}
174
175Expected<void> FastWindingNumber::calcFromGrid( std::vector<float>& res, const Vector3i& dims, const AffineXf3f& gridToMeshXf, float beta, const ProgressCallback& cb )
176{
177 MR_TIMER;
178 if ( auto maybe = prepareData_( subprogress( cb, 0.0, 0.5f ) ); !maybe )
179 return unexpected( std::move( maybe.error() ) );
180
181 const auto getCudaMatrix = [] ( const AffineXf3f& xf )
182 {
183 Matrix4 res;
184 res.x.x = xf.A.x.x; res.x.y = xf.A.x.y; res.x.z = xf.A.x.z;
185 res.y.x = xf.A.y.x; res.y.y = xf.A.y.y; res.y.z = xf.A.y.z;
186 res.z.x = xf.A.z.x; res.z.y = xf.A.z.y; res.z.z = xf.A.z.z;
187 res.b.x = xf.b.x; res.b.y = xf.b.y; res.b.z = xf.b.z;
188 res.isIdentity = false;
189 return res;
190 };
191 const Matrix4 cudaGridToMeshXf = ( gridToMeshXf == AffineXf3f{} ) ? Matrix4{} : getCudaMatrix( gridToMeshXf );
192
193 const auto totalSize = (size_t)dims.x * dims.y * dims.z;
194 const auto bufferSize = maxBufferSizeAlignedByBlock( getCudaSafeMemoryLimit(), dims, sizeof( float ) );
195
196 DynamicArrayF cudaResult;
197 CUDA_LOGE_RETURN_UNEXPECTED( cudaResult.resize( bufferSize ) );
198 if ( !reportProgress( cb, 0.6f ) )
199 return unexpectedOperationCanceled();
200
201 const auto cb1 = subprogress( cb, 0.60f, 1.00f );
202 const auto iterCount = chunkCount( totalSize, bufferSize );
203 size_t iterIndex = 0;
204
205 for ( const auto [offset, size] : splitByChunks( totalSize, bufferSize ) )
206 {
207 const auto cb2 = subprogress( cb1, iterIndex++, iterCount );
208
209 fastWindingNumberFromGrid(
210 int3 { dims.x, dims.y, dims.z },
211 cudaGridToMeshXf,
212 data_->toData(),
213 cudaResult.data(),
214 beta,
215 size,
216 offset
217 );
218 CUDA_LOGE_RETURN_UNEXPECTED( cudaGetLastError() );
219 if ( !reportProgress( cb2, 0.25f ) )
220 return unexpectedOperationCanceled();
221
222 CUDA_LOGE_RETURN_UNEXPECTED( cudaResult.copyTo( res.data() + offset, size ) );
223 if ( !reportProgress( cb2, 1.00f ) )
224 return unexpectedOperationCanceled();
225 }
226
227 return {};
228}
229
230Expected<void> FastWindingNumber::calcFromGridWithDistances( std::vector<float>& res, const Vector3i& dims, const AffineXf3f& gridToMeshXf, const DistanceToMeshOptions& options, const ProgressCallback& cb )
231{

Callers

nothing calls this directly

Calls 13

subprogressFunction · 0.85
getCudaSafeMemoryLimitFunction · 0.85
reportProgressFunction · 0.85
chunkCountFunction · 0.85
splitByChunksFunction · 0.85
errorMethod · 0.80
toDataMethod · 0.80
copyToMethod · 0.80
unexpectedFunction · 0.50
resizeMethod · 0.45

Tested by

no test coverage detected