B
    \                 @   s.   d dl Zd dlmZmZ d	ddZdd ZdS )
    N)	ellipkinc	ellipeincg      ?g      ?g      ?Fc          	   C   s  | dks|dks|dkr t dtjd tj|  }ttj| ||f  | }ttj| ||f | d }xxtdD ]l}|| ||  d dkr||  d8  < t|| || || }	d|	krx||  t|	|	dk  8  < qxW tj|d |d |d |d |d |d |d |d |d f \}
}}|sp|
t	|  d |t	| d  |t	| d  dk}n4|
t	|  d |t	| d  |t	| d  d }|S )a  
    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.

    r   z&Parameters a, b, and c must all be > 0)   r   r   r         )

ValueErrornpZr_ZceilZfloorrangeZarangemaxZmgridfloat)abcZspacingZlevelsetoffsetZlowZhighZdimZnumxyzZarr r   2lib/python3.7/site-packages/skimage/draw/draw3d.py	ellipsoid   s(    " r   c             C   s  | dks|dks|dkr t d| ||g}|jdd |d } |d }|d }dtj |  | | }td|d | d	   d
 }t| d |d  d
 }| d |d |d   t|d | d |d    }t||}t||}	dtj |d ||d  | |  || |	   }
||
fS )a  
    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.

    r   z&Parameters a, b, and c must all be > 0T)reverser   r   gUUUUUU?g      ?g       @g      ?)r   sortr	   ZpiZarcsinr   ellip_Fellip_E)r   r   r   abcZvolZphidmFEZsurfr   r   r   ellipsoid_statsC   s$    


r    )r   F)	Znumpyr	   Zscipy.specialr   r   r   r   r   r    r   r   r   r   <module>   s   
=