Hello Chris,

Thanks a lot for your answer and for the explanations about how it works.

I retried my little example (see image_hit_coords_2.py in this email),
especially with the updated version of FloatCanvas.py from SVN, and here
are the results :

* when you launch image_hit_coords_2.py,  the canvas.Scale is 1.02686
(because of the choice I did for the image, and for the Frame's width=350).
* the only values I can get for x (when MOTION on the image) are : [-0.34,
0.63, 1.60, ..., 298.62, 299.60]
* the theoritical values should be : [0, 1, 2, 3, ..., 308] (i.e. 309
values because my image's width is 309), but of course, as there is the
scaling factors, it is normal that we have floats, I totally agree with
that.

With a scale of 102.686 % (not far from 100%!), having a max of 299.60
instead of 308 might be a bit far from what we should get.

With such a scale (nearly 103%), I was expecting having values from 0 to
something like 308 or 307 or 306. But here 299.60 seems a bit far away,
don't you think so ?

Do you think there is something wrong in the way I compute x and y ? :

    def OnMotion(self, event):
        x, y = event.HitCoords[0] - event.BoundingBox[0,0],
event.BoundingBox[1,1] - event.HitCoords[1]
        print self.canvas.Scale, x, y

Thanks a lot,

Best regards, jo



2014-03-18 22:46 GMT+01:00 Chris Barker <[email protected]>:

> On Tue, Mar 18, 2014 at 4:12 AM, Nouvelle Collection <
> [email protected]> wrote:
>
>
>>  A small question : sometimes I want to get the (x,y) hitcoords when
>> clicking on an 309x34 pixels image, and I would like x to be an integer in
>> [0, 308], but when self.canvas.ZoomToBB() has been used, sometimes the
>> (x,y) coordinates are a bit "off" of some pixels.
>>
>> For example, when using     x = event.HitCoords[0] -
>> event.BoundingBox[0,0],  the range I get for x is [-1.2598, 302.24277]   =>
>> how to get [0,308] instead ?
>>
>> Is there a parameter somewhere for HitCoords accuracy ? (high, medium,
>> etc.)
>>
>
> No -- it's limited by pixel accuracy for the mouse click, and floating
> point accuracy for the scaling calculation.  So it depends on the zoom
> level.
>
> 1) you'll want to round.
>
> 2) It depends on the zoom level -- if you have 308 pixel wide image, but
> are showing it so that 4 pixels in the image are only one pixel big on the
> screen, you can only get so close.
>
> When I try this with the ScaledBitmap2 demo, it seems to work as well as
> I"d expect.
>
> The scale depends on two thing: how the ScaledImage is originally sclaed
> to World Coords:
>
>         img = FloatCanvas.ScaledBitmap2( image,
>                                         (0,0),
>                                         Height=image.GetHeight(),
>                                         Position = 'tl',
>                                         Quality='high'
>                                         )
> This is setting the Height in world coords the same as the image height in
> pixels -- so you should get a 1:1 scaling of pixels to works coords
>
> print Canvas.Scale
>
> will tell you how WorldCoords are being scaled to the final drawn image:
>
>         print "The Scale is set to:", self.Canvas.Scale
>
> For me, if it's close to 1.0, it works pretty well, much under one, and
> you're seeing the limitations of pixel resolution.
>
> However, I did find a big (mis-feature?): The ScaledBitmaps were getting
> the HitLineWidth from the default DrawObject. But for those, you really
> don't want a line width for the hit-test bitmap. It was set to 3 pixels, so
> was letting the image be "hit" an extra 1-2 pixels outside the actual image.
>
> Fixed in SVN.
>
> -Chris
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>>
>> Best regards, Jo
>> ____
>>
>> import wx
>> from wx.lib.floatcanvas import FloatCanvas
>>
>> class TestFrame(wx.Frame):
>>     def __init__(self, *args, **kwargs):
>>         wx.Frame.__init__(self, *args, **kwargs)
>>         self.canvas =FloatCanvas.FloatCanvas(self, BackgroundColor =
>> "DARK SLATE BLUE")
>>         MainSizer = wx.BoxSizer(wx.VERTICAL)
>>         MainSizer.Add(self.canvas, 4, wx.EXPAND)
>>         self.SetSizer(MainSizer)
>>         img = wx.Image('mypng(309x34).png')
>>         A = self.canvas.AddScaledBitmap(img, (0,0),
>> Height=img.GetHeight(), Position = 'tl')
>>         A.Bind(FloatCanvas.EVT_FC_MOTION, self.OnMotion)
>>         wx.CallAfter(self.canvas.ZoomToBB)
>>
>>     def OnMotion(self, event):
>>         x, y = event.HitCoords[0] - event.BoundingBox[0,0],
>> event.BoundingBox[1,1] - event.HitCoords[1]
>>         print x, y     # the max range I can get for x is [-1.2598,
>> 302.24277]   => how to get [0,308] instead ?
>>
>> app = wx.App(0)
>> frame = TestFrame(None, title="Image hitcoords", size=(300,200))
>> frame.Show(True)
>> app.MainLoop()
>>
>>
>>
>>
>>
>> _______________________________________________
>> FloatCanvas mailing list
>> [email protected]
>> http://mailman.paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas
>>
>>
>
>
> --
>
> 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
>
> [email protected]
>
> _______________________________________________
> FloatCanvas mailing list
> [email protected]
> http://mailman.paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas
>
>
import wx
from wx.lib.floatcanvas import FloatCanvas

class TestFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        self.canvas =FloatCanvas.FloatCanvas(self, BackgroundColor = "DARK SLATE BLUE")
        MainSizer = wx.BoxSizer(wx.VERTICAL)
        MainSizer.Add(self.canvas, 4, wx.EXPAND)
        self.SetSizer(MainSizer)
        img = wx.Image('mypng(309x34).png')   
        A = self.canvas.AddScaledBitmap(img, (0,0), Height=img.GetHeight(), Position = 'tl')
        A.Bind(FloatCanvas.EVT_FC_MOTION, self.OnMotion)
        wx.CallAfter(self.canvas.ZoomToBB)
                        
    def OnMotion(self, event):
        x, y = event.HitCoords[0] - event.BoundingBox[0,0], event.BoundingBox[1,1] - event.HitCoords[1]
        print self.canvas.Scale, x, y  

app = wx.App(0)
frame = TestFrame(None, title="Image hitcoords", size=(350,200))
frame.Show(True)
app.MainLoop()

<<attachment: mypng(309x34).png>>

_______________________________________________
FloatCanvas mailing list
[email protected]
http://mailman.paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas

Reply via email to