
    ը	fb                        d 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Z	 dd	l 	 e 	 dd	l dd	l dd	l dd	l dd	l dd	l 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a+da,d Z-d Z.	  e/ e0e1      e2e1      Z3 e3e-      a4 e/ e0e1      e1      Z5 e5e.      a6 G d de7      Z8 G d de7      Z9 G d de9      Z:y# e
$ r"  ed      Z edez   ej                         Y w xY w# e$ r-Z ed
j'                  e      ej                         Y dZ[dZ[ww xY w# e$ r eZY w xY w# e
eef$ r.Z ed
j'                  e      ej                         Y dZ[dZ[ww xY w# e$ r Y w xY w)a_  
@package nviz.wxnviz

@brief wxGUI 3D view mode (ctypes-based classes)

This module implements 3D visualization mode for map display (ctypes
required).

List of classes:
 - wxnviz::Nviz
 - wxnviz::Texture
 - wxnviz::ImageTexture
 - wxnviz::TextTexture

(C) 2008-2011 by the GRASS Development Team

This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.

@author Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
@author Pythonized by Glynn Clements
@author Anna Kratochvilova <KratochAnna seznam.cz> (Google SoC 2011)
    )print_functionN)sqrt)matrixzThis module requires the NumPy module, which could not be imported. It probably is not installed (it's not part of the standard Python distribution). See the Numeric Python site (http://numpy.scipy.org) for information on downloading source or binaries.zwxnviz.py: )file)*zwxnviz.py: {})Debug)autoCropImageFromFile)DecodeString)wxPythonPhoenix)Rectc                     t         rHt        j                  j                  dk\  rt	        | j
                        } t         j                  |        yt        |        y)zRedirect stderr   r   )logsysversion_infomajorr
   datawriteprint)msgtypes     ,/usr/lib/grass83/gui/wxpython/nviz/wxnviz.pyprint_errorr   L   sE     !!Q&sxx(C		#  	c
    c                     t         rBt         j                         dk(  st         j                  d       t         j                  |        yt	        |        y)zRedirect progress infod   r   )progressGetRangeSetRangeSetValuer   )values    r   print_progressr"   Y   sE       "c)c"%   	er   c                      e Zd Zd Zd Zd ZdydZd Zd Zd Z	d Z
dyd	Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdzdZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d- Z/d. Z0d/ Z1d0 Z2d1 Z3d2 Z4d3 Z5d4 Z6d5 Z7	 	 	 	 	 d{d7Z8	 d|d8Z9d9 Z:d: Z;d; Z<d< Z=d}d=Z>d}d>Z?d? Z@d@ ZAdA ZBdB ZCdC ZDdD ZEdE ZFdF ZGdG ZHdH ZIdI ZJdJ ZKdK ZLdL ZMdM ZNdN ZOdO ZPdP ZQdQ ZRdR ZSdS ZTdT ZUdU ZVdV ZWdW ZXdX ZYdY ZZdZ Z[d[ Z\d\ Z]d] Z^d^ Z_d_ Z`d` Zada Zbdb Zcdc Zdd~ddZede Zfdf ZgddgZhdh Zidi Zjdj Zkdk Zldl Zmdm ZndydnZodydoZpddpZqdq Zrdr Zsds Ztdt Zudu Zvdv Zwdw Zxdx Zyy6)Nvizc                 x   |a |at        d       t        t               t        t               | j                          t               | _	        t        | j                        | _        t               | _        t        | j                        | _        dx| _        | _        d| _        t%        j&                  dd       y)zpInitialize Nviz class instance

        :param glog: logging area
        :param gprogress: progressbar
        wxnvizF   zNviz::Nviz()N)r   r   	G_gisinitG_set_error_routineerrfuncG_set_percent_routineperfuncInitnv_datadata_objpointerr   Colors	color_objcolorwidthheight	showLightr   r   )selfglog	gprogresss      r   __init__zNviz.__init__p   s     (G$g&			DMM*	T^^,
#%%
T[		!^$r   c                 B    t                t                | `| `d| _        y)zDestroy Nviz class instanceN)G_unset_error_routineG_unset_percent_routiner   r0   r   r8   s    r   __del__zNviz.__del__   s    !IMr   c                     t         j                  dk7  r$t        j                  t        j                  d       t                t                t                t                t                t                y)zInitialize windowwin32CN)r   platformlocale	setlocale
LC_NUMERICG_unset_windowRast_unset_windowRast__init_window
GS_libinitGVL_libinitGVL_init_regionr?   s    r   r.   z	Nviz.Init   sF    <<7"V..4r   c                     t        ||z        | _        t        ||z        | _        t        j                  dd| j                  | j                         t        | j                  | j                        S )zGL canvas resized

        :param width: window width
        :param height: window height

        :return: 1 on success
        :return: 0 on failure (window resized by default to 20x20 px)
        r   z(Nviz::ResizeWindow(): width=%d height=%d)intr5   r6   r   r   Nviz_resize_window)r8   r5   r6   scales       r   ResizeWindowzNviz.ResizeWindow   sY     '
&5.)		94::t{{	
 "$**dkk::r   c                 ,    t        | j                        S )z;Get longest dimension, used for initial size of north arrow)Nviz_get_longdimr   r?   s    r   
GetLongDimzNviz.GetLongDim       		**r   c                    t               }t        | j                  |       t               }t               }t               }t	        t        |      t        |      t        |             t        j                  dd|j                  |j                  |j                         ||j                  |j                  |j                  fS )zlSet default view (based on loaded data)

        :return: z-exag value, default, min and max height
        r(   z1Nviz::SetViewDefault(): hdef=%f, hmin=%f, hmax=%f)	Nviz_get_exagNviz_change_exagr   c_doubleNviz_get_exag_heightbyrefr   r   r!   )r8   z_exaghdefhminhmaxs        r   SetViewDefaultzNviz.SetViewDefault   s     F+ zzzU4[%+uT{C		?JJJJJJ	
 

DJJ

;;r   c           	          t        |       t        ||       t        |       t        |       t	        j
                  dd|||||       y)zChange view settings
        :param x,y: position
        :param height:
        :param persp: perpective
        :param twist:
        r   z:Nviz::SetView(): x=%f, y=%f, height=%f, persp=%f, twist=%fN)Nviz_set_viewpoint_heightNviz_set_viewpoint_positionNviz_set_viewpoint_twistNviz_set_viewpoint_perspr   r   )r8   xyr6   persptwists         r   SetViewzNviz.SetView   sG     	"&)#Aq) ' '		H	
r   c                     t               }t               }t               }t        t        |             t        t        |      t        |             |j                  |j                  |j                  fS N)rZ   Nviz_get_viewpoint_heightr\   Nviz_get_viewpoint_positionr!   )r8   rg   rh   hs       r   GetViewpointPositionzNviz.GetViewpointPosition   sN    JJJ!%(+#E!HeAh7!''**r   c                     t        t        ||z        t        ||z               t        j                  dd||z  ||z         y)zALook here feature
        :param x,y: screen coordinates
        r   zNviz::LookHere(): x=%f, y=%fN)Nviz_look_hererO   r   r   )r8   rg   rh   rQ   s       r   LookHerezNviz.LookHere   s9    
 	s1u9~s1u9~6		!3QYE	Jr   c                 P    t        t        d       t        j                  dd       y)z*Center view at center of displayed surfacer'   r   zNviz::LookAtCenter()N)Nviz_set_focus_mapMAP_OBJ_UNDEFINEDr   r   r?   s    r   LookAtCenterzNviz.LookAtCenter   s    ,b1		!+,r   c                 B   t        j                  dd       t        | j                        rtt	               }t	               }t	               }t        | j                  t        |      t        |      t        |             |j                  |j                  |j                  fS y)z	Get focusr   zNviz::GetFocus())r'   r'   r'   )r   r   Nviz_has_focusr   c_floatNviz_get_focusr\   r!   r8   rg   rh   zs       r   GetFocuszNviz.GetFocus   sl    		!'($))$	A	A	A499eAha%(C77AGGQWW,,r   c                 `    t        j                  dd       t        | j                  |||       y)z	Set focusr   zNviz::SetFocus()N)r   r   Nviz_set_focusr   r}   s       r   SetFocuszNviz.SetFocus  s#    		!'(tyy!Q*r   c                     t        j                  dd       t        dz         }t        t	        |             |d   |d   |d   fS )zGet viewdirr   zNviz::GetViewdir()r   r(      )r   r   r{   GS_get_viewdirr\   )r8   dirs     r   
GetViewdirzNviz.GetViewdir  sA    		!)*{ouSz"1vs1vs1v%%r   c                     t        j                  dd|||fz         t        dz         }t        |||f      D ]
  \  }}|||<    t	        t        |             y)zSet viewdirr   z$Nviz::SetViewdir(): x=%f, y=%f, z=%fN)r   r   r{   	enumerateGS_set_viewdirr\   )r8   rg   rh   r~   r   icoords          r   
SetViewdirzNviz.SetViewdir  sZ    		!;q!QiGH{o!1a), 	HAuCF	uSz"r   c                 \    t        j                  dd|       t        | j                  |      S )zKSet z-exag value

        :param z_exag: value

        :return: 1
        r   zNviz::SetZExag(): z_exag=%f)r   r   rY   r   )r8   r]   s     r   SetZExagzNviz.SetZExag  s&     			!2F;		622r   c                     t        j                  dd|       t        | j                  dd       |rt	        | j                  |       yt        | j                         y)zDraw canvas

        Draw quick mode:
         - DRAW_QUICK_SURFACE
         - DRAW_QUICK_VLINES
         - DRAW_QUICK_VPOINTS
         - DRAW_QUICK_VOLUME

        :param quick: if true draw in wiremode
        :param quick_mode: quick mode
        r   zNviz::Draw(): quick=%dr'   N)r   r   Nviz_draw_cplaner   Nviz_draw_quickNviz_draw_all)r8   quick
quick_modes      r   Drawz	Nviz.Draw"  sB     			!-u5B+DIIz2$))$r   c                 l    t        j                  dd       t        t        | j                               y)z)Erase map display (with background color)r(   zNviz::EraseMap()N)r   r   GS_clearNviz_get_bgcolorr   r?   s    r   EraseMapzNviz.EraseMap7  s#    		!'(!$)),-r   c                    t        | j                         t                t        | j                  t	        d             t        t        | j                               t        | j                         t        j                  dd       y)zInitialize viewwhiter(   zNviz::InitView()N)
Nviz_init_datar   Nviz_set_surface_attr_defaultNviz_set_bgcolorNviz_color_from_strr   r   Nviz_init_viewr   r   r?   s    r   InitViewzNviz.InitView<  sY     	tyy! 	&'$7$@A!$)),-tyy!		!'(r   c                 B    t        | j                  t        |             y)zISet background color

        :param str color_str: color string
        N)r   r   r   )r8   	color_strs     r   
SetBgColorzNviz.SetBgColorL  s    
 	$7	$BCr   c	           
         t        | j                  |||||       t        | j                  ||       t        | j                  |t	        |d         t	        |d         t	        |d                t        | j                  ||       y)a  Change lighting settings

        :param x,y,z: position
        :param color: light color (as string)
        :param bright: light brightness
        :param ambient: light ambient
        :param w: local coordinate (default to 0)
        :param lid: light id
        r   r(   r   N)Nviz_set_light_positionr   Nviz_set_light_brightNviz_set_light_colorrO   Nviz_set_light_ambient)	r8   rg   rh   r~   r4   brightambientwlids	            r   SetLightzNviz.SetLightS  sk     	 		31a;diif5IIsCaM3uQx=#eAh-	
 	tyy#w7r   c           
      x   t        |d      }|t        t        d      |       yt        t        t        ||      d| j                        }|rat        |d      }|!t        t        d      |       t        |       yt        |t        t        t        t        ||      d| j                         nd|r1t        |t        t        t        dt        |      | j                         n1t        |t        t        t        t        ||      d| j                         t        t        d       t        j                   dd||       |S )	a  Load raster map (surface)

        :param name: raster map name
        :param color_name: raster map for color (None for color_value)
        :param color_value: color string (named color or RGB triptet)

        :return: object id
        :return: -1 on failure
         NzRaster map <%s> not foundr'                 r(   z$Nviz::LoadRaster(): name=%s -> id=%d)G_find_raster2	G_warning_Nviz_new_map_objMAP_OBJ_SURFG_fully_qualified_namer   GS_delete_surfaceNviz_set_attr	ATT_COLORMAP_ATT	CONST_ATTr   rv   rw   r   r   r8   name
color_namecolor_valuemapsetids         r   LoadSurfacezNviz.LoadSurfaced  s     b)>a34d; 0v>TYY
 #J3F~!78*E!"%&z6:		 #K0		 &tV4		 	,b1		!;T2F	r   c           
          t        t        d|| j                        }t        |t        t        t
        dt        |      | j                         t        t        d       t        j                  dd|       |S )zAdd new constant surfaceNr'   r(   zNviz::AddConstant(): id=%d)r   r   r   r   r   r   r   rv   rw   r   r   )r8   r!   r4   r   s       r   AddConstantzNviz.AddConstant  s_    lD%C&II	
 	,b1		!126	r   c                 h    t        |      syt        j                  dd|       t        |      dk  ryy)zsUnload surface

        :param id: surface id

        :return: 1 on success
        :return: 0 on failure
        r   r(   zNviz::UnloadSurface(): id=%d)GS_surf_existsr   r   r   r8   r   s     r   UnloadSurfacezNviz.UnloadSurface  s3     b!		!3R8R 1$r   c                    d}t               dk(  rNt        t        dd| j                        }t	               }t        t        |            }t        |d   t        d       t        |d      }|t        t        d      |       |r't        t        t        ||      d| j                        }n&t        t        t        ||      d| j                        }t        j                   dd	||       ||fS )
zLoad vector map overlay

        :param name: vector map name
        :param points: if true load 2d points rather then 2d lines

        :return: object id, id of base surface (or -1 if it is not loaded)
        :return: -1 on failure
        r'   r   Nr      r   zVector map <%s> not foundr(   z$Nviz::LoadVector(): name=%s -> id=%d)GS_num_surfsr   r   r   c_intGS_get_surf_listr\   GS_set_att_const
ATT_TRANSPG_find_vector2r   r   MAP_OBJ_SITEr   MAP_OBJ_VECTr   r   )r8   r   pointsbaseIdnsurf	surf_listr   r   s           r   
LoadVectorzNviz.LoadVector  s     >Q%lD#tyyIFGE(u6IYq\:s;b)>a34d;!4T6BCB "4T6BCB 			!;T2F6zr   c                     t        j                  dd|       |rt        |      syt        |      dk  ryyt	        |      syt        |      dk  ryy)zUnload vector set

        :param id: vector set id
        :param points: vector points or lines set

        :return: 1 on success
        :return: 0 on failure
        r(   zNviz::UnloadVector(): id=%dr   )r   r   GP_site_existsGP_delete_siteGV_vect_existsGV_delete_vector)r8   r   r   s      r   UnloadVectorzNviz.UnloadVector  sX     			!2B7!"%b!A%  ""%#a'r   c                 P    t        ||      }t        j                  dd|||       |S )zCheck if surface is selected (currently unused)

        :param vid: vector id
        :param sid: surface id

        :return: True if selected
        :return: False if not selected
        r(   z<Nviz::VectorSurfaceSelected(): vid=%s, sid=%d -> selected=%d)GV_surf_is_selectedr   r   )r8   vidsidselecteds       r   VectorSurfaceSelectedzNviz.VectorSurfaceSelected  s2     'sC0		J	
 r   c           
      X   t        |d      }|t        t        d      |       yt        t        t        ||      d| j                        }|rat        |d      }|!t        t        d      |       t        |       yt        |t        t        t        t        ||      d| j                         nd|r1t        |t        t        t        dt        |      | j                         n1t        |t        t        t        t        ||      d| j                         t        j                  dd||       |S )	a  Load 3d raster map (volume)

        :param name: 3d raster map name
        :param color_name: 3d raster map for color (None for color_value)
        :param color_value: color string (named color or RGB triptet)

        :return: object id
        :return: -1 on failure
        r   Nz3d raster map <%s> not foundr'   r   r   r(   z$Nviz::LoadVolume(): name=%s -> id=%d)G_find_raster3dr   r   r   MAP_OBJ_VOLr   r   GVL_delete_volr   r   r   r   r   r   r   r   s         r   
LoadVolumezNviz.LoadVolume  s    !r*>a67> /f=sDII
 $Z4F~!:;ZHr"&z6:		 #K0		 &tV4		 			!;T2F	r   c                 h    t        |      syt        j                  dd|       t        |      dk  ryy)zqUnload volume

        :param id: volume id

        :return: 1 on success
        :return: 0 on failure
        r   r(   zNviz::UnloadVolume(): id=%d)GVL_vol_existsr   r   r   r   s     r   UnloadVolumezNviz.UnloadVolumeW  s3     b!		!2B7"!r   c                 2    | j                  |t        ||      S )a  Set surface topography

        :param id: surface id
        :param map: if true use map otherwise constant
        :param value: map name of value

        :return: 1 on success
        :return: -1 surface not found
        :return: -2 setting attributes failed
        )SetSurfaceAttrATT_TOPOr8   r   mapr!   s       r   SetSurfaceTopozNviz.SetSurfaceTopoi       ""2xe<<r   c                 2    | j                  |t        ||      S )a  Set surface color

        :param id: surface id
        :param map: if true use map otherwise constant
        :param value: map name or value

        :return: 1 on success
        :return: -1 surface not found
        :return: -2 setting attributes failed
        )r   r   r   s       r   SetSurfaceColorzNviz.SetSurfaceColorv       ""2y#u==r   c                 2    | j                  |t        d|      S )a$  Set surface mask

        .. todo::
            invert

        :param id: surface id
        :param invert: if true invert mask
        :param value: map name of value

        :return: 1 on success
        :return: -1 surface not found
        :return: -2 setting attributes failed
        T)r   ATT_MASK)r8   r   invertr!   s       r   SetSurfaceMaskzNviz.SetSurfaceMask  s     ""2xu==r   c                 2    | j                  |t        ||      S )a/  Set surface mask

        ..todo::
            invert

        :param id: surface id
        :param map: if true use map otherwise constant
        :param value: map name of value

        :return: 1 on success
        :return: -1 surface not found
        :return: -2 setting attributes failed
        )r   r   r   s       r   SetSurfaceTranspzNviz.SetSurfaceTransp  s     ""2z3>>r   c                 2    | j                  |t        ||      S )a  Set surface shininess

        :param id: surface id
        :param map: if true use map otherwise constant
        :param value: map name of value

        :return: 1 on success
        :return: -1 surface not found
        :return: -2 setting attributes failed
        )r   	ATT_SHINEr   s       r   SetSurfaceShinezNviz.SetSurfaceShine  r   r   c                 2    | j                  |t        ||      S )a!  Set surface emission (currently unused)

        :param id: surface id
        :param map: if true use map otherwise constant
        :param value: map name of value

        :return: 1 on success
        :return: -1 surface not found
        :return: -2 setting attributes failed
        )r   ATT_EMITr   s       r   SetSurfaceEmitzNviz.SetSurfaceEmit  r   r   c           	      .   t        |      sy|r$t        |t        |t        |d| j                        }nC|t
        k(  rt        |      }nt        |      }t        |t        |t        d|| j                        }t        j                  dd||||       |dk  ryy)	a3  Set surface attribute

        :param id: surface id
        :param attr: attribute desc
        :param map: if true use map otherwise constant
        :param value: map name of value

        :return: 1 on success
        :return: -1 surface not found
        :return: -2 setting attributes failed
        r'   r   Nr   z8Nviz::SetSurfaceAttr(): id=%d, attr=%d, map=%d, value=%sr   r(   )r   r   r   r   r   r   r   floatr   r   r   )r8   r   attrr   r!   retvals          r   r   zNviz.SetSurfaceAttr  s     b!L$diiXCy )%0ElL$	4diiXC		F	
 7r   c                 .    | j                  |t              S )zUnset surface mask

        :param id: surface id

        :return: 1 on success
        :return: -1 surface not found
        :return: -2 setting attributes failed
        :return: -1 on failure
        )UnsetSurfaceAttrr   r   s     r   UnsetSurfaceMaskzNviz.UnsetSurfaceMask  s     $$R22r   c                 .    | j                  |t              S )zUnset surface transparency

        :param id: surface id

        :return: 1 on success
        :return: -1 surface not found
        :return: -2 setting attributes failed
        )r  r   r   s     r   UnsetSurfaceTranspzNviz.UnsetSurfaceTransp  s     $$R44r   c                 .    | j                  |t              S )zUnset surface emission (currently unused)

        :param id: surface id

        :return: 1 on success
        :return: -1 surface not found
        :return: -2 setting attributes failed
        )r  r  r   s     r   UnsetSurfaceEmitzNviz.UnsetSurfaceEmit  s     $$R22r   c                 z    t        |      syt        j                  dd||       t        |t        |      }|dk  ryy)zUnset surface attribute

        :param id: surface id
        :param attr: attribute descriptor

        :return: 1 on success
        :return: -1 surface not found
        :return: -2 setting attributes failed
        r'   r   z(Nviz::UnsetSurfaceAttr(): id=%d, attr=%dr   r  r(   )r   r   r   Nviz_unset_attrr   )r8   r   r  r	  s       r   r  zNviz.UnsetSurfaceAttr  s=     b!		!?TJb,57r   c                     t        j                  dd|||       |dkD  r t        |      syt        |||||      dk  ryyt	        ||||       y)a  Set surface resolution

        :param id: surface id
        :param fine: x/y fine resolution
        :param coarse: x/y coarse resolution

        :return: 1 on success
        :return: -1 surface not found
        :return: -2 setting attributes failed
        r   z0Nviz::SetSurfaceRes(): id=%d, fine=%d, coarse=%dr   r'   r  r(   )r   r   r   GS_set_drawresGS_setall_drawres)r8   r   finecoarses       r   SetSurfaceReszNviz.SetSurfaceRes  s`     			A2tV	
 6!"%b$ff=A  dD&&9r   c                     t        j                  dd||       |dkD  rt        |      syt        ||      dk  ryyt	        |      dk  ryy)a  Set draw style

        Draw styles:
         - DM_GOURAUD
         - DM_FLAT
         - DM_FRINGE
         - DM_WIRE
         - DM_COL_WIRE
         - DM_POLY
         - DM_WIRE_POLY
         - DM_GRID_WIRE
         - DM_GRID_SURF

        :param id: surface id (<= 0 for all)
        :param style: draw style

        :return: 1 on success
        :return: -1 surface not found
        :return: -2 setting attributes failed
        r   z(Nviz::SetSurfaceStyle(): id=%d, style=%dr   r'   r  r(   )r   r   r   GS_set_drawmodeGS_setall_drawmode)r8   r   styles      r   SetSurfaceStylezNviz.SetSurfaceStyle6  sQ    * 			!?UK6!"%r5)A-e$q(r   c                 2   t        j                  dd||       t        |      }|dkD  rt        |      syt	        ||       yt               }t        t        |            }t        |j                        D ]  }||   }t	        ||        t        |       d}y)aH  Set color of wire

        .. todo::
            all

        :param id: surface id (< 0 for all)
        :param color_str: color string (R:G:B)

        :return: 1 on success
        :return: -1 surface not found
        :return: -2 setting attributes failed
        :return: 1 on success
        :return: 0 on failure
        r   z%Nviz::SetWireColor(): id=%d, color=%sr   r'   Nr(   )r   r   r   r   GS_set_wire_colorr   r   r\   ranger!   G_free)r8   r   r   r4   nsurfsr   r   s          r   SetWireColorzNviz.SetWireColor[  s     			!<b)L#I.6!"%b%(  WF(v7I6<<( -q\!"e,- 9Ir   c                 `   t        |      sg S t               t               t               }}}t        |t        |      t        |      t        |             t	        j
                  dd||j                  |j                  |j                         |j                  |j                  |j                  gS )zGet surface position

        :param id: surface id

        :return: x,y,z
        :return: zero-length vector on error
        r   z3Nviz::GetSurfacePosition(): id=%d, x=%f, y=%f, z=%f)r   r{   GS_get_transr\   r   r   r!   r8   r   rg   rh   r~   s        r   GetSurfacePositionzNviz.GetSurfacePosition  s     b!I)WY	a1Rq58U1X6		AGGGGGG	
 !''**r   c                 l    t        |      syt        j                  dd||||       t        ||||       y)zSet surface position

        :param id: surface id
        :param x,y,z: translation values

        :return: 1 on success
        :return: -1 surface not found
        :return: -2 setting position failed
        r'   r   z3Nviz::SetSurfacePosition(): id=%d, x=%f, y=%f, z=%fr(   )r   r   r   GS_set_transr'  s        r   SetSurfacePositionzNviz.SetSurfacePosition  s:     b!		!JBPQSTVWXRAq!r   c                     t        |      syt        j                  dd||||       t        |      }t	        |d|||      dk  ryy)a$  Set mode of vector line overlay

        :param id: vector id
        :param color_str: color string
        :param width: line width
        :param use_z: display 3d or on surface

        :return: -1 vector set not found
        :return: -2 on failure
        :return: 1 on success
        r'   r   z:Nviz::SetVectorMode(): id=%d, color=%s, width=%d, use_z=%dr(   r   r  )r   r   r   r   GV_set_style)r8   r   r   r5   use_zr4   s         r   SetVectorLineModezNviz.SetVectorLineMode  sV     b!		H	
 $I. AueU3a7r   c                 h    t        |      syt        j                  dd||       t        |dd|       y)zSet vector height above surface (lines)

        :param id: vector set id
        :param height:

        :return: -1 vector set not found
        :return: 1 on success
        r'   r   z-Nviz::SetVectorLineHeight(): id=%d, height=%fr   r(   )r   r   r   GV_set_transr8   r   r6   s      r   SetVectorLineHeightzNviz.SetVectorLineHeight  s3     b!		!Db&QRc6*r   c                 T    t        |      syt        |      syt        ||      dk  ryy)a  Set reference surface of vector set (lines)

        :param id: vector set id
        :param surf_id: surface id

        :return: 1 on success
        :return: -1 vector set not found
        :return: -2 surface not found
        :return: -3 on failure
        r'   r  r   r(   )r   r   GV_select_surfr8   r   surf_ids      r   SetVectorLineSurfacezNviz.SetVectorLineSurface  /     b!g&"g&*r   c                 T    t        |      syt        |      syt        ||      dk  ryy)a  Unset reference surface of vector set (lines)

        :param id: vector set id
        :param surf_id: surface id

        :return: 1 on success
        :return: -1 vector set not found
        :return: -2 surface not found
        :return: -3 on failure
        r'   r  r   r5  r(   )r   r   GV_unselect_surfr7  s      r   UnsetVectorLineSurfacezNviz.UnsetVectorLineSurface  /     b!g&B(1,r   c           	          t        |      sy|dkD  r|dz  }t        j                  dd|||||       t        |      }t	        |||||      dk  ryy)	a  Set mode of vector point overlay

        :param id: vector id
        :param color_str: color string
        :param width: line width
        :param size: size of the symbol
        :param marker: type of the symbol

        :return: -1 vector set not found
        r'      r   r   zINviz::SetVectorPointMode(): id=%d, color=%s, width=%d, size=%f, marker=%dr   r  r(   )r   r   r   r   GP_set_style)r8   r   r   r5   sizemarkerr4   s          r   SetVectorPointModezNviz.SetVectorPointMode	  sk     b! A:aKF		+		
 $I.E5$7!;r   c                 h    t        |      syt        j                  dd||       t        |dd|       y)zSet vector height above surface (points)

        :param id: vector set id
        :param height:

        :return: -1 vector set not found
        :return: 1 on success
        r'   r   z.Nviz::SetVectorPointHeight(): id=%d, height=%fr   r(   )r   r   r   GP_set_transr2  s      r   SetVectorPointHeightzNviz.SetVectorPointHeight-  s3     b!		!Er6RRc6*r   c                 T    t        |      syt        |      syt        ||      dk  ryy)a  Set reference surface of vector set (points)

        :param id: vector set id
        :param surf_id: surface id

        :return: 1 on success
        :return: -1 vector set not found
        :return: -2 surface not found
        :return: -3 on failure
        r'   r  r   r5  r(   )r   r   GP_select_surfr7  s      r   SetVectorPointSurfacezNviz.SetVectorPointSurface?  r:  r   c                 0    t        ||| j                        S )a  Read vector colors

        :param name: vector map name
        :param mapset: mapset name (empty string (\c "") for search path)

        :return: -1 on error
        :return: 0 if color table missing
        :return: 1 on success (color table found)
        )Vect_read_colorsr4   )r8   r   r   s      r   ReadVectorColorszNviz.ReadVectorColorsU  s      fdjj99r   c                     t               }|dk(  rt        |t        |            }n|dk(  rt        |t        |            }dk  ry| j	                  |d      S )a  Check if color table exists.

        :param id: vector set id
        :param type: vector set type (lines/points)

        :return: 1 color table exists
        :return: 0 no color table found
        :return: -1 on error
        :return: -2 vector set not found
        r   linesr   r  r   )c_char_pGP_get_sitenamer\   GV_get_vectnamerM  )r8   r   r   r   r	  s        r   CheckColorTablezNviz.CheckColorTablea  sW     z8!"eDk2CW_!"eDk2C7$$T2..r   Nc           	          t               }t        |t        |            }	|	dk  ry| j                  |d      }	|	dk  ry|rt	        ||||||| j
                         yt	        ||||||d       y)aR  Set thematic style for vector points

        :param id: vector set id
        :param layer: layer number for thematic mapping
        :param colorTable: use color table
        :param color: color column name
        :param width: width column name
        :param size: size column name
        :param symbol: symbol column name
        r   r'   r   N)rP  rQ  r\   rM  GP_set_style_thematicr4   )
r8   r   layerr4   
colorTabler5   rB  symbolr   r	  s
             r   SetPointsStyleThematiczNviz.SetPointsStyleThematicx  sp    ( zb%+.7##D"-7!"eUE4T!"eUE4Nr   c                     t               }t        |t        |            }|dk  ry| j                  |d      }|dk  ry|rt	        ||||| j
                         yt	        ||||d       y)a  Set thematic style for vector lines

        :param id: vector set id
        :param layer: layer number for thematic mapping
        :param color: color column name
        :param colorTable: use color table
        :param width: width column name
        r   r'   r   N)rP  rR  r\   rM  GV_set_style_thematicr4   )r8   r   rV  r4   rW  r5   r   r	  s           r   SetLinesStyleThematiczNviz.SetLinesStyleThematic  sh     zb%+.7##D"-7!"eUE4::F!"eUE4@r   c                     t        |       y)z&Unset thematic style for vector pointsN)GV_unset_style_thematicr   s     r   UnsetLinesStyleThematiczNviz.UnsetLinesStyleThematic  
    #r   c                     t        |       y)z%Unset thematic style for vector linesN)GP_unset_style_thematicr   s     r   UnsetPointsStyleThematiczNviz.UnsetPointsStyleThematic  r`  r   c                 T    t        |      syt        |      syt        ||      dk  ryy)a	  Unset reference surface of vector set (points)

        :param id: vector set id
        :param surf_id: surface id

        :return: 1 on success
        :return: -1 vector set not found
        :return: -2 surface not found
        :return: -3 on failure
        r'   r  r   r5  r(   )r   r   GP_unselect_surfr7  s      r   UnsetVectorPointSurfacezNviz.UnsetVectorPointSurface  r>  r   c                 D    t        |      syt        |t        |            S )zSet z mode (use z coordinate or not)

        :param id: volume id
        :param zMode: bool

        :return: -1 on failure
        :return: 0 when no 3d
        :return: 1 on success
        r'   )r   GP_set_zmoderO   )r8   r   zModes      r   SetVectorPointZModezNviz.SetVectorPointZMode  s      b!BE
++r   c                     t        |      sy|t        |      }|dk  s||k7  ryt        |      dk  ryt        |      }t        ||dz
  t        |      S )zAdd new isosurface

        :param id: volume id
        :param level: isosurface level (topography)
        :param isosurf_id: isosurface id

        :return: -1 on failure
        :return: 1 on success
        r'   r   r(   )r   GVL_isosurf_num_isosurfsGVL_isosurf_addGVL_isosurf_set_att_constr   )r8   r   level
isosurf_idnum	nisosurfss         r   AddIsosurfacezNviz.AddIsosurface  sa     b!!*2.CQw*+2" -R0	(Y]HeLLr   c                 ~    t        |      sy|t        |      }|dk  s||k7  ryt        |      dk  ryt        |      S )zAdd new slice

        :param id: volume id
        :param slice_id: slice id

        :return: -1 on failure
        :return: number of slices
        r'   r   )r   GVL_slice_num_slicesGVL_slice_add)r8   r   slice_idrq  s       r   AddSlicezNviz.AddSlice  sJ     b!&r*CQw(c/q #B''r   c                 ^    t        |      sy|t        |      kD  ryt        ||      }|dk  ryy)zDelete isosurface

        :param id: volume id
        :param isosurf_id: isosurface id

        :return: 1 on success
        :return: -1 volume not found
        :return: -2 isosurface not found
        :return: -3 on failure
        r'   r  r   r5  r(   )r   rl  GVL_isosurf_del)r8   r   rp  r	  s       r   DeleteIsosurfacezNviz.DeleteIsosurface  s9     b!044b*-7r   c                 ^    t        |      sy|t        |      kD  ryt        ||      }|dk  ryy)zDelete slice

        :param id: volume id
        :param slice_id: slice id

        :return: 1 on success
        :return: -1 volume not found
        :return: -2 slice not found
        :return: -3 on failure
        r'   r  r   r5  r(   )r   ru  GVL_slice_del)r8   r   rw  r	  s       r   DeleteSlicezNviz.DeleteSlice(  s9     b!*2..B)7r   c                 |    t        |      sy|t        |      kD  ry|rt        ||      }nt        ||      }|dk  ryy)a1  Move isosurface up/down in the list

        :param id: volume id
        :param isosurf_id: isosurface id
        :param up: if true move up otherwise down

        :return: 1 on success
        :return: -1 volume not found
        :return: -2 isosurface not found
        :return: -3 on failure
        r'   r  r   r5  r(   )r   rl  GVL_isosurf_move_upGVL_isosurf_move_down)r8   r   rp  upr	  s        r   MoveIsosurfacezNviz.MoveIsosurface@  sH     b!044%b*5C'J7C7r   c                 |    t        |      sy|t        |      kD  ry|rt        ||      }nt        ||      }|dk  ryy)a   Move slice up/down in the list

        :param id: volume id
        :param slice_id: slice id
        :param up: if true move up otherwise down

        :return: 1 on success
        :return: -1 volume not found
        :return: -2 slice not found
        :return: -3 on failure
        r'   r  r   r5  r(   )r   ru  GVL_slice_move_upGVL_slice_move_down)r8   r   rw  r  r	  s        r   	MoveSlicezNviz.MoveSlice\  sH     b!*2..#B1C%b(3C7r   c                 4    | j                  ||t        ||      S )ab  Set isosurface level

        :param id: volume id
        :param isosurf_id: isosurface id (0 - MAX_ISOSURFS)
        :param map: if true use map otherwise constant
        :param value: map name of value

        :return: 1 on success
        :return: -1 volume not found
        :return: -2 isosurface not found
        :return: -3 on failure
        )SetIsosurfaceAttrr   r8   r   rp  r   r!   s        r   SetIsosurfaceTopozNviz.SetIsosurfaceTopox       %%b*hUKKr   c                 4    | j                  ||t        ||      S )ab  Set isosurface color

        :param id: volume id
        :param isosurf_id: isosurface id (0 - MAX_ISOSURFS)
        :param map: if true use map otherwise constant
        :param value: map name of value

        :return: 1 on success
        :return: -1 volume not found
        :return: -2 isosurface not found
        :return: -3 on failure
        )r  r   r  s        r   SetIsosurfaceColorzNviz.SetIsosurfaceColor       %%b*ieLLr   c                 4    | j                  ||t        d|      S )a  Set isosurface mask

        .. todo::
            invert

        :param id: volume id
        :param isosurf_id: isosurface id (0 - MAX_ISOSURFS)
        :param invert: true for invert mask
        :param value: map name to be used for mask

        :return: 1 on success
        :return: -1 volume not found
        :return: -2 isosurface not found
        :return: -3 on failure
        T)r  r   )r8   r   rp  r   r!   s        r   SetIsosurfaceMaskzNviz.SetIsosurfaceMask  s      %%b*heLLr   c                 4    | j                  ||t        ||      S )ai  Set isosurface transparency

        :param id: volume id
        :param isosurf_id: isosurface id (0 - MAX_ISOSURFS)
        :param map: if true use map otherwise constant
        :param value: map name of value

        :return: 1 on success
        :return: -1 volume not found
        :return: -2 isosurface not found
        :return: -3 on failure
        )r  r   r  s        r   SetIsosurfaceTranspzNviz.SetIsosurfaceTransp  s     %%b*j#uMMr   c                 4    | j                  ||t        ||      S )af  Set isosurface shininess

        :param id: volume id
        :param isosurf_id: isosurface id (0 - MAX_ISOSURFS)
        :param map: if true use map otherwise constant
        :param value: map name of value

        :return: 1 on success
        :return: -1 volume not found
        :return: -2 isosurface not found
        :return: -3 on failure
        )r  r   r  s        r   SetIsosurfaceShinezNviz.SetIsosurfaceShine  r  r   c                 4    | j                  ||t        ||      S )ax  Set isosurface emission (currently unused)

        :param id: volume id
        :param isosurf_id: isosurface id (0 - MAX_ISOSURFS)
        :param map: if true use map otherwise constant
        :param value: map name of value

        :return: 1 on success
        :return: -1 volume not found
        :return: -2 isosurface not found
        :return: -3 on failure
        )r  r  r  s        r   SetIsosurfaceEmitzNviz.SetIsosurfaceEmit  r  r   c           	          t        |      sy|t        |      dz
  kD  ry|rt        ||||      }n.|t        k(  rt	        |      }nt        |      }t        ||||      }t        j                  dd|||||       |dk  ryy)a  Set isosurface attribute

        :param id: volume id
        :param isosurf_id: isosurface id (0 - MAX_ISOSURFS)
        :param attr: attribute desc
        :param map: if true use map otherwise constant
        :param value: map name of value

        :return: 1 on success
        :return: -1 volume not found
        :return: -2 isosurface not found
        :return: -3 setting attributes failed
        r'   r(   r  r   zGNviz::SetIsosurfaceAttr(): id=%d, isosurf=%d, attr=%d, map=%s, value=%sr   )	r   rl  GVL_isosurf_set_att_mapr   r   r  rn  r   r   )r8   r   rp  r  r   r!   r	  r
  s           r   r  zNviz.SetIsosurfaceAttr  s     b!04q88)"j$FCy )%0El+B
D#FC		(		
 7r   c                 0    | j                  ||t              S )a  Unset isosurface mask

        :param id: volume id
        :param isosurf_id: isosurface id (0 - MAX_ISOSURFS)

        :return: 1 on success
        :return: -1 volume not found
        :return: -2 isosurface not found
        :return: -3 setting attributes failed
        )UnsetIsosurfaceAttrr   r8   r   rp  s      r   UnsetIsosurfaceMaskzNviz.UnsetIsosurfaceMask       ''JAAr   c                 0    | j                  ||t              S )a  Unset isosurface transparency

        :param id: volume id
        :param isosurf_id: isosurface id (0 - MAX_ISOSURFS)

        :return: 1 on success
        :return: -1 volume not found
        :return: -2 isosurface not found
        :return: -3 setting attributes failed
        )r  r   r  s      r   UnsetIsosurfaceTranspzNviz.UnsetIsosurfaceTransp  s     ''J
CCr   c                 0    | j                  ||t              S )a*  Unset isosurface emission (currently unused)

        :param id: volume id
        :param isosurf_id: isosurface id (0 - MAX_ISOSURFS)

        :return: 1 on success
        :return: -1 volume not found
        :return: -2 isosurface not found
        :return: -3 setting attributes failed
        )r  r  r  s      r   UnsetIsosurfaceEmitzNviz.UnsetIsosurfaceEmit  r  r   c                     t        |      sy|t        |      dz
  kD  ryt        j                  dd|||       t	        |||      }|dk  ryy)a1  Unset surface attribute

        :param id: surface id
        :param isosurf_id: isosurface id (0 - MAX_ISOSURFS)
        :param attr: attribute descriptor

        :return: 1 on success
        :return: -1 volume not found
        :return: -2 isosurface not found
        :return: -2 on failure
        r'   r(   r  r   z7Nviz::UnsetSurfaceAttr(): id=%d, isosurf_id=%d, attr=%dr   )r   rl  r   r   GVL_isosurf_unset_att)r8   r   rp  r  r	  s        r   r  zNviz.UnsetIsosurfaceAttr*  s]     b!04q88		E	
 $B
D97r   c                 @    t        |      syt        ||      }|dk  ryy)zSet draw mode for isosurfaces

        :param id: isosurface id
        :param mode: isosurface draw mode

        :return: 1 on success
        :return: -1 volume set not found
        :return: -2 on failure
        r'   r   r  r(   )r   GVL_isosurf_set_drawmoder8   r   moder	  s       r   SetIsosurfaceModezNviz.SetIsosurfaceModeK  s(     b!&r407r   c                 @    t        |      syt        ||      }|dk  ryy)zSet draw mode for slices

        :param id: slice id
        :param mode: slice draw mode

        :return: 1 on success
        :return: -1 volume set not found
        :return: -2 on failure
        r'   r   r  r(   )r   GVL_slice_set_drawmoder  s       r   SetSliceModezNviz.SetSliceMode_  s(     b!$R.7r   c                 D    t        |      syt        ||||      }|dk  ryy)zSet draw resolution for isosurfaces

        :param id: isosurface id
        :param res: resolution value

        :return: 1 on success
        :return: -1 volume set not found
        :return: -2 on failure
        r'   r   r  r(   )r   GVL_isosurf_set_drawresr8   r   resr	  s       r   SetIsosurfaceReszNviz.SetIsosurfaceRess  s,     b!%b#sC87r   c                 D    t        |      syt        ||||      }|dk  ryy)zSet draw resolution for slices

        :param id: slice id
        :param res: resolution value

        :return: 1 on success
        :return: -1 volume set not found
        :return: -2 on failure
        r'   r   r  r(   )r   GVL_slice_set_drawresr  s       r   SetSliceReszNviz.SetSliceRes  s,     b!#BS#67r   c
                 l    t        |      sy|t        |      kD  ryt        |||||||||		      }
|
dk  ryy)a/  Set slice position

        :param id: volume id
        :param slice_id: slice id
        :param x1,x2,y1,y2,z1,z2: slice coordinates
        :param dir: axis

        :return: 1 on success
        :return: -1 volume not found
        :return: -2 slice not found
        :return: -3 on failure
        r'   r  r   r(   )r   ru  GVL_slice_set_pos)r8   r   rw  x1x2y1y2z1z2r   r	  s              r   SetSlicePositionzNviz.SetSlicePosition  sG     b!*2..Hb"b"b"cJ7r   c                 `    t        |      sy|t        |      kD  ryt        |||      }|dk  ryy)a  Set slice transparency

        :param id: volume id
        :param slice_id: slice id
        :param value: transparency value (0 - 255)

        :return: 1 on success
        :return: -1 volume not found
        :return: -2 slice not found
        :return: -3 on failure
        r'   r  r   r(   )r   ru  GVL_slice_set_transp)r8   r   rw  r!   r	  s        r   SetSliceTranspzNviz.SetSliceTransp  s;     b!*2.."2x77r   c                 f    t        |      sy|t        |      dz
  kD  ryt        |||      }|dk  ryy)a  Set inout mode

        :param id: volume id
        :param isosurf_id: isosurface id
        :param inout: mode true/false

        :return: 1 on success
        :return: -1 volume set not found
        :return: -2 isosurface not found
        :return: -3 on failure
        r'   r(   r  r   r5  )r   rl  GVL_isosurf_set_flags)r8   r   rp  inoutr	  s        r   SetIsosurfaceInOutzNviz.SetIsosurfaceInOut  s@     b!04q88#B
E:7r   c                 `   t        |      sg S t               t               t               }}}t        |t        |      t        |      t        |             t	        j
                  dd||j                  |j                  |j                         |j                  |j                  |j                  gS )zGet volume position

        :param id: volume id

        :return: x,y,z
        :return: zero-length vector on error
        r   z2Nviz::GetVolumePosition(): id=%d, x=%f, y=%f, z=%f)r   r{   GVL_get_transr\   r   r   r!   r'  s        r   GetVolumePositionzNviz.GetVolumePosition  s     b!I)WY	a1b%(E!HeAh7		@GGGGGG	
 !''**r   c                 l    t        |      syt        j                  dd||||       t        ||||       y)zSet volume position

        :param id: volume id
        :param x,y,z: translation values

        :return: 1 on success
        :return: -1 volume not found
        :return: -2 setting position failed
        r'   r   z2Nviz::SetVolumePosition(): id=%d, x=%f, y=%f, z=%fr(   )r   r   r   GVL_set_transr'  s        r   SetVolumePositionzNviz.SetVolumePosition  s9     b!		!I2qRSUVWb!Q"r   c                 v    t        |      syt        j                  dd||       t        |t	        |             y)zDisplay volume wire box

        :param id: volume id
        :param ifBox: True to draw wire box, False otherwise
        :type ifBox: bool
        :return: 1 on success
        :return: -1 volume not found
        r'   r   z)Nviz::SetVolumeDrawBox(): id=%d, ifBox=%dr(   )r   r   r   GVL_set_draw_wirerO   )r8   r   ifBoxs      r   SetVolumeDrawBoxzNviz.SetVolumeDrawBox  s3     b!		!@"eL"c%j)r   c                 ,    t        | j                        S rm   )Nviz_get_current_cplaner   r?   s    r   GetCPlaneCurrentzNviz.GetCPlaneCurrent&  s    &tyy11r   c                 ,    t        | j                        S )z Returns number of cutting planes)Nviz_num_cplanesr   r?   s    r   GetCPlanesCountzNviz.GetCPlanesCount)  rV   r   c           	         t               t               t               }}}t        | j                        }t        | j                  |t	        |      t	        |      t	        |             |j
                  |j
                  |j
                  fS )z4Returns rotation parameters of current cutting plane)r{   r  r   Nviz_get_cplane_rotationr\   r!   r8   rg   rh   r~   currents        r   GetCPlaneRotationzNviz.GetCPlaneRotation-  s\    )WY	a1)$))4 GU1XuQxqRww((r   c           	         t               t               t               }}}t        | j                        }t        | j                  |t	        |      t	        |      t	        |             |j
                  |j
                  |j
                  fS )z7Returns translation parameters of current cutting plane)r{   r  r   Nviz_get_cplane_translationr\   r!   r  s        r   GetCPlaneTranslationzNviz.GetCPlaneTranslation6  s]    )WY	a1)$))4#DIIwa%(ERSHUww((r   c                     t        | j                        }t        | j                  ||||       t        | j                  dd       y)zSSet current clip plane rotation

        :param x,y,z: rotation parameters
        r'   N)r  r   Nviz_set_cplane_rotationr   r  s        r   SetCPlaneRotationzNviz.SetCPlaneRotation?  s6    
 *$))4 GQ1=B+r   c                     t        | j                        }t        | j                  ||||       t        | j                  dd       t	        j
                  dd||||       y)zYSet current clip plane translation

        :param x,y,z: translation parameters
        r'   r   z5Nviz::SetCPlaneTranslation(): id=%d, x=%f, y=%f, z=%fN)r  r   Nviz_set_cplane_translationr   r   r   r  s        r   SetCPlaneTranslationzNviz.SetCPlaneTranslationH  sS    
 *$))4#DIIw1a@B+		FQRTUWX	
r   c                     t        | j                        }t        | j                  |||      }|r0t        | j                  dd       | j	                         \  }}}|||fS y)Nr'   )NNN)r  r   Nviz_set_cplane_herer   r  )r8   rg   rh   r  r	  r~   s         r   SetCPlaneInteractivelyzNviz.SetCPlaneInteractivelyT  sY    )$))4"499gq!<TYYB///1GAq!a7N#r   c                 0    t        | j                  |       y)zKSelect cutting plane

        :param index: index of cutting plane
        N)Nviz_on_cplaner   r8   indexs     r   SelectCPlanezNviz.SelectCPlane^  s    
 	tyy%(r   c                 0    t        | j                  |       y)zMUnselect cutting plane

        :param index: index of cutting plane
        N)Nviz_off_cplaner   r  s     r   UnselectCPlanezNviz.UnselectCPlanee  s    
 			5)r   c                 0    t        | j                  |       y)z^Select current cutting plane

        :param index: type of fence - from 0 (off) to 4
        N)Nviz_set_fence_colorr   r  s     r   SetFenceColorzNviz.SetFenceColorl  s    
 	TYY.r   c                 ,    t        | j                        S )zGet xy range)Nviz_get_xyranger   r?   s    r   
GetXYRangezNviz.GetXYRanges  rV   r   c                     t               t               }}t        | j                  t        |      t        |             |j                  |j                  fS )zGet z range)r{   Nviz_get_zranger   r\   r!   )r8   minmaxs      r   	GetZRangezNviz.GetZRangew  s:    9giS		5:uSz:yy#))##r   c                    | j                   }| j                  }| j                  ||       t        t	        | j
                               | j                  dd       |dk(  rt        |       nt        |       | j                  ||       y)zSave current GL screen to ppm/tif file

        :param filename: file name
        :param width: image width
        :param height: image height
        :param itype: image type ('ppm' or 'tif')
        Fr'   ppmN)	r5   r6   rR   r   r   r   r   GS_write_ppmGS_write_tif)r8   filenamer5   r6   itype	widthOrig
heightOrigs          r   
SaveToFilezNviz.SaveToFile}  sm     JJ	[[
%(!$)),-		%E>"")Z0r   c                 H    | j                   rt        | j                         yy)zDraw lighting modelN)r7   Nviz_draw_modelr   r?   s    r   DrawLightingModelzNviz.DrawLightingModel  s    >>DII& r   c                 .    t        | j                         y)zDraw fringeN)Nviz_draw_fringer   r?   s    r   
DrawFringezNviz.DrawFringe  s    #r   c                     t        |d         dz   t        |d         z   dz   t        |d         z   }t        | j                  |t        |      |t	        |      t	        |      t	        |      t	        |             y)zSet fringe

        :param sid: surface id
        :param color: color
        :param elev: elevation (height)
        :param nw,ne,sw,se: fringe edges (turn on/off)
        r   :r(   r   N)strNviz_set_fringer   r   rO   )	r8   r   r4   elevnwneswsescolors	            r   	SetFringezNviz.SetFringe  sn     U1X$s58}4s:Sq]JII'GGGG		
r   c                 ,    t        | j                        S )zDraw north arrow)Nviz_draw_arrowr   r?   s    r   	DrawArrowzNviz.DrawArrow  s    tyy))r   c           	      F    t        | j                  |||t        |            S )zSet north arrow from canvas coordinates

        :param sx,sy: canvas coordinates
        :param size: arrow length
        :param color: arrow color
        )Nviz_set_arrowr   r   )r8   sxsyrB  r4   s        r   SetArrowzNviz.SetArrow  s!     diiR7J57QRRr   c                 .    t        | j                         y)zDelete north arrowN)Nviz_delete_arrowr   r?   s    r   DeleteArrowzNviz.DeleteArrow  s    $))$r   c           
      H    t        | j                  ||||t        |            S )zSet scale bar from canvas coordinates

        :param sx,sy: canvas coordinates
        :param id: scale bar id
        :param size: scale bar length
        :param color: scale bar color
        )Nviz_set_scalebarr   r   )r8   r   r  r  rB  r4   s         r   SetScalebarzNviz.SetScalebar  s(     !IIr2r4)<U)C
 	
r   c                 ,    t        | j                        S )zDraw scale bar)Nviz_draw_scalebarr   r?   s    r   DrawScalebarzNviz.DrawScalebar  s    !$)),,r   c                 0    t        | j                  |       y)zDelete scalebarN)Nviz_delete_scalebarr   r   s     r   DeleteScalebarzNviz.DeleteScalebar  s    TYY+r   c           
         t               }t               }t               }t               }t        j                  dd||z  ||z  fz         t	        t        ||z        t        ||z        t        |      t        |      t        |      t        |            }|dk(  ry|j                  |j                  |j                  |j                  fS )zLGet point on surface

        :param sx,sy: canvas coordinates (LL)
        r@  z&Nviz::GetPointOnSurface(): sx=%d sy=%dr   )NNNN)r   r{   r   r    GS_get_selected_point_on_surfacerO   r\   r!   )	r8   r  r  rQ   r   rg   rh   r~   rq  s	            r   GetPointOnSurfacezNviz.GetPointOnSurface  s    
 gIII		72:rEz:RR	
 /U
OSe_eCj%(E!HeTUh
 !8+		177AGGQWW55r   c                 N   | j                  |||      \  }}}}|syt        d      }t        d      }	t        |t        |||       t	        |t
        |	||       ||||t        |j                        j                  dd      j                  dd      t        |	j                        dS )zIQuery surface map

        :param sx,sy: canvas coordinates (LL)
        N   (r   ))r   rg   rh   r~   	elevationr4   )	r)  create_string_bufferGS_get_cat_at_xyr   GS_get_val_at_xyr   r
   r!   replace)
r8   r  r  rQ   r   rg   rh   r~   catstrvalstrs
             r   QueryMapzNviz.QueryMap  s    
 --b"e<Q1%c*%c*h15iA6 %fll3;;CDLLSRTU!&,,/
 	
r   c                     t               }t        ||d   |d   |d   |d   t        |      t        |             |j                  S )z#Get distance measured along surfacer   r(   )r{   GS_get_distance_alongsurfr\   rO   r!   )r8   r   p1p2useExagds         r   GetDistanceAlongSurfacezNviz.GetDistanceAlongSurface  sC    I!A1r!ubeU1Xs7|	
 wwr   c                    t        dz         }t        t        |             t        ||z  ||z  z         t	        | j
                  dz         z  dz  }g }g }t        |      D ]5  \  }}|j                  |       |dz   dz  dk(  s#|j                  |       g }7 t        |      j                  }	||d}}}
|	d   |
z  |	d   |z  z   |	d	   |z  z   }|	d
   |
z  |	d   |z  z   |	d   |z  z   }|	d   |
z  |	d   |z  z   |	d   |z  z   }||||fS )zwGet rotation parameters (angle, x, y, z axes)

        :param dx,dy: difference from previous mouse drag event
           r(   g     f@   r   r   r   r   )r(   r   )r   r   r   r(   )r(   r(   )r   r(   )r   r   )r(   r   )r   r   )
rZ   Nviz_get_modelviewr\   r   r  r5   r   appendr   I)r8   dxdy	modelviewanglemrowr   iteminvaxayazrg   rh   r~   s                   r   GetRotationParameterszNviz.GetRotationParameters	  s8   
 ]%	5+,R"WrBw&'%

Q*??%G + 	GAtJJtA{a		
 QikkSBINSY^+c$i"n<INSY^+c$i"n<INSY^+c$i"n<aA~r   c                      t        ||||       y)zSet rotation parameters
        Rotate scene (difference from current state).

        :param angle: angle
        :param x,y,z: axis coordinate
        N)Nviz_set_rotation)r8   rH  rg   rh   r~   s        r   RotatezNviz.Rotate!  s     	%Aq)r   c                     t                y)zStop rotating the sceneN)Nviz_unset_rotationr?   s    r   UnsetRotationzNviz.UnsetRotation*  s    r   c                     t                y)zReset scene rotationN)Nviz_init_rotationr?   s    r   ResetRotationzNviz.ResetRotation.  s    r   c                 |    t        dz         }t        t        |             g }|D ]  }|j                  |        |S )zGet rotation matrixr>  )rZ   GS_get_rotation_matrixr\   rC  )r8   r   returnMatrixrK  s       r   GetRotationMatrixzNviz.GetRotationMatrix2  sB    R-"uV}- 	&D%	&r   c                     t        dz         }t        t        |            D ]
  }||   ||<    t        t	        |             y)zSet rotation matrixr>  N)rZ   r!  lenGS_set_rotation_matrixr\   )r8   r   mtrxr   s       r   SetRotationMatrixzNviz.SetRotationMatrix;  s?    2 s6{# 	 AQiDG	 uT{+r   c                 D    t        | j                  | j                         y rm   )Nviz_set_2Dr5   r6   r?   s    r   Start2DzNviz.Start2DB  s    DJJ,r   c                     t        dz         }t        |      D ]
  \  }}|||<    t        dz         }t        |d         |d<   t        |d         |d<   t	        | j
                  |||       y)zFly through the scene

        :param flyInfo: fly parameters
        :param mode: 0 or 1 for different fly behaviour
        :param exagInfo: parameters changing fly speed
        r   r   mover   turnr(   N)r{   r   r   rO   Nviz_flythroughr   )r8   flyInfor  exagInfoflyr   rK  exags           r   
FlyThroughzNviz.FlyThroughE  ss     {o ) 	GAtCF		}hv&'Qhv&'Q		3d3r   )r(   rA  )NFNNN)NFNrm   )   ro  r  )FFFFT)z__name__
__module____qualname__r;   r@   r.   rR   rU   ra   rk   rq   rt   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r  r  r  r  r  r  r$  r(  r+  r/  r3  r9  r=  rD  rG  rJ  rM  rS  rY  r\  r_  rc  rf  rj  rs  rx  r{  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r#  r&  r)  r5  r<  rP  rS  rV  rY  r]  rb  re  rn   r   r   r$   r$   o   s   %6	; +<2
,+K-

+
&#3%*.
) D8"CJ$$ D0&;z$=>> ? >=%N
3	5	3,4#J"H+2&@$,,"H$,
:/6  OF >BA2$$,,M4(,0088LMM$NML,\BDBB((((442+2&$2+)),

$)*/+$1*'
$
(*S%

-,6(
.0*,-4r   r$   c                   T    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 ZddZd Zy)Texturez!Class representing OpenGL texturec                 x   || _         t        |      | _        | j                  j                         x| _        | _        | j                  j                         x| _        | _        || _	        || _
        d| _        | j                  j                         s| j                  j                          | j                          t               }t!        t#        |             |j$                  | _        | j&                  | j                  k  s| j&                  | j                  k  rd| _        y| j+                         | _        y)zLoad image to texture

        :param filepath: path to image file
        :param overlayId: id of overlay (1 for legend, 101 and more for text)
        :param coords: image coordinates
        TN)pathr	   imageGetWidthr5   
orig_width	GetHeightr6   orig_heightr   coordsactiveHasAlpha	InitAlphaResizer   Nviz_get_max_texturer\   r!   maxSize	textureIdLoad)r8   filepath	overlayIdr~  r  s        r   r;   zTexture.__init__X  s     	*84
'+zz':':'<<
T_)-)=)=)??d& zz""$JJ  " 	 'U7^,}}<<$**$t{{(B!DN!YY[DNr   c                     | j                   rt        | j                          t        j                  | j                         y)zDelete textureN)r  Nviz_del_texturegrass
try_removerx  r?   s    r   r@   zTexture.__del__x  s'    >>T^^,#r   c                    dx}}| j                   t        d|      kD  r|dz  }| j                   t        d|      kD  r| j                  t        d|      kD  r|dz  }| j                  t        d|      kD  r| j                  j	                  t        d|      t        d|      fd       | j                  j                         | _         | j                  j                         | _        y)zResize image to match 2^nr(   r   r@  )rB  posN)r5   powr6   ry  r  rz  r|  )r8   nrI  s      r   r  zTexture.Resize~  s    	Ajj3q!9$FA jj3q!9$kkC1I%FA kkC1I%

Aq	3q!956BZZ((*
jj**,r   c                    | j                   j                         rd}nd}|| j                  z  | j                  z  }| j                  dz
  }t	        |z         }d| j                  z  | j                  z  }| j                  | j                  z  }t        j                  t        |      dz   | j                   j                               }| j                   j                         r{t        r;t        j                  t        |      dz   | j                   j                               }n:t        j                  t        |      dz   | j                   j                               }t        j                          t        | j                        D ]  }	t        | j                        D ]  }
||
||	z
  | j                  z  z   dz  dz      ||
|	| j                  z  z   |z  dz   <   ||
||	z
  | j                  z  z   dz  dz      ||
|	| j                  z  z   |z  dz   <   ||
||	z
  | j                  z  z   dz  dz      ||
|	| j                  z  z   |z  dz   <   | j                   j                         s|
||	z
  | j                  z  z      ||
|	| j                  z  z   |z  dz   <     t        j                          t!        || j                  | j                  | j                   j                               }|S )zLoad image to texturer?  r   r(   Br   r   )ry  r  r5   r6   c_ubytestructunpackr
  GetDatar   GetAlphaGetAlphaDatawxBeginBusyCursorr!  EndBusyCursorNviz_load_image)r8   bytesPerPixelbytesrev_valimbytes3bytes1	imageData	alphaDatar   jr   s               r   r  zTexture.Load  s   :: MM

*T[[8++/o TZZ$++-dkk)MM#f+"3TZZ5G5G5IJ	:: "MM#f+*;TZZ=P=P=RS	"MM#f+*;TZZ=T=T=VW	 	t{{# 	A4::& ?H'A+33q81<@ADJJ&-7!;< @I'A+33q81<@ADJJ&-7!;< @I'A+33q81<@ADJJ&-7!;< ::&&(CLgkTZZ77DBA

N*m;a?@	 	RT[[$**:M:M:OP	r   c                     t        | j                  d   | j                  d   | j                  | j                  | j                         y)zDraw texture as an imager   r(   N)Nviz_draw_imager~  r5   r6   r  r?   s    r   r   zTexture.Draw  s1    KKNDKKNDJJT^^	
r   c                     t        | j                  d   | j                  d   | j                  | j                        }|j	                  ||       |j                  ||      S )Nr   r(   )r   r~  r{  r}  Inflate
ContainsXY)r8   rg   rh   radiuscopys        r   HitTestzTexture.HitTest  sK    DKKNDKKNDOOTEUEUVVV$q!$$r   c                 `    | j                   dxx   |z  cc<   | j                   dxx   |z  cc<   y)zMove texture on the screenr   r(   N)r~  )r8   rE  rF  s      r   MoveTexturezTexture.MoveTexture  s&    A"A"r   c                 |    |d   | j                   d   z
  }|d   | j                   d   z
  }| j                  ||       y)zSet coordinatesr   r(   N)r~  r  )r8   r~  rE  rF  s       r   	SetCoordszTexture.SetCoords  s>    AYQ'AYQ'R r   c                     | j                   S )zReturns image id.)r   r?   s    r   GetIdzTexture.GetId  s    wwr   c                     || _         y rm   r  )r8   r  s     r   	SetActivezTexture.SetActive  s	    r   c                     | j                   S rm   r  r?   s    r   IsActivezTexture.IsActive  s    {{r   Nrp  )rq  rr  rs  __doc__r;   r@   r  r  r   r  r  r  r  r  r  rt  r   r   rv  rv  U  s>    +)@$	-'R
%

!r   rv  c                   "    e Zd ZdZd Zd Zd Zy)ImageTexturez5Class representing OpenGL texture as an overlay imagec                 D    t         j                  | |||       || _        y)zLoad image to texture

        :param filepath: path to image file
        :param overlayId: id of overlay (1 for legend)
        :param coords: image coordinates
        :param cmd: d.legend command
        )r  r  r~  N)rv  r;   cmd)r8   r  r  r~  r  s        r   r;   zImageTexture.__init__  s"     	IfUr   c                     | j                   S )zReturns overlay command.)r  r?   s    r   GetCmdzImageTexture.GetCmd  s    xxr   c                 h    t        | j                               t        |j                               k(  S rm   )sortedr  )r8   rK  s     r   CorrespondszImageTexture.Corresponds  s#    dkkm$t{{}(===r   N)rq  rr  rs  r  r;   r  r  rt  r   r   r  r    s    ?
>r   r  );r  
__future__r   r   rE   r  mathr   numpyr   ImportErrorr   r   r   stderrr  ctypesKeyErroreformatWindowsError	NameErrorOSErrorgrass.lib.gisgrass.lib.raster3dgrass.lib.vectorgrass.lib.ogsfgrass.lib.nvizgrass.lib.raster	TypeError
core.debugr   
core.utilsr	   	core.gcmdr
   core.globalvarr   gui_core.wrapr   grass.scriptscriptr  r   r   r   r"   	CFUNCTYPE	UNCHECKEDr   Stringerrtyper+   pertyper-   objectr$   rv  r  rt  r   r   <module>r     s  0 & 
   
0 
66$"  "  , " *  


		%(&%8Gk"G	%(%0Gn%G
c46 c4L?{f {|>7 >cE  0
	C 
-#
CJJ/0  6	/
 
 
##**556
  L 	\9- 6	/
 
 
##**556Z  		sb   C C8 D- D; =/E4 $C54C58D*=#D%%D*-D87D8;E1#E,,E14E<;E<