stl_read

PURPOSE ^

STL_READ Read in an stl file and output an EIDORS model struct

SYNOPSIS ^

function mdl = stl_read(fname)

DESCRIPTION ^

STL_READ  Read in an stl file and output an EIDORS model struct
 This function is a wrapper for the Matlab Central contribution by 
 Adam H. Aitkenhead called READ_stl from "Mesh voxelization"
 http://www.mathworks.de/matlabcentral/fileexchange/27390-mesh-voxelisation

 See also stl_write

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function mdl = stl_read(fname)
0002 %STL_READ  Read in an stl file and output an EIDORS model struct
0003 % This function is a wrapper for the Matlab Central contribution by
0004 % Adam H. Aitkenhead called READ_stl from "Mesh voxelization"
0005 % http://www.mathworks.de/matlabcentral/fileexchange/27390-mesh-voxelisation
0006 %
0007 % See also stl_write
0008 
0009 % Copyright 2013 Bartlomiej Grychtol
0010 % License: GPL version 2 or 3
0011 % $Id: stl_read.m 6926 2024-05-31 15:34:13Z bgrychtol $
0012 
0013 if ischar(fname) && strcmp(fname, 'UNIT_TEST'), do_unit_test; return, end
0014 
0015 [V] = READ_stl(fname);
0016 N = reshape(shiftdim(V,1),3,[])'; 
0017 [nodes, ~, n] = unique(N,'rows');
0018 mdl.nodes = nodes;
0019 mdl.elems = reshape(uint32(n)',3,[])';
0020 same = mdl.elems(:,1) == mdl.elems(:,2) | mdl.elems(:,2) == mdl.elems(:,3) | mdl.elems(:,1) == mdl.elems(:,3);
0021 mdl.elems(same,:) = [];
0022 mdl.boundary = mdl.elems;
0023 
0024 [~,name,ext] = fileparts(fname);
0025 mdl = eidors_obj('fwd_model',mdl,'name',[name ext]);
0026 
0027 
0028 function do_unit_test
0029    a = [
0030    -0.8981   -0.7492   -0.2146    0.3162    0.7935    0.9615    0.6751    0.0565   -0.3635   -0.9745
0031     0.1404    0.5146    0.3504    0.5069    0.2702   -0.2339   -0.8677   -0.6997   -0.8563   -0.4668 ]';
0032 fmdl = ng_mk_extruded_model({2,{a,0.5*a,0.2*a},1},[],[]);
0033 
0034 fv.faces    = find_boundary(fmdl);
0035 fv.vertices = fmdl.nodes;
0036 stl_write(fv, 'test.stl');
0037 mdl = stl_read('test.stl');
0038 show_fem(mdl)
0039 delete('test.stl');
0040 
0041

Generated on Sun 29-Dec-2024 11:41:59 by m2html © 2005