Skip to content

Commit

Permalink
more timers inside doubleOffsetVdb
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedr committed Sep 17, 2024
1 parent 8cf9ec6 commit c5469aa
Showing 1 changed file with 43 additions and 18 deletions.
61 changes: 43 additions & 18 deletions source/MRVoxels/MRVDBConversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,36 @@ VoidOrErrStr makeSignedByWindingNumber( FloatGrid& grid, const Vector3f& voxelSi
return {};
}

static FloatGrid meshToUnsignedDistanceField_(
const std::vector<openvdb::Vec3s> & points, std::vector<openvdb::Vec3I> & tris, const std::vector<openvdb::Vec4I> & quads,
float surfaceOffset, const ProgressCallback & cb )
{
assert ( surfaceOffset > 0 );
MR_TIMER
openvdb::math::Transform::Ptr xform = openvdb::math::Transform::createLinearTransform();
ProgressInterrupter interrupter( cb );
auto resGrid = MakeFloatGrid( openvdb::tools::meshToUnsignedDistanceField<openvdb::FloatGrid, ProgressInterrupter>
( interrupter, *xform, points, tris, quads, surfaceOffset ) );
if ( interrupter.getWasInterrupted() )
return {};
return resGrid;
}

static FloatGrid meshToLevelSet_(
const std::vector<openvdb::Vec3s> & points, std::vector<openvdb::Vec3I> & tris, const std::vector<openvdb::Vec4I> & quads,
float surfaceOffset, const ProgressCallback & cb )
{
assert ( surfaceOffset > 0 );
MR_TIMER
openvdb::math::Transform::Ptr xform = openvdb::math::Transform::createLinearTransform();
ProgressInterrupter interrupter( cb );
auto resGrid = MakeFloatGrid( openvdb::tools::meshToLevelSet<openvdb::FloatGrid, ProgressInterrupter>
( interrupter, *xform, points, tris, quads, surfaceOffset ) );
if ( interrupter.getWasInterrupted() )
return {};
return resGrid;
}

Expected<Mesh> doubleOffsetVdb( const MeshPart& mp, const DoubleOffsetSettings & settings )
{
MR_TIMER
Expand All @@ -476,7 +506,6 @@ Expected<Mesh> doubleOffsetVdb( const MeshPart& mp, const DoubleOffsetSettings &

std::vector<openvdb::Vec3s> points;
std::vector<openvdb::Vec3I> tris;
std::vector<openvdb::Vec4I> quads;
convertToVDMMesh( mp, AffineXf3f(), Vector3f::diagonal( settings.voxelSize ), points, tris );

if ( !reportProgress( settings.progress, 0.1f ) )
Expand All @@ -485,16 +514,11 @@ Expected<Mesh> doubleOffsetVdb( const MeshPart& mp, const DoubleOffsetSettings &
const bool needSignUpdate = !mp.mesh.topology.isClosed( mp.region );

auto sp = subprogress( settings.progress, 0.1f, needSignUpdate ? 0.2f : 0.3f );
openvdb::math::Transform::Ptr xform = openvdb::math::Transform::createLinearTransform();
ProgressInterrupter interrupter1( sp );
auto grid = MakeFloatGrid(
needSignUpdate ?
openvdb::tools::meshToUnsignedDistanceField<openvdb::FloatGrid, ProgressInterrupter>
( interrupter1, *xform, points, tris, {}, std::abs( offsetInVoxelsA ) + 1 ) :
openvdb::tools::meshToLevelSet<openvdb::FloatGrid, ProgressInterrupter>
( interrupter1, *xform, points, tris, std::abs( offsetInVoxelsA ) + 1 ) );

if ( interrupter1.getWasInterrupted() )
auto grid = needSignUpdate ?
meshToUnsignedDistanceField_( points, tris, {}, std::abs( offsetInVoxelsA ) + 1, sp ) :
meshToLevelSet_( points, tris, {}, std::abs( offsetInVoxelsA ) + 1, sp );

if ( !grid || !reportProgress( sp, 1.0f ) )
return unexpectedOperationCanceled();

if ( needSignUpdate )
Expand All @@ -510,17 +534,18 @@ Expected<Mesh> doubleOffsetVdb( const MeshPart& mp, const DoubleOffsetSettings &
return unexpected( signRes.error() );
}

openvdb::tools::volumeToMesh( *grid, points, tris, quads, offsetInVoxelsA, settings.adaptivity );
std::vector<openvdb::Vec4I> quads;
{
Timer t( "volumeToMesh" );
openvdb::tools::volumeToMesh( *grid, points, tris, quads, offsetInVoxelsA, settings.adaptivity );
}

if ( !reportProgress( settings.progress, 0.5f ) )
return unexpectedOperationCanceled();
sp = subprogress( settings.progress, 0.5f, 0.7f );

ProgressInterrupter interrupter2( sp );
grid = MakeFloatGrid( openvdb::tools::meshToLevelSet<openvdb::FloatGrid, ProgressInterrupter>
( interrupter2, *xform, points, tris, quads, std::abs( offsetInVoxelsB ) + 1 ) );
sp = subprogress( settings.progress, 0.5f, 0.9f );

if ( interrupter2.getWasInterrupted() || !reportProgress( settings.progress, 0.9f ) )
grid = meshToLevelSet_( points, tris, quads, std::abs( offsetInVoxelsB ) + 1, sp );
if ( !grid || !reportProgress( sp, 1.0f ) )
return unexpectedOperationCanceled();

auto expTriMesh = gridToTriMesh( *grid, GridToMeshSettings{
Expand Down

0 comments on commit c5469aa

Please sign in to comment.