From b6d198362c370458128dd0cd97eb1edd611dfc86 Mon Sep 17 00:00:00 2001 From: cignoni Date: Wed, 31 Oct 2012 06:58:08 +0000 Subject: [PATCH] Small changes to the compactVector (added a check on empty vectors) and improved the sample on allocation. --- .../trimesh_allocate/trimesh_allocate.cpp | 19 ++++++++----------- vcg/complex/allocate.h | 3 ++- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/apps/sample/trimesh_allocate/trimesh_allocate.cpp b/apps/sample/trimesh_allocate/trimesh_allocate.cpp index 63b1df0c..428cee49 100644 --- a/apps/sample/trimesh_allocate/trimesh_allocate.cpp +++ b/apps/sample/trimesh_allocate/trimesh_allocate.cpp @@ -46,19 +46,17 @@ class MyMesh : public vcg::tri::TriMesh< std::vector, std::vector::AddVertices(m,3); - vcg::tri::Allocator::AddFaces(m,1); + MyMesh::VertexIterator vi = vcg::tri::Allocator::AddVertices(m,3); + MyMesh::FaceIterator fi = vcg::tri::Allocator::AddFaces(m,1); MyMesh::VertexPointer ivp[3]; - MyMesh::VertexIterator vi=m.vert.begin(); - ivp[0]=&*vi;(*vi).P()=MyMesh::CoordType ( 0.0, 0.0, 0.0); ++vi; - ivp[1]=&*vi;(*vi).P()=MyMesh::CoordType ( 1.0, 0.0, 0.0); ++vi; - ivp[2]=&*vi;(*vi).P()=MyMesh::CoordType ( 0.0, 1.0, 0.0); ++vi; + ivp[0]=&*vi; vi->P()=MyMesh::CoordType ( 0.0, 0.0, 0.0); ++vi; + ivp[1]=&*vi; vi->P()=MyMesh::CoordType ( 1.0, 0.0, 0.0); ++vi; + ivp[2]=&*vi; vi->P()=MyMesh::CoordType ( 0.0, 1.0, 0.0); ++vi; - MyFace &f=m.face[0]; - f.V(0)=ivp[0]; - f.V(1)=ivp[1]; - f.V(2)=ivp[2]; + fi->V(0)=ivp[0]; + fi->V(1)=ivp[1]; + fi->V(2)=ivp[2]; // a potentially dangerous pointer to a mesh element MyMesh::FacePointer fp = &m.face[0]; @@ -77,7 +75,6 @@ int main() vcg::tri::Allocator::DeleteFace(m,m.face[3]); // If you loop in a mesh with deleted elements you have to skip them! - MyMesh::FaceIterator fi; for(fi = m.face.begin(); fi!=m.face.end(); ++fi ) { if(!fi->IsD()) // <---- Check added diff --git a/vcg/complex/allocate.h b/vcg/complex/allocate.h index 2c5b9350..939efb25 100644 --- a/vcg/complex/allocate.h +++ b/vcg/complex/allocate.h @@ -609,7 +609,8 @@ public: */ static void PermutateVertexVector(MeshType &m, PointerUpdater &pu) { - for(unsigned int i=0;i