Debian Bug report logs - #365757
octave-epstk: eps lines not optimized

version graph

Package: octave-epstk; Maintainer for octave-epstk is (unknown);

Reported by: Francesco Potorti` <Potorti@isti.cnr.it>

Date: Tue, 2 May 2006 18:03:02 UTC

Severity: wishlist

Found in version octave-epstk/2.1-2

Fixed in version octave-epstk/2.1-4

Done: Rafael Laboissiere <rafael@debian.org>

Bug is archived. No further changes may be made.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, Francesco Potorti` <Potorti@isti.cnr.it>, Debian Octave Group <pkg-octave-devel@lists.alioth.debian.org>:
Bug#365757; Package octave-epstk. (full text, mbox, link).


Acknowledgement sent to Francesco Potorti` <Potorti@isti.cnr.it>:
New Bug report received and forwarded. Copy sent to Francesco Potorti` <Potorti@isti.cnr.it>, Debian Octave Group <pkg-octave-devel@lists.alioth.debian.org>. (full text, mbox, link).


Message #5 received at submit@bugs.debian.org (full text, mbox, reply):

From: Francesco Potorti` <Potorti@isti.cnr.it>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: octave-epstk: eps lines not optimized
Date: Tue, 02 May 2006 19:43:16 +0200
Package: octave-epstk
Version: 2.1-2
Severity: wishlist

Very often, while plotting big quantities of data, I have redundant
points.  For example this X Y vector:

0 0                         0 0
1 1			    1 1
2 1			    8 1
3 1			    8 4
4 1			    9 5
8 1  could be reduced to
8 1
8 2
8 3
8 4
9 5

as far as plotting is concerned.  This optimisation reduces the size of
the eps file and the time it needs to be rendered either on screen or by
a printer.  I had cases where such an optimisation reduces the size by
ten times.

It would be nice it plot() did this.  It should merge two successive
segments if the second one is a prolongation of the first one, with a
tolerance depending on the plot scale.

-- System Information:
Debian Release: testing/unstable
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'testing-proposed-updates')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.4.30-pre2-pr-hrt-1kHz-1
Locale: LANG=C, LC_CTYPE=it_IT@euro (charmap=ANSI_X3.4-1968) (ignored: LC_ALL set to C)

Versions of packages octave-epstk depends on:
ii  octave2.1                     1:2.1.73-7 GNU Octave language for numerical 

octave-epstk recommends no packages.

-- no debconf information



Information forwarded to debian-bugs-dist@lists.debian.org, Debian Octave Group <pkg-octave-devel@lists.alioth.debian.org>:
Bug#365757; Package octave-epstk. (full text, mbox, link).


Acknowledgement sent to Thomas Weber <thomas.weber.mail@gmail.com>:
Extra info received and forwarded to list. Copy sent to Debian Octave Group <pkg-octave-devel@lists.alioth.debian.org>. (full text, mbox, link).


Message #10 received at 365757@bugs.debian.org (full text, mbox, reply):

From: Thomas Weber <thomas.weber.mail@gmail.com>
To: Francesco Potorti` <Potorti@isti.cnr.it>, 365757@bugs.debian.org
Subject: Re: [Pkg-octave-devel] Bug#365757: octave-epstk: eps lines not optimized
Date: Thu, 11 May 2006 20:25:19 +0200
Am Dienstag, den 02.05.2006, 19:43 +0200 schrieb Francesco Potorti`:
> Very often, while plotting big quantities of data, I have redundant
> points.  For example this X Y vector: 
> 
> 0 0                         0 0
> 1 1			    1 1
> 2 1			    8 1
> 3 1			    8 4
> 4 1			    9 5
> 8 1  could be reduced to
> 8 1
> 8 2
> 8 3
> 8 4
> 9 5
> 
> as far as plotting is concerned.  This optimisation reduces the size of
> the eps file and the time it needs to be rendered either on screen or by
> a printer.  I had cases where such an optimisation reduces the size by
> ten times.

I had some thoughts about this. My (personal) opinion is that this
should not be implemented in a specific plot package, but as a general
function.

Reasons:
1.) I believe a plot package should plot the data it was given; data
manipulation should happen before that.
2.) While the consquences of large data sets are really bad with EPS
files, other vector-based formats (like SVG) will suffer from the same
problems.

Francesco, do you have such a simplifying function already?

Regards,
	Thomas




Information forwarded to debian-bugs-dist@lists.debian.org, Debian Octave Group <pkg-octave-devel@lists.alioth.debian.org>:
Bug#365757; Package octave-epstk. (full text, mbox, link).


Acknowledgement sent to Francesco Potorti` <Potorti@isti.cnr.it>:
Extra info received and forwarded to list. Copy sent to Debian Octave Group <pkg-octave-devel@lists.alioth.debian.org>. (full text, mbox, link).


Message #15 received at 365757@bugs.debian.org (full text, mbox, reply):

From: Francesco Potorti` <Potorti@isti.cnr.it>
To: Thomas Weber <thomas.weber.mail@gmail.com>
Cc: 365757@bugs.debian.org
Subject: Re: [Pkg-octave-devel] Bug#365757: octave-epstk: eps lines not optimized
Date: Fri, 12 May 2006 18:25:49 +0200
>> Very often, while plotting big quantities of data, I have redundant
>> points.  For example this X Y vector: 
>> 
>> 0 0                         0 0
>> 1 1			    1 1
>> 2 1			    8 1
>> 3 1			    8 4
>> 4 1			    9 5
>> 8 1  could be reduced to
>> 8 1
>> 8 2
>> 8 3
>> 8 4
>> 9 5
>> 
>> as far as plotting is concerned.  This optimisation reduces the size of
>> the eps file and the time it needs to be rendered either on screen or by
>> a printer.  I had cases where such an optimisation reduces the size by
>> ten times.
>
>I had some thoughts about this. My (personal) opinion is that this
>should not be implemented in a specific plot package, but as a general
>function.

Sure.  But such a function could be called by eplot.  I think that such
a function should be part of the eplot package for a start, and could be
removed from there if it becomes part of octave or octave-forge in a
future.

>Francesco, do you have such a simplifying function already?

No, but I have an algorithm for simplifying successive horizontal and
vertical segments, which are the most common case in my experience.  It
should be extended to general segments.

The algorithm is as follows (for horizontal segments only, just do it
twice by exchanging X and Y for vertical segments):

referenceY = invalid
for each segment		# segment is (X1,Y1)--(X2,Y2)
  if referenceY == invalid
    referenceY = Y1
    if Y2 != referenceY +/- slack
      referenceY = invalid
  else if Y2 == referenceY +/- slack
    merge the previous segment with the current one by removing the
    middle point
  else
    referenceY = invalid

slack should be set to something near the resolution of the plot, like
1/1000 of the plot size.

Maybe I will try to write it and let you know.

-- 
Francesco Potortì (ricercatore)        Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR          Fax:   +39 050 313 8091
via G. Moruzzi 1, I-56124 Pisa         Email: Potorti@isti.cnr.it
Web: http://fly.isti.cnr.it/           Key:   fly.isti.cnr.it/public.key



Information forwarded to debian-bugs-dist@lists.debian.org, Debian Octave Group <pkg-octave-devel@lists.alioth.debian.org>:
Bug#365757; Package octave-epstk. (full text, mbox, link).


Acknowledgement sent to Francesco Potorti` <Potorti@isti.cnr.it>:
Extra info received and forwarded to list. Copy sent to Debian Octave Group <pkg-octave-devel@lists.alioth.debian.org>. (full text, mbox, link).


Message #20 received at 365757@bugs.debian.org (full text, mbox, reply):

From: Francesco Potorti` <Potorti@isti.cnr.it>
To: Octave source list <octave-sources@bevo.che.wisc.edu>
Cc: 365757@bugs.debian.org, Thomas Weber <thomas.weber.mail@gmail.com>
Subject: plotcollapse
Date: Mon, 15 May 2006 19:39:22 +0200
This function solves a problem of mine when plotting data.  It often
happens to me to have a lot of redundant points for measured data,
points that are mostly invisible on paper or screen because they are
very near one another.  Moreover, when plotting lines, often a straight
line is composed by a great number of small segments, which makes a huge
.eps file.

This function can be called on data to be plotted to optimise them by
removing unnecessary points before generating the plot.  Data that I use
are typically reduced by ten times.  You will appreciate this if you
happen to plot data series of simulated or measured data with hundreds
or more samples.

Segment optimisation can be disabled for point plots.  Point plot
optimisation is done as a special case of general segment optimisation,
but it could probably be rewritten with a separate vectorialised
algorithm that makes it much faster.

Only the common case of points with increasing abscissae is optimised.
Optimisation in the general case is more complex and probably not worth
doing for plotting.

If you try it on your data please let me know how it works.


## Copyright © 2006  Francesco Potortì
##
## 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 2 of the License, or
## (at your option) 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, write to the Free Software Foundation,
## Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301, USA.

## -*- texinfo -*-
## @deftypefn {Function File} {} plotcollapse (@var{P})
## @deftypefnx {Function File} {} plotcollapse (@var{P}, @var{so})
## @deftypefnx {Function File} {} plotcollapse (@var{P}, @var{so}, @var{res})
##
## Optimise plot data by removing redundant points and segments
##
## The first parameter @var{P} is a two-column matrix, abscissae and
## ordinates, to be plotted with a line.  The second optional argument
## @var{so}, defaulting to @var{true}, disables segment optimisation when
## set to @var{false}. The third optional argument @var{res} is the size of
## the largest error on the plot with respect to the range of values; it
## defaults to 1/1000.  Returns a two-column matrix containing a subset of
## the rows of @var{P}. A line plot of @var{P} has the same appearance as a
## line plot of the output, with errors smaller than @var{res}.  When
## creating point plots, set @var{so} to @var{false}.
## @end deftypefn

## Author: Francesco Potortì <Potorti@isti.cnr.it>
## $Revision: 1.4 $
## Usage: plotcollapse(P[, so[, res]])
## Description: Optimise plot data by removing redundant points and segments

function C = plotcollapse (P, so, res)
  ## Only the common case of points with increasing abscissae is optimised.
  ## Optimisation in the general case is more complex and probably not worth
  ## doing for plotting.

  if (columns(P) != 2 || rows(P) < 1)
    error("P must contain at least one point");
  endif
  if (nargin < 2)
    so = true;			# do segment optimisation
  endif
  if (nargin < 3 || res <= 0)
    res = 1e-3;			# default resolution is 1000 dots/axis
  endif

  l = rows(P);			# length of P
  E = range(P)' * res;		# slack: admissible error on coordinates
  V = !zeros(l,1);		# valid points

  # For each segment, r and s are its extremes
  r = 1; R = P(1,:)';		# start of the latest segment
  s = 0;			# end of the latest segment undefined
  M = [];			# rotation matrix

  for t = r+1:l
    T = P(t,:)';

    if (s == 0)			# searching for end of segment
      if (norm((T-R)./E) < 1)	# t too near to r
	V(t) = false;		# do not plot t
	continue;
      endif
    elseif (norm((T-S)./E) < 1)	# t too near to s
      V(t) = false;		# do not plot t
      continue;
    elseif (T(1) < S(1))	# going back
      r = t; R = T;		# restart from here
      s = 0;			# and go looking for end of segment
      M = [];			# reset rotation matrix
      continue;
    elseif (so)			# we have a segment and not going back
      if (abs(dot(T-R,D)) < 1)	# we can collapse
	V(s) = false;		# do not plot s
      else			# set a new segment
	r = s; R = S;		# new start
	M = [];			# rebuild rotation matrix
      endif
    endif
    s = t; S = T;		# new end of segment

    if (so && rows(M) == 0)
      M = inv([(S-R), [0,-1;1,0]*(S-R)]); # rotation matrix
      MS = M*E;			# rotated slack
      D = M(2,:)'/MS(2);	# projection vector for distance
    endif
  endfor

  C = P(V,:);
endfunction



Information forwarded to debian-bugs-dist@lists.debian.org, Debian Octave Group <pkg-octave-devel@lists.alioth.debian.org>:
Bug#365757; Package octave-epstk. (full text, mbox, link).


Acknowledgement sent to Francesco Potorti` <Potorti@isti.cnr.it>:
Extra info received and forwarded to list. Copy sent to Debian Octave Group <pkg-octave-devel@lists.alioth.debian.org>. (full text, mbox, link).


Message #25 received at 365757@bugs.debian.org (full text, mbox, reply):

From: Francesco Potorti` <Potorti@isti.cnr.it>
To: Octave source list <octave-sources@bevo.che.wisc.edu>
Cc: 365757@bugs.debian.org, Thomas Weber <thomas.weber.mail@gmail.com>
Subject: plotcollapse
Date: Tue, 16 May 2006 15:54:55 +0200
I sent this message before, but it may have got lost in the mailing list
reorganisation.  I resend it with an improved and much faster version of
the same program.

This function solves a problem of mine when plotting data.  It often
happens to me to have a lot of redundant points for measured data,
points that are mostly invisible on paper or screen because they are
very near one another.  Moreover, when plotting lines, often a straight
line is composed by a great number of small segments, which makes a huge
.eps file.

This function can be called on data to be plotted to optimise them by
removing unnecessary points before generating the plot.  Data that I use
are typically reduced by ten times.  You will appreciate this if you
happen to plot data series of simulated or measured data with hundreds
or more samples.

Segment optimisation can be disabled for point plots.  Point plot
optimisation is done as a special case of general segment optimisation,
but it could probably be rewritten with a separate vectorialised
algorithm that makes it much faster.

Only the common case of points with increasing abscissae is optimised.
Optimisation in the general case is more complex and probably not worth
doing for plotting.

If you try it on your data please let me know how it works.

## Copyright © 2006  Francesco Potortì
##
## 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 2 of the License, or
## (at your option) 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, write to the Free Software Foundation,
## Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301, USA.

## -*- texinfo -*-
## @deftypefn {Function File} {} plotcollapse (@var{P})
## @deftypefnx {Function File} {} plotcollapse (@var{P}, @var{so})
## @deftypefnx {Function File} {} plotcollapse (@var{P}, @var{so}, @var{res})
##
## Optimise plot data by removing redundant points and segments
##
## The first parameter @var{P} is a two-column matrix to be plotted as X and
## Y coordinates.   The second optional argument @var{so} disables segment
## optimisation when set to @var{false} (default is @var{true}). The third
## optional argument @var{res} is the size of the largest error on the plot:
## if it is a scalar, it is meant relative to the range of X and Y values
## (default 1e-3); if it is a 2x1 array, it contains the absolute errors for
## X and Y.  Returns a two-column matrix containing a subset of the rows of
## @var{P}. A line plot of @var{P} has the same appearance as a line plot of
## the output, with errors smaller than @var{res}.  When creating point
## plots, set @var{so} to @var{false}.
## @end deftypefn

## Author: Francesco Potortì <Potorti@isti.cnr.it>
## $Revision: 2.7 $
## Usage: plotcollapse(P[, so[, res]])
## Description: Optimise plot data by removing redundant points and segments

function C = plotcollapse (P, so, res)

  if (!ismatrix(P) || columns(P) != 2)
    error("P must be a matrix with two columns");
  endif
  if (nargin < 2)
    so = true;			# do segment optimisation
  endif
  if (nargin < 3)
    res = 1e-3;			# default resolution is 1000 dots/axis
  endif

  ## Slack: admissible error on coordinates on the output plot
  if (isscalar(res))
    if (res <= 0)
      error("res must be positive");
    endif
    E = range(P)' * res;	# build error vector using range of data
  elseif (ismatrix(res))
    if (!all(size(res) == [2 1]) || any(res <= 0))
      error("res must be a 2x1 matrix with positive values");
    endif
    E = res;			# take error vector as it is
  else
    error("res should be a scalar or matrix");
  endif

  if (rows(P) < 3)
    C = P;
    return;			# nothing to do
  endif
  P ./= repmat(E',rows(P),1);	# normalize P
  rot = [0,-1;1,0];		# rotate a vector pi/4 anticlockwise

  ## Iteratively remove points too near to the previous point
  while (1)
    V = [true; sumsq(diff(P),2) > 1]; # points far from the previous ones
    if (all(V)) break; endif
    V = [true; diff(V) >= 0];	# identify the sequence leaders
    P = P(V,:);			# remove them
  endwhile

  ## Remove points laying near to a segment: for each segment R->S, build a
  ## unitary-lenght projection vector D perpendicular to R->S, and project
  ## R->T over D to compute the distance ot T from R->S.
  if (so)			# segment optimisation
    ## For each segment, r and s are its extremes
    r = 1; R = P(1,:)';		# start of segment
    s = 2; S = P(2,:)';		# end of the segment
    rebuild = true;		# build first projection vector

    for t = 3:rows(P)
      if (rebuild)		# build projection vector
	D = rot*(S-R)/sqrt(sumsq(S-R)); # projection vector for distance
	rebuild = false;	# keep current projection vector
      endif

      T = P(t,:)';		# next point

      if (abs(sum((T-R).*D)) < 1 # T is aligned
	  && sum((T-R).*(S-R)) > 0) # going forward
	V(s) = false;		# do not plot s
      else			# set a new segment
	r = s; R = S;		# new start of segment
	rebuild = true;		# rebuild projection vector
      endif
      s = t; S = T;		# new end of segment
    endfor
  endif

  C = P(V,:) .* repmat(E',sum(V),1); # denormalize P
endfunction



Reply sent to Rafael Laboissiere <rafael@debian.org>:
You have taken responsibility. (full text, mbox, link).


Notification sent to Francesco Potorti` <Potorti@isti.cnr.it>:
Bug acknowledged by developer. (full text, mbox, link).


Message #30 received at 365757-close@bugs.debian.org (full text, mbox, reply):

From: Rafael Laboissiere <rafael@debian.org>
To: 365757-close@bugs.debian.org
Subject: Bug#365757: fixed in octave-epstk 2.1-4
Date: Sat, 12 Aug 2006 05:02:19 -0700
Source: octave-epstk
Source-Version: 2.1-4

We believe that the bug you reported is fixed in the latest version of
octave-epstk, which is due to be installed in the Debian FTP archive:

octave-epstk_2.1-4.diff.gz
  to pool/main/o/octave-epstk/octave-epstk_2.1-4.diff.gz
octave-epstk_2.1-4.dsc
  to pool/main/o/octave-epstk/octave-epstk_2.1-4.dsc
octave-epstk_2.1-4_all.deb
  to pool/main/o/octave-epstk/octave-epstk_2.1-4_all.deb



A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 365757@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Rafael Laboissiere <rafael@debian.org> (supplier of updated octave-epstk package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@debian.org)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Format: 1.7
Date: Sat, 12 Aug 2006 13:34:58 +0200
Source: octave-epstk
Binary: octave-epstk
Architecture: source all
Version: 2.1-4
Distribution: unstable
Urgency: low
Maintainer: Debian Octave Group <pkg-octave-devel@lists.alioth.debian.org>
Changed-By: Rafael Laboissiere <rafael@debian.org>
Description: 
 octave-epstk - GNU Octave encapsulated postscript toolkit
Closes: 365757
Changes: 
 octave-epstk (2.1-4) unstable; urgency=low
 .
   [ Thomas Weber ]
   * Add plotcollapse.m script from Francesco Potorti` (Closes: #365757)
     Update copyright file accordingly.
 .
   [ Rafael Laboissiere ]
   * debian/control:
     - Hardcoded the binary depend to octave2.9 | octave2.1, since epstk
       works with both version of Octave.  This is an interim solution in
       waiting a better way to reintroduce the ${octave:Depends}
       variable in substvars.
     - Build-depends on both octave2.1-headers and octave2.9-headers
Files: 
 e501af0e78a1fddba56766bd22dac068 739 math optional octave-epstk_2.1-4.dsc
 b99342c90ab2ea726a0bd86fdef7477a 8189 math optional octave-epstk_2.1-4.diff.gz
 5f5669850cd8240c1b672907ff386df4 2069170 math optional octave-epstk_2.1-4_all.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFE3cDSk3oga0pdcv4RAqn/AJ4xedQI+MyhDgIZ+ELJzx1vTww6lQCeO7zG
uoN2NOFbN598x4RLavvyRz8=
=d4QU
-----END PGP SIGNATURE-----




Information forwarded to debian-bugs-dist@lists.debian.org, Debian Octave Group <pkg-octave-devel@lists.alioth.debian.org>:
Bug#365757; Package octave-epstk. (full text, mbox, link).


Acknowledgement sent to Francesco Potorti <Potorti@isti.cnr.it>:
Extra info received and forwarded to list. Copy sent to Debian Octave Group <pkg-octave-devel@lists.alioth.debian.org>. (full text, mbox, link).


Message #35 received at 365757@bugs.debian.org (full text, mbox, reply):

From: Francesco Potorti <Potorti@isti.cnr.it>
To: 365757@bugs.debian.org
Subject: Re: Bug#365757 closed by Rafael Laboissiere <rafael@debian.org> (Bug#365757: fixed in octave-epstk 2.1-4)
Date: Sat, 12 Aug 2006 18:26:39 +0200
>   [ Thomas Weber ]
>   * Add plotcollapse.m script from Francesco Potorti` (Closes: #365757)
>     Update copyright file accordingly.

In the meantime, I have improved the script (significantly faster and
more robust) and have renamed it, as it turns out that "decimating" is
the common term for referring to such algorithms.  Here is the improved
program:

===File /home/pot/math/octavelib/graph/plotdecimate.m=======
## Copyright © 2006  Francesco Potortì
##
## 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 2 of the License, or
## (at your option) 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, write to the Free Software Foundation,
## Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301, USA.

## -*- texinfo -*-
## @deftypefn {Function File} {} plotdecimate (@var{P})
## @deftypefnx {Function File} {} plotdecimate (@var{P}, @var{so})
## @deftypefnx {Function File} {} plotdecimate (@var{P}, @var{so}, @var{res})
##
## Optimise plot data by removing redundant points and segments
##
## The first parameter @var{P} is a two-column matrix to be plotted as X and
## Y coordinates.   The second optional argument @var{so} disables segment
## optimisation when set to @var{false} (default is @var{true}). The third
## optional argument @var{res} is the size of the largest error on the plot:
## if it is a scalar, it is meant relative to the range of X and Y values
## (default 1e-3); if it is a 2x1 array, it contains the absolute errors for
## X and Y.  Returns a two-column matrix containing a subset of the rows of
## @var{P}. A line plot of @var{P} has the same appearance as a line plot of
## the output, with errors smaller than @var{res}.  When creating point
## plots, set @var{so} to @var{false}.
## @end deftypefn

## Author: Francesco Potortì <Potorti@isti.cnr.it>
## $Revision: 2.7 $
## Usage: plotdecimate(P[, so[, res]])
## Description: Optimise plot data by removing redundant points and segments

function C = plotdecimate (P, so, res)

  if (!ismatrix(P) || columns(P) != 2)
    error("P must be a matrix with two columns");
  endif
  if (nargin < 2)
    so = true;			# do segment optimisation
  endif
  if (nargin < 3)
    res = 1e-3;			# default resolution is 1000 dots/axis
  endif

  ## Slack: admissible error on coordinates on the output plot
  if (isscalar(res))
    if (res <= 0)
      error("res must be positive");
    endif
    E = range(P)' * res;	# build error vector using range of data
  elseif (ismatrix(res))
    if (!all(size(res) == [2 1]) || any(res <= 0))
      error("res must be a 2x1 matrix with positive values");
    endif
    E = res;			# take error vector as it is
  else
    error("res should be a scalar or matrix");
  endif

  if (rows(P) < 3)
    C = P;
    return;			# nothing to do
  endif
  P ./= repmat(E',rows(P),1);	# normalize P
  rot = [0,-1;1,0];		# rotate a vector pi/4 anticlockwise

  ## Iteratively remove points too near to the previous point
  while (1)
    V = [true; sumsq(diff(P),2) > 1]; # points far from the previous ones
    if (all(V)) break; endif
    V = [true; diff(V) >= 0];	# identify the sequence leaders
    P = P(V,:);			# remove them
  endwhile

  ## Remove points laying near to a segment: for each segment R->S, build a
  ## unitary-lenght projection vector D perpendicular to R->S, and project
  ## R->T over D to compute the distance ot T from R->S.
  if (so)			# segment optimisation
    ## For each segment, r and s are its extremes
    r = 1; R = P(1,:)';		# start of segment
    s = 2; S = P(2,:)';		# end of the segment
    rebuild = true;		# build first projection vector

    for t = 3:rows(P)
      if (rebuild)		# build projection vector
	D = rot*(S-R)/sqrt(sumsq(S-R)); # projection vector for distance
	rebuild = false;	# keep current projection vector
      endif

      T = P(t,:)';		# next point

      if (abs(sum((T-R).*D)) < 1 # T is aligned
	  && sum((T-R).*(S-R)) > 0) # going forward
	V(s) = false;		# do not plot s
      else			# set a new segment
	r = s; R = S;		# new start of segment
	rebuild = true;		# rebuild projection vector
      endif
      s = t; S = T;		# new end of segment
    endfor
  endif

  C = P(V,:) .* repmat(E',sum(V),1); # denormalize P
endfunction
============================================================




Information forwarded to debian-bugs-dist@lists.debian.org, Debian Octave Group <pkg-octave-devel@lists.alioth.debian.org>:
Bug#365757; Package octave-epstk. (full text, mbox, link).


Acknowledgement sent to Rafael Laboissiere <rafael@debian.org>:
Extra info received and forwarded to list. Copy sent to Debian Octave Group <pkg-octave-devel@lists.alioth.debian.org>. (full text, mbox, link).


Message #40 received at 365757@bugs.debian.org (full text, mbox, reply):

From: Rafael Laboissiere <rafael@debian.org>
To: Francesco Potorti <Potorti@isti.cnr.it>, 365757@bugs.debian.org
Subject: Re: [Pkg-octave-devel] Bug#365757: closed by Rafael Laboissiere <rafael@debian.org> (Bug#365757: fixed in octave-epstk 2.1-4)
Date: Sat, 12 Aug 2006 20:14:33 +0200
* Francesco Potorti <Potorti@isti.cnr.it> [2006-08-12 18:26]:

> >   [ Thomas Weber ]
> >   * Add plotcollapse.m script from Francesco Potorti` (Closes: #365757)
> >     Update copyright file accordingly.
> 
> In the meantime, I have improved the script (significantly faster and
> more robust) and have renamed it, as it turns out that "decimating" is
> the common term for referring to such algorithms.  Here is the improved
> program:
>
> [...]

Thanks, I already committed it to the SVN repository of the octave-epstk
package.

-- 
Rafael



Bug archived. Request was from Debbugs Internal Request <owner@bugs.debian.org> to internal_control@bugs.debian.org. (Tue, 26 Jun 2007 00:28:00 GMT) (full text, mbox, link).


Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Sat Jul 1 14:22:05 2023; Machine Name: buxtehude

Debian Bug tracking system

Debbugs is free software and licensed under the terms of the GNU Public License version 2. The current version can be obtained from https://bugs.debian.org/debbugs-source/.

Copyright © 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson, 2005-2017 Don Armstrong, and many other contributors.