% by Tolga Birdal
% Create a structured mesh out of vertices and use the same technique for
% resizing the mesh.
% This function creates a structured mesh out of ordered vertices.
% It's useful for dealing with depth maps and treating them as meshes.
% Kinect or ToF cameras would be an option.
% gen_structured_mesh is a C mex file doing the actual meshing.
% It doesnt' produce sorted vertex-face list, so if we really require
% sorting, we should do it separately (a sample which does the sorting is
% also included). To display the mesh, I make use of Dr. Vladimir
% Bondarenk's drawMesh function.
% The code itself includes the test function. Just run it without any
% Copyright (c) 2011, Tolga Birdal <http://www.tbirdal.me>
% generate a random 5x5 mesh vertices
% at this point we don't know what faces are
% this mesh contains no zeros. If there were zeros, they would be
% treated as a disconnection.
MeshZ=rand(5,5); % notice that this is simply a structured mesh already
V=[MeshX(:), MeshY(:), MeshZ(:)];
% generate the faces in a structured manner
F1=F1+1; % shift to matlab indexing
% create and interpolate the mesh to be 10x10
[V2, F2]=create_structured_mesh_sorted(V, 100);
% display both meshes
% create an interpolated/sorted structured mesh, given the ordered vertices
% and the new dimension of the mesh. In other sense, it could also be
% viewed as a simiple mesh refinement.
% Notice that this sample requires a square mesh. sqrt(length(V)) should
% be an integer.
function [Vs, Fs]=create_structured_mesh_sorted(V, newDim)
% first interpolate the vertices
% now create the faces. mesh values have no importance here.
[VsT,FsT]=points_to_mesh_structured (ones(size(X))); FsT=FsT+1;
% optionally sort the faces to be in order. this part is really optional.