Hi,

I asked the question below on Oct 26 (thanks for the answers).  In summery I am
drawing a large number of unconnected lines on a graph and zooming in on it. I
have since improved the performance, but it is still some 300 times slower than
equivalent code written in C using Open GL (see the times below).

I was wondering if anyone can suggest ways of speeding up the drawing.  I
include some relevant code and some times I have got.  For the full code please
see my web page http://www.hgmp.mrc.ac.uk/~hmorgan2/my_files.html

I am running it on a Sun Ultra 10 under solaris.

Times (per screen redraw, in milliseconds)

10,000 lines
Java, not using GeneralPath ~185ms
Java, using GeneralPath ~300ms
C, inaccurate measure ~5ms

110,000 lines
Java, not using General Path ~1500ms
C, more accurate measure ~50ms

Breakdown of times for Java, not using GeneralPath:-
clearRect - 30ms
prepareScale - ~55ms
drawLines - ~90ms

public void update(Graphics oldGraphics)
{
        g = (Graphics2D)oldGraphics;
        g.drawImage(offImage, at, null);
}

final void redrawImage()
{
        offScreenGraphics.clearRect(0, 0, 1024, 1024);
        prepareScale();
        drawLines(offScreenGraphics);
}
final void drawLines(Graphics2D g)
{
        if(useGP)
        {
                g.setColor(Color.blue);
                g.draw( polyLinePath );
        } else
        {
                g.setColor(Color.blue);
                for(i = 0; i<Array.getLength(xNewValues1); ++i)
                {
                        g.drawLine(xNewValues1[i], (size - yNewValues1[i]),
xNewValues2[i], (size - yNewValues2[i]));
                }
        }
}

final void prepareScale()
{
        at.setToTranslation(xPos, yPos);
        at.scale((xfactor / imageXFactor), (yfactor / imageYFactor));
        at.translate(-xPos, -yPos);
}

I have purposefully not used clipping because the worst case is most important,
ie. when the screen is zoomed out and all the lines are in view.  Also the
sorting algorithm that would be needed would be for the preprocessing would be
built into the program that outputs the lines.

Previous message:----------------------------------------------------

>>>
>>>Hi,
>>>
>>>I am drawing scientific graphs consisting of a large number (over 1000) of
>>>unconnected lines.  The user can zoom in using a JSlider.  It takes around 50
>>>milliseconds to perform a zoom, and this flickers when the slider is dragged.
 I
>>>tried double buffering and this increased the time it took to draw ten fold.
>>>
>>>Should I be able to get better performance with java 2D.  Does anyone have
any
>>>suggestions about how to improve my code.  Any help would be greatly
>>>appreciated.
>>>
>>>
>>>I include my code for doing the drawing.
>>>
>>>void drawGraph(Graphics g)
>>>  {
>>>    g2d = (Graphics2D)g;
>>>    int i;
>>>    at = new AffineTransform();
>>>    g2d.translate(xPos, yPos);
>>>    at.setToScale(factor, factor);
>>>    g2d.transform(at);
>>>    g2d.translate(-xPos, -yPos);
>>>
>>>// Draw Grid
>>>    g2d.setColor(Color.red);
>>>    for(i=0; i<20; ++i)
>>>    {
>>>     j = i*size;
>>>     g2d.drawLine(i*size,0,i*size,(19 * size));
>>>    }
>>>
>>>    for(i=0; i<20; ++i)
>>>    {
>>>     j =  i*size;
>>>     g2d.drawLine(0,i*siz,(19 * size),i*size);
>>>    }
>>>
>>>    g2d.setColor(Color.blue);
>>>
>>>// Draw Line
>>>    drawLineToPoints(g2d, xValues1, yValues1, xValues2, yValues2);
>>>  }
>>>
>>>// Function to draw the line
>>>  void drawLineToPoints(Graphics2D g2d, Vector xValues1, Vector yValues1,
Vector
>>>xValues2, Vector yValues2)
>>>  {
>>>     for(int a=0; a<xValues1.size(); ++a)
>>>     {
>>>             g2d.drawLine(getInt(xValues1, (a)),((19 * size + 1) -
>>>getInt(yValues1, (a))),getInt(xValues2, (a)),((19 * size + 1) -
getInt(yValues2,
>>>(a))));
>>>     }
>>>  }

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to