1 %% Copyright (c) 2010 Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
3 %% This program is free software: you can redistribute it and/or modify
4 %% it under the terms of the GNU General Public License as published by
5 %% the Free Software Foundation, either version 3 of the License, or
8 %% This program is distributed in the hope that it will be useful,
9 %% but WITHOUT ANY WARRANTY; without even the implied warranty of
10 %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 %% GNU General Public License for more details.
13 %% You should have received a copy of the GNU General Public License
14 %% along with this program. If not, see <http://www.gnu.org/licenses/>.
17 %% @deftypefn {Function File} {@var{fileStr} =} data2geo (@var{data}, @var{lc})
18 %% @deftypefnx {Function File} {@var{fileStr} =} data2geo (@dots{}, @var{param}, @var{value})
19 %% Uses data to build a file compatible with Gmsh.
21 %% @var{data} is assumed to describe a polygon in @code{polygon2d} format.
22 %% The argument @var{lc} specifies the edge size.
24 %% The optional parameters can be 'output' followed with a string specifying a file
25 %% to write, and 'spherical' followed by a real number @var{r} indicating that the
26 % polygon describes a spherical surface of radious @var{r}.
28 %% @seealso{polygon2d, @@svg/path2polygon}
31 function strFile = data2geo(data,lc,varargin)
33 nl = @()sprintf('\n');
39 filegiven = find(cellfun(@(x)strcmpi(x,'output'),varargin));
40 spherical = find(cellfun(@(x)strcmpi(x,'spherical'),varargin));
45 data(:,3) = zeros(n,1);
48 header = ' // File created with Octave';
50 strFile = [strFile header nl()];
53 strFile = [strFile '// Points' nl()];
56 strFile = [strFile pointGeo(i,data(i,:),lc)];
60 strFile = [strFile '// Lines' nl()];
62 strFile = [strFile lineGeo(i,i,i+1)];
64 strFile = [strFile lineGeo(n,n,1)];
67 strFile = [strFile lineLoopGeo(n+1,n,1:n)];
71 sphr = varargin{spherical+1};
75 strFile = [strFile pointGeo(n+1,sphr,lc)];
76 strFile = [strFile ruledSurfGeo(n+3,1,n+1,n+1)];
78 strFile = [strFile planeSurfGeo(n+2,1,n+1)];
82 outfile = varargin{filegiven+1};
83 fid = fopen(outfile,'w');
84 fprintf(fid,'%s',strFile);
86 disp(['DATA2GEO: Geometry file saved to ' outfile])
91 %! points = [0 0 0; 0.1 0 0; 0.1 .3 0; 0 0.3 0];
92 %! strFile = data2geo(points,0.009);
96 %! dc = svg('drawing6.svg');
98 %! P = dc.path2polygon(ids{1},12)(1:end-1,:);
99 %! P = bsxfun(@minus, P, centroid(P));
100 %! P = simplifypolygon(P,'tol',5e-1);
101 %! filename = tmpnam ();
102 %! meshsize = sqrt(mean(sumsq(diff(P,1,1),2)))/2;
103 %! data2geo (P, meshsize, 'output', [filename '.geo']);
106 %! T = msh2m_gmsh(filename);
107 %! pdemesh(T.p,T.e,T.t)
109 %! % --------------------------------------------------------------------------
110 %! % We load the drawing6.svg file into Octave and transform it into a polygon.
111 %! % Then we create a temporary file where the .geo mesh will be written.
112 %! % If the packages msh and fpl are available, a mesh is created from the .geo