From cb2d0752dff0548376f5a5b1345d59861bc21fed Mon Sep 17 00:00:00 2001 From: Paolo Cignoni cignoni Date: Tue, 25 Oct 2016 22:07:46 +0000 Subject: [PATCH] Cleaning messages and parameters --- .../filter_screened_poisson.cpp | 107 ++++++++++-------- .../filter_screened_poisson.xml | 22 ++-- 2 files changed, 67 insertions(+), 62 deletions(-) diff --git a/src/meshlabplugins/filter_screened_poisson/filter_screened_poisson.cpp b/src/meshlabplugins/filter_screened_poisson/filter_screened_poisson.cpp index 40fa5dcd0..55a1f4ef6 100644 --- a/src/meshlabplugins/filter_screened_poisson/filter_screened_poisson.cpp +++ b/src/meshlabplugins/filter_screened_poisson/filter_screened_poisson.cpp @@ -149,7 +149,7 @@ public: Real SamplesPerNodeVal; Real ScaleVal; bool ConfidenceFlag; - bool NormalWeightsFlag; + bool CleanFlag; bool DensityFlag; Real PointWeightVal; int AdaptiveExponentVal; @@ -177,7 +177,7 @@ public: SamplesPerNodeVal =1.5f; ScaleVal=1.1f; ConfidenceFlag=false; - NormalWeightsFlag=false; + CleanFlag=false; DensityFlag=false; PointWeightVal = 4.0f; AdaptiveExponentVal=1; @@ -504,9 +504,9 @@ int _Execute(OrientedPointStream< Real > *pointStream, Box3m bb, CMeshO &pm, Poi Point3D pp = iXForm*pt->point; vcg::tri::Allocator::AddVertex(pm,Point3m(pp[0],pp[1],pp[2])); pm.vert.back().Q() = pt->value; - pm.vert.back().C()[0] = pt->color[0]*255.0; - pm.vert.back().C()[1] = pt->color[1]*255.0; - pm.vert.back().C()[2] = pt->color[2]*255.0; + pm.vert.back().C()[0] = pt->color[0]; + pm.vert.back().C()[1] = pt->color[1]; + pm.vert.back().C()[2] = pt->color[2]; } for (int ii=0; ii < mesh.outOfCorePointCount(); ii++){ Vertex pt; @@ -514,9 +514,9 @@ int _Execute(OrientedPointStream< Real > *pointStream, Box3m bb, CMeshO &pm, Poi Point3D pp = iXForm*pt.point; vcg::tri::Allocator::AddVertex(pm,Point3m(pp[0],pp[1],pp[2])); pm.vert.back().Q() = pt.value; - pm.vert.back().C()[0] = pt.color[0]*1.0; - pm.vert.back().C()[1] = pt.color[1]*1.0; - pm.vert.back().C()[2] = pt.color[2]*1.0; + pm.vert.back().C()[0] = pt.color[0]; + pm.vert.back().C()[1] = pt.color[1]; + pm.vert.back().C()[2] = pt.color[2]; } std::vector< CoredVertexIndex > polygon; @@ -545,16 +545,17 @@ int _Execute(OrientedPointStream< Real > *pointStream, Box3m bb, CMeshO &pm, Poi template -void PoissonClean(MeshType &m, bool scaleNormal) +void PoissonClean(MeshType &m, bool scaleNormal, bool cleanFlag) { - - if(m.face.size()>0) - vcg::tri::Clean::RemoveUnreferencedVertex(m); + if(cleanFlag) { + if(m.face.size()>0) + vcg::tri::Clean::RemoveUnreferencedVertex(m); + } vcg::tri::Allocator::CompactEveryVector(m); vcg::tri::UpdateNormal::NormalizePerVertex(m); if(scaleNormal) { - for(typename MeshType::VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi) + for(auto vi=m.vert.begin();vi!=m.vert.end();++vi) vi->N() *= vi->Q(); } } @@ -562,7 +563,7 @@ void PoissonClean(MeshType &m, bool scaleNormal) bool HasGoodNormal(CMeshO &m) { for(auto vi=m.vert.begin();vi!=m.vert.end();++vi) - if(vcg::SquaredNorm(vi->N()) < std::numeric_limits::min()) + if(vcg::SquaredNorm(vi->N()) < std::numeric_limits::min()*10.0) return false; return true; @@ -572,36 +573,7 @@ bool FilterScreenedPoissonPlugin::applyFilter( const QString& filterName,MeshDoc { if (filterName == "Screened Poisson Surface Reconstruction") { - MeshModel *mm =md.mm(); PoissonParam pp; - bool goodNormal=true, goodColor=true; - if(env.evalBool("visibleLayer") == false) { - goodNormal=HasGoodNormal(md.mm()->cm); - goodColor = md.mm()->hasDataMask(MeshModel::MM_VERTCOLOR); - } else{ - MeshModel *_mm=0; - while(_mm=md.nextVisibleMesh(_mm)) { - goodNormal &= HasGoodNormal(_mm->cm); - goodColor &= _mm->hasDataMask(MeshModel::MM_VERTCOLOR); - - } - } - - if(!goodNormal) - { - this->errorMessage = "Filter requires correct per vertex normals\n that your point could has a proper, not-null, normal for each sample"; - return false; - } - - MeshModel *pm =md.addNewMesh("","Poisson mesh",false); - md.setVisible(pm->id(),false); - pm->updateDataMask(MeshModel::MM_VERTQUALITY); - if(goodColor) pm->updateDataMask(MeshModel::MM_VERTCOLOR); - - - MeshModelPointStream meshStream(mm->cm); - MeshDocumentPointStream documentStream(md); - pp.MaxDepthVal = env.evalInt("depth"); pp.FullDepthVal = env.evalInt("fullDepth"); pp.CGDepthVal= env.evalInt("cgDepth"); @@ -610,20 +582,55 @@ bool FilterScreenedPoissonPlugin::applyFilter( const QString& filterName,MeshDoc pp.PointWeightVal = env.evalFloat("pointWeight"); pp.ItersVal = env.evalInt("iters"); pp.ConfidenceFlag = env.evalBool("confidence"); - pp.NormalWeightsFlag = env.evalBool("nWeights"); pp.DensityFlag = true; + pp.CleanFlag = env.evalBool("preClean"); + + bool goodNormal=true, goodColor=true; + if(env.evalBool("visibleLayer") == false) + { + PoissonClean(md.mm()->cm, pp.ConfidenceFlag, pp.CleanFlag); + goodNormal=HasGoodNormal(md.mm()->cm); + goodColor = md.mm()->hasDataMask(MeshModel::MM_VERTCOLOR); + } + else + { + MeshModel *_mm=0; + while(_mm=md.nextVisibleMesh(_mm)) { + PoissonClean(_mm->cm, pp.ConfidenceFlag, pp.CleanFlag); + goodNormal &= HasGoodNormal(_mm->cm); + goodColor &= _mm->hasDataMask(MeshModel::MM_VERTCOLOR); + } + } + + if(!goodNormal) + { + this->errorMessage = "Filter requires correct per vertex normals.
" + "E.g. it is necessary that your ALL the input vertices have a proper, not-null normal.
" + "If you enconuter this error on a triangulated mesh try to use the Remove Unreferenced Vertices " + "filter (usually unreferenced vertices on surfaces have null normals).
" + "Enabling the Cleaning option also works."; + return false; + } + + MeshModel *pm =md.addNewMesh("","Poisson mesh",false); + md.setVisible(pm->id(),false); + pm->updateDataMask(MeshModel::MM_VERTQUALITY); + if(goodColor) pm->updateDataMask(MeshModel::MM_VERTCOLOR); + if(env.evalBool("visibleLayer")) { - MeshModel *m=0; - while((m=md.nextVisibleMesh(m))) - PoissonClean(m->cm, (pp.ConfidenceFlag || pp.NormalWeightsFlag)); - Box3m bb = md.bbox(); + Box3m bb; + MeshModel *_mm=0; + while(_mm=md.nextVisibleMesh(_mm)) + bb.Add(_mm->cm.Tr,_mm->cm.bbox); + + MeshDocumentPointStream documentStream(md); _Execute >(&documentStream,bb,pm->cm,pp,cb); } else { - PoissonClean(mm->cm, (pp.ConfidenceFlag || pp.NormalWeightsFlag)); - _Execute >(&meshStream,mm->cm.bbox,pm->cm,pp,cb); + MeshModelPointStream meshStream(md.mm()->cm); + _Execute >(&meshStream,md.mm()->cm.bbox,pm->cm,pp,cb); } pm->UpdateBoxAndNormals(); md.setVisible(pm->id(),true); diff --git a/src/meshlabplugins/filter_screened_poisson/filter_screened_poisson.xml b/src/meshlabplugins/filter_screened_poisson/filter_screened_poisson.xml index e0752a2f6..f4c5862ae 100644 --- a/src/meshlabplugins/filter_screened_poisson/filter_screened_poisson.xml +++ b/src/meshlabplugins/filter_screened_poisson/filter_screened_poisson.xml @@ -2,8 +2,7 @@ The filter uses the original code of Michael Kazhdan and Matthew Bolitho implementing the algorithm described in the following paper:
Michael Kazhdan, Hugues Hoppe,
"Screened Poisson surface reconstruction"
@@ -34,18 +33,18 @@ ACM Trans. Graphics, 32(3), 2013
The default value for this parameter is 0.]]> - + - + + The default value is 1.5.]]> @@ -55,22 +54,21 @@ ACM Trans. Graphics, 32(3), 2013
The default value for this parameter is 4.]]> - + - - - - + + +