00001 #ifndef RINGWALKER_H 00002 #define RINGWALKER_H 00003 00004 /**************************************************************************** 00005 * VCGLib o o * 00006 * Visual and Computer Graphics Library o o * 00007 * _ O _ * 00008 * Copyright(C) 2004 \/)\/ * 00009 * Visual Computing Lab /\/| * 00010 * ISTI - Italian National Research Council | * 00011 * \ * 00012 * All rights reserved. * 00013 * * 00014 * This program is free software; you can redistribute it and/or modify * 00015 * it under the terms of the GNU General Public License as published by * 00016 * the Free Software Foundation; either version 2 of the License, or * 00017 * (at your option) any later version. * 00018 * * 00019 * This program is distributed in the hope that it will be useful, * 00020 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00022 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * 00023 * for more details. * 00024 * * 00025 ****************************************************************************/ 00026 00027 #include <vcg/simplex/face/jumping_pos.h> 00028 #include <vcg/complex/algorithms/update/flag.h> 00029 00030 namespace vcg 00031 { 00032 namespace tri 00033 { 00034 00037 00041 template <class MeshType> 00042 class Nring 00043 { 00044 public: 00045 00046 typedef typename MeshType::FaceType FaceType; 00047 typedef typename MeshType::VertexType VertexType; 00048 typedef typename MeshType::ScalarType ScalarType; 00049 typedef typename MeshType::FaceIterator FaceIterator; 00050 typedef typename MeshType::VertexIterator VertexIterator; 00051 typedef typename MeshType::CoordType CoordType; 00052 00053 00054 std::vector<VertexType*> allV; 00055 std::vector<FaceType*> allF; 00056 00057 std::vector<VertexType*> lastV; 00058 std::vector<FaceType*> lastF; 00059 00060 MeshType* m; 00061 00062 Nring(VertexType* v, MeshType* m) : m(m) 00063 { 00064 assert((unsigned)(v - &*m->vert.begin()) < m->vert.size()); 00065 insertAndFlag(v); 00066 00067 } 00068 00069 ~Nring() 00070 { 00071 clear(); 00072 } 00073 00074 void insertAndFlag1Ring(VertexType* v) 00075 { 00076 insertAndFlag(v); 00077 00078 typename face::Pos<FaceType> p(v->VFp(),v); 00079 assert(p.V() == v); 00080 00081 int count = 0; 00082 face::Pos<FaceType> ori = p; 00083 do 00084 { 00085 insertAndFlag(p.F()); 00086 p.FlipF(); 00087 p.FlipE(); 00088 assert(count++ < 100); 00089 } while (ori != p); 00090 00091 } 00092 00093 void insertAndFlag(FaceType* f) 00094 { 00095 if (!f->IsV()) 00096 { 00097 allF.push_back(f); 00098 lastF.push_back(f); 00099 f->SetV(); 00100 insertAndFlag(f->V(0)); 00101 insertAndFlag(f->V(1)); 00102 insertAndFlag(f->V(2)); 00103 } 00104 } 00105 00106 void insertAndFlag(VertexType* v) 00107 { 00108 if (!v->IsV()) 00109 { 00110 allV.push_back(v); 00111 lastV.push_back(v); 00112 v->SetV(); 00113 } 00114 } 00115 00116 00117 static void clearFlags(MeshType* m) 00118 { 00119 tri::UpdateFlags<MeshType>::VertexClearV(*m); 00120 tri::UpdateFlags<MeshType>::FaceClearV(*m); 00121 } 00122 00123 void clear() 00124 { 00125 for(unsigned i=0; i< allV.size(); ++i) 00126 allV[i]->ClearV(); 00127 for(unsigned i=0; i< allF.size(); ++i) 00128 allF[i]->ClearV(); 00129 00130 allV.clear(); 00131 allF.clear(); 00132 } 00133 00134 void expand() 00135 { 00136 std::vector<VertexType*> lastVtemp = lastV; 00137 00138 lastV.clear(); 00139 lastF.clear(); 00140 00141 for(typename std::vector<VertexType*>::iterator it = lastVtemp.begin(); it != lastVtemp.end(); ++it) 00142 { 00143 insertAndFlag1Ring(*it); 00144 } 00145 } 00146 00147 void expand(int k) 00148 { 00149 for(int i=0;i<k;++i) 00150 expand(); 00151 } 00152 }; 00153 00154 }} // end namespace NAMESPACE 00155 #endif // RINGWALKER_H