
    a6ds                     ,    d dl Zd dlmZmZ ddZd ZdS )    N)	ellipkinc	ellipeinc      ?r   r   Fc           	      .   | dk    s|dk    s|dk    rt          d          t          j        d         t          j        |         z  }t          j        t          j        | ||f          |z
            }t          j        t          j        | ||f         |z   dz             }t          d          D ]}||         ||         z
  dz  dk    r||xx         dz  cc<   t          j        ||         ||         ||                   }	d|	vr,||xx         t          j        |	|	dk                        z  cc<   t          j        |d         |d         |d         |d         |d         |d         |d         |d         |d         f         \  }
}}|sF|
t          |           z  dz  |t          |          z  dz  z   |t          |          z  dz  z   dk    }nD|
t          |           z  dz  |t          |          z  dz  z   |t          |          z  dz  z   dz
  }|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   &Parameters a, b, and c must all be > 0)   r	   r	   r	         )

ValueErrornpr_ceilfloorrangearangemaxmgridfloat)abcspacinglevelsetoffsetlowhighdimnumxyzarrs                 3lib/python3.11/site-packages/skimage/draw/draw3d.py	ellipsoidr%      s'   8 	
QAFFQABBBU7^beGn,F 'BE!Q'N"V+
,
,C8BE!Q'NV+a/00DQxx - -IC A%**HHHMHHHiC$s)WS\::C<<HHHs37|,,,HHH hs1vd1ggaj01vd1ggaj01vd1ggaj01 2GAq!  (E!HH"E!HH"#E!HH"#'() E!HH"E!HH"#E!HH"#&'( J    c                 X   | dk    s|dk    s|dk    rt          d          | ||g}|                    d           |d         } |d         }|d         }dt          j        z  | z  |z  |z  }t          j        d|dz  | d	z  z  z
  d
z            }t          | dz  |dz  z
  d
z            }| dz  |dz  |dz  z
  z  t          |dz  | dz  |dz  z
  z            z  }t          ||          }t          ||          }	dt          j        z  |dz  ||dz  z  |z  |z  z   ||z  |	z  z   z  }
||
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   r   T)reverser	   r   gUUUUUU?r   g       @g      ?)r   sortr   piarcsinr   ellip_Fellip_E)r   r   r   abcvolphidmFEsurfs              r$   ellipsoid_statsr6   B   sn   , 	
QAFFQABBB a)CHHTHAAAAAA 25.1
q
 1
$C )R16Q"W-.36
7
7CqAvQ3&''A	
a16AF?	#	qAva!q&)	*	*
+AQAQAru9QAF
Q*+A	" #D 9r&   )r   F)	numpyr   scipy.specialr   r,   r   r-   r%   r6    r&   r$   <module>r:      sW        F F F F F F F F: : : :z0 0 0 0 0r&   