ó
 \c           @   s>   d  d l  Z d  d l m Z m Z d e d  Z d   Z	 d S(   iÿÿÿÿN(   t	   ellipkinct	   ellipeincg      ð?c         C   s  |  d k s$ | d k s$ | d k r3 t  d   n  t j d t j | } t j t j |  | | f |  } t j t j |  | | f | d  } x t d  D] } | | | | d d k rØ | | c d 8<n  t j | | | | | |  }	 d |	 k r£ | | c t j |	 |	 d k   8<q£ q£ Wt j | d | d | d  | d | d | d  | d | d | d  f \ }
 } } | sÔ|
 t	 |   d | t	 |  d | t	 |  d d k } n< |
 t	 |   d | t	 |  d | t	 |  d d } | S(   s±  
    Generates ellipsoid with semimajor axes aligned with grid dimensions
    on grid with specified `spacing`.

    Parameters
    ----------
    a : float
        Length of semimajor axis aligned with x-axis.
    b : float
        Length of semimajor axis aligned with y-axis.
    c : float
        Length of semimajor axis aligned with z-axis.
    spacing : tuple of floats, length 3
        Spacing in (x, y, z) spatial dimensions.
    levelset : bool
        If True, returns the level set for this ellipsoid (signed level
        set about zero, with positive denoting interior) as np.float64.
        False returns a binarized version of said level set.

    Returns
    -------
    ellip : (N, M, P) array
        Ellipsoid centered in a correctly sized array for given `spacing`.
        Boolean dtype unless `levelset=True`, in which case a float array is
        returned with the level set above 0.0 representing the ellipsoid.

    i    s&   Parameters a, b, and c must all be > 0i   i   i   (   i   i   i   (
   t
   ValueErrort   npt   r_t   ceilt   floort   ranget   aranget   maxt   mgridt   float(   t   at   bt   ct   spacingt   levelsett   offsett   lowt   hight   dimt   numt   xt   yt   zt   arr(    (    s2   lib/python2.7/site-packages/skimage/draw/draw3d.pyt	   ellipsoid   s(    $$'!*(##c         C   sa  |  d k s$ | d k s$ | d k r3 t  d   n  |  | | g } | j d t  | d }  | d } | d } d d t j |  | | } t j d | d |  d	 d
  } t |  d | d d
  } |  d | d | d t | d |  d | d  } t | |  } t | |  }	 d t j | d | | d | | | | |	 }
 | |
 f S(   s  
    Calculates analytical surface area and volume for ellipsoid with
    semimajor axes aligned with grid dimensions of specified `spacing`.

    Parameters
    ----------
    a : float
        Length of semimajor axis aligned with x-axis.
    b : float
        Length of semimajor axis aligned with y-axis.
    c : float
        Length of semimajor axis aligned with z-axis.

    Returns
    -------
    vol : float
        Calculated volume of ellipsoid.
    surf : float
        Calculated surface area of ellipsoid.

    i    s&   Parameters a, b, and c must all be > 0t   reversei   i   i   g      @g      ð?g       @g      à?(	   R   t   sortt   TrueR   t   pit   arcsinR   t   ellip_Ft   ellip_E(   R   R   R   t   abct   volt   phit   dt   mt   Ft   Et   surf(    (    s2   lib/python2.7/site-packages/skimage/draw/draw3d.pyt   ellipsoid_statsC   s$    $


#!
(   g      ð?g      ð?g      ð?(
   t   numpyR   t   scipy.specialR    R    R   R!   t   FalseR   R*   (    (    (    s2   lib/python2.7/site-packages/skimage/draw/draw3d.pyt   <module>   s   =