Home > arte3.2.0 > tools > stl_read.m

stl_read

PURPOSE ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS ^

function [F, V, C] = stl_read(filename)

DESCRIPTION ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 [F, V, C] = STL_READ(filename)
 Read all the vertex contained in the FILENAME STL .
 (Standard Tessellation Language) file 
 Refer to http://en.wikipedia.org/wiki/STL_%28file_format%29 for more
 details.
 
 [F, V, C] = STL_READ(filename) returns:
   F defines the faces in numbers.
   V defines the cartesian coordinates of each of the faces. These coordinates are
       expressed in meters in the links DH reference frame.
   C is not currently used.

  See also STLWRITE, SURF2STL

   Author: Arturo Gil. Universidad Miguel Hernández de Elche.
   email: arturo.gil@umh.es date:   05/02/2012
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0002 % [F, V, C] = STL_READ(filename)
0003 % Read all the vertex contained in the FILENAME STL .
0004 % (Standard Tessellation Language) file
0005 % Refer to http://en.wikipedia.org/wiki/STL_%28file_format%29 for more
0006 % details.
0007 %
0008 % [F, V, C] = STL_READ(filename) returns:
0009 %   F defines the faces in numbers.
0010 %   V defines the cartesian coordinates of each of the faces. These coordinates are
0011 %       expressed in meters in the links DH reference frame.
0012 %   C is not currently used.
0013 %
0014 %  See also STLWRITE, SURF2STL
0015 %
0016 %   Author: Arturo Gil. Universidad Miguel Hernández de Elche.
0017 %   email: arturo.gil@umh.es date:   05/02/2012
0018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0019 
0020 % Copyright (C) 2012, by Arturo Gil Aparicio
0021 %
0022 % This file is part of ARTE (A Robotics Toolbox for Education).
0023 %
0024 % ARTE is free software: you can redistribute it and/or modify
0025 % it under the terms of the GNU Lesser General Public License as published by
0026 % the Free Software Foundation, either version 3 of the License, or
0027 % (at your option) any later version.
0028 %
0029 % ARTE is distributed in the hope that it will be useful,
0030 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0031 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0032 % GNU Lesser General Public License for more details.
0033 %
0034 % You should have received a copy of the GNU Leser General Public License
0035 % along with ARTE.  If not, see <http://www.gnu.org/licenses/>.
0036 function [F, V, C] = stl_read(filename)
0037 V=[];
0038 F=[];
0039 
0040 file = fopen(filename, 'r');
0041 
0042 %first, get all cartesian points
0043 [V, point_numbers]=get_cartesian(file,  'vertex');
0044 
0045 fclose(file);
0046 
0047 n=size(V,1);
0048 
0049 F = [(1:3:n)' (2:3:n)' (3:3:n)'];
0050 C=zeros(n,1);
0051 
0052 
0053 function [data, point_numbers] =get_cartesian(file, tag)
0054 
0055 %tag length
0056 n=length(tag);
0057 data=[];
0058 point_numbers = [];
0059 %get every cartesian point
0060 while 1    
0061     tline = fgets(file);
0062     
0063     if tline == -1
0064         fprintf('EndOfFile found... ');
0065         error = 1;        
0066         break;
0067     end
0068 
0069     %#num
0070     [temp, remain] = strtok(tline, '  '); 
0071     
0072     if strncmp(temp, tag, length(tag))
0073         %Read data
0074         [a] = sscanf(remain,'%f');  
0075         
0076         data = [data; a'];      
0077     end       
0078 end

Generated on Fri 03-Jan-2014 12:20:01 by m2html © 2005