
    9i82                        S SK r S SKrSSKJr  SSKJr   SSSSSSSS	.S
 jjrS rS r	\R                  " S S/SS/SS /S S /S S/SS/SS /S S /S S /SS/SS/S S //S5      r\R                  " S S /S S/SS/SS /S S /S S/SS/SS /S S /S S /SS/SS//S5      r\R                  " S S /S S /S S /S S /SS/SS/SS/SS/S S/S S/S S/S S//S5      rS rS rg)    N   )_marching_cubes_lewiner_luts)_marching_cubes_lewiner_cy)      ?r   r   descentTlewiner)spacinggradient_direction	step_sizeallow_degeneratemethodmaskc                Z    SnUS:X  a  SnOUS:w  a  [        S5      e[        U UUUUUUUS9$ )ah  Marching cubes algorithm to find surfaces in 3d volumetric data.

In contrast with Lorensen et al. approach [2]_, Lewiner et
al. algorithm is faster, resolves ambiguities, and guarantees
topologically correct results. Therefore, this algorithm generally
a better choice.

Parameters
----------
volume : (M, N, P) ndarray
    Input data volume to find isosurfaces. Will internally be
    converted to float32 if necessary.
level : float, optional
    Contour value to search for isosurfaces in `volume`. If not
    given or None, the average of the min and max of vol is used.
spacing : length-3 tuple of floats, optional
    Voxel spacing in spatial dimensions corresponding to numpy array
    indexing dimensions (M, N, P) as in `volume`.
gradient_direction : string, optional
    Controls if the mesh was generated from an isosurface with gradient
    descent toward objects of interest (the default), or the opposite,
    considering the *left-hand* rule.
    The two options are:
    * descent : Object was greater than exterior
    * ascent : Exterior was greater than object
step_size : int, optional
    Step size in voxels. Default 1. Larger steps yield faster but
    coarser results. The result will always be topologically correct
    though.
allow_degenerate : bool, optional
    Whether to allow degenerate (i.e. zero-area) triangles in the
    end-result. Default True. If False, degenerate triangles are
    removed, at the cost of making the algorithm slower.
method: {'lewiner', 'lorensen'}, optional
    Whether the method of Lewiner et al. or Lorensen et al. will be used.
mask : (M, N, P) array, optional
    Boolean array. The marching cube algorithm will be computed only on
    True elements. This will save computational time when interfaces
    are located within certain region of the volume M, N, P-e.g. the top
    half of the cube-and also allow to compute finite surfaces-i.e. open
    surfaces that do not end at the border of the cube.

Returns
-------
verts : (V, 3) array
    Spatial coordinates for V unique mesh vertices. Coordinate order
    matches input `volume` (M, N, P). If ``allow_degenerate`` is set to
    True, then the presence of degenerate triangles in the mesh can make
    this array have duplicate vertices.
faces : (F, 3) array
    Define triangular faces via referencing vertex indices from ``verts``.
    This algorithm specifically outputs triangles, so each face has
    exactly three indices.
normals : (V, 3) array
    The normal direction at each vertex, as calculated from the
    data.
values : (V,) array
    Gives a measure for the maximum value of the data in the local region
    near each vertex. This can be used by visualization tools to apply
    a colormap to the mesh.

See Also
--------
skimage.measure.mesh_surface_area
skimage.measure.find_contours

Notes
-----
The algorithm [1]_ is an improved version of Chernyaev's Marching
Cubes 33 algorithm. It is an efficient algorithm that relies on
heavy use of lookup tables to handle the many different cases,
keeping the algorithm relatively easy. This implementation is
written in Cython, ported from Lewiner's C++ implementation.

To quantify the area of an isosurface generated by this algorithm, pass
verts and faces to `skimage.measure.mesh_surface_area`.

Regarding visualization of algorithm output, to contour a volume
named `myvolume` about the level 0.0, using the ``mayavi`` package::

  >>>
  >> from mayavi import mlab
  >> verts, faces, _, _ = marching_cubes(myvolume, 0.0)
  >> mlab.triangular_mesh([vert[0] for vert in verts],
                          [vert[1] for vert in verts],
                          [vert[2] for vert in verts],
                          faces)
  >> mlab.show()

Similarly using the ``visvis`` package::

  >>>
  >> import visvis as vv
  >> verts, faces, normals, values = marching_cubes(myvolume, 0.0)
  >> vv.mesh(np.fliplr(verts), faces, normals, values)
  >> vv.use().Run()

To reduce the number of triangles in the mesh for better performance,
see this `example
<https://docs.enthought.com/mayavi/mayavi/auto/example_julia_set_decimation.html#example-julia-set-decimation>`_
using the ``mayavi`` package.

References
----------
.. [1] Thomas Lewiner, Helio Lopes, Antonio Wilson Vieira and Geovan
       Tavares. Efficient implementation of Marching Cubes' cases with
       topological guarantees. Journal of Graphics Tools 8(2)
       pp. 1-15 (december 2003).
       :DOI:`10.1080/10867651.2003.10487582`
.. [2] Lorensen, William and Harvey E. Cline. Marching Cubes: A High
       Resolution 3D Surface Construction Algorithm. Computer Graphics
       (SIGGRAPH 87 Proceedings) 21(4) July 1987, p. 163-170).
       :DOI:`10.1145/37401.37422`
FlorensenTr   z/method should be either 'lewiner' or 'lorensen')use_classicr   )
ValueError_marching_cubes_lewiner)	volumelevelr	   r
   r   r   r   r   r   s	            g/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/measure/_marching_cubes_lewiner.pymarching_cubesr   	   sP    z K	9	JKK"	 	    c                    [        U [        R                  5      (       a  U R                  S:w  a  [	        S5      eU R
                  S   S:  d&  U R
                  S   S:  d  U R
                  S   S:  a  [	        S5      e[        R                  " U [        R                  5      n Uc%  SU R                  5       U R                  5       -   -  nO<[        U5      nXR                  5       :  d  XR                  5       :  a  [	        S5      e[        U5      S:w  a  [	        S	5      e[        U5      nUS:  a  [	        S
5      e[        U5      n[        5       nUb%  UR
                  U R
                  :X  d  [	        S5      e[        R                   n	U	" XXXg5      u  pp[        U
5      (       d  [#        S5      e[        R$                  " U
5      n
[        R$                  " U5      nSUl        US:X  a  [        R$                  " U5      nOUS:X  d  [	        SU S35      e[        R&                  " US5      (       d  U
[        R(                  U   -  n
U(       a  XX4$ [        R*                  nU" U
R-                  [        R                  5      XU5      $ )z\Lewiner et al. algorithm for marching cubes. See
marching_cubes_lewiner for documentation.

   z(Input volume should be a 3D numpy array.r      r   z#Input array must be at least 2x2x2.      ?z/Surface level must be within volume data range.z'`spacing` must consist of three floats.zstep_size must be at least one.z)volume and mask must have the same shape.z(No surface found at the given iso value.)r   r   ascentzIncorrect input z( in `gradient_direction`, see docstring.)r   r   r   )
isinstancenpndarrayndimr   shapeascontiguousarrayfloat32minmaxfloatlenintbool_get_mc_lutsr   r   RuntimeErrorfliplrarray_equalr_remove_degenerate_facesastype)r   r   r	   r
   r   r   r   r   Lfuncverticesfacesnormalsvaluesfuns                  r   r   r      s0     fbjj))fkkQ.>CDD||Afll1o1V\\!_q5H>??!!&"**5F }vzz|fjjl23e::<5::<#7NOO
7|qBCCII1}:;;{#K 	A zzV\\)HII &44D'+q[($HW x==EFF yy"Hii G EKY& 		% 8+12 3 
 	
 >>'9--beeGn,//(@@8??2::.GGr   c                     U u  p[         R                  " UR                  S5      5      n[        R                  " USS9nXl        U$ )Nzutf-8int8)dtype)base64decodebytesencoder    
frombufferr#   )argsr#   textbytsars        r   	_to_arrayrE      s<    KEdkk'23D	t6	*BHIr   r;   c                  
   [        [        S5      (       Gd  [        R                  " / [        P[
        P[        P[        [        R                  5      P[        [        R                  5      P[        [        R                  5      P[        [        R                  5      P[        [        R                  5      P[        [        R                  5      P[        [        R                  5      P[        [        R                  5      P[        [        R                   5      P[        [        R"                  5      P[        [        R$                  5      P[        [        R&                  5      P[        [        R(                  5      P[        [        R*                  5      P[        [        R,                  5      P[        [        R.                  5      P[        [        R0                  5      P[        [        R2                  5      P[        [        R4                  5      P[        [        R6                  5      P[        [        R8                  5      P[        [        R:                  5      P[        [        R<                  5      P[        [        R>                  5      P[        [        R@                  5      P[        [        RB                  5      P[        [        RD                  5      P[        [        RF                  5      P[        [        RH                  5      P[        [        RJ                  5      P[        [        RL                  5      P[        [        RN                  5      P[        [        RP                  5      P[        [        RR                  5      P[        [        RT                  5      P[        [        RV                  5      P[        [        RX                  5      P[        [        RZ                  5      P[        [        R\                  5      P[        [        R^                  5      P[        [        R`                  5      P[        [        Rb                  5      P[        [        Rd                  5      P[        [        Rf                  5      P[        [        Rh                  5      P[        [        Rj                  5      P[        [        Rl                  5      P[        [        Rn                  5      P76 [        l8        [        Rp                  $ )z#Kind of lazy obtaining of the luts.THE_LUTS)9hasattrmclutsr   LutProviderEDGETORELATIVEPOSXEDGETORELATIVEPOSYEDGETORELATIVEPOSZrE   CASESCLASSICCASESTILING1TILING2	TILING3_1	TILING3_2	TILING4_1	TILING4_2TILING5TILING6_1_1TILING6_1_2	TILING6_2	TILING7_1	TILING7_2	TILING7_3TILING7_4_1TILING7_4_2TILING8TILING9TILING10_1_1TILING10_1_1_TILING10_1_2
TILING10_2TILING10_2_TILING11TILING12_1_1TILING12_1_1_TILING12_1_2
TILING12_2TILING12_2_
TILING13_1TILING13_1_
TILING13_2TILING13_2_
TILING13_3TILING13_3_
TILING13_4TILING13_5_1TILING13_5_2TILING14TEST3TEST4TEST6TEST7TEST10TEST12TEST13SUBCONFIG13rG    r   r   r,   r,      sB   6:&&4@@ 4
4
4
 4
 f))*	4

 fll#4
 fnn%4
 fnn%4
 f&&'4
 f&&'4
 f&&'4
 f&&'4
 fnn%4
 f(()4
 f(()4
 f&&'4
  f&&'!4
" f&&'#4
$ f&&'%4
& f(()'4
( f(())4
* fnn%+4
, fnn%-4
. f))*/4
0 f**+14
2 f))*34
4 f''(54
6 f(()74
8 foo&94
: f))*;4
< f**+=4
> f))*?4
@ f''(A4
B f(()C4
D f''(E4
F f(()G4
H f''(I4
J f(()K4
L f''(M4
N f(()O4
P f''(Q4
R f))*S4
T f))*U4
V foo&W4
X fll#Y4
Z fll#[4
\ fll#]4
^ fll#_4
` fmm$a4
b fmm$c4
d fmm$e4
f f(()g4
l ??r   c                     X   nUSS2SSS24   USS2SSS24   -
  nUSS2SSS24   USS2SSS24   -
  nA[         R                  " X45      S-  R                  SS9S-  R                  5       S-  $ )a  Compute surface area, given vertices and triangular faces.

Parameters
----------
verts : (V, 3) array of floats
    Array containing coordinates for V unique mesh vertices.
faces : (F, 3) array of ints
    List of length-3 lists of integers, referencing vertex coordinates as
    provided in `verts`.

Returns
-------
area : float
    Surface area of mesh. Units now [coordinate units] ** 2.

Notes
-----
The arguments expected by this function are the first two outputs from
`skimage.measure.marching_cubes`. For unit correct output, ensure correct
`spacing` was passed to `skimage.measure.marching_cubes`.

This algorithm works properly only if the ``faces`` provided are all
triangles.

See Also
--------
skimage.measure.marching_cubes

Nr   r   r   )axisr   g       @)r    crosssum)vertsr6   actual_vertsabs        r   mesh_surface_arear   ;  s    > <LQ1WQ1W 55AQ1WQ1W 55A XXa^q %%1%-499;cAAr   )N)r=   numpyr     r   rI   r   r   r   rE   arrayrK   rL   rM   r,   r   r~   r   r   <module>r      s     4 (
 K  	K\OHd  XX1qeQqE1Q%!A!uaUAa5STUVRWYZ[\X]_`ab^cefghdikmst XX1qeQqE1Q%!A!uaUAa5STUVRWYZ[\X]_`ab^cefghdikmst XX1qeQqE1Q%!A!uaUAa5STUVRWYZ[\X]_`ab^cefghdikmst 9x%Br   