@@ -1647,7 +1647,7 @@ float Tool::estimateVoxelSize(int maxDim, float halfWidth, int geo_age)
16471647 throw std::invalid_argument (" estimateVoxelSize: invalid maxDim" );
16481648 }
16491649 const auto d = bbox.extents ()[bbox.maxExtent ()];// longest extent of bbox along any coordinate axis
1650- return static_cast <float >(static_cast <float >(d)/static_cast <float >(maxDim - static_cast <int >(2 .f * halfWidth)));
1650+ return static_cast <float >(static_cast <double >(d)/static_cast <double >(maxDim - static_cast <int >(2 .f * halfWidth)));
16511651}// Tool::estimateVoxelSize
16521652
16531653// ==============================================================================================================
@@ -1692,28 +1692,31 @@ void Tool::meshToLevelSet()
16921692// ==============================================================================================================
16931693
16941694// vdb_tool -read ~/dev/data/ply/cube.ply -soup2ls dim=64 lod=4 erode=5 -o vdb="*" stdout.vdb | vdb_view
1695- // ./openvdb_cmd/vdb_tool/vdb_tool -i ~/dev/data/obj/Robot_arm.obj -soup2ls voxel=51 .2 lod=8 erode=16 -print -o codec=blosc openvdb_10.vdb
1695+ // ./openvdb_cmd/vdb_tool/vdb_tool -i ~/dev/data/obj/Robot_arm.obj -soup2ls voxel=0 .2 lod=8 erode=16 -print -o codec=blosc openvdb_10.vdb
16961696void Tool::soupToLevelSet ()
16971697{
16981698 const std::string &name = mParser .getAction ().name ;
16991699 OPENVDB_ASSERT (name == " soup2ls" );
17001700 try {
17011701 mParser .printAction ();
1702- const int dim = mParser .get <int >(" dim" );// initial dimension
1703- float voxel = mParser .get <float >(" voxel" );// initial voxel size
1702+ const int dim = mParser .get <int >(" dim" );// final dimension
1703+ float voxel = mParser .get <float >(" voxel" );// final voxel size
17041704 const float width = mParser .get <float >(" width" );
17051705 const int geo_age = mParser .get <int >(" geo" );
17061706 const int nErode = mParser .get <int >(" erode" );
17071707 const int nLOD = mParser .get <int >(" lod" );
17081708 const bool keep = mParser .get <bool >(" keep" );
17091709 std::string grid_name = mParser .get <std::string>(" name" );
1710- if (voxel == 0 .0f ) voxel = this ->estimateVoxelSize (dim, width, geo_age);
1710+ if (voxel == 0 .0f ) {
1711+ voxel = this ->estimateVoxelSize (dim, width, geo_age);
1712+ std::cerr << " estimated voxel size = " << voxel << " from dim = " << dim << std::endl;
1713+ }
17111714 auto it = this ->getGeom (geo_age);
17121715 const Geometry &mesh = **it;
17131716 if (mesh.isPoints ()) this ->warning (" Warning: -soup2ls was called on points, not a mesh! Hint: use -points2ls instead!" );
17141717 bool isSDF = false ;
17151718 util::CpuTimer timer;
1716- double t_offset = 0.0 , t_erode = 0.0 , t_upsample = 0.0 ;// all in milliseconds
1719+ double t_offset = 0.0 , t_deform = 0.0 , t_upscale = 0.0 ;// all in milliseconds
17171720
17181721 auto myUpsample = [&](const GridT &grid)->GridT ::Ptr{
17191722 timer.start ();
@@ -1726,7 +1729,7 @@ void Tool::soupToLevelSet()
17261729#else
17271730 GridT::Ptr outGrid = createLevelSet<GridT>(dx/2 , width);
17281731 tools::resampleToMatch<tools::BoxSampler>(grid, *outGrid);
1729- t_upsample += timer.milliseconds ();
1732+ t_upscale += timer.milliseconds ();
17301733 return outGrid;
17311734#endif
17321735 };// myUpsample
@@ -1780,18 +1783,18 @@ void Tool::soupToLevelSet()
17801783 filter->offset (dx);// erode by dx
17811784 isSDF = false ;// the next CSG operation will mess up the SDF
17821785 auto tmp = tools::csgUnionCopy (grid, gridB);
1783- t_erode += timer.milliseconds ();
1786+ t_deform += timer.milliseconds ();
17841787 return tmp;
17851788 };// myLevelSetDeform
17861789
17871790 if (mParser .verbose ) mTimer .start (" Soup -> SDF" );
17881791
17891792 // Main algorithm
1790- float dx = voxel, target_dx = dx / pow (2 , nLOD) ; // lets use the same notation for the voxel size as the paper
1793+ float dx = voxel * pow (2 , nLOD);
17911794 auto grid = myOffset (dx);
17921795 // grid->setName("soup2ls_"+std::to_string(dx));
17931796 // mGrid.push_back(grid);
1794- while (dx > target_dx ) {
1797+ while (dx > voxel ) {
17951798 dx *= 0 .5f ;// refinement
17961799 grid = myUpsample (*grid);
17971800 auto base = myOffset (dx);
@@ -1800,14 +1803,14 @@ void Tool::soupToLevelSet()
18001803 // mGrid.push_back(grid);
18011804 }
18021805 // grid = tools::levelSetRebuild(*grid, /*iso-value=*/0.0f, width);// SDF -> mesh -> SDF
1803- if (dx!=target_dx ) std::cerr << " dx = " << dx << " , target_dx = " << target_dx << std::endl;
1804- t_offset /= 1000.0 ;
1805- t_erode /= 1000.0 ;
1806- t_upsample /= 1000.0 ;
1807- std::cerr << " offset = " << t_offset
1808- << " s, erode = " << t_erode
1809- << " s, upsample = " << t_upsample
1810- << " s, total = " << (t_offset + t_erode + t_upsample ) << " s\n " ;
1806+ if (dx!=voxel ) std::cerr << " dx = " << dx << " , expected dx = " << voxel << std::endl;
1807+ t_offset /= 1000.0 ;
1808+ t_deform /= 1000.0 ;
1809+ t_upscale /= 1000.0 ;
1810+ std::cerr << " upsample = " << t_upscale
1811+ << " s, offset = " << t_offset
1812+ << " s, deform = " << t_deform
1813+ << " s, total = " << (t_offset + t_deform + t_upscale ) << " s\n " ;
18111814
18121815 if (grid_name.empty ()) grid_name = " soup2ls_" + mesh.getName ();
18131816 grid->setName (grid_name);
0 commit comments