3
ÌœŸW§  ã               @   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jƒ  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 ƒ }|jƒ  |jƒ  || _tjƒ }t|d�}|j|ƒ tƒ }|j	|ƒ t
ƒ }|j	|ƒ d|j_t
ƒ }d|j_d|j_d|j_|j	|ƒ tdd�}|j	|ƒ dg|j_tƒ }|j	|ƒ |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   é   ç      à?ç      ð?FN)r   r   r   )r   r   r   )r   r   r   )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/venv/lib/python3.6/site-packages/mayavi/tests/test_contour.pyÚsetUp   s@    








zTestContour.setUpc             C   s   | j 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jdƒ |jd }| j|jjdƒ | j|jjdƒ | j|jjdƒ |jd }|jj}| j|j	dƒ | j|dgƒ |j
jjjjj}| j|d dƒ | j|d dƒ |jd	 }	|	j}
| jtj|
jd ƒd
ƒ | jtj|
jd ƒdƒ | j|
jjdƒ dS )zDo the actual testing.r   r   r   é   Tr   é   g      @é   g¼‰Ø—²Òœ<ç      à?ç      ð?g        FN)r   r   r   )r3   r3   r4   )r"   ÚchildrenÚassertEqualr   r   r   r   r   r   r   ÚactorZmapperÚinputZ
point_dataÚscalarsÚranger   Ú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   | j ƒ  dS )zTest if the test fixture worksN)rA   )r&   r+   r+   r,   Útest_contourp   s    zTestContour.test_contourc             C   s²   | j }| j}| j}|j}|jƒ |_||_|jjƒ |_|jjƒ |_dg|j_|jjƒ |_|jjƒ |_|j}|jjƒ |_||_d|j	_
|jjƒ |_|jjƒ |_|jjƒ |_| jƒ  dS )zQTest if the modules respond correctly when the components
           are changed.g      @FN)r#   r%   r$   r   Ú	__class__r7   r   Znormalsr   r   r    ZcutterrA   )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ƒ|_|j|ƒ |jdƒ |j|ƒ |j|ƒ |j	| _| 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!   rA   )r&   Úenginer"   Úfr+   r+   r,   Útest_save_and_restore“   s    




z!TestContour.test_save_and_restorec             C   sx   | j }|jjƒ }|jj|ƒ |jd jd }d|jj_| jƒ  tj	|ƒ}||jd< |jd jd }d|jj_| jƒ  dS )z5Test if the MayaVi2 visualization can be deep-copied.r   r   FNéÿÿÿÿrJ   )
r"   r5   ÚpopÚappendr   r   r    rA   ÚcopyÚdeepcopy)r&   ÚsÚsourcer%   Zsource1r+   r+   r,   Útest_deepcopied©   s    




zTestContour.test_deepcopiedN)
Ú__name__Ú
__module__Ú__qualname__r-   r/   rA   rB   rD   rI   rQ   r+   r+   r+   r,   r      s   4r   Ú__main__)Úos.pathr   Úior   rM   r<   ÚunittestÚ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
   ÚTestCaser   rR   Úmainr+   r+   r+   r,   Ú<module>   s    +