[comp.sys.amiga.advocacy] Contour plotting

bcphyagi@csunb.csun.edu (Stephen Walton) (02/28/91)

Well, I went to try and generate a contour plot of a 512 by 512 real
data set the other week on the MS/DOS machines we have at our observatory.
Using the demo version of this "wonderful, beautiful, powerful" program
called GRAFTOOL for MS/DOS (which has received rave reviews) I had to:
1) generate a 3-d plot of the image (1 hour) and 2) ask the program to
generate the contour plot (another hour+, I haven't had the patience to
run it to completion).  This is on a _20 MHz_ 386 machine!

To do the same thing on my good old Amiga 2000 (no FPU, 7 MHz 68000),
I malloc'ed a 512 by 512 float array and called Tony Richardson's
plcont() routine from his PLPLOT library.  Total time for generating
the plot was less than 5 minutes.  It is less than 1 minute on a 3000.

Just thought y'all would like to know this.
--
Stephen R. Walton, Dept. of Physics and Astronomy, Cal State Northridge
bcphyagi@csunb.csun.edu until my Suns come back up

alex@bilver.uucp (Alex Matulich) (03/01/91)

In article <1991Feb27.194218.12227@csun.edu> bcphyagi@csunb.csun.edu (Stephen Walton) writes:
>Using the demo version of this "wonderful, beautiful, powerful" program
>called GRAFTOOL for MS/DOS (which has received rave reviews) I had to:
>1) generate a 3-d plot of the image (1 hour) and 2) ask the program to
>generate the contour plot (another hour+, I haven't had the patience to
>run it to completion).  This is on a _20 MHz_ 386 machine!
>
>To do the same thing on my good old Amiga 2000 (no FPU, 7 MHz 68000),
>I malloc'ed a 512 by 512 float array and called Tony Richardson's
>plcont() routine from his PLPLOT library.  Total time for generating
>the plot was less than 5 minutes.  It is less than 1 minute on a 3000.

Comparing two machines according to completely different contour algorithms
tells nobody anything.  As a programmer who has written contour-drawing
algorithms for different purposes, I think I can shed some light on this. 
 
If you are only going to display your contour plots on a video screen, there
are a LOT of things you can do to speed up the algorithm.  On the other hand,
if you are going to output your contours to a pen plotter, which is what
I think GRAFTOOL's algorithm was designed for, things slow down considerably.
 
For the pen-plotter algorithm, you have to design the routine to minimize
the number of pen lifts and pen color changes.  If you don't, a simple
plot can take 4 or 5 hours to complete.  This means that your algorithm
must find a contour of a desired level, figure out how to trace it all
around your data array, keep track of where the pen has been so the program
knows when a contour closes or whether a given contour has already been
drawn if there are several same-level contour lines in your data.  Only
one contour interval can be handled at a time, which means, if your data
contains 50 contour intervals, your array will have to be scanned that many
times to complete the plot.  You can reasonbaly expect an efficient 
pen-plotter algorithm to complete a 512x512 plot in about an hour, depending
on the complexity of the data and the number of contour intervals in it.
This was what I observed on a 33 MHz 68030 Hewlett-Packard workstation which
I was programming.
 
A screen-only contour plot is very fast.  The fastest algorithm is to
simply paint each pixel on the screen using a color calculated from an
interpolation of your data.  This results in filled-color contours instead
of line drawings.  For line drawings, you can simply draw all the contours
in a data cell, move to the next cell and draw all its contours, and so on
(this would result in thousands of unnecessary pen lifts and moves and
color changes for pen-plotter output).

Take a careful look at the capabilities of your contouring programs on
the Amiga and IBM compatibles.  What are they designed for?  I would
venture that the GRAFTOOLS algorithm would take just as long if it were
run on the Amiga.  And your Amiga PLPLOT library would probably run
in as short a time if it were ported to MSDOS.

-- 
 _ |__  Alex Matulich   (alex@bilver.UUCP)
 /(+__>  Unicorn Research Corp, 4621 N Landmark Dr, Orlando, FL 32817
//| \     UUCP:  ...uunet!tarpit!bilver!alex
///__)     bitnet:  IN%"bilver!alex@uunet.uu.net"

kent@swrinde.nde.swri.edu (Kent D. Polk) (03/01/91)

In article <1991Feb28.173901.27728@bilver.uucp> alex@bilver.uucp (Alex Matulich) writes:
>In article <1991Feb27.194218.12227@csun.edu> bcphyagi@csunb.csun.edu (Stephen Walton) writes:
>>Using the demo version of this "wonderful, beautiful, powerful" program
>>called GRAFTOOL for MS/DOS (which has received rave reviews) I had to:
>>1) generate a 3-d plot of the image (1 hour) and 2) ask the program to
>>generate the contour plot (another hour+, I haven't had the patience to
>>run it to completion).  This is on a _20 MHz_ 386 machine!
>>
>>To do the same thing on my good old Amiga 2000 (no FPU, 7 MHz 68000),
>>I malloc'ed a 512 by 512 float array and called Tony Richardson's
>>plcont() routine from his PLPLOT library.  Total time for generating
>>the plot was less than 5 minutes.  It is less than 1 minute on a 3000.
>
>Comparing two machines according to completely different contour algorithms
>tells nobody anything.  As a programmer who has written contour-drawing
>algorithms for different purposes, I think I can shed some light on this. 
> 
>If you are only going to display your contour plots on a video screen, there
>are a LOT of things you can do to speed up the algorithm.  On the other hand,
>if you are going to output your contours to a pen plotter, which is what
>I think GRAFTOOL's algorithm was designed for, things slow down considerably.

I think you missed the point as well as not knowing what PLPLOT is.
First, PLPLOT is a device-independent 3D PLOTTING library for the Amiga
and Unix boxes. It supports pen plotters, which are its lowest common
denominator, postscript, tektronics, IFF, etc., so there are no
algorithms to speed up things for screens.  The screen operations on an
Amiga are simply tremendously faster, and the architecture of the
machine allows a much more straightforward approach to writing
software, and I expect this is where PLPLOT really picks up its speed,
as compared to GRAFTOOL.

I also believe Mr. Walton was comparing overall the ease with which you
can perform operations on an Amiga, regardless of how you accomplish
it, versus the MSDOS environment. If this is the case, I second his
view.  While there may not be as much 'packaged' software on the Amiga,
the PD offerings like PLPLOT and the ease with which data can be moved
from program to program on the Amiga (kind of like Unix filters :^) allow
a remarkable environment for those who don't mind a little brainwork.

>Take a careful look at the capabilities of your contouring programs on
>the Amiga and IBM compatibles.  What are they designed for?  I would
>venture that the GRAFTOOLS algorithm would take just as long if it were
>run on the Amiga.  And your Amiga PLPLOT library would probably run
>in as short a time if it were ported to MSDOS.

One of our guys looked into porting it. The severe limitations of
MS-DOS would require a tremendous effort to get around the 64k segment
limitations.  You can't even compile the PLPLOT stick fonts under
MS-DOS! From my programming experiences on both machines, I would say
that for 'similar' platforms, the MSDOS programs would run much slower;
tremendously slower when using screen graphics.

Back to PLPLOT. We use it quite a bit. While it definitely has some
limitations, it is a very capable library. Maybe some day I'll get
around to fixing some of the problems. The author has decided to not
continue further development. Anyone want to pick this up?

Kent Polk: Southwest Research Institute (512) 522-2882
Internet : kent@swrinde.nde.swri.edu
UUCP     : $ {cs.utexas.edu, gatech!petro, sun!texsun}!swrinde!kent

bcphyagi@csunb.csun.edu (Stephen Walton) (03/02/91)

In article <1991Feb28.173901.27728@bilver.uucp> alex@bilver.uucp (Alex
Matulich) writes:

>Comparing two machines according to completely different contour algorithms
>tells nobody anything.

It does if the two algorithms purport to accomplish the same thing--it
tells you how long it will take each machine to perform the task I
require. 

>If you are only going to display your contour plots on a video screen,
>there are a LOT of things you can do to speed up the algorithm.

PLPLOT is not in this category.  It supports the Amiga screen,
Tektronix terminals, HP Laser Jet II and Postscript printers, and HP
7451 pen plotters.  Besides, I was in fact comparing the relative times
required to get screen plots. 

You also missed the point that this two-hour+ operation to generate the
contours in GRAFTOOL is *required before* you can get the pen plot.
PLPLOT will generate the pen plot directly. 

>For the pen-plotter algorithm, you have to design the routine to minimize
>the number of pen lifts and pen color changes.

PLPLOT uses an algorithm like this.  If you watch it run on the Amiga
screen, it does in fact produce one contour interval at a time, making
a complete pass through the data for each contour level.  I admit that
I've never tried the pen plot part, but I bet it takes much less than
the time GRAFTOOL takes to just do the screen version. 

>I would venture that the GRAFTOOLS algorithm would take just as long if
>it were run on the Amiga.

I can easily believe this :-) .

>And your Amiga PLPLOT library would probably run in as short a time if
>it were ported to MSDOS.

Please tell me how to run the following loop under MSDOS:

        float **z;

	z = (float **) malloc(512 * sizeof(float *));
	for (i = 0; i < 512; i++)
		z[i] = (float *) malloc(512 * sizeof(float));
--
Stephen R. Walton, Dept. of Physics and Astronomy, Cal State Northridge
bcphyagi@csunb.csun.edu until my Suns come back up

alex@bilver.uucp (Alex Matulich) (03/04/91)

In article <1991Mar1.213257.6960@csun.edu> bcphyagi@csunb.csun.edu (Stephen Walton) writes:
>>Comparing two machines according to completely different contour algorithms
>>tells nobody anything.
>
>It does if the two algorithms purport to accomplish the same thing--it
>tells you how long it will take each machine to perform the task I
>require. 

I apologize for misunderstanding the way PPLOT worked.  However, I still think
your statement above is incorrect.  Two dissimilar algorithms that have the
same end result cannot be used to make a valid comparison between two
dissimilar architectures as well.  At best you are just comparing the
algorithms, but a hardware comparison was implied in your original article.
I didn't know that the Amiga graphics package was device-independent.  In
that case, I am impressed!  It's contouring algorithm must be extremely
well-designed and optimized compared to the IBM GRAFTOOLS package.

>You also missed the point that this two-hour+ operation to generate the
>contours in GRAFTOOL is *required before* you can get the pen plot.
>PLPLOT will generate the pen plot directly. 

I didn't know that.  Yecch!

>>For the pen-plotter algorithm, you have to design the routine to minimize
>>the number of pen lifts and pen color changes.
>
>PLPLOT uses an algorithm like this.  If you watch it run on the Amiga
>screen, it does in fact produce one contour interval at a time, making
>a complete pass through the data for each contour level.  I admit that
>I've never tried the pen plot part, but I bet it takes much less than
>the time GRAFTOOL takes to just do the screen version. 

Here the plotter speed and the size of it's data buffer is the primary
factor in the speed of the output.  With no buffer (like an HP 7475 plotter)
the plotter might well take two hours with _either_ algorithm, depending
on the complexity of your data.  I learned this from painful experience!

>Please tell me how to run the following loop under MSDOS:
>
>        float **z;
>
>	z = (float **) malloc(512 * sizeof(float *));
>	for (i = 0; i < 512; i++)
>		z[i] = (float *) malloc(512 * sizeof(float));

Easy.  The pointers must be declared as far or huge, and malloc() should
be substituted with _fmalloc() or whatever equivalent your MSDOS compiler
has.  I like programming on the Amiga because I don't have to worry about
memory-model issues, but I have to do MSDOS programming too, and the available
C compilers provide reasonable work-arounds given the constraints of
the architecture.
 
I have noticed one case in my own projects where a 25 MHz 80386 runs a
program slower than a 14-Mhz 68000 Amiga.  It was a sort routine.  The
MSDOS cpu can only use two registers for user programs, whereas the
68000 can use many more.  For tight multi-nested loops, this is an important
factor in speed.  Maybe it's also a factor in your observed differences
between the speed of contour plots.

-- 
 _ |__  Alex Matulich   (alex@bilver.UUCP)
 /(+__>  Unicorn Research Corp, 4621 N Landmark Dr, Orlando, FL 32817
//| \     UUCP:  ...uunet!tarpit!bilver!alex
///__)     bitnet:  IN%"bilver!alex@uunet.uu.net"