3
®?d]¼  ã               @   s@   d Z ddlZddlZddlZdd„ Zdd„ Zdd„ Zd	d
„ ZdS )zLMiscellaneous functions and classes that don't fit into specific
categories.é    Nc                sF   dt jt jt jt jt jt jg}ˆ |kr6tdˆ |f ƒ‚‡ fdd„}|S )aÒ  set_call_data_type(type) -- convenience decorator to easily set the CallDataType attribute
    for python function used as observer callback.
    For example:

    import vtk

    @vtk.calldata_type(vtk.VTK_STRING)
    def onError(caller, event, calldata):
        print("caller: %s - event: %s - msg: %s" % (caller.GetClassName(), event, calldata))

    lt = vtk.vtkLookupTable()
    lt.AddObserver(vtk.vtkCommand.ErrorEvent, onError)
    lt.SetTableRange(2,1)
    Zstring0zC'%s' is not a supported VTK call data type. Supported types are: %sc                s
   ˆ | _ | S )N)ZCallDataType)Úf)Útype© ú,/tmp/pip-build-op5p2y5_/vtk/vtk/util/misc.pyÚwrap   s    zcalldata_type.<locals>.wrap)ÚvtkZ
VTK_STRINGZ
VTK_OBJECTZVTK_INTZVTK_LONGZ
VTK_DOUBLEZ	VTK_FLOATÚ	TypeError)r   Zsupported_call_data_typesr   r   )r   r   Úcalldata_type   s
    r	   c              C   s†   d} x@t dttjƒƒD ],}tj| dkr|ttjƒd k r|d } qW | dkrZtj|  }n(ytjd }W n tk
r€   d}Y nX |S )z:vtkGetDataRoot() -- return vtk example data directory
    é   r   z-DZVTK_DATA_ROOTz../../../../VTKDataéÿÿÿÿr   )ÚrangeÚlenÚsysÚargvÚosÚenvironÚKeyError)Z	dataIndexÚiZdataRootr   r   r   ÚvtkGetDataRoot    s     
r   c              C   sb   d} x@t dttjƒƒD ],}tj| dkr|ttjƒd k r|d } qW | dkrZtj|  }nd}|S )z3vtkGetTempDir() -- return vtk testing temp dir
    r
   r   z-TÚ.r   r   )r   r   r   r   )Z	tempIndexr   ZtempDirr   r   r   ÚvtkGetTempDir2   s     r   c             C   s  d}x@t dttjƒƒD ],}tj| dkr|ttjƒd k r|d }qW |d	k�rtjjtƒ tj| ƒ}tj	ƒ }|j
| ƒ tjj|ƒr†n,tjƒ }|j|ƒ |j|jƒ ƒ |jƒ  d}tjƒ }|j|ƒ tjƒ }|j|jƒ ƒ |j|jƒ ƒ |jƒ  |jƒ dk�rdS tjjd|jƒ  ƒ dS dS )
zÇvtkRegressionTestImage(renWin) -- produce regression image for window

    This function writes out a regression .png file for a vtkWindow.
    Does anyone involved in testing care to elaborate?
    r
   r   z-VNé
   zFailed image test: %f
é   r   r   )r   r   r   r   r   ÚpathÚjoinr   r   ZvtkWindowToImageFilterZSetInputÚisfileZvtkPNGWriterZSetFileNameZSetInputConnectionZGetOutputPortZWriteZvtkPNGReaderZvtkImageDifferenceZSetImageConnectionZUpdateZGetThresholdedErrorÚstderrÚwrite)ZrenWinZ
imageIndexr   ÚfnameZrt_w2ifZrt_pngwZrt_pngZrt_idr   r   r   ÚvtkRegressionTestImageB   s6     



r   )Ú__doc__r   r   r   r	   r   r   r   r   r   r   r   Ú<module>   s
   