X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fgeometry-1.5.0%2Fio%2Fdeprecated%2Fsvgnormalize.m;fp=octave_packages%2Fgeometry-1.5.0%2Fio%2Fdeprecated%2Fsvgnormalize.m;h=381d29ab28090891676dd32a4c1f3e14a8462877;hp=0000000000000000000000000000000000000000;hb=c880e8788dfc484bf23ce13fa2787f2c6bca4863;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/geometry-1.5.0/io/deprecated/svgnormalize.m b/octave_packages/geometry-1.5.0/io/deprecated/svgnormalize.m new file mode 100644 index 0000000..381d29a --- /dev/null +++ b/octave_packages/geometry-1.5.0/io/deprecated/svgnormalize.m @@ -0,0 +1,68 @@ +%% Copyright (c) 2011 Juan Pablo Carbajal +%% +%% This program is free software: you can redistribute it and/or modify +%% it under the terms of the GNU General Public License as published by +%% the Free Software Foundation, either version 3 of the License, or +%% any later version. +%% +%% This program is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +%% GNU General Public License for more details. +%% +%% You should have received a copy of the GNU General Public License +%% along with this program. If not, see . + +%% -*- texinfo -*- +%% @deftypefn {Function File} @var{SVGn} = loadSVG (@var{SVG}) +%% Scales and reflects the @var{SVG} structure and returns a modified @var{SVGn} +%% structure. +%% +%% The height and width of the SVG are scaled such that the diagonal of the +%% bounding box has length 1. Coordinates are trasnfomed such that a plot of the +%% paths coincides with the visualization of the original SVG. +%% +%% @seealso{svgload, svgpath2polygon} +%% @end deftypefn + +function SVGn = svgnormalize (SVG) + + SVGn = SVG; + if ~SVG.normalized + % Translate + TransV = [0, SVG.height/2]; + % Scale + Dnorm = sqrt (SVG.width ^ 2 + SVG.height ^ 2); + S = (1 / Dnorm) * eye (2); + for i = 1:numel (SVG.path) + nc = size (SVG.path(i).coord, 1); + % Translate to middle + T = repmat (TransV,nc, 1); + SVGn.path(i).coord = SVG.path(i).coord - T; + % Reflect + SVGn.path(i).coord(:, 2) = -SVGn.path(i).coord(:,2); + T(:,2) = -T(:,2); + % Translate to bottom + SVGn.path(i).coord = SVGn.path(i).coord - T; + %Scale + SVGn.path(i).coord = SVGn.path(i).coord * S; + end + SVGn.height = SVG.height / Dnorm; + SVGn.width = SVG.width / Dnorm; + SVGn.normalized = true; + end + +end + +%!demo +%! file = 'tmp__.svg'; +%! fid = fopen (file,'w'); +%! svgfile = ''; +%! fprintf (fid,"%s\n",svgfile); +%! fclose (fid); +%! SVG = svgload (file); +%! SVGn = svgnormalize (SVG); +%! SVGn +%! plot([SVGn.path.coord(:,1); SVGn.path.coord(1,1)], ... +%! [SVGn.path.coord(:,2); SVGn.path.coord(1,2)]); +%! delete (file);