From d47ee966a26c35c77f5ac4fefbc3f73fa86e0c60 Mon Sep 17 00:00:00 2001 From: cnr-isti-vclab Date: Fri, 7 May 2004 09:27:07 +0000 Subject: [PATCH] Initial Commit --- vcg/complex/trimesh/subset.h | 109 +++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 vcg/complex/trimesh/subset.h diff --git a/vcg/complex/trimesh/subset.h b/vcg/complex/trimesh/subset.h new file mode 100644 index 00000000..b13d5075 --- /dev/null +++ b/vcg/complex/trimesh/subset.h @@ -0,0 +1,109 @@ + + + +#ifndef __VCGLIB_TRISUBSET +#define __VCGLIB_TRISUBSET + + +#include + + +namespace vcg { +namespace tri { + + +template < class STL_VERT_CONT, class STL_FACE_CONT > class Mesh; + + +template +struct InsertedV +{ + InsertedV(I_MESH_TYPE::vertex_type *_v, + I_MESH_TYPE::face_pointer _f, + int _z):v(_v),f(_f),z(_z) + {} + + I_MESH_TYPE::vertex_type *v; + I_MESH_TYPE::face_pointer f; + int z; + + const bool operator <(const InsertedV & o) + { + return (v +void SubSet(STL_CONT & subSet, S_MESH_TYPE & m) +{ + vector< InsertedV > newVertices; + STL_CONT::iterator pfi; + S_MESH_TYPE::vertex_iterator vi; + vector redirect; + + for(pfi=subSet.begin(); pfi!=subSet.end(); ++pfi) + m.face.push_back(*(*pfi)); + + S_MESH_TYPE::face_iterator fi; + for(fi=m.face.begin(); fi!=m.face.end(); ++fi) + { + newVertices.push_back(InsertedV((*fi).V(0), &(*fi),0)); + newVertices.push_back(InsertedV((*fi).V(1), &(*fi),1)); + newVertices.push_back(InsertedV((*fi).V(2), &(*fi),2)); + } + + sort(newVertices.begin(), newVertices.end()); + + vector< InsertedV >::iterator curr, next; + int pos=0; + curr=next=newVertices.begin(); + while(next!=newVertices.end()) + { + if((*curr)!=(*next)) + pos++; + (*next).f->V((*next).z)=(S_MESH_TYPE::vertex_pointer)pos; + curr=next; + next++; + } + + vector< InsertedV >::iterator newE=unique(newVertices.begin(), newVertices.end()); + for(curr=newVertices.begin(); curr!=newE; ++curr) + m.vert.push_back(*((*curr).v)); + + for(vi=m.vert.begin(); vi!=m.vert.end(); ++vi) + redirect.push_back(&(*vi)); + + for(fi=m.face.begin(); fi!=m.face.end(); ++fi) + { + (*fi).V(0)=redirect[(int)(*fi).V(0)]; + (*fi).V(1)=redirect[(int)(*fi).V(1)]; + (*fi).V(2)=redirect[(int)(*fi).V(2)]; + } + m.vn = m.vert.size(); + m.fn = m.face.size(); + m.ClearFlags(); +} + + +} // End Namespace TriMesh +} // End Namespace vcg + + +#endif + +