crease_cut.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2008                                                \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
00021 *                                                                           *
00022 ****************************************************************************/
00023 
00024 #ifndef __VCG_CREASE_CUT
00025 #define __VCG_CREASE_CUT
00026 #include<vcg/simplex/face/jumping_pos.h>
00027 #include<vcg/complex/algorithms/update/normal.h>
00028 namespace vcg {
00029 namespace tri {
00030 
00034 template<class MESH_TYPE>
00035 void CreaseCut(MESH_TYPE &m, float angleRad)
00036 {
00037   tri::UpdateFlags<MESH_TYPE>::FaceFauxSignedCrease(m, -angleRad, angleRad);
00038   CutMeshAlongNonFauxEdges(m);
00039 }
00040 
00049 template<class MESH_TYPE>
00050 void CutMeshAlongNonFauxEdges(MESH_TYPE &m)
00051 {
00052   typedef typename MESH_TYPE::FaceIterator              FaceIterator;
00053   typedef typename MESH_TYPE::FaceType                          FaceType;
00054   
00055   tri::Allocator<MESH_TYPE>::CompactVertexVector(m);
00056   tri::Allocator<MESH_TYPE>::CompactFaceVector(m);    
00057   tri::RequireFFAdjacency(m);
00058   
00059   tri::UpdateFlags<MESH_TYPE>::VertexClearV(m);
00060   std::vector<int> indVec(m.fn*3,-1);
00061   int newVertexCounter=m.vn;
00062   int startVn=m.vn;
00063   for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
00064   {
00065     for(int j=0;j<3;++j)
00066       if(!(*fi).V(j)->IsV() )  // foreach unvisited vertex we loop around it searching for creases.
00067       {
00068         (*fi).V(j)->SetV();
00069         
00070         face::JumpingPos<FaceType> iPos(&*fi,j,(*fi).V(j));
00071         size_t vertInd = Index(m, iPos.V()); 
00072         bool isBorderVertex = iPos.FindBorder();   // for border vertex we start from the border.
00073         face::JumpingPos<FaceType> startPos=iPos;
00074         if(!isBorderVertex)                        // for internal vertex we search the first crease and start from it
00075         {
00076           do {
00077               bool creaseFlag = !iPos.IsFaux();
00078               iPos.NextFE();
00079               if(creaseFlag) break;
00080           } while (startPos!=iPos);
00081           startPos=iPos;                       // the found crease become the new starting pos.
00082         }
00083         
00084         int locCreaseCounter=0;
00085         int curVertexCounter =vertInd;
00086         
00087         do { // The real Loop          
00088           size_t faceInd = Index(m,iPos.F());
00089           indVec[faceInd*3+ iPos.VInd()] = curVertexCounter;
00090           
00091           if(!iPos.IsFaux()) 
00092           { //qDebug("  Crease FOUND");
00093             ++locCreaseCounter;
00094             curVertexCounter=newVertexCounter;
00095             newVertexCounter++;
00096           }
00097           iPos.NextFE();
00098         } while (startPos!=iPos);
00099         if(locCreaseCounter>0 && (!isBorderVertex) ) newVertexCounter--;
00100         //printf("For vertex %i found %i creases\n",vertInd,locCreaseCounter);
00101       }
00102   } // end foreach face/vert 
00103 
00104   // Now the indVec vector contains for each the new index of each vertex (duplicated as necessary)
00105   // We do a second loop to copy split vertexes into new positions
00106   tri::Allocator<MESH_TYPE>::AddVertices(m,newVertexCounter-m.vn);
00107   
00108   tri::UpdateFlags<MESH_TYPE>::VertexClearV(m);
00109   for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
00110     for(int j=0;j<3;++j) 
00111     {
00112       size_t faceInd = Index(m, *fi);
00113       size_t vertInd = Index(m, (*fi).V(j));
00114       int curVertexInd = indVec[faceInd*3+ j];
00115       assert(curVertexInd != -1);
00116       assert(curVertexInd < m.vn);
00117       if(curVertexInd < startVn) assert(size_t(curVertexInd) == vertInd);
00118       if(curVertexInd >= startVn)
00119       {
00120         m.vert[curVertexInd].ImportData(*((*fi).V(j)));
00121         (*fi).V(j) = & m.vert[curVertexInd];
00122       }
00123     }
00124 }
00125 
00126 } // end namespace tri
00127 } // end namespace vcg
00128 #endif
00129 


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:30:10