diff --git a/vcg/complex/algorithms/voronoi_volume_sampling.h b/vcg/complex/algorithms/voronoi_volume_sampling.h index a1d780b0..e6040401 100644 --- a/vcg/complex/algorithms/voronoi_volume_sampling.h +++ b/vcg/complex/algorithms/voronoi_volume_sampling.h @@ -44,6 +44,7 @@ public: typedef typename MeshType::VertexPointer VertexPointer; typedef typename MeshType::CoordType CoordType; typedef typename MeshType::FacePointer FacePointer; + typedef typename MeshType::FaceType FaceType; typedef typename vcg::GridStaticPtr GridType; typedef SimpleVolume > VVSVolume; @@ -385,7 +386,7 @@ void QuadricRelaxVoronoiSamples(int relaxStep) } -ScalarType ImplicitFunction(const CoordType &p, Param &pp) +ScalarType ImplicitFunction(const CoordType &p, const Param &pp) { CoordType closest; ScalarType surfDist = this->DistanceFromSurface(p,closest); @@ -421,35 +422,128 @@ ScalarType ImplicitFunction(const CoordType &p, Param &pp) * PruningPoisson: mesh of inside and surface points, it's the voronoi3d diagram * n_voxel: number of voxels for the greater side */ -void BuildScaffoldingMesh(MeshType &scaffoldingMesh, Param &pp) +void BuildScaffoldingMeshOld(MeshType &scaffoldingMesh, const Param &pp) { VVSVolume volume; - int sizeX = (baseMesh.bbox.DimX() / pp.voxelSide)+1; - int sizeY = (baseMesh.bbox.DimY() / pp.voxelSide)+1; - int sizeZ = (baseMesh.bbox.DimZ() / pp.voxelSide)+1; - + const Point3i sizInt = Point3i::Construct(baseMesh.bbox.Dim()/pp.voxelSide)+Point3i(1,1,1); int t0=clock(); BoxType bb = BoxType::Construct(baseMesh.bbox); bb.Offset(pp.voxelSide+pp.isoThr*2.0f); - volume.Init(Point3i(sizeX,sizeY,sizeZ),bb); - int cnt=0; - for(ScalarType i=0;i(scaffoldingMesh, volume, mc,0); int t2=clock(); - printf("Fill Volume (%3i %3i %3i) %5.2f\n", sizeX,sizeY,sizeZ,float(t1-t0)/CLOCKS_PER_SEC); + printf("Fill Volume (%3i %3i %3i) %5.2f\n", sizInt[0],sizInt[1],sizInt[2],float(t1-t0)/CLOCKS_PER_SEC); printf("Marching %i tris %5.2f\n", scaffoldingMesh.fn,float(t2-t1)/CLOCKS_PER_SEC); } + +void BuildScaffoldingMesh(MeshType &scaffoldingMesh, const Param &pp) +{ + VVSVolume volume; + const Point3i sizInt = Point3i::Construct(baseMesh.bbox.Dim()/pp.voxelSide)+Point3i(1,1,1); + int t0=clock(); + BoxType bb = BoxType::Construct(baseMesh.bbox); + bb.Offset(pp.voxelSide+pp.isoThr*2.0f); + volume.Init(sizInt,bb); + for(int i=0;i(scaffoldingMesh, volume, mc,0); + int t2=clock(); + printf("Fill Volume (%3i %3i %3i) %5.2f\n", sizInt[0],sizInt[1],sizInt[2],float(t1-t0)/CLOCKS_PER_SEC); + printf("Marching %i tris %5.2f\n", scaffoldingMesh.fn,float(t2-t1)/CLOCKS_PER_SEC); +} + + +void OptimizeIsosurf(MeshType &m, const Param &pp) +{ + int t0=clock(); + int flipCnt=0; + tri::Allocator::CompactEveryVector(m); + tri::UpdateTopology::FaceFace(m); + for(int i=0;iP2(foi))/2.0; + + ScalarType oldVal = ImplicitFunction(midOld,pp); + ScalarType newVal = ImplicitFunction(midNew,pp); + if(fabs(oldVal)-fabs(newVal) > pp.voxelSide/4.0) + { + face::FlipEdge(f,j); + flipCnt++; + } + } + } + } + int t1=clock(); + printf("Optimize Isosurf performed %i edge flip in %5.2f s\n",flipCnt,float(t1-t0)/CLOCKS_PER_SEC); +} + + /** * @brief Compute an evaulation of the thickness as distance from the medial axis. * It starts from a montecarlo volume sampling and try to search for the samples that can be part of the medial axis.