Marco,

Thank you for the nice words and contribution.

Since I was opening up the code today anyway, I made your small change 
in the source -- you are right, it's nice to be able to subclass the 
BBox. Subclassing numpy arrays is a bit tricky, thanks for figuring this 
out.

I've cc'd this to the FloatCanvas list for the archives.

-Chris

On 10/7/11 11:09 AM, Marco Oster wrote:

> Chris,
>
> I think I have an improvement of your fine FC widget, see patch:
>
> --- /tmp/BBox.py    2011-10-07 19:48:08.000000000 +0200
> +++ BBox.py    2011-10-07 19:18:11.000000000 +0200
> @@ -29,7 +29,7 @@
>          fromPoints
>
>      """
> -    def __new__(subclass, data):
> +    def __new__(cls, data):
>          """
>          Takes Data as an array. Data is any python sequence that can be 
> turned into a
>          2x2 numpy array of floats:
> @@ -51,7 +51,7 @@
>          if arr[0,0] > arr[1,0] or arr[0,1] > arr[1,1]:
>              # note: zero sized BB OK.
>              raise ValueError("BBox values not aligned: \n minimum values 
> must be less that maximum values")
> -        return N.ndarray.__new__(BBox, shape=arr.shape, dtype=arr.dtype, 
> buffer=arr)
> +        return N.ndarray.__new__(cls, shape=arr.shape, dtype=arr.dtype, 
> buffer=arr)
>
>      def Overlaps(self, BB):
>          """
>
> The change actually enables subclassing of BBox objects. I it for checking of 
> hit events on rotated rectangular objects, in conjunction with some BBox 
> based hit test code found on the mailing list. It boils down to something 
> like that:
>
> class RectBBox(BBox.BBox):
>
>     def __new__(self, data, edges=None):
>         return BBox.BBox.__new__(self, data)
>
>     def __init__(self, data, edges=None):
>         ''' assume edgepoints are ordered such you can walk along all edges 
> with left rotation sense
>             This may be:
>             left-top
>             left-bottom
>             right-bottom
>             right-top
>
>             or any rotation.
>         '''
>         BBox.BBox(data)
>         self.edges = np.asarray(edges)
>
>         print "new rectbbox created"
>
>
>     def ac_leftOf_ab(self, a, b, c):
>         ab = np.array(b) - np.array(a)
>         ac = np.array(c) - np.array(a)
>
>         return (ac[0]*ab[1] - ac[1]*ab[0]) <= 0
>
>     def PointInside(self, point):
>         print "point inside called"
>
>         for edge in xrange(4):
>             if self.ac_leftOf_ab(self.edges[edge],
>                                  self.edges[(edge+1)%4],
>                                  point):
>                 continue
>             else:
>                 return False
>         return True
>
> I evaluate FloatCanvas for position-aware drawing of electron micrographs 
> taken with a TEM. Attached is a screenshot of the results of my code mess :) 
> Imaged area is about 3mm in diameter, at an approximate magnification of 160. 
> The differently rotated insets are taken at 500x and 6000x. Specimen were 
> meant to be vitrified liposomes, but there was next to nothing in.
>
> Thank you for sharing the nice package and please keep up the good work!
> Marco


-- 
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://paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas

Reply via email to