Testing for points inside a polygon

Ed Leafe wrote:

However, I tested your code right now and I get:

Point 1: (255, 0, 0, 255)
Point 2: (0, 0, 0, 255)
Point 3: (255, 0, 0, 255)

This is Windows XP, Python 2.5, wxPython 2.8.3.

    Hmm... I tested on OS X, Python 2.4.3, wxPython 2.8.3, and got the results I previously posted. So I copied the code to my XP machine (same version of Python and wxPython as you), and got your results. I also got your results when running on Kubuntu 7.04, Python 2.5.1, wxPython 2.8.3.

    So it seems that this is an OS X issue. Fortunately, the project this is for is Windows-only, so I can proceed. But is this behavior by design on OS X, or a bug?

It's a platform limitation. The CoreGraphics API does not provide any way to get read access to the buffer in the graphics context where the pixels are stored. This is the same reason that using wxDC logical functions no longer works on Mac. IIUC the Mac has never had a native API for doing logical function blending, and so in the past when we using the old QuickDraw APIs wxMac would do the combining of pixel values itself. But QuickDraw is now mostly dead and we need to use CoreGraphics, which is much better in many ways, but does not provide the same access that we (ab)used before to do things like GetPixel and logical blends.

One way to do what you are trying that does still work is to draw your polygon to the memory dc and then instead of trying to fetch the pixel via the DC, use the new raw bitmap access functions to get it directly from the bitmap. There is an example of this in the newest FloatCanvas.

···

On May 8, 2007, at 9:27 AM, Andrea Gavana wrote:

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Ed Leafe wrote:

    Sorry to be dense, but I don't see that example. Do you mean in the 2.8.3 demo for FloatCanvas?

no, the CVS or 2.8.4 pre-release version.

FloatCanvas uses the same trick to do hit-testing, and I recently changed it some to accommodate this limitation on the Mac. See my other note for a link to the code (that's the FloatCanvas SVN, but it's the same as the wx.lib version at this point).

-CHB

···

--
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