ó
±éRc           @  sT   d  d l  m Z d  d l j Z d  d l j Z d  d l Z d e f d „  ƒ  YZ	 d S(   iÿÿÿÿ(   t   print_functionNt   Triangulationc           B  sw   e  Z d  Z d
 d
 d „ Z d „  Z e d „  ƒ Z d „  Z d „  Z	 e
 d „  ƒ Z d „  Z e d „  ƒ Z d	 „  Z RS(   sd  
    An unstructured triangular grid consisting of npoints points and
    ntri triangles.  The triangles can either be specified by the user
    or automatically generated using a Delaunay triangulation.

    Read-only attributes:

      *x*: array of shape (npoints).
        x-coordinates of grid points.

      *y*: array of shape (npoints).
        y-coordinates of grid points.

      *triangles*: integer array of shape (ntri,3).
        For each triangle, the indices of the three points that make
        up the triangle, ordered in an anticlockwise manner.

      *mask*: optional boolean array of shape (ntri).
        Which triangles are masked out.

      *edges*: integer array of shape (?,2).
        All edges of non-masked triangles.  Each edge is the start
        point index and end point index.  Each edge (start,end and
        end,start) appears only once.

      *neighbors*: integer array of shape (ntri,3).
        For each triangle, the indices of the three triangles that
        share the same edges, or -1 if there is no such neighboring
        triangle.  neighbors[i,j] is the triangle that is the neighbor
        to the edge from point index triangles[i,j] to point index
        triangles[i,(j+1)%3].

    For a Triangulation to be valid it must not have duplicate points,
    triangles formed from colinear points, or overlapping triangles.
    c         C  st  t  j | d t  j ƒ|  _ t  j | d t  j ƒ|  _ |  j j |  j j k sf t |  j j ƒ d k ru t d ƒ ‚ n  d  |  _	 d  |  _
 d  |  _ | d  k rJt j |  j |  j ƒ } t  j | j | j ƒ d t  j ƒ|  _ | d  k rít  j | j | j ƒ d t  j ƒ|  _
 t  j | j d t  j ƒ} t  j | d d d ƒ|  _ qín£ t  j | d t  j ƒ|  _ |  j j d k s�|  j j d d k rœt d ƒ ‚ n  |  j j ƒ  t |  j ƒ k rÉt d ƒ ‚ n  |  j j ƒ  d	 k  rít d
 ƒ ‚ n  | d  k	 r^t  j | d t  j ƒ|  _	 t |  j	 j ƒ d k sL|  j	 j d	 |  j j d	 k r^t d ƒ ‚ q^n  d  |  _ d  |  _ d  S(   Nt   dtypei   s'   x and y must be equal-length 1-D arrayst   axisi   i   s   triangles must be a (?,3) arrays&   triangles max element is out of boundsi    s&   triangles min element is out of boundss3   mask array must have same length as triangles array(   t   npt   asarrayt   float64t   xt   yt   shapet   lent
   ValueErrort   Nonet   maskt   _edgest
   _neighborst   delaunayR   t   to_client_point_indicest   triangle_nodest   int32t	   trianglest   edge_dbt   triangle_neighborst   rollt   arrayt   ndimt   maxt   mint   boolt   _cpp_triangulationt
   _trifinder(   t   selfR   R   R   R   t   dtt	   neighbors(    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/tri/triangulation.pyt   __init__+   s@    0			!( 	c         C  s   |  j  ƒ  j | ƒ S(   sb  
        Calculate plane equation coefficients for all unmasked triangles from
        the point (x,y) coordinates and specified z-array of shape (npoints).
        Returned array has shape (npoints,3) and allows z-value at (x,y)
        position in triangle tri to be calculated using
        z = array[tri,0]*x + array[tri,1]*y + array[tri,2].
        (   t   get_cpp_triangulationt   calculate_plane_coefficients(   R   t   z(    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/tri/triangulation.pyR$   [   s    c         C  s.   |  j  d  k r' |  j ƒ  j ƒ  |  _  n  |  j  S(   N(   R   R   R#   t	   get_edges(   R   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/tri/triangulation.pyt   edgese   s    c         C  sL   |  j  d  k rE t j |  j |  j |  j |  j |  j |  j	 ƒ |  _  n  |  j  S(   N(
   R   R   t   _triR   R   R   R   R   R   R   (   R   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/tri/triangulation.pyR#   k   s
    c         C  s7   |  j  d k	 r, |  j j d |  j  d d ƒS|  j Sd S(   sC   
        Return an array of triangles that are not masked.
        i   R   i    N(   R   R   R   t   compress(   R   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/tri/triangulation.pyt   get_masked_trianglest   s    c          O  s`  t  |  d t ƒ r* |  d } |  d }  n)|  d } |  d } |  d }  | j d d ƒ } t } | d k r‘ t |  ƒ d k r‘ |  d } t } n  | d k	 rÖ y t j | d t j	 ƒ} WqÖ t
 k
 rÒ d } qÖ Xn  | d k	 r| j d k s| j d d k rd } n  | d k	 r,| r,|  d }  n  | j d d ƒ } t | | | | ƒ } | |  | f S(	   sÎ  
        Return a Triangulation object from the args and kwargs, and
        the remaining args and kwargs with the consumed values removed.

        There are two alternatives: either the first argument is a
        Triangulation object, in which case it is returned, or the args
        and kwargs are sufficient to create a new Triangulation to
        return.  In the latter case, see Triangulation.__init__ for
        the possible args and kwargs.
        i    i   i   R   R   i   R   N(   t
   isinstanceR   t   popR   t   FalseR
   t   TrueR   R   R   R   R   R	   (   t   argst   kwargst   triangulationR   R   R   t	   from_argsR   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/tri/triangulation.pyt   get_from_args_and_kwargs}   s0    




		c         C  s8   |  j  d k r1 d d l m } | |  ƒ |  _  n  |  j  S(   sÃ   
        Return the default :class:`matplotlib.tri.TriFinder` of this
        triangulation, creating it if necessary.  This allows the same
        TriFinder object to be easily shared.
        iÿÿÿÿ(   t   TrapezoidMapTriFinderN(   R   R   t   matplotlib.tri.trifinderR4   (   R   R4   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/tri/triangulation.pyt   get_trifinder«   s    c         C  s.   |  j  d  k r' |  j ƒ  j ƒ  |  _  n  |  j  S(   N(   R   R   R#   t   get_neighbors(   R   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/tri/triangulation.pyR!   ·   s    c         C  sÔ   | d k r d |  _ nb t j | d t j ƒ|  _ t |  j j ƒ d k sk |  j j d |  j j d k rz t d ƒ ‚ n  |  j	 d k	 rŸ |  j	 j
 |  j ƒ n  d |  _ d |  _ |  j d k	 rÐ |  j j ƒ  n  d S(   sp   
        Set or clear the mask array.  This is either None, or a boolean
        array of shape (ntri).
        R   i   i    s3   mask array must have same length as triangles arrayN(   R   R   R   R   R   R
   R	   R   R   R   t   set_maskR   R   R   t   _initialize(   R   R   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/tri/triangulation.pyR8   ½   s     		N(   t   __name__t
   __module__t   __doc__R   R"   R$   t   propertyR'   R#   R*   t   staticmethodR3   R6   R!   R8   (    (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/tri/triangulation.pyR      s   #0	
				.	(
   t
   __future__R    t   matplotlib.delaunayR   t   matplotlib._triR(   t   numpyR   t   objectR   (    (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/tri/triangulation.pyt   <module>   s   