Ë
    ¯·g�#  ã                   ón  — d Z ddlmZ ddlmZmZmZ ddlZ e«       j                  «       Z	e	dk(  rej                  Zne	dk(  rej                  Z e«       j                  «       Zedk(  rej                  Zej                  Znedk(  rej                  Zej"                  Zd„ Zd	„ Zd
„ Zd„ Zdd„Zdd„Zd„ Zy)a¶  This module adds support to easily import and export NumPy
(http://numpy.scipy.org) arrays into/out of VTK arrays.  The code is
loosely based on TVTK (https://svn.enthought.com/enthought/wiki/TVTK).

This code depends on an addition to the VTK data arrays made by Berk
Geveci to make it support Python's buffer protocol (on Feb. 15, 2008).

The main functionality of this module is provided by the two functions:
    numpy_to_vtk,
    vtk_to_numpy.


Caveats:
--------

 - Bit arrays in general do not have a numpy equivalent and are not
   supported.  Char arrays are also not easy to handle and might not
   work as you expect.  Patches welcome.

 - You need to make sure you hold a reference to a Numpy array you want
   to import into VTK.  If not you'll get a segfault (in the best case).
   The same holds in reverse when you convert a VTK array to a numpy
   array -- don't delete the VTK array.


Created by Prabhu Ramachandran in Feb. 2008.
é   )ÚvtkConstantsé    )ÚvtkDataArrayÚvtkIdTypeArrayÚvtkLongArrayNé   é   c                 ó¢  — t         j                  t        j                  t         j                  t        j
                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j                   t        j"                  t         j$                  t        j&                  t         j(                  t        j*                  t         j,                  t        j&                  t         j.                  t        j*                  i}|j1                  «       D ]<  \  }}| |k(  s/t        j2                  | |«      s| t        j4                  |«      k(  sŒ:|c S  t7        dt9        | «      z  «      ‚)z+Returns a VTK typecode given a numpy array.z)Could not find a suitable VTK type for %s)ÚnumpyÚuint8r   ÚVTK_UNSIGNED_CHARÚuint16ÚVTK_UNSIGNED_SHORTÚuint32ÚVTK_UNSIGNED_INTÚuint64ÚVTK_UNSIGNED_LONG_LONGÚint8ÚVTK_SIGNED_CHARÚint16Ú	VTK_SHORTÚint32ÚVTK_INTÚint64ÚVTK_LONG_LONGÚfloat32Ú	VTK_FLOATÚfloat64Ú
VTK_DOUBLEÚ	complex64Ú
complex128ÚitemsÚ
issubdtypeÚdtypeÚ	TypeErrorÚstr)Únumpy_array_typeÚ_np_vtkÚkeyÚvtk_types       ú=lib/python3.12/site-packages/vtkmodules/util/numpy_support.pyÚget_vtk_array_typer,   1   s%  € ô �{‰{œ<×9Ñ9Ü—‘œ\×<Ñ<Ü—‘œ\×:Ñ:Ü—‘œ\×@Ñ@Ü—
‘
œ<×7Ñ7Ü—‘œL×2Ñ2Ü—‘œL×0Ñ0Ü—‘œL×6Ñ6Ü—‘œl×4Ñ4Ü—‘œl×5Ñ5Ü—‘¤× 6Ñ 6Ü× Ñ ¤×!8Ñ!8ð:€Gð !Ÿ™ž‰ˆˆXØ˜sÒ"Ü×ÑÐ,¨cÔ2ØœuŸ{™{¨3Ó/Ó/ØŠOð	 )ô
 Ø3´sÐ;KÓ7LÑMóOð Oó    c                  óR  — t         j                  t        j                  t         j                  t        j
                  t         j                  t        j
                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j                   t"        t         j$                  t        j&                  t         j(                  t*        t         j,                  t        j.                  t         j0                  t2        t         j4                  t        j6                  t         j8                  t        j:                  i} | S )z7Returns the VTK array type to numpy array type mapping.)r   ÚVTK_BITr   r   ÚVTK_CHARr   r   r   r   r   r   r   r   r   r   r   ÚVTK_LONGÚLONG_TYPE_CODEr   r   ÚVTK_UNSIGNED_LONGÚULONG_TYPE_CODEr   r   ÚVTK_ID_TYPEÚID_TYPE_CODEr   r   r   r   )Ú_vtk_nps    r+   Úget_vtk_to_numpy_typemapr8   H   så   € ä×#Ñ#¤E§K¡KÜ×%Ñ%¤e§j¡jÜ×,Ñ,¬U¯Z©ZÜ×.Ñ.¬u¯{©{Ü×&Ñ&¤u§{¡{Ü×/Ñ/´·±Ü×$Ñ$¤U§[¡[Ü×-Ñ-¬e¯l©lÜ×%Ñ%¤nÜ×*Ñ*¬5¯;©;Ü×.Ñ.¬Ü×3Ñ3´E·L±LÜ×(Ñ(¬Ü×&Ñ&¤u§}¡}Ü×'Ñ'¬¯©ð7€Gð €Nr-   c                 ó   — t        «       |    S )z6Returns a numpy array typecode given a VTK array type.)r8   )Úvtk_array_types    r+   Úget_numpy_array_typer;   \   s   € ä#Ó% nÑ5Ð5r-   c                 ó,   — t        j                  | «      S )zkInternal function used to create a VTK data array from another
    VTK array given the VTK array type.
    )r   ÚCreateDataArray)Úvtk_arr_types    r+   Úcreate_vtk_arrayr?   a   s   € ô ×'Ñ'¨Ó5Ð5r-   c                 ó2  — t        j                  | «      }|j                  j                  st        j                  |«      }|j
                  }|j                  j                  sJ d«       ‚t        |«      dk  sJ d«       ‚t        j                  |j                  t        j                  t        «      j                  «      rJ d«       ‚|r|}nt        |j                  «      }t        |«      }	 |d   }t        |«      dk(  r|j                  d«       n|j                  |d   «       |j                  |d   «       t        |«      }t        j                  |j                  |«      s"|j                  t        j                  |«      k(  rt        j                   |«      }	n&t        j                   |«      j#                  |«      }	d}|j%                  |	t        |	«      d«       |r%|j'                  «       }
|
j)                  |«       |
}|S ||_        |S #  d}Y �Œ$xY w)a=  Converts a real numpy Array to a VTK array object.

    This function only works for real arrays.
    Complex arrays are NOT handled.  It also works for multi-component
    arrays.  However, only 1, and 2 dimensional arrays are supported.
    This function is very efficient, so large arrays should not be a
    problem.

    If the second argument is set to 1, the array is deep-copied from
    from numpy. This is not as efficient as the default behavior
    (shallow copy) and uses more memory but detaches the two arrays
    such that the numpy array can be released.

    WARNING: You must maintain a reference to the passed numpy array, if
    the numpy data is gc'd and VTK will point to garbage which will in
    the best case give you a segfault.

    Parameters:

    num_array
      a 1D or 2D, real numpy array.

    z%Only contiguous arrays are supported.é   z5Only arrays of dimensionality 2 or lower are allowed!z…Complex numpy arrays cannot be converted to vtk arrays.Use real() or imag() to get a component of the array before passing it to vtk.r   ©r   r   )r   ÚasarrayÚflagsÚ
contiguousÚascontiguousarrayÚshapeÚlenr#   r$   ÚcomplexÚtyper,   r?   ÚSetNumberOfComponentsÚSetNumberOfTuplesr;   ÚravelÚastypeÚSetVoidArrayÚNewInstanceÚDeepCopyÚ_numpy_reference)Ú	num_arrayÚdeepÚ
array_typeÚzrG   Úvtk_typecodeÚresult_arrayÚtestVarÚ	arr_dtypeÚz_flatÚcopys              r+   Únumpy_to_vtkr]   h   sÑ  € ô2 	�‰�iÓ €AØ�7‰7×ÒÜ×#Ñ# AÓ&ˆà�G‰G€EØ�7‰7×ÒÐFÐFÓFÐÜˆu‹:˜Š>ð CØBóCˆ>ä×Ñ §¡¬¯©´WÓ)=×)BÑ)BÔCð !ð!ó!ÐCñ Ø!‰ä)¨!¯'©'Ó2ˆÜ# LÓ1€LðØ˜‘(ˆô
 ˆ5ƒz�Q‚Ø×*Ñ*¨1Õ-à×*Ñ*¨5°©8Ô4à×"Ñ" 5¨¡8Ô,ô % \Ó2€IÜ×Ñ˜Ÿ™ Ô+Ø‡w�w”%—+‘+˜iÓ(Ò(Ü—‘˜Q“‰ä—‘˜Q“×&Ñ& yÓ1ˆð ˆð ×Ñ˜f¤c¨&£k°1Ô5ÙØ×'Ñ'Ó)ˆØ�‰�lÔ#Øˆð Ðð )*ˆÔ%ØÐøðAØ‹ús   Ã-H ÈHc                 ó2  — t        «       j                  «       }| j                  }|dk(  r*|t        j                  k7  rAt        dt        |«      z  «      ‚|t        j                  k7  rt        dt        |«      z  «      ‚t        | |t        j                  «      S )Nr   z.Expecting a numpy.int32 array, got %s instead.z.Expecting a numpy.int64 array, got %s instead.)r   ÚGetDataTypeSizer$   r   r   Ú
ValueErrorr&   r   r]   r   r5   )rS   rT   Úisizer$   s       r+   Únumpy_to_vtkIdTypeArrayrb   º   sŠ   € ÜÓ×,Ñ,Ó.€EØ�O‰O€EØ�‚zØ”E—K‘KÒÜØ=ÄÀUÃÑLóNð Nð ”E—K‘KÒÜØ=ÄÀUÃÑLóNð Nô ˜	 4¬×)AÑ)AÓBÐBr-   c                 ó  — | j                  «       }|t        «       j                  «       v s
J d|z  «       ‚|t        j                  k7  sJ d«       ‚| j                  «       | j                  «       f}t        |«      }	 t        j                  | |¬«      }|d   dk(  r|d   f}	 ||_        |S # t        $ r$ |d   dk(  rt        j                  ||¬«      }n‚ Y ŒDw xY w# t        $ r$ |d   dk(  rt        j                  ||¬«      }Y |S ‚ w xY w)aL  Converts a VTK data array to a numpy array.

    Given a subclass of vtkDataArray, this function returns an
    appropriate numpy array containing the same data -- it actually
    points to the same data.

    WARNING: This does not work for bit arrays.

    Parameters

    vtk_array
      The VTK data array to be converted.

    zUnsupported array type %szBit arrays are not supported.)r$   r   r   )ÚGetDataTyper8   Úkeysr   r/   ÚGetNumberOfTuplesÚGetNumberOfComponentsr;   r   Ú
frombufferr`   ÚemptyrG   )Ú	vtk_arrayÚtyprG   r$   Úresults        r+   Úvtk_to_numpyrm   È   s0  € ð ×
Ñ
Ó
!€CØÔ*Ó,×1Ñ1Ó3Ñ3ð +Ø& sÑ*ó+Ð3à”,×&Ñ&Ò&ÐGÐ(GÓGÐ&à×'Ñ'Ó)Ø×+Ñ+Ó-ð.€Eô ! Ó%€EðÜ×!Ñ! )°5Ô9ˆð ˆQ�x�1‚}Ø�q‘�ˆðØˆŒð €Møô+ ò 	ð
 �‰8�qŠ=ä—[‘[ ¨eÔ4‰Fàñ ð	ûô ò Ø�‰8�qŠ=ô —K‘K ¨UÔ3‰6à€Mð ðús$   Á;B* Â!C Â**CÃCÃ(DÄD)r   NrB   )Ú__doc__Ú r   Úvtkmodules.vtkCommonCorer   r   r   r   r_   ÚVTK_ID_TYPE_SIZEr   r6   r   ÚVTK_LONG_TYPE_SIZEr2   r   r4   r   r,   r8   r;   r?   r]   rb   rm   © r-   r+   Ú<module>rt      sº   ðñõ8 ß OÑ OÛ ñ "Ó#×3Ñ3Ó5Ð Ø�qÒØ—;‘;�LØ˜ÒØ—;‘;€Lá!“^×3Ñ3Ó5Ð Ø˜ÒØ—[‘[€NØ—l‘l�OØ˜1ÒØ—[‘[€NØ—l‘l€OòOò.ò(6ò
6óPódCó0r-   