You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by "Auzinger, Thomas" <TA...@ert.com> on 2007/04/13 21:40:46 UTC

Newbie problem with batik speed

I'm new to Batik and used it for a prototype that displays waveforms and
measurements.  I'd like to learn some "best practices" for Batik. It works
o.k., except for the following:

1.	I wanted to have a  big crosshair instead of the default cursor, so
I defined one in the static SVG document that I put all my data in.:
<g id="cursor" transform="translate(0,0)">
	<line stroke-width=".1" style="fill:none;stroke:red" y1="-10"
y2="10" x1="0" x2="0"/>
	<line stroke-width=".1" style="fill:none;stroke:red" x1="-10"
x2="10" y1="0" y2="0"/>
</g>

In my mousemotionlistener I change the translate(*,*) to whatever it needs
to be.  This works, but it is kind of sluggish, and the SVG cursor is always
somewhat behind the system cursor:
    public void moveCursor(MouseEvent e) {
        try {
            AffineTransform at = this.jsvgCanvas.getViewBoxTransform()
                                                .createInverse();
            Point2D p = new Point2D.Double(e.getX(), e.getY());
            p = at.transform(p, null);

            if (EcgApplet.cursorTransform == null) {
                Element cursor = this.jsvgCanvas.getSVGDocument()
                                                .getElementById("cursor");
                EcgApplet.cursorTransform =
cursor.getAttributeNode("transform");
            }

            EcgApplet.cursorTransform.setValue("translate(" + p.getX() + ","
                                               + p.getY() + ")");
        }
        catch (Exception ex) {
            ex.printStackTrace();
            System.out.println(ex);
        }
    }
(If the design looks bad it's because it is, this prototype will be thrown
away)

2.	Displaying the measurements (i.e. drawing about 84 lines and 24
texts) takes about 2-3 seconds on a 3GHz dual core machine.
The method below is called 12 times:

    public void displayItem(GlobalAnalysisItem ai, int beat, int height) {
        long t0 = System.currentTimeMillis();
        String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
        SVGDocument doc = jsvgCanvas.getSVGDocument();
        int lArrow = 3;
        int x1 = ai.getOnSet().intValue() / 2;
        int x2 = ai.getOffSet().intValue() / 2;
        int yBase = 100;
        int yTop = -200;
        int yLine = -height;
        int yName = yLine - 2;
        int yValue = yLine + 5;
        String name = AnalysisItem.displayType(ai.getTypeID());
        String value = ai.getValue().intValue() + "";

        Element dimensioning1 = doc.getElementById("dimensioning");
        Element dimensioning = jsvgCanvas.getSVGDocument()
                                         .createElementNS(svgNS, "g");

        // calipers
        long t0a0 = System.currentTimeMillis();
        dimensioning.appendChild(createLine(x1, yBase, x1, yTop));

        long t0a = System.currentTimeMillis();
        System.err.println("displayItemA:" + (t0a - t0a0));
        dimensioning.appendChild(createLine(x2, yBase, x2, yTop));

        // line
        dimensioning.appendChild(createLine(x1, yLine, x2, yLine));

        // left arrow
        dimensioning.appendChild(createLine(x1, yLine, x1 + lArrow,
                                            yLine + (lArrow / 2)));
        dimensioning.appendChild(createLine(x1, yLine, x1 + lArrow,
                                            yLine - (lArrow / 2)));

        // right arrow
        dimensioning.appendChild(createLine(x2, yLine, x2 - lArrow,
                                            yLine + (lArrow / 2)));
        dimensioning.appendChild(createLine(x2, yLine, x2 - lArrow,
                                            yLine - (lArrow / 2)));

        // name
        dimensioning.appendChild(createText((x1 + x2) / 2, yName, name));

        // value
        dimensioning.appendChild(createText((x1 + x2) / 2, yValue, value));

        dimensioning1.appendChild(dimensioning);

        long t1 = System.currentTimeMillis();
        System.err.println("displayItem:" + (t1 - t0));
    }

Is there anything blatantly wrong with what I'm doing?  What can I do
better?

Thanks,

Thomas

Re: Newbie problem with batik speed

Posted by th...@kodak.com.
Hi Thomas,

"Auzinger, Thomas" <TA...@ert.com> wrote on 04/13/2007 03:40:46 PM:

> I'm new to Batik and used it for a prototype that displays waveforms
> and measurements.  I'd like to learn some "best practices" for Batik. 
> It works o.k., except for the following:
> 1.      I wanted to have a  big crosshair instead of the default 
> cursor, so I defined one in the static SVG document that I put all 
> my data in.:

    Actually SVG supports a user defined cursor (subject to 
platform restrictions).

> <g id="cursor" transform="translate(0,0)">
>         <line stroke-width=".1" style="fill:none;stroke:red" 
> y1="-10" y2="10" x1="0" x2="0"/>
>         <line stroke-width=".1" style="fill:none;stroke:red" 
> x1="-10" x2="10" y1="0" y2="0"/>
> </g>

> In my mousemotionlistener I change the translate(*,*) to whatever it
> needs to be.  This works, but it is kind of sluggish, and the SVG 
> cursor is always somewhat behind the system cursor:

   It looks like you are modifying the document outside of the
Canvas RunnableQueue.  This will cause the cursor to always lag.
Even if you fix this it will likely still lag a bit since it takes
a lot of work to render a cursor like this, but it should be better
and in particular it should now align when the cursor stops moving.

>     public void moveCursor(MouseEvent e) {
>         try {
>             AffineTransform at = this.jsvgCanvas.getViewBoxTransform()
>                                                 .createInverse();
>             Point2D p = new Point2D.Double(e.getX(), e.getY());
>             p = at.transform(p, null);
>             if (EcgApplet.cursorTransform == null) {
>                 Element cursor = this.jsvgCanvas.getSVGDocument()
> .getElementById("cursor");
>                 EcgApplet.cursorTransform = cursor.getAttributeNode(
> "transform");
>             }
>             EcgApplet.cursorTransform.setValue("translate(" + p.getX() + 
","
>                                                + p.getY() + ")");
>         }
>         catch (Exception ex) {
>             ex.printStackTrace();
>             System.out.println(ex);
>         }
>     }
> (If the design looks bad it's because it is, this prototype will be 
> thrown away)
> 2.      Displaying the measurements (i.e. drawing about 84 lines and 
> 24 texts) takes about 2-3 seconds on a 3GHz dual core machine.
> The method below is called 12 times:
>     public void displayItem(GlobalAnalysisItem ai, int beat, int height) 
{
>         long t0 = System.currentTimeMillis();
>         String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
>         SVGDocument doc = jsvgCanvas.getSVGDocument();
>         int lArrow = 3;
>         int x1 = ai.getOnSet().intValue() / 2;
>         int x2 = ai.getOffSet().intValue() / 2;
>         int yBase = 100;
>         int yTop = -200;
>         int yLine = -height;
>         int yName = yLine - 2;
>         int yValue = yLine + 5;
>         String name = AnalysisItem.displayType(ai.getTypeID());
>         String value = ai.getValue().intValue() + "";
>         Element dimensioning1 = doc.getElementById("dimensioning");
>         Element dimensioning = jsvgCanvas.getSVGDocument()
>                                          .createElementNS(svgNS, "g");
>         // calipers
>         long t0a0 = System.currentTimeMillis();
>         dimensioning.appendChild(createLine(x1, yBase, x1, yTop));
>         long t0a = System.currentTimeMillis();
>         System.err.println("displayItemA:" + (t0a - t0a0));
>         dimensioning.appendChild(createLine(x2, yBase, x2, yTop));
>         // line
>         dimensioning.appendChild(createLine(x1, yLine, x2, yLine));
>         // left arrow
>         dimensioning.appendChild(createLine(x1, yLine, x1 + lArrow,
>                                             yLine + (lArrow / 2)));
>         dimensioning.appendChild(createLine(x1, yLine, x1 + lArrow,
>                                             yLine - (lArrow / 2)));
>         // right arrow
>         dimensioning.appendChild(createLine(x2, yLine, x2 - lArrow,
>                                             yLine + (lArrow / 2)));
>         dimensioning.appendChild(createLine(x2, yLine, x2 - lArrow,
>                                             yLine - (lArrow / 2)));
>         // name
>         dimensioning.appendChild(createText((x1 + x2) / 2, yName, 
name));
>         // value
>         dimensioning.appendChild(createText((x1 + x2) / 2, yValue, 
value));
>         dimensioning1.appendChild(dimensioning);
>         long t1 = System.currentTimeMillis();
>         System.err.println("displayItem:" + (t1 - t0));
>     }
> Is there anything blatantly wrong with what I'm doing?  What can I do 
better?
> Thanks,
> Thomas

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Newbie problem with batik speed

Posted by th...@kodak.com.
Hi Thomas,

"Auzinger, Thomas" <TA...@ert.com> wrote on 04/13/2007 03:40:46 PM:

> 2.      Displaying the measurements (i.e. drawing about 84 lines and 
> 24 texts) takes about 2-3 seconds on a 3GHz dual core machine.
> The method below is called 12 times:

>     public void displayItem(GlobalAnalysisItem ai, int beat, int height) 
{


     try {
 jsvgCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new 
Runnable() {
                public void run() { ea.displayIDMs(); }
         });
      } catch (Exception ix) {}
 
   You shouldn't submit 12 separate Runnables otherwise the canvas will 
rerender the document between each runnable.  Submit one runnable that
calls displayItem 12 times.



---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org