a
    «ˆc§  ã                   @   sª   d dl mZ d dlmZ d dlZd dlZd dlZd dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ G dd„ dejƒZedkr¦e ¡  dS )é    )Úabspath)ÚBytesION)Ú
NullEngine)ÚVTKDataSource)ÚOutline)Ú
IsoSurface)ÚContourGridPlane)ÚScalarCutPlane)Údatasetsc                   @   sD   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )ÚTestContourc           
      C   sö   t ƒ }| ¡  | ¡  || _t ¡ }t|d�}| |¡ tƒ }| 	|¡ t
ƒ }| 	|¡ d|j_t
ƒ }d|j_d|j_d|j_| 	|¡ tdd�}| 	|¡ dg|j_tƒ }| 	|¡ |j}	d|	_d|	_d|	j_d	|	j_|j| _|| _|| _|| _d
S )zlInitial setting up of test fixture, automatically called by TestCase before any other test method is invoked)Údataé   TÚy)Úcompute_normalsé   ©r   r   é   ©ç      à?r   g      ð?FN)r   ÚstartZ	new_sceneÚer
   ZgenerateStructuredGridr   Z
add_sourcer   Z
add_moduler   Ú
grid_planeÚpositionÚcontourÚfilled_contoursÚaxisr   Úcontoursr	   Úimplicit_planeÚnormalÚoriginÚwidgetÚenabledÚcurrent_sceneÚsceneÚcgp2ÚisoÚcp)
Úselfr   ZsgridÚsrcÚoÚcgp1r$   r%   r&   Úip© r,   ú\/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mayavi/tests/test_contour.pyÚsetUp   s@    








zTestContour.setUpc                 C   s   | j  ¡  dS )zaFor necessary clean up, automatically called by TestCase after the test methods have been invokedN)r   Ústop©r'   r,   r,   r-   ÚtearDownN   s    
zTestContour.tearDownc                 C   s   | j }|jd }|jd }|jd }|  |jjd¡ |jd }|  |jjd¡ |  |jjd¡ |  |jjd¡ |jd }|jj}|  |j	d¡ |  |dg¡ |j
jjjjj}|  |d d¡ |  |d d¡ |jd	 }	|	j}
|  t |
jd
 ¡d¡ |  t |
jd ¡d¡ |  |
jjd¡ dS )zDo the actual testing.r   r   r   é   Tr   é   ç      @é   r   g¼‰Ø—²Òœ<r   g        FN)r#   ÚchildrenÚassertEqualr   r   r   r   r   r   r   ÚactorZmapperÚinputZ
point_dataZscalarsÚranger   ZassertAlmostEqualÚnumpyÚsumr   r   r    r!   )r'   r#   r(   Úmmr*   r$   r%   ÚctrÚrngr&   r+   r,   r,   r-   ÚcheckS   s*    





zTestContour.checkc                 C   s   |   ¡  dS )zTest if the test fixture worksN)r@   r0   r,   r,   r-   Útest_contourp   s    zTestContour.test_contourc                 C   s²   | j }| j}| j}|j}| ¡ |_||_|j ¡ |_|j ¡ |_dg|j_|j ¡ |_|j ¡ |_|j}|j ¡ |_||_d|j	_
|j ¡ |_|j ¡ |_|j ¡ |_|  ¡  dS )zQTest if the modules respond correctly when the components
           are changed.r4   FN)r$   r&   r%   r   Ú	__class__r8   r   Znormalsr   r    r!   Zcutterr@   )r'   r$   r&   r%   r>   r+   r,   r,   r-   Útest_components_changedx   s&    

z#TestContour.test_components_changedc                 C   sX   | j }| j}tƒ }tdƒ|_| |¡ | d¡ | |¡ | |¡ |j	| _|  
¡  dS )z6Test if saving a visualization and restoring it works.ztest.mv2r   N)r   r#   r   r   ÚnameZsave_visualizationÚseekZclose_sceneZload_visualizationr"   r@   )r'   Zenginer#   Úfr,   r,   r-   Útest_save_and_restore“   s    




z!TestContour.test_save_and_restorec                 C   sx   | j }|j ¡ }|j |¡ |jd jd }d|jj_|  ¡  t 	|¡}||jd< |jd jd }d|jj_|  ¡  dS )z5Test if the MayaVi2 visualization can be deep-copied.r   éÿÿÿÿFN)
r#   r6   ÚpopÚappendr   r    r!   r@   ÚcopyÚdeepcopy)r'   ÚsÚsourcer&   Zsource1r,   r,   r-   Útest_deepcopied©   s    




zTestContour.test_deepcopiedN)
Ú__name__Ú
__module__Ú__qualname__r.   r1   r@   rA   rC   rG   rO   r,   r,   r,   r-   r      s   4r   Ú__main__)Úos.pathr   Úior   rK   r;   ZunittestZmayavi.core.null_enginer   Zmayavi.sources.vtk_data_sourcer   Zmayavi.modules.outliner   Zmayavi.modules.iso_surfacer   Z!mayavi.modules.contour_grid_planer   Zmayavi.modules.scalar_cut_planer	   Zmayavi.testsr
   ZTestCaser   rP   Úmainr,   r,   r,   r-   Ú<module>   s    +