[OpenMap Users] OMRasterObject's shape is not rotated with image

From: Joshua Foster <jfoster_at_dtiweb.net>
Date: Fri, 15 Jan 2010 10:56:16 -0500

Hi all, I believe I have found a bug in OMRasterObject. The java.awt.Shape associated with the OMRasterObject does not honor the image's rotation angle.

For a square image this is mostly OK, but for non-square it can cause a lot of headache... imagine a tall, narrow image rotated 90 degrees (via setRotationAngle()), then the user clicks near the edge of the onscreen image and we use contains() to determine if the click is within the image bounds. It will fail, because the Shape that contains() checks is the shape of the original, non-rotated image.

I have a patch for this - it requires minor changes to setShape() and rotate() in OMRasterObject. The changes are delimited with // BUGFIX

----------------------------------------

    /**
     * Set the rectangle, based on the location and size of the image.
     */
    public void setShape() {

        // generate shape that is a boundary of the generated image.
        // We'll make it a GeneralPath rectangle.
        int w = width;
        int h = height;

        if (imageFilter != null) {
            w = filteredWidth;
            h = filteredHeight;
        }

        setShape(createBoxShape(point1.x, point1.y, w, h));
        
        // JAF - BUGFIX - rotate Shape to match image rotation
        if( rotationAngle != 0 ) {
            java.awt.geom.AffineTransform xform =
                java.awt.geom.AffineTransform.getRotateInstance( rotationAngle,
                    point1.x + w/2, point1.y + h/2 );

            getShape().transform( xform );
        }
        // End BUGFIX
    }

    /**
     * Called from within render(). This method should call rotate()
     * on the provided Graphics2D object, setting the rotation angle
     * and the rotation point. By default, the rotation angle is
     * whatever is set in the OMRasterObject, and the rotation point
     * is the offset point plus half the image width in the horizonal
     * direction, and half the image in the vertical direction.
     */
    protected void rotate(Graphics2D g) {
        int w = width;
        int h = height;

        // JAF - BUGFIX - rotate Shape to match image rotation
        // We can't use the width and height from the Shape anymore it might
        // have been rotated. Use the dimensions of the original image (or the
        // filtered dimensions if filtered).
        //if (shape != null) {
        // java.awt.Rectangle rect = shape.getBounds();
        // w = (int) rect.getWidth();
        // h = (int) rect.getHeight();
        //}
        
        if (imageFilter != null) {
            w = filteredWidth;
            h = filteredHeight;
        }
        // End BUGFIX

        ((Graphics2D) g).rotate(rotationAngle, point1.x + w / 2, point1.y + h
                / 2);
    }
________________________________________

In setShape(), I just use an AffineTransform to rotate the Shape. This requires a modification in rotate(), since for some reason it used the Shape's bounds as the image size instead of the filtered width and height.

Does this fix seem acceptable? Is modifying the Shape in this way likely to cause problems elsewhere? I haven't done extensive testing, but everything seems to work for me.




Joshua Foster
Sr. Computer Programmer
2721 X-Ray Drive
Gastonia, NC 28054
(704) 824-0199 x217
(704) 824-0241 Fax

jfoster_at_dtiweb.net
www.dtiweb.net
This message may contain sensitive, proprietary and/or privileged information. Disclosure is not authorized unless provided in writing by Defense Technologies, Inc. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation.
 

--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Fri Jan 15 2010 - 11:11:26 EST

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:09 EDT