From 0e037cabc1215bc69cd04fe5668e3ddd59268245 Mon Sep 17 00:00:00 2001 From: cignoni Date: Thu, 15 Jan 2009 01:31:09 +0000 Subject: [PATCH] added multisampling distance field evaluation --- vcg/complex/trimesh/create/resampler.h | 59 +++++++++++++++++--------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/vcg/complex/trimesh/create/resampler.h b/vcg/complex/trimesh/create/resampler.h index 78f80a57..ce9ba755 100644 --- a/vcg/complex/trimesh/create/resampler.h +++ b/vcg/complex/trimesh/create/resampler.h @@ -92,6 +92,7 @@ template bbox= _bbox; @@ -102,6 +103,7 @@ template IPiToPf(Point3i(x,y,z),testPt); + this->IPfToPf(pp,testPt); vcg::Point3f closestNormV,closestNormF; vcg::Point3f closestPt; @@ -162,7 +164,7 @@ template IsD()); bool retIP; @@ -183,7 +185,7 @@ template fabs(signF)) signBest = signV; @@ -191,34 +193,54 @@ template 0) posCnt ++; + } + if(posCnt<=MultiSample/2) distSum = -distSum; + return field_value(true, distSum/MultiSample); } /// compute the values if an entire slice (per y) distances>dig of a cell are signed with double of /// the distance of the bb void ComputeSliceValues(int slice,field_value *slice_values) { - float dist; for (int i=0; i<=this->siz.X(); i++) { for (int k=0; k<=this->siz.Z(); k++) { int index=GetSliceIndex(i,k); - if (DistanceFromMesh(i,slice,k,_oldM,dist))///compute the distance,inside volume of the mesh is negative - { - //put computed values in the slice values matrix - slice_values[index]=field_value(true,dist); - //end putting values - } - else - slice_values[index]=field_value(false,0); + Point3f pp(i,slice,k); + if(this->MultiSampleFlag) slice_values[index] = MultiDistanceFromMesh(pp,_oldM); + else slice_values[index] = DistanceFromMesh(pp,_oldM); } } //ComputeConsensus(slice,slice_values); } /* - For some reasons it can happens that the sign of the computed distance is not correct. + For some reasons it can happens that the sign of the computed distance could not correct. + this function tries to correct these issues by flipping the isolated voxels with discordant sign */ void ComputeConsensus(int slice, field_value *slice_values) { @@ -574,18 +596,17 @@ typedef Walker /*< Old_Mesh,New_Mesh>*/ MyWalker; typedef vcg::tri::MarchingCubes MyMarchingCubes; ///resample the mesh using marching cube algorithm ,the accuracy is the dimension of one cell the parameter -static void Resample(Old_Mesh &old_mesh,New_Mesh &new_mesh,vcg::Point3 accuracy,float max_dist, float thr=0, bool DiscretizeFlag=false, vcg::CallBackPos *cb=0 ) +static void Resample(Old_Mesh &old_mesh,New_Mesh &new_mesh, Box3f volumeBox, vcg::Point3 accuracy,float max_dist, float thr=0, bool DiscretizeFlag=false, bool MultiSampleFlag=false, vcg::CallBackPos *cb=0 ) { ///be sure that the bounding box is updated vcg::tri::UpdateBounding::Box(old_mesh); - Box3f volumeBox = old_mesh.bbox; - volumeBox.Offset(volumeBox.Diag()/10.0f); MyWalker walker(volumeBox,accuracy); walker.max_dim=max_dist+fabs(thr); walker.offset = - thr; walker.DiscretizeFlag = DiscretizeFlag; + walker.MultiSampleFlag = MultiSampleFlag; MyMarchingCubes mc(new_mesh, walker); walker.BuildMesh(old_mesh,new_mesh,mc,cb); }