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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)Ú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 	e
 ¡ dkd¡dd„ ƒZdd„ Zdd„ Zdd„ Zdd„ ZdS )Ú	TestGlyphc                 C   sR   t  ddd¡}t  |d¡}t  |¡}t  dd¡}d|dd	d
…< t  |d¡}||fS )zkTrivial data -- creates an elementatry scalar field and a
        constant vector field along the 'x' axis.ç        g      $@g{®Gáz„?)é
   r   r   i¸  Údç      ð?é   Né   )r   r   r   r   )ÚnumpyZarangeZreshapeZ	transposeÚzeros)ÚselfÚsÚv© r   úZ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mayavi/tests/test_glyph.pyÚ	make_data   s    
zTestGlyph.make_datac                 C   s6  t ƒ }| ¡  | ¡ }|| _|| _tƒ }|  ¡ \}}d|_||_||_	| 
|¡ tƒ }| |¡ tƒ }| |¡ d|jj_d|jj_d|jj_d|jj_d|jj_tƒ }|j}	|	j}
d|
_|
jd |
_| |¡ |jjd	d
d� tƒ }|j}	|	j}
|
jd |
_d|
_| |¡ |jjd	dd� || _|| _|j| _d S )N)éûÿÿÿr   r   ÚcenterÚ
use_normalç      à?é   r   Útailr   )r   r   r   )r   r   r   )ÚnormalÚoriginé   Úhead)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_planeZ	trait_setÚgr   Úcurrent_sceneÚscene)r   r$   r   r   ZscZvecÚor1   r   r%   Úgsr   r   r   ÚsetUp&   sL    









zTestGlyph.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   ÚtearDownZ   s    
zTestGlyph.tearDownFc                 C   s|  | j }|jd }|jd jd }|  |jjjd¡ |  |jjjd¡ |  |jjjd¡ |  |jj	j
d¡ |jd jj}|jjjj}|rÀ|  |d¡ |r¤|  ||¡ qÌ|jjj}|  ||| ¡ n|  ||¡ |jd jd }	|	j}
|
j}|  |jd¡ |  |j|jd ¡ |  t |	jjd	¡d
¡ |jd jd }	|	j}
|
j}|  |j|jd ¡ |  |jd¡ |  t |	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   r   r   r    r   )r
   r   r
   Tr   r!   N)r3   ÚchildrenÚassertEqualr%   r&   r'   r(   r)   r,   r-   r.   ÚoutputsÚoutputZnumber_of_pointsÚinputZassertNotEqualZassertLessEqualr*   r+   r/   r   Zallcloser0   r   )r   ÚmaskÚmask_random_moder   Úsrcr1   Zn_output_pointsZn_glyph_input_pointsr+   r   r%   r5   r   r   r   Úcheck_   sL    

ÿÿÿÿÿzTestGlyph.checkc                 C   s   |   ¡  dS )zTest if the test fixture worksN)rB   r8   r   r   r   Ú
test_glyphˆ   s    zTestGlyph.test_glyphÚ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)r?   r@   N)r3   r:   r%   Úmask_input_pointsrB   ©r   r   rA   r1   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)r?   N)r3   r:   r%   r*   Zrandom_moderE   rB   rF   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}| ¡ |_||_|  ¡  dS )zS"Test if the modules respond correctly when the components
            are changed.N)r1   r   r,   Ú	__class__r%   Zcutterr0   rB   )r   r1   r   r%   Úipr   r   r   Útest_components_changed    s    


z!TestGlyph.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$   r3   r   r   ÚnameZsave_visualizationÚseekZclose_sceneZload_visualizationr2   rB   )r   Zenginer3   Úfr   r   r   Útest_save_and_restoreµ   s    




zTestGlyph.test_save_and_restorec                 C   sJ   | j }|j}g |_|j |¡ |  ¡  t |¡}||jdd…< |  ¡  dS )z5Test if the MayaVi2 visualization can be deep-copied.N)r3   r:   ÚextendrB   ÚcopyÚdeepcopy)r   r   ÚsourcesZsources1r   r   r   Útest_deepcopiedÉ   s    
zTestGlyph.test_deepcopiedN)FF)Ú__name__Ú
__module__Ú__qualname__r   r6   r9   rB   rC   ÚunittestZskipIfÚplatformÚsystemrG   rH   rK   rO   rT   r   r   r   r   r	      s   4
)
	
r	   Ú__main__)Úos.pathr   Úior   rY   rQ   r   rX   Zmayavi.core.null_enginer   Zmayavi.sources.array_sourcer   Zmayavi.modules.outliner   Zmayavi.modules.glyphr   Zmayavi.modules.vector_cut_planer   ZTestCaser	   rU   Úmainr   r   r   r   Ú<module>   s    H