From 8b9efe576d7b72fc2ac11eb358dc0fd392bfb4c7 Mon Sep 17 00:00:00 2001 From: cignoni Date: Wed, 27 Jan 2016 22:46:12 +0000 Subject: [PATCH] Added a TrivialMidPoint Refine that always works and do not need any topology... --- vcg/complex/algorithms/refine.h | 57 ++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/vcg/complex/algorithms/refine.h b/vcg/complex/algorithms/refine.h index 93718c7b..f95ed2d3 100644 --- a/vcg/complex/algorithms/refine.h +++ b/vcg/complex/algorithms/refine.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -886,7 +887,6 @@ struct CenterPointBarycenter : public std::unary_function > class TriSplit { @@ -964,6 +964,61 @@ public: } }; // end class TriSplit +template +void TrivialMidPointRefine(MeshType & m) +{ + typedef typename MeshType::VertexIterator VertexIterator; + typedef typename MeshType::FaceIterator FaceIterator; + typedef typename MeshType::VertexPointer VertexPointer; + typedef typename MeshType::FacePointer FacePointer; + + Allocator::CompactEveryVector(m); + int startFn = m.fn; + FaceIterator lastf = tri::Allocator::AddFaces(m,m.fn*3); + VertexIterator lastv = tri::Allocator::AddVertices(m,m.fn*3); + + /* + * v0 + * / \ + * / f0 \ + * / \ + * mp01----------mp02 + * / \ f3 / \ + * / f1 \ / f2 \ + * / \ / \ + *v1 ---------- mp12------------v2 + * + */ + + for(int i=0;iV(0) = v0; f0->V(1) = mp01; f0->V(2) = mp02; + f1->V(0) = v1; f1->V(1) = mp12; f1->V(2) = mp01; + f2->V(0) = v2; f2->V(1) = mp02; f2->V(2) = mp12; + f3->V(0) = mp12; f3->V(1) = mp02; f3->V(2) = mp01; + mp01->P() = (v0>v1) ? (v0->P()+v1->P())/2.0 : (v1->P()+v0->P())/2.0; + mp12->P() = (v1>v2) ? (v1->P()+v2->P())/2.0 : (v2->P()+v1->P())/2.0; + mp02->P() = (v0>v2) ? (v0->P()+v2->P())/2.0 : (v2->P()+v0->P())/2.0; + } + + int vd = tri::Clean::RemoveDuplicateVertex(m); + printf("Vertex unification %i\n",vd); + int vu = tri::Clean::RemoveUnreferencedVertex(m); + printf("Vertex unref %i\n",vu); + Allocator::CompactEveryVector(m); +} + } // namespace tri } // namespace vcg