1 %% Copyright (c) 2011 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{SVGn} = loadSVG (@var{SVG})
18 %% Scales and reflects the @var{SVG} structure and returns a modified @var{SVGn}
21 %% The height and width of the SVG are scaled such that the diagonal of the
22 %% bounding box has length 1. Coordinates are trasnfomed such that a plot of the
23 %% paths coincides with the visualization of the original SVG.
25 %% @seealso{svgload, svgpath2polygon}
28 function SVGn = svgnormalize (SVG)
33 TransV = [0, SVG.height/2];
35 Dnorm = sqrt (SVG.width ^ 2 + SVG.height ^ 2);
36 S = (1 / Dnorm) * eye (2);
37 for i = 1:numel (SVG.path)
38 nc = size (SVG.path(i).coord, 1);
40 T = repmat (TransV,nc, 1);
41 SVGn.path(i).coord = SVG.path(i).coord - T;
43 SVGn.path(i).coord(:, 2) = -SVGn.path(i).coord(:,2);
46 SVGn.path(i).coord = SVGn.path(i).coord - T;
48 SVGn.path(i).coord = SVGn.path(i).coord * S;
50 SVGn.height = SVG.height / Dnorm;
51 SVGn.width = SVG.width / Dnorm;
52 SVGn.normalized = true;
58 %! file = 'tmp__.svg';
59 %! fid = fopen (file,'w');
60 %! svgfile = '<html><body><svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="250" width="250"><path d="M150,0 75,200 225,200 Z" /></svg></body></html>';
61 %! fprintf (fid,"%s\n",svgfile);
63 %! SVG = svgload (file);
64 %! SVGn = svgnormalize (SVG);
66 %! plot([SVGn.path.coord(:,1); SVGn.path.coord(1,1)], ...
67 %! [SVGn.path.coord(:,2); SVGn.path.coord(1,2)]);