Home > matGeom > meshes3d > readMesh.m

readMesh

PURPOSE ^

Read a 3D mesh by inferring format from file name.

SYNOPSIS ^

function varargout = readMesh(fileName)

DESCRIPTION ^

 Read a 3D mesh by inferring format from file name.

   Usage:
   [V, F] = readMesh(FILENAME)
   Read the data stored in file FILENAME and return the vertex and face
   arrays as NV-by-3 array and NF-by-N array respectively, where NV is the
   number of vertices and NF is the number of faces.

   MESH = readMesh(FILENAME)
   Read the data stored in file FILENAME and return the mesh into a struct
   with fields 'vertices' and 'faces'.

   Example
     mesh = readMesh('apple.ply');
     figure; drawMesh(mesh);
     view([180 -70]); axis equal;

   See also
     meshes3d, writeMesh, readMesh_off, readMesh_ply, readMesh_stl

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = readMesh(fileName)
0002 % Read a 3D mesh by inferring format from file name.
0003 %
0004 %   Usage:
0005 %   [V, F] = readMesh(FILENAME)
0006 %   Read the data stored in file FILENAME and return the vertex and face
0007 %   arrays as NV-by-3 array and NF-by-N array respectively, where NV is the
0008 %   number of vertices and NF is the number of faces.
0009 %
0010 %   MESH = readMesh(FILENAME)
0011 %   Read the data stored in file FILENAME and return the mesh into a struct
0012 %   with fields 'vertices' and 'faces'.
0013 %
0014 %   Example
0015 %     mesh = readMesh('apple.ply');
0016 %     figure; drawMesh(mesh);
0017 %     view([180 -70]); axis equal;
0018 %
0019 %   See also
0020 %     meshes3d, writeMesh, readMesh_off, readMesh_ply, readMesh_stl
0021 %
0022  
0023 % ------
0024 % Author: David Legland
0025 % e-mail: david.legland@inrae.fr
0026 % INRAE - BIA Research Unit - BIBS Platform (Nantes)
0027 % Created: 2020-11-20,    using Matlab 9.8.0.1323502 (R2020a)
0028 % Copyright 2020 INRAE.
0029 
0030 [~, ~, ext] = fileparts(fileName);
0031 switch lower(ext)
0032     case '.off'
0033         mesh = readMesh_off(fileName);
0034     case '.ply'
0035         mesh = readMesh_ply(fileName);
0036     case '.stl'
0037         mesh = readMesh_stl(fileName);
0038     otherwise
0039         error('Unrecognized file format for rezading mesh: %s', ext);
0040 end
0041 
0042 % format output arguments
0043 if nargout < 2
0044     varargout = {mesh};
0045 else
0046     varargout = {mesh.vertices, mesh.faces};
0047 end

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019