3
îÈ‘[  ã               @   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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)ÚArraySource)ÚOutline)ÚGlyph)ÚVectorCutPlanec               @   sr   e Zd Zdd„ Zdd„ Zdd„ Zddd	„Zd
d„ Zej	e
jƒ dkdƒdd„ ƒZdd„ Zdd„ Zdd„ Zdd„ ZdS )Ú	TestGlyphc             C   sR   t jdddƒ}t j|dƒ}t j|ƒ}t jddƒ}d|dd	d
…< t j|dƒ}||fS )zkTrivial data -- creates an elementatry scalar field and a
        constant vector field along the 'x' axis.g        g      $@g{®Gáz„?é
   i¸  Údg      ð?é   Né   )r
   r
   r
   )r
   r
   r
   r   )ÚnumpyÚarangeÚreshapeÚ	transposeÚzeros)ÚselfÚsÚv© r   úZ/home/yuhw/wc/wire-cell-python/venv/lib/python3.6/site-packages/mayavi/tests/test_glyph.pyÚ	make_data   s    
zTestGlyph.make_datac             C   s6  t ƒ }|jƒ  |jƒ }|| _|| _tƒ }| jƒ \}}d|_||_||_	|j
|ƒ tƒ }|j|ƒ tƒ }|j|ƒ d|jj_d|jj_d|jj_d|jj_d|jj_tƒ }|j}	|	j}
d|
_|
jd |
_|j|ƒ |jjddd� tƒ }|j}	|	j}
|
jd |
_d|
_|j|ƒ |jjddd� || _|| _|j| _d S )Né   ÚcenterÚ
use_normalg      à?é   g      ð?Útailr   r   r   )ÚnormalÚoriginé   Úheadéûÿÿÿr"   r"   )r"   r"   r"   )r   r   r   )r   r   r   )r   r   r   éþÿÿÿ)r   r#   r   ) r   ÚstartZ	new_sceneÚer   r   r   r   Zscalar_dataZvector_dataZ
add_sourcer   Z
add_moduler   ÚglyphÚglyph_sourceÚglyph_positionÚvector_modeÚscale_factorÚmask_pointsÚon_ratioÚactorÚpropertyÚ
line_widthr   Ú
glyph_listÚimplicit_planeÚ	trait_setÚgr   Úcurrent_sceneÚscene)r   r%   r   r   ÚscÚvecÚor3   r   r&   Úgsr   r   r   ÚsetUp&   sL    









zTestGlyph.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   ÚtearDownZ   s    
zTestGlyph.tearDownFc             C   s|  | j }|jd }|jd jd }| j|jjjdƒ | j|jjjdƒ | j|jjjdƒ | j|jj	j
dƒ |jd jj}|jjjj}|rÀ| j|dƒ |r¤| j||ƒ qÌ|jjj}| j||| ƒ n| j||ƒ |jd jd }	|	j}
|
j}| j|jdƒ | j|j|jd ƒ | jtj|	jjdƒd
ƒ |jd jd }	|	j}
|
j}| j|j|jd ƒ | j|jdƒ | jtj|	jjdƒd
ƒ dS )z�Do the actual testing with and without masking. For masking,
           both the presence and absence of random mode is also tested.
        r   r   r   r   g      à?ç      ð?r    r   ç        Tr   r!   N)r>   r=   r>   )r>   r=   r>   )r5   ÚchildrenÚassertEqualr&   r'   r(   r)   r*   r-   r.   r/   ÚoutputsÚoutputZnumber_of_pointsÚinputÚassertNotEqualÚassertLessEqualr+   r,   r0   r   Úallcloser1   r   )r   ÚmaskÚmask_random_moder   Úsrcr3   Zn_output_pointsZn_glyph_input_pointsr,   r   r&   r9   r   r   r   Úcheck_   s>    


zTestGlyph.checkc             C   s   | j ƒ  dS )zTest if the test fixture worksN)rJ   )r   r   r   r   Ú
test_glyphˆ   s    zTestGlyph.test_glyphZDarwinz#Test crashes on OSX. See issue #373c             C   s:   | j }|jd }|jd jd }d|j_| jddd� dS )zPTest if masking input points works with random mode.
           Tests Issue #165r   r   T)rG   rH   N)r5   r?   r&   Úmask_input_pointsrJ   )r   r   rI   r3   r   r   r   Ú'test_mask_input_points_with_random_modeŒ   s
    
z1TestGlyph.test_mask_input_points_with_random_modec             C   sB   | j }|jd }|jd jd }d|jj_d|j_| jdd� dS )zSTest if masking input points works without random mode.
           Tests Issue #165r   r   T)rG   N)r5   r?   r&   r+   Zrandom_moderL   rJ   )r   r   rI   r3   r   r   r   Ú*test_mask_input_points_without_random_mode–   s    

z4TestGlyph.test_mask_input_points_without_random_modec             C   s~   | j }| j}|jjƒ |_|j}|jƒ |_||_|j}|jƒ |_||_|jjƒ |_|jjƒ |_|j}|jƒ |_||_| jƒ  dS )zS"Test if the modules respond correctly when the components
            are changed.N)r3   r   r-   Ú	__class__r&   Zcutterr1   rJ   )r   r3   r   r&   Úipr   r   r   Útest_components_changed    s    


z!TestGlyph.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%   r5   r   r   ÚnameZsave_visualizationÚseekZclose_sceneZload_visualizationr4   rJ   )r   Úenginer5   Úfr   r   r   Útest_save_and_restoreµ   s    




zTestGlyph.test_save_and_restorec             C   sJ   | j }|j}g |_|jj|ƒ | jƒ  tj|ƒ}||jdd…< | jƒ  dS )z5Test if the MayaVi2 visualization can be deep-copied.N)r5   r?   ÚextendrJ   ÚcopyÚdeepcopy)r   r   ÚsourcesZsources1r   r   r   Útest_deepcopiedÉ   s    
zTestGlyph.test_deepcopiedN)FF)Ú__name__Ú
__module__Ú__qualname__r   r:   r<   rJ   rK   ÚunittestÚskipIfÚplatformÚsystemrM   rN   rQ   rV   r[   r   r   r   r   r	      s   4
)

r	   Ú__main__)Úos.pathr   Úior   ra   rX   r   r_   Úmayavi.core.null_enginer   Zmayavi.sources.array_sourcer   Zmayavi.modules.outliner   Zmayavi.modules.glyphr   Zmayavi.modules.vector_cut_planer   ÚTestCaser	   r\   Úmainr   r   r   r   Ú<module>   s    H