Ë
    îì�iH2  ã                   ó¨  — d dl Z d dlZddlmZ ddlmZ 	 dddddddd	œd
„Zd„ Zd„ Z	 ej                  d dgddgdd gd d gd dgddgdd gd d gd d gddgddgd d ggd«      Z ej                  d d gd dgddgdd gd d gd dgddgdd gd d gd d gddgddggd«      Z ej                  d d gd d gd d gd d gddgddgddgddgd dgd dgd dgd dggd«      Zd„ Zd„ Zy)é    Né   )Ú_marching_cubes_lewiner_luts)Ú_marching_cubes_lewiner_cy)ç      ð?r   r   ÚdescentTÚlewiner)ÚspacingÚgradient_directionÚ	step_sizeÚallow_degenerateÚmethodÚmaskc          
      ó\   — d}|dk(  rd}n|dk7  rt        d«      ‚t        | |||||||¬«      S )a  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 : {'descent', 'ascent'}, 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	            úŒ/var/www/ITT-ServiceAPI-Services/ITT-Document-Scan/mrzscanner/mrzenv/lib/python3.12/site-packages/skimage/measure/_marching_cubes_lewiner.pyÚmarching_cubesr   	   sP   € ðz €KØ�ÒØ‰Ø	�9Ò	ÜÐJÓKÐKÜ"ØØØØØØØØô	ð 	ó    c                 óà  — t        | t        j                  «      r| j                  dk7  rt	        d«      ‚| j
                  d   dk  s$| j
                  d   dk  s| j
                  d   dk  rt	        d«      ‚t        j                  | t        j                  «      } |€%d| j                  «       | j                  «       z   z  }n<t        |«      }|| j                  «       k  s|| j                  «       kD  rt	        d«      ‚t        |«      dk7  rt	        d	«      ‚t        |«      }|dk  rt	        d
«      ‚t        |«      }t        «       }|�$|j
                  | j
                  k(  st	        d«      ‚t        j                   }	 |	| |||||«      \  }
}}}t        |
«      st#        d«      ‚t        j$                  |
«      }
t        j$                  |«      }d|_        |dk(  rt        j$                  |«      }n|dk(  st	        d|› d�«      ‚t        j&                  |d«      s|
t        j(                  |   z  }
|r|
|||fS t        j*                  } ||
j-                  t        j                  «      |||«      S )zdLewiner 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   —   s<  € ô  �fœbŸj™jÔ)¨f¯k©k¸QÒ.>ÜÐCÓDÐDØ‡|�|�A�˜Ò˜fŸl™l¨1™o°Ò1°V·\±\À!±_ÀqÒ5HÜÐ>Ó?Ð?Ü×!Ñ! &¬"¯*©*Ó5€Fð €}Ø�v—z‘z“| f§j¡j£lÑ2Ñ3‰ä�e“ˆØ�6—:‘:“<Ò 5¨6¯:©:«<Ò#7ÜÐNÓOÐOä
ˆ7ƒ|�qÒÜÐBÓCÐCä�I“€IØ�1‚}ÜÐ:Ó;Ð;ä�{Ó#€Kô 	‹€Að ÐØ�z‰z˜VŸ\™\Ò)ÜÐHÓIÐIô &×4Ñ4€DÙ'+Ø��q˜) [°$ó(Ñ$€Hˆe�W˜fô ˆxŒ=ÜÐEÓFÐFô �y‰y˜Ó"€HÜ�i‰i˜Ó €Gð €E„KØ˜YÒ&ô —	‘	˜%Ó ‰Ø 8Ò+ÜØÐ1Ð2ð 3ð ó
ð 	
ô �>‰>˜' 9Ô-ØœbŸe™e G™nÑ,ˆáØ˜ ¨Ð/Ð/ä(×@Ñ@ˆÙ�8—?‘?¤2§:¡:Ó.°°wÀÓGÐGr   c                 ó”   — | \  }}t        j                  |j                  d«      «      }t        j                  |d¬«      }||_        |S )Nzutf-8Úint8)Údtype)Úbase64ÚdecodebytesÚencoder    Ú
frombufferr#   )Úargsr#   ÚtextÚbytsÚars        r   Ú	_to_arrayrE   é   s@   € Ø�K€Eˆ4Ü×Ñ˜dŸk™k¨'Ó2Ó3€DÜ	�‰�t 6Ô	*€BØ€B„HØ€Ir   r;   c                  ó 
  — t        t        d«      �sÞt        j                  g t        ‘t
        ‘t        ‘t        t        j                  «      ‘t        t        j                  «      ‘t        t        j                  «      ‘t        t        j                  «      ‘t        t        j                  «      ‘t        t        j                  «      ‘t        t        j                  «      ‘t        t        j                  «      ‘t        t        j                   «      ‘t        t        j"                  «      ‘t        t        j$                  «      ‘t        t        j&                  «      ‘t        t        j(                  «      ‘t        t        j*                  «      ‘t        t        j,                  «      ‘t        t        j.                  «      ‘t        t        j0                  «      ‘t        t        j2                  «      ‘t        t        j4                  «      ‘t        t        j6                  «      ‘t        t        j8                  «      ‘t        t        j:                  «      ‘t        t        j<                  «      ‘t        t        j>                  «      ‘t        t        j@                  «      ‘t        t        jB                  «      ‘t        t        jD                  «      ‘t        t        jF                  «      ‘t        t        jH                  «      ‘t        t        jJ                  «      ‘t        t        jL                  «      ‘t        t        jN                  «      ‘t        t        jP                  «      ‘t        t        jR                  «      ‘t        t        jT                  «      ‘t        t        jV                  «      ‘t        t        jX                  «      ‘t        t        jZ                  «      ‘t        t        j\                  «      ‘t        t        j^                  «      ‘t        t        j`                  «      ‘t        t        jb                  «      ‘t        t        jd                  «      ‘t        t        jf                  «      ‘t        t        jh                  «      ‘t        t        jj                  «      ‘t        t        jl                  «      ‘t        t        jn                  «      ‘­Ž t        _8        t        jp                  S )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,   ÿ   s?  € ä”6˜:Õ&Ü4×@Ñ@ð 4
Üð4
äð4
ô ð4
ô ”f×)Ñ)Ó*ð	4
ô
 ”f—l‘lÓ#ð4
ô ”f—n‘nÓ%ð4
ô ”f—n‘nÓ%ð4
ô ”f×&Ñ&Ó'ð4
ô ”f×&Ñ&Ó'ð4
ô ”f×&Ñ&Ó'ð4
ô ”f×&Ñ&Ó'ð4
ô ”f—n‘nÓ%ð4
ô ”f×(Ñ(Ó)ð4
ô ”f×(Ñ(Ó)ð4
ô ”f×&Ñ&Ó'ð4
ô  ”f×&Ñ&Ó'ð!4
ô" ”f×&Ñ&Ó'ð#4
ô$ ”f×&Ñ&Ó'ð%4
ô& ”f×(Ñ(Ó)ð'4
ô( ”f×(Ñ(Ó)ð)4
ô* ”f—n‘nÓ%ð+4
ô, ”f—n‘nÓ%ð-4
ô. ”f×)Ñ)Ó*ð/4
ô0 ”f×*Ñ*Ó+ð14
ô2 ”f×)Ñ)Ó*ð34
ô4 ”f×'Ñ'Ó(ð54
ô6 ”f×(Ñ(Ó)ð74
ô8 ”f—o‘oÓ&ð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 ”f—o‘oÓ&ðW4
ôX ”f—l‘lÓ#ðY4
ôZ ”f—l‘lÓ#ð[4
ô\ ”f—l‘lÓ#ð]4
ô^ ”f—l‘lÓ#ð_4
ô` ”f—m‘mÓ$ða4
ôb ”f—m‘mÓ$ðc4
ôd ”f—m‘mÓ$ðe4
ôf ”f×(Ñ(Ó)òg4
ŒŒôl �?‰?Ðr   c                 óì   — | |   }|dd…ddd…f   |dd…ddd…f   z
  }|dd…ddd…f   |dd…ddd…f   z
  }~t        j                  ||«      dz  j                  d¬«      dz  j                  «       dz  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˜š1�WÑ ªQ°²1¨WÑ 5Ñ5€AØ’Q˜š1�WÑ ªQ°²1¨WÑ 5Ñ5€AØô �X‰X�a˜‹^˜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ð  �R—X‘X  1  q¨ e¨Q¨q¨E°1°Q°%¸!¸A¸ÀÀ!¸uÀaÈÀUÈAÈaÈ5ÐSTÐUVÐRWÐYZÐ[\ÐX]Ð_`ÐabÐ^cÐefÐghÐdiÐkÐmsÓtÐ Ø�R—X‘X  1  q¨ e¨Q¨q¨E°1°Q°%¸!¸A¸ÀÀ!¸uÀaÈÀUÈAÈaÈ5ÐSTÐUVÐRWÐYZÐ[\ÐX]Ð_`ÐabÐ^cÐefÐghÐdiÐkÐmsÓtÐ Ø�R—X‘X  1  q¨ e¨Q¨q¨E°1°Q°%¸!¸A¸ÀÀ!¸uÀaÈÀUÈAÈaÈ5ÐSTÐUVÐRWÐYZÐ[\ÐX]Ð_`ÐabÐ^cÐefÐghÐdiÐkÐmsÓtÐ ò9óx%Br   