OGL module problems

Hello to all,

I am trying to use ogl to select a subregion of an image and clip it.
Basically I want to put a movable, resizable, rotatable rectangle on a
photo, and extract the subimage selected by the bounding box of the
rectangle. This is to be able to crop to the interesting part of a
photo.

However, I saw that even if there is a Rotate method in OGL, it is not
implemented, or at least only for the polygon shape ! Or I am missing
something there ?

Secondly I saw that OGL doesnt allow to put it in top of a wxBitmap or
whatever holding another thing than a background colour. I could
modify this by changing the OnPaint method of the ShapeCanvas class.
This is the quick change I did:

    # START new onpaint methid for shapecanvas
    def OnPaint(self, evt):
        dc = wx.PaintDC(self)
        self.PrepareDC(dc)

        try:
            # try getting a bitmap from the parent object
            bitmap = self.parent.GetBitmap()
            dc.Clear()
            dc.DrawBitmap(bitmap, 0, 0, False)
        except:
            # fallback to set a background colour
            dc.SetBackground(wx.Brush(self.GetBackgroundColour(),
wx.SOLID))
            dc.Clear()

        if self.GetDiagram():
            self.GetDiagram().Redraw(dc)
    # STOP new onpaint methid for shapecanvas

However the PolygonShape is not good for the job, because it preserves
the width/height ratio so even if I do a 4-point polygon to emulate a
rectangle, I wont be able to resize only width or only height.

Another problem I found is I try to bind the keyboard events, because
I want to bind the 'r' and 'R' keys to do a Rotate (clockwise and
counter-clockwise) but OGL doesnt seem to handle the keyboard events.

So if someone could only help me a bit ? Or maybe tell me if there is
an alternative to OGL ? I would be very grateful.

Thank you,

kpoman wrote:

I am trying to use ogl to select a subregion of an image and clip it.
Basically I want to put a movable, resizable, rotatable rectangle on a
photo, and extract the subimage selected by the bounding box of the
rectangle. This is to be able to crop to the interesting part of a
photo.

This sounds like you are pushing OGL beyond what it is intended to do.

However, I saw that even if there is a Rotate method in OGL, it is not
implemented, or at least only for the polygon shape ! Or I am missing
something there ?

well, I think OGL uses wx.DC to render, and you can't render a rotated rectangle with a DC, so that probably explains it.

However the PolygonShape is not good for the job, because it preserves
the width/height ratio so even if I do a 4-point polygon to emulate a
rectangle, I wont be able to resize only width or only height.

you'll probably have to subclass PolygonShape (or make a new shape type) to do this -- I can't tell you how hard it is to do that.

Or maybe tell me if there is
an alternative to OGL ? I would be very grateful.

wx.lib.floatcanvas could do this pretty well, though not quite out of the box:

Use a FloatCanvas.ScaledImage2 for your image.

You can't rotate a recatngle in floatcanvas either, for the same reason. (indeed, floatcanvas doesn't directly support rotation of anything).

However, you can subclass Polygon (or make a new DrawObject). and add whatever methods you want to it: rotation, etc.

Take a look at the Demos is SVN to see how to manipulate objects with the mouse:

http://svn.wxwidgets.org/viewvc/wx/wxPython/3rdParty/FloatCanvas/Demos/

In particular, look at BNAEditor, PolyEditor, and TextBox2

If you are Windows, another option is FloatCanvas2 -- it is built on wxGraphicsContext, and support rotation, etc. out of the box.

There is a little bit of information in TRAC:

http://trac.paulmcnett.com/floatcanvas

Please feel free to send you questions to the floatcanvas list:

http://mail.paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov