[python@lee-morgan.net] Re: [wxPython] OGL exhausting GDI heap (Win32)

writes:

Sorry I can't help you with theGDI heap problem...

> I'm bending OGL's purpose a little and trying to use it as a very simple 2D mapping
> component (if anyone knows a better solution I'd love to hear it!).

I ttok another route, deciding that I would be bending OGL's purpose too
mush to tbe worth it.

I now have a class that creates a window that will display objects
(polygons, text, rectangles, circles, etc) in Lat-long space (or any
floating point coordinates). It is zoomable and scollable, does a simple
flat-earth projection. I hav't had the chance to work on it for a while,
but I'm hoping to re-visit it soon.

I'd be glad to send it to you if you like, and be even happier if you
want to contribute to it! What are your requirements for a "2d mapping
component"?

Let me know if you want to take a look.

Yes please. I'd also be happy to contribute, to some wxpython component to do
this.

At the moment my requirements are very simple - scrollable, object positioning,
fp co-ords, no projection corrections, drop down menus on the objects. Currently
I'm using small bitmaps to represent objects - likely to be the main cause of my
GDI probs - but could use shapes instead. Ideally i'd like to be able to switch
between the two.

In the future I'd like to add object rotations, waypoint/keyposition nodes,
group selection, a way of layering maps - selectable terrain/road network/grid
etc, map in map location box etc etc. There's bound to be other stuff I may need
but at this point I should remind myself I'm much more efficient at dreaming up
new functionality than at implementing it!

···

python@lee-morgan.net wrote:

-Chris

--
Christopher Barker,
Ph.D.
ChrisHBarker@home.net --- --- ---
http://members.home.net/barkerlohmann ---@@ -----@@ -----@@
                                   ------@@@ ------@@@ ------@@@
Oil Spill Modeling ------ @ ------ @ ------ @
Water Resources Engineering ------- --------- --------
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------

--
wxPython

Lee Morgan wrote:

> Let me know if you want to take a look.

Yes please. I'd also be happy to contribute, to some wxpython component to do
this.

you can find it at:

http://members.home.net/barkerlohmann/downloads/download.html

At the moment my requirements are very simple - scrollable, object positioning,
fp co-ords,

got that.

no projection corrections

can eaqsily be turned off, but if yo are using lat-long data, you might
as well have a projection, particularly if you are at high latitudes.

drop down menus on the objects.

That I don't have. I'd really like to add events to it however. The
tricky part, as I see it, is doing the hit test part. You'd have to have
a fast way to figure out which object the user just clicked on. For
rectangular objects, that's pretty easy, but for polygons, it could be
pretty tricky to do fast in Python... anyone have any ideas?

Currently
I'm using small bitmaps to represent objects - likely to be the main cause of my
GDI probs - but could use shapes instead.

I like vector drawing better.. it just makes more sense to me, and it
can be zoomed a whole lot easier...

Ideally i'd like to be able to switch between the two.

I'd like to be able to add bitmaps as well, but I'm not sure how I would
deal with the zooming... I have some ideas..

In the future I'd like to add object rotations, waypoint/keyposition nodes,
group selection, a way of layering maps - selectable terrain/road network/grid
etc, map in map location box etc etc.

All good stuff...

There's bound to be other stuff I may need
but at this point I should remind myself I'm much more efficient at dreaming up
new functionality than at implementing it!

Me too!

By the way, you might want to take a look at Klass Holwerda's Vector
drawing canvas. It's C++ only at the moment, but Robin has said he's
interested in wrapping it for wxPython when it gets stable, and It could
be just what we need...

http://www.xs4all.nl/~kholwerd/wxstuff/canvas/

-Chris

···

--
Christopher Barker,
Ph.D.
ChrisHBarker@home.net --- --- ---
http://members.home.net/barkerlohmann ---@@ -----@@ -----@@
                                   ------@@@ ------@@@ ------@@@
Oil Spill Modeling ------ @ ------ @ ------ @
Water Resources Engineering ------- --------- --------
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------

Chris Barker <chrishbarker@home.net> writes:

Lee Morgan wrote:
> > Let me know if you want to take a look.

> Yes please. I'd also be happy to contribute, to some wxpython component to do
> this.

you can find it at:

http://members.home.net/barkerlohmann/downloads/download.html

Great, I hope to look at it this weekend.

> At the moment my requirements are very simple - scrollable, object positioning,
> fp co-ords,

got that.

> no projection corrections

can eaqsily be turned off, but if yo are using lat-long data, you might
as well have a projection, particularly if you are at high latitudes.

>drop down menus on the objects.

That I don't have. I'd really like to add events to it however. The
tricky part, as I see it, is doing the hit test part. You'd have to have
a fast way to figure out which object the user just clicked on. For
rectangular objects, that's pretty easy, but for polygons, it could be
pretty tricky to do fast in Python... anyone have any ideas?

That part I'd need before I could use it. You could hit test a bounding box
first and then the shape, and you could even see if its worth maintaining some
partitioning structure like a quadtree. But I agree, I think it would be better
this was handled at a lower level.

> I'm using small bitmaps to represent objects - likely to be the main cause of my
> GDI probs - but could use shapes instead.

I like vector drawing better.. it just makes more sense to me, and it
can be zoomed a whole lot easier...

> Ideally i'd like to be able to switch between the two.

I'd like to be able to add bitmaps as well, but I'm not sure how I would
deal with the zooming... I have some ideas..

> In the future I'd like to add object rotations, waypoint/keyposition nodes,
> group selection, a way of layering maps - selectable terrain/road network/grid
> etc, map in map location box etc etc.

All good stuff...

> There's bound to be other stuff I may need
> but at this point I should remind myself I'm much more efficient at dreaming up
> new functionality than at implementing it!

Me too!

By the way, you might want to take a look at Klass Holwerda's Vector
drawing canvas. It's C++ only at the moment, but Robin has said he's
interested in wrapping it for wxPython when it gets stable, and It could
be just what we need...

Yeah, I'd heard of wxCanvas and thought it sounded as if it would be a good
base, and the vector drawing canvas looks very suitable. I wonder how far away
stablility is.

···

http://www.xs4all.nl/~kholwerd/wxstuff/canvas/

-Chris

--
Christopher Barker,
Ph.D.
ChrisHBarker@home.net --- --- ---
http://members.home.net/barkerlohmann ---@@ -----@@ -----@@
                                   ------@@@ ------@@@ ------@@@
Oil Spill Modeling ------ @ ------ @ ------ @
Water Resources Engineering ------- --------- --------
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------

--
wxPython

python@lee-morgan.net wrote:

> >drop down menus on the objects.
>
> That I don't have. I'd really like to add events to it however. The
> tricky part, as I see it, is doing the hit test part. You'd have to have
> a fast way to figure out which object the user just clicked on. For
> rectangular objects, that's pretty easy, but for polygons, it could be
> pretty tricky to do fast in Python... anyone have any ideas?

That part I'd need before I could use it. You could hit test a bounding box
first and then the shape, and you could even see if its worth maintaining some
partitioning structure like a quadtree. But I agree, I think it would be better
this was handled at a lower level.

I just took a look at Pysketch, and this is what he came up with:

    def objectContainsPoint(self, x, y):
        """ Returns true iff this object contains the given point.
        
            This is used to determine if the user clicked on the object.
        """
        # Firstly, ignore any points outside of the object's bounds.
        
        if x < self.position.x: return false
        if x > self.position.x + self.size.x: return false
        if y < self.position.y: return false
        if y > self.position.y + self.size.y: return false
        
        if self.type in [obj_RECT, obj_TEXT]:
            # Rectangles and text are easy -- they're always selected if
the
            # point is within their bounds.
            return true
            
            # Now things get tricky. There's no straightforward way of
knowing
            # whether the point is within the object's bounds...to get
around this,
            # we draw the object into a memory-based bitmap and see if
the given
            # point was drawn. This could no doubt be done more
efficiently by
            # some tricky maths, but this approach works and is simple
enough.
            
        bitmap = wxEmptyBitmap(self.size.x + 10, self.size.y + 10)
        dc = wxMemoryDC()
        dc.SelectObject(bitmap)
        dc.BeginDrawing()
        dc.SetBackground(wxWHITE_BRUSH)
        dc.Clear()
        dc.SetPen(wxPen(wxBLACK, self.lineSize + 5, wxSOLID))
        dc.SetBrush(wxBLACK_BRUSH)
        self._privateDraw(dc, wxPoint(5, 5), true)
        dc.EndDrawing()
        pixel = dc.GetPixel(x - self.position.x + 5, y - self.position.y
+ 5)
        if (pixel.Red() == 0) and (pixel.Green() == 0) and (pixel.Blue()
== 0):
            return true
        else:
            return false
           
A pretty nifty trick, but I can't help wondering if that is too much
overhead for what should be a relatively simple process. I had actually
considered something similar, but keeping a separate pixmap in the
background that would get drawn to when the object was created. Each
object would be drawn in a different color, so that at the end the color
of each pixel would indicate which object that pixel belonged too. The
problem is that it would essentially double the drawing speed, but it
would make for a very fast hit-test!

I'd love to hear any ideas.

Someday soon I'll probably either borrow this code, or write some of my
own, and add it to my canvas.

-Chris

···

Yeah, I'd heard of wxCanvas and thought it sounded as if it would be a good
base, and the vector drawing canvas looks very suitable. I wonder how far away
stablility is.

> http://www.xs4all.nl/~kholwerd/wxstuff/canvas/
>
> -Chris
>
>
>
> --
> Christopher Barker,
> Ph.D.
> ChrisHBarker@home.net --- --- ---
> http://members.home.net/barkerlohmann ---@@ -----@@ -----@@
> ------@@@ ------@@@ ------@@@
> Oil Spill Modeling ------ @ ------ @ ------ @
> Water Resources Engineering ------- --------- --------
> Coastal and Fluvial Hydrodynamics --------------------------------------
> ------------------------------------------------------------------------
>

--
wxPython

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

--
Christopher Barker,
Ph.D.
ChrisHBarker@home.net --- --- ---
http://members.home.net/barkerlohmann ---@@ -----@@ -----@@
                                   ------@@@ ------@@@ ------@@@
Oil Spill Modeling ------ @ ------ @ ------ @
Water Resources Engineering ------- --------- --------
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------