From 17f0ac043125b3aa4a733c724f3f5708d4d444f6 Mon Sep 17 00:00:00 2001 From: cignoni Date: Mon, 16 Feb 2009 00:59:24 +0000 Subject: [PATCH] added another grid building function. This one build up a possibly incomplete grid. --- vcg/complex/trimesh/create/platonic.h | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/vcg/complex/trimesh/create/platonic.h b/vcg/complex/trimesh/create/platonic.h index 488b31a8..fb4a1e00 100644 --- a/vcg/complex/trimesh/create/platonic.h +++ b/vcg/complex/trimesh/create/platonic.h @@ -690,6 +690,52 @@ void FaceGrid(MeshType & in, int w, int h) } } + +// Build a regular grid mesh of faces as a typical height field mesh +// Vertexes are assumed to be already be allocated, but not oll the grid vertexes are present. +// For this purpos a grid of indexes is also passed. negative indexes means that there is no vertex. + +template +void FaceGrid(MeshType & in, std::vector &grid, int w, int h) +{ + assert(in.vn == (int)in.vert.size()); // require a compact vertex vector + assert(in.vn <= w*h); // the number of vertices should match the number of expected grid vertices + +// V0 V1 +// i+0,j+0 -- i+0,j+1 +// | \ | +// | \ | +// | \ | +// | \ | +// i+1,j+0 -- i+1,j+1 +// V2 V3 + + + for(int i=0;i=0 && V2i>=0 && V3i>=0 ) + { + typename MeshType::FaceIterator f= Allocator::AddFaces(in,1); + f->V(0)=&(in.vert[V0i]); + f->V(1)=&(in.vert[V3i]); + f->V(2)=&(in.vert[V2i]); + } + if(V0i>=0 && V1i>=0 && V3i>=0 ) + { + typename MeshType::FaceIterator f= Allocator::AddFaces(in,1); + f->V(0)=&(in.vert[V0i]); + f->V(1)=&(in.vert[V1i]); + f->V(2)=&(in.vert[V3i]); + } + } +} + template void Cylinder(const int &slices, const int &stacks, MeshType & m){ float rad_step = M_PI / (float)stacks;