From 682586d0fa3195035c5a57b3a1e5dd6e72083a45 Mon Sep 17 00:00:00 2001 From: cignoni Date: Sun, 12 Jun 2016 21:09:13 +0000 Subject: [PATCH] small change to refactor the use of viewpoint for normal disambiguation --- vcg/complex/algorithms/pointcloud_normal.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/vcg/complex/algorithms/pointcloud_normal.h b/vcg/complex/algorithms/pointcloud_normal.h index e844de4e..c3e958b7 100644 --- a/vcg/complex/algorithms/pointcloud_normal.h +++ b/vcg/complex/algorithms/pointcloud_normal.h @@ -121,10 +121,19 @@ public: if(p.coherentAdjNum==0) return; // tree.setMaxNofNeighbors(p.coherentAdjNum+1); + if(p.useViewPoint) // Simple case use the viewpoint position to determine the right orientation of each point + { + for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi) + { + if ( vi->N().dot(p.viewPoint- vi->P())<0.0f) + vi->N()=-(*vi).N(); + } + return; + } + tri::UpdateFlags::VertexClearV(m); std::vector heap; VertexIterator vi=m.vert.begin(); - while(true) { // search an unvisited vertex @@ -133,10 +142,6 @@ public: if(vi==m.vert.end()) return; - if ( p.useViewPoint && - ( vi->N().dot(p.viewPoint- vi->P())<0.0f) ) - vi->N()=-(*vi).N(); - vi->SetV(); AddNeighboursToHeap(m,&*vi,p.coherentAdjNum,tree,heap); @@ -149,7 +154,6 @@ public: { a.trg->SetV(); if(a.src->cN()*a.trg->cN()<0.0f) - if(!p.useViewPoint || ( a.trg->N().dot(p.viewPoint- a.trg->P())<0.0f)) // test to prevent flipping according to viewpos a.trg->N()=-a.trg->N(); AddNeighboursToHeap(m,a.trg,p.coherentAdjNum,tree,heap); }