Revision: 4012
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4012&view=rev
Author:   mdboom
Date:     2007-10-26 10:01:28 -0700 (Fri, 26 Oct 2007)

Log Message:
-----------
Added BboxTransformFrom/To for more efficient bounding box transforms.

Modified Paths:
--------------
    branches/transforms/lib/matplotlib/axes.py
    branches/transforms/lib/matplotlib/figure.py
    branches/transforms/lib/matplotlib/legend.py
    branches/transforms/lib/matplotlib/patches.py
    branches/transforms/lib/matplotlib/projections/polar.py
    branches/transforms/lib/matplotlib/quiver.py
    branches/transforms/lib/matplotlib/transforms.py

Modified: branches/transforms/lib/matplotlib/axes.py
===================================================================
--- branches/transforms/lib/matplotlib/axes.py  2007-10-26 15:58:50 UTC (rev 
4011)
+++ branches/transforms/lib/matplotlib/axes.py  2007-10-26 17:01:28 UTC (rev 
4012)
@@ -560,8 +560,7 @@
         """
        self.dataLim = mtransforms.Bbox.unit()
         self.viewLim = mtransforms.Bbox.unit()
-        self.transAxes = mtransforms.BboxTransform(
-            mtransforms.Bbox.unit(), self.bbox)
+        self.transAxes = mtransforms.BboxTransformTo(self.bbox)
 
         # Transforms the x and y axis separately by a scale factor
         # It is assumed that this part will have non-linear components
@@ -569,8 +568,8 @@
 
         # An affine transformation on the data, generally to limit the
         # range of the axes
-        self.transLimits = mtransforms.BboxTransform(
-            mtransforms.TransformedBbox(self.viewLim, self.transScale), 
mtransforms.Bbox.unit())
+        self.transLimits = mtransforms.BboxTransformFrom(
+            mtransforms.TransformedBbox(self.viewLim, self.transScale))
 
         # The parentheses are important for efficiency here -- they
         # group the last two (which are usually affines) separately

Modified: branches/transforms/lib/matplotlib/figure.py
===================================================================
--- branches/transforms/lib/matplotlib/figure.py        2007-10-26 15:58:50 UTC 
(rev 4011)
+++ branches/transforms/lib/matplotlib/figure.py        2007-10-26 17:01:28 UTC 
(rev 4012)
@@ -19,7 +19,7 @@
 
 from legend import Legend
 from ticker import FormatStrFormatter
-from transforms import Affine2D, Bbox, BboxTransform, TransformedBbox
+from transforms import Affine2D, Bbox, BboxTransformTo, TransformedBbox
 from cm import ScalarMappable
 from contour import ContourSet
 from projections import projection_factory, get_projection_names, \
@@ -136,7 +136,7 @@
        
         self.frameon = frameon
 
-        self.transFigure = BboxTransform(Bbox.unit(), self.bbox)
+        self.transFigure = BboxTransformTo(self.bbox)
 
         self.figurePatch = Rectangle(
             xy=(0,0), width=1, height=1,

Modified: branches/transforms/lib/matplotlib/legend.py
===================================================================
--- branches/transforms/lib/matplotlib/legend.py        2007-10-26 15:58:50 UTC 
(rev 4011)
+++ branches/transforms/lib/matplotlib/legend.py        2007-10-26 17:01:28 UTC 
(rev 4012)
@@ -34,7 +34,7 @@
 from patches import Patch, Rectangle, RegularPolygon, Shadow, bbox_artist, 
draw_bbox
 from collections import LineCollection, RegularPolyCollection
 from text import Text
-from transforms import Affine2D, Bbox, BboxTransform
+from transforms import Affine2D, Bbox, BboxTransformTo
 
 def line_cuts_bbox(line, bbox):
     """ Return True if and only if line cuts bbox. """
@@ -165,7 +165,7 @@
             raise TypeError("Legend needs either Axes or Figure as parent")
         self.parent = parent
         self._offsetTransform = Affine2D()
-        self._parentTransform = BboxTransform(Bbox.unit(), parent.bbox)
+        self._parentTransform = BboxTransformTo(parent.bbox)
         Artist.set_transform(self, self._offsetTransform + 
self._parentTransform)
         
         if loc is None:

Modified: branches/transforms/lib/matplotlib/patches.py
===================================================================
--- branches/transforms/lib/matplotlib/patches.py       2007-10-26 15:58:50 UTC 
(rev 4011)
+++ branches/transforms/lib/matplotlib/patches.py       2007-10-26 17:01:28 UTC 
(rev 4012)
@@ -346,8 +346,7 @@
         left, right = self.convert_xunits((xy[0], xy[0] + width))
         bottom, top = self.convert_yunits((xy[1], xy[1] + height))
        self._bbox = transforms.Bbox.from_extents(left, bottom, right, top)
-       self._rect_transform = transforms.BboxTransform(
-           transforms.Bbox.unit(), self._bbox)
+       self._rect_transform = transforms.BboxTransformTo(self._bbox)
     __init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd
 
     def get_path(self):

Modified: branches/transforms/lib/matplotlib/projections/polar.py
===================================================================
--- branches/transforms/lib/matplotlib/projections/polar.py     2007-10-26 
15:58:50 UTC (rev 4011)
+++ branches/transforms/lib/matplotlib/projections/polar.py     2007-10-26 
17:01:28 UTC (rev 4012)
@@ -10,8 +10,8 @@
 from matplotlib.patches import Circle
 from matplotlib.path import Path
 from matplotlib.ticker import Formatter, Locator
-from matplotlib.transforms import Affine2D, Affine2DBase, Bbox, BboxTransform, 
\
-    IdentityTransform, Transform, TransformWrapper
+from matplotlib.transforms import Affine2D, Affine2DBase, Bbox, \
+    BboxTransformTo, IdentityTransform, Transform, TransformWrapper
 
 class PolarAxes(Axes):
     """
@@ -179,7 +179,7 @@
     def _set_lim_and_transforms(self):
        self.dataLim = Bbox.unit()
         self.viewLim = Bbox.unit()
-        self.transAxes = BboxTransform(Bbox.unit(), self.bbox)
+        self.transAxes = BboxTransformTo(self.bbox)
 
         # Transforms the x and y axis separately by a scale factor
         # It is assumed that this part will have non-linear components

Modified: branches/transforms/lib/matplotlib/quiver.py
===================================================================
--- branches/transforms/lib/matplotlib/quiver.py        2007-10-26 15:58:50 UTC 
(rev 4011)
+++ branches/transforms/lib/matplotlib/quiver.py        2007-10-26 17:01:28 UTC 
(rev 4012)
@@ -239,7 +239,7 @@
         elif self.coord == 'inches':
             dx = ax.figure.dpi
             bb = transforms.Bbox.from_extents(0, 0, dx, dy)
-            trans = transforms.BboxTransform(Bbox.unit(), bb)
+            trans = transforms.BboxTransformTo(bb)
             self.set_transform(trans)
         else:
             raise ValueError('unrecognized coordinates')

Modified: branches/transforms/lib/matplotlib/transforms.py
===================================================================
--- branches/transforms/lib/matplotlib/transforms.py    2007-10-26 15:58:50 UTC 
(rev 4011)
+++ branches/transforms/lib/matplotlib/transforms.py    2007-10-26 17:01:28 UTC 
(rev 4012)
@@ -211,6 +211,9 @@
     def __array__(self, *args, **kwargs):
         return self.get_points()
 
+    def is_unit(self):
+        return list(self.get_points().flatten()) == [0., 0., 1., 1.]
+    
     def _get_x0(self):
         return self.get_points()[0, 0]
     x0 = property(_get_x0)
@@ -1830,6 +1833,86 @@
             self._invalid = 0
         return self._mtx
     get_matrix.__doc__ = Affine2DBase.get_matrix.__doc__
+
+
+class BboxTransformTo(Affine2DBase):
+    """
+    BboxTransformSimple linearly transforms points from the unit Bbox
+    to another Bbox.
+    """
+    is_separable = True
+
+    def __init__(self, boxout):
+        """
+        Create a new BboxTransform that linearly transforms points
+        from the unit Bbox to boxout.
+        """
+        assert boxout.is_bbox
+        
+        Affine2DBase.__init__(self)
+        self._boxout = boxout
+        self.set_children(boxout)
+        self._mtx = None
+        self._inverted = None
+
+    def __repr__(self):
+        return "BboxTransformTo(%s)" % (self._boxout)
+    __str__ = __repr__
+        
+    def get_matrix(self):
+        if self._invalid:
+            outl, outb, outw, outh = self._boxout.bounds
+            if DEBUG and (outw == 0 or outh == 0):
+                raise ValueError("Transforming to a singular bounding box.")
+            self._mtx = npy.array([[outw,  0.0, outl],
+                                   [ 0.0, outh, outb],
+                                   [ 0.0,  0.0,  1.0]],
+                                  npy.float_)
+            self._inverted = None
+            self._invalid = 0
+        return self._mtx
+    get_matrix.__doc__ = Affine2DBase.get_matrix.__doc__
+
+
+class BboxTransformFrom(Affine2DBase):
+    """
+    BboxTransform linearly transforms points from one Bbox to the unit
+    Bbox.
+    """
+    is_separable = True
+
+    def __init__(self, boxin):
+        """
+        Create a new BboxTransform that linearly transforms points
+        from boxin to the unit Bbox.
+        """
+        assert boxin.is_bbox
+        
+        Affine2DBase.__init__(self)
+        self._boxin = boxin
+        self.set_children(boxin)
+        self._mtx = None
+        self._inverted = None
+
+    def __repr__(self):
+        return "BboxTransformFrom(%s)" % (self._boxin)
+    __str__ = __repr__
+        
+    def get_matrix(self):
+        if self._invalid:
+            inl, inb, inw, inh = self._boxin.bounds
+            if DEBUG and (inw == 0 or inh == 0):
+                raise ValueError("Transforming from a singular bounding box.")
+            x_scale = 1.0 / inw
+            y_scale = 1.0 / inh
+            self._mtx = npy.array([[x_scale, 0.0    , (-inl*x_scale)],
+                                   [0.0    , y_scale, (-inb*y_scale)],
+                                   [0.0    , 0.0    , 1.0        ]],
+                                  npy.float_)
+            self._inverted = None
+            self._invalid = 0
+        return self._mtx
+    get_matrix.__doc__ = Affine2DBase.get_matrix.__doc__
     
 
 class TransformedPath(TransformNode):


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to