From 9609fd94e35c7846ea41d13478c46d260d326673 Mon Sep 17 00:00:00 2001 From: cDc Date: Wed, 6 Nov 2024 14:41:53 +0200 Subject: [PATCH] mesh: finetune params for thin structures (cherry picked from commit c02207b1aec03dee83e30d41e786d972646f7aaf) --- apps/ReconstructMesh/ReconstructMesh.cpp | 6 +++--- libs/MVS/Mesh.cpp | 18 +++++++----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/apps/ReconstructMesh/ReconstructMesh.cpp b/apps/ReconstructMesh/ReconstructMesh.cpp index 7d3e9853a..54584267f 100644 --- a/apps/ReconstructMesh/ReconstructMesh.cpp +++ b/apps/ReconstructMesh/ReconstructMesh.cpp @@ -128,7 +128,7 @@ bool Application::Initialize(size_t argc, LPCTSTR* argv) ("input-file,i", boost::program_options::value(&OPT::strInputFileName), "input filename containing camera poses and image list") ("pointcloud-file,p", boost::program_options::value(&OPT::strPointCloudFileName), "dense point-cloud with views file name to reconstruct (overwrite existing point-cloud)") ("output-file,o", boost::program_options::value(&OPT::strOutputFileName), "output filename for storing the mesh") - ("min-point-distance,d", boost::program_options::value(&OPT::fDistInsert)->default_value(2.5f), "minimum distance in pixels between the projection of two 3D points to consider them different while triangulating (0 - disabled)") + ("min-point-distance,d", boost::program_options::value(&OPT::fDistInsert)->default_value(1.5f), "minimum distance in pixels between the projection of two 3D points to consider them different while triangulating (0 - disabled)") ("integrate-only-roi", boost::program_options::value(&OPT::bUseOnlyROI)->default_value(false), "use only the points inside the ROI") ("constant-weight", boost::program_options::value(&OPT::bUseConstantWeight)->default_value(true), "considers all view weights 1 instead of the available weight") ("free-space-support,f", boost::program_options::value(&OPT::bUseFreeSpaceSupport)->default_value(false), "exploits the free-space support in order to reconstruct weakly-represented surfaces") @@ -474,8 +474,8 @@ int main(int argc, LPCTSTR* argv) numVertices-scene.mesh.vertices.size(), numFaces-scene.mesh.faces.size(), TD_TIMER_GET_FMT().c_str()); } const float fDecimate(OPT::nTargetFaceNum ? static_cast(OPT::nTargetFaceNum) / scene.mesh.faces.size() : OPT::fDecimateMesh); - scene.mesh.Clean(fDecimate, OPT::fRemoveSpurious, OPT::bRemoveSpikes, OPT::nCloseHoles, OPT::nSmoothMesh, OPT::fEdgeLength, false); - scene.mesh.Clean(1.f, 0.f, OPT::bRemoveSpikes, OPT::nCloseHoles, 0u, 0.f, false); // extra cleaning trying to close more holes + scene.mesh.Clean(1.f, OPT::fRemoveSpurious, OPT::bRemoveSpikes, OPT::nCloseHoles, OPT::nSmoothMesh, OPT::fEdgeLength, false); + scene.mesh.Clean(fDecimate, 0.f, OPT::bRemoveSpikes, OPT::nCloseHoles, 0u, 0.f, false); // extra cleaning trying to close more holes scene.mesh.Clean(1.f, 0.f, false, 0u, 0u, 0.f, true); // extra cleaning to remove non-manifold problems created by closing holes scene.obb = initialOBB; diff --git a/libs/MVS/Mesh.cpp b/libs/MVS/Mesh.cpp index 0ef88716a..65eda30d6 100644 --- a/libs/MVS/Mesh.cpp +++ b/libs/MVS/Mesh.cpp @@ -848,26 +848,22 @@ void Mesh::Clean(float fDecimate, float fSpurious, bool bRemoveSpikes, unsigned // remove spurious components if (fSpurious > 0) { FloatArr edgeLens(0, mesh.EN()); - for (CLEAN::Mesh::EdgeIterator ei=mesh.edge.begin(); ei!=mesh.edge.end(); ++ei) { - const CLEAN::Vertex::CoordType& P0((*ei).V(0)->P()); - const CLEAN::Vertex::CoordType& P1((*ei).V(1)->P()); - edgeLens.Insert((P1-P0).Norm()); + for (CLEAN::Mesh::EdgeType& edge: mesh.edge) { + const CLEAN::Vertex::CoordType& P1(edge.V(1)->P()); + const CLEAN::Vertex::CoordType& P0(edge.V(0)->P()); + edgeLens.Insert((P1-P0).SquaredNorm()); } - #if 0 - const auto ret(ComputeX84Threshold(edgeLens.Begin(), edgeLens.size(), 3.f*fSpurious)); - const float thLongEdge(ret.first+ret.second); - #else - const float thLongEdge(edgeLens.GetNth(edgeLens.size()*95/100)*fSpurious); - #endif // remove faces with too long edges + const float thLongEdge(SQRT(edgeLens.GetNth(edgeLens.size()*95/100))*fSpurious); const size_t numLongFaces(vcg::tri::UpdateSelection::FaceOutOfRangeEdge(mesh, 0, thLongEdge)); for (CLEAN::Mesh::FaceIterator fi=mesh.face.begin(); fi!=mesh.face.end(); ++fi) if (!(*fi).IsD() && (*fi).IsS()) vcg::tri::Allocator::DeleteFace(mesh, *fi); DEBUG_ULTIMATE("Removed %d faces with edges longer than %f", numLongFaces, thLongEdge); // remove isolated components + const float thLongSize(SQRT(edgeLens.GetNth(edgeLens.size()*55/100))*fSpurious); vcg::tri::UpdateTopology::FaceFace(mesh); - const std::pair delInfo(vcg::tri::Clean::RemoveSmallConnectedComponentsDiameter(mesh, thLongEdge)); + const std::pair delInfo(vcg::tri::Clean::RemoveSmallConnectedComponentsDiameter(mesh, thLongSize)); DEBUG_ULTIMATE("Removed %d connected components out of %d", delInfo.second, delInfo.first); }