vcglib icon indicating copy to clipboard operation
vcglib copied to clipboard

function ExtractPolygon in vcg/complex/algorithms/polygon_support.h seems to drop in endless loop

Open Lancelot899 opened this issue 3 years ago • 0 comments

static void ExtractPolygon(typename TriMeshType::FacePointer tfp,
                              std::vector<typename TriMeshType::VertexPointer> &vs,
                              std::vector<typename TriMeshType::FacePointer> &fs)
   {
       vs.clear();
       fs.clear();
       // find a non faux edge
       int se = -1;
       for(int i=0; i<3; i++) if (!( tfp->IsF(i))) { se = i; break;}

       // all faux edges return an empty vertex vector!
       if(se==-1) return;
       if(tfp->IsV()) return;

       // initialize a pos on the first non faux edge
       face::Pos<typename TriMeshType::FaceType> start(tfp,se,tfp->V(se));
       face::Pos<typename TriMeshType::FaceType> p(start);

       fs.push_back(p.F());
       p.F()->SetV();

       do
       {
           assert(!p.F()->IsF(p.E()));
           vs.push_back(p.V());
           p.FlipE();

           /////   _
           ///  /_\ /_\
           ///  \ /_\ / 
           ////   \ /
           /// left to right,top to bottom,anti-clockwise
           ///  f0(0, 1, 2) f1(2, 1, 3) f2(3, 1, 4)
           ///  f3(1, 0, 5) f4(1, 5, 6) f5(6, 1, 4)
           ///              f6(6, 5, 7)
           /// 
           /// assume fid = 4, vid = 1
           /// initial se = 0,stand edge : 1->5, then pos(4, 0, 0)
           ///  p.FlipE() --> pos(4, 2, 0)  stands f4 :  6->1
           ///  **seems to drop in endless loop**
           while( p.F()->IsF(p.E()) )
           {
             /// pos(5, 0, 1) f5 : 6->1 --- loop0
             /// pos(2, 1, 1) f2 : 1->4 --- loop1
             /// pos(1, 2, 0) f1 : 3->1 --- loop2
             /// pos(0, 1, 1) f0 : 1->2 --- loop3
             /// pos(3, 1, 0) f3 : 0->1 --- loop4
               p.FlipF();
               if(!p.F()->IsV()) {
                 fs.push_back(p.F());
                 p.F()->SetV();
               }
               /// pos(5, 1, 1) f5 : 1->4 ---loop0
               /// pos(2, 0, 1) f2 : 3->1 --- loop1
               /// pos(1, 0, 1) f1 : 1->2 --- loop2
               /// pos(0, 0, 1) f0 : 0->1 --- loop3
               /// pos(3, 0, 0) f3 : 1->5 --- loop4
               p.FlipE();
           }
           p.FlipV();
       } while(p!=start);
       //assert(vs.size() == fs.size()+2);
   }

Lancelot899 avatar Jul 03 '21 15:07 Lancelot899