<s> """<STR_LIT>""" <EOL> try : <EOL> from sip import setapi <EOL> setapi ( "<STR_LIT>" , <NUM_LIT:2> ) <EOL> setapi ( "<STR_LIT>" , <NUM_LIT:2> ) <EOL> except ImportError : <EOL> pass <EOL> from PyQt4 import QtGui , QtCore <EOL> import sys <EOL> import numpy as np <EOL> from vispy import app , gloo <EOL> from vispy . util . transforms import perspective , translate , rotate <EOL> from vispy . geometry import meshdata as md <EOL> from vispy . geometry import generation as gen <EOL> OBJECT = { '<STR_LIT>' : [ ( '<STR_LIT>' , <NUM_LIT:3> , <NUM_LIT:1000> , '<STR_LIT:int>' , <NUM_LIT:3> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:3> , <NUM_LIT:1000> , '<STR_LIT:int>' , <NUM_LIT:3> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:0.1> , <NUM_LIT:10> , '<STR_LIT>' , <NUM_LIT:1.0> ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , <NUM_LIT:4> , <NUM_LIT:1000> , '<STR_LIT:int>' , <NUM_LIT:4> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:4> , <NUM_LIT:1000> , '<STR_LIT:int>' , <NUM_LIT:4> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:0.1> , <NUM_LIT:10> , '<STR_LIT>' , <NUM_LIT:1.0> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:0.1> , <NUM_LIT:10> , '<STR_LIT>' , <NUM_LIT:1.0> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:0.1> , <NUM_LIT:10> , '<STR_LIT>' , <NUM_LIT:1.0> ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , <NUM_LIT:3> , <NUM_LIT:1000> , '<STR_LIT:int>' , <NUM_LIT:3> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:0.1> , <NUM_LIT:10> , '<STR_LIT>' , <NUM_LIT:1.0> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:0.1> , <NUM_LIT:10> , '<STR_LIT>' , <NUM_LIT:1.0> ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , <NUM_LIT:4> , <NUM_LIT:1000> , '<STR_LIT:int>' , <NUM_LIT:4> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:4> , <NUM_LIT:1000> , '<STR_LIT:int>' , <NUM_LIT:4> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> , <NUM_LIT:10> , '<STR_LIT>' , <NUM_LIT:0.1> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:0.1> , <NUM_LIT:10> , '<STR_LIT>' , <NUM_LIT:1.0> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:0.1> , <NUM_LIT:10> , '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:0.0> , <NUM_LIT> , '<STR_LIT>' , <NUM_LIT> ) ] } <EOL> vert = """<STR_LIT>""" <EOL> frag = """<STR_LIT>""" <EOL> DEFAULT_COLOR = ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> class MyMeshData ( md . MeshData ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , vertices = None , faces = None , edges = None , <EOL> vertex_colors = None , face_colors = None ) : <EOL> md . MeshData . __init__ ( self , vertices = None , faces = None , edges = None , <EOL> vertex_colors = None , face_colors = None ) <EOL> def get_glTriangles ( self ) : <EOL> """<STR_LIT>""" <EOL> vtype = [ ( '<STR_LIT>' , np . float32 , <NUM_LIT:3> ) , <EOL> ( '<STR_LIT>' , np . float32 , <NUM_LIT:3> ) , <EOL> ( '<STR_LIT>' , np . float32 , <NUM_LIT:4> ) ] <EOL> vertices = self . get_vertices ( ) <EOL> normals = self . get_vertex_normals ( ) <EOL> faces = np . uint32 ( self . get_faces ( ) ) <EOL> edges = np . uint32 ( self . get_edges ( ) . reshape ( ( - <NUM_LIT:1> ) ) ) <EOL> colors = self . get_vertex_colors ( ) <EOL> nbrVerts = vertices . shape [ <NUM_LIT:0> ] <EOL> V = np . zeros ( nbrVerts , dtype = vtype ) <EOL> V [ : ] [ '<STR_LIT>' ] = vertices <EOL> V [ : ] [ '<STR_LIT>' ] = normals <EOL> V [ : ] [ '<STR_LIT>' ] = colors <EOL> return V , faces . reshape ( ( - <NUM_LIT:1> ) ) , edges . reshape ( ( - <NUM_LIT:1> ) ) <EOL> class ObjectParam ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , list_param ) : <EOL> self . name = name <EOL> self . list_param = list_param <EOL> self . props = { } <EOL> self . props [ '<STR_LIT>' ] = True <EOL> for nameV , minV , maxV , typeV , iniV in list_param : <EOL> self . props [ nameV ] = iniV <EOL> class ObjectWidget ( QtGui . QWidget ) : <EOL> """<STR_LIT>""" <EOL> signal_objet_changed = QtCore . pyqtSignal ( ObjectParam , name = '<STR_LIT>' ) <EOL> def __init__ ( self , parent = None , param = None ) : <EOL> super ( ObjectWidget , self ) . __init__ ( parent ) <EOL> if param is None : <EOL> self . param = ObjectParam ( '<STR_LIT>' , OBJECT [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . param = param <EOL> self . gb_c = QtGui . QGroupBox ( u"<STR_LIT>" % self . param . name ) <EOL> self . gb_c . setCheckable ( True ) <EOL> self . gb_c . setChecked ( self . param . props [ '<STR_LIT>' ] ) <EOL> self . gb_c . toggled . connect ( self . update_param ) <EOL> lL = [ ] <EOL> self . sp = [ ] <EOL> gb_c_lay = QtGui . QGridLayout ( ) <EOL> for nameV , minV , maxV , typeV , iniV in self . param . list_param : <EOL> lL . append ( QtGui . QLabel ( nameV , self . gb_c ) ) <EOL> if typeV == '<STR_LIT>' : <EOL> self . sp . append ( QtGui . QDoubleSpinBox ( self . gb_c ) ) <EOL> self . sp [ - <NUM_LIT:1> ] . setDecimals ( <NUM_LIT:2> ) <EOL> self . sp [ - <NUM_LIT:1> ] . setSingleStep ( <NUM_LIT:0.1> ) <EOL> self . sp [ - <NUM_LIT:1> ] . setLocale ( QtCore . QLocale ( QtCore . QLocale . English ) ) <EOL> elif typeV == '<STR_LIT:int>' : <EOL> self . sp . append ( QtGui . QSpinBox ( self . gb_c ) ) <EOL> self . sp [ - <NUM_LIT:1> ] . setMinimum ( minV ) <EOL> self . sp [ - <NUM_LIT:1> ] . setMaximum ( maxV ) <EOL> self . sp [ - <NUM_LIT:1> ] . setValue ( iniV ) <EOL> for pos in range ( len ( lL ) ) : <EOL> gb_c_lay . addWidget ( lL [ pos ] , pos , <NUM_LIT:0> ) <EOL> gb_c_lay . addWidget ( self . sp [ pos ] , pos , <NUM_LIT:1> ) <EOL> self . sp [ pos ] . valueChanged . connect ( self . update_param ) <EOL> self . gb_c . setLayout ( gb_c_lay ) <EOL> vbox = QtGui . QVBoxLayout ( ) <EOL> hbox = QtGui . QHBoxLayout ( ) <EOL> hbox . addWidget ( self . gb_c ) <EOL> hbox . addStretch ( <NUM_LIT:1.0> ) <EOL> vbox . addLayout ( hbox ) <EOL> vbox . addStretch ( <NUM_LIT:1.0> ) <EOL> self . setLayout ( vbox ) <EOL> def update_param ( self , option ) : <EOL> """<STR_LIT>""" <EOL> self . param . props [ '<STR_LIT>' ] = self . gb_c . isChecked ( ) <EOL> keys = map ( lambda x : x [ <NUM_LIT:0> ] , self . param . list_param ) <EOL> for pos , nameV in enumerate ( keys ) : <EOL> self . param . props [ nameV ] = self . sp [ pos ] . value ( ) <EOL> self . signal_objet_changed . emit ( self . param ) <EOL> class Canvas ( app . Canvas ) : <EOL> def __init__ ( self , ) : <EOL> app . Canvas . __init__ ( self ) <EOL> self . size = <NUM_LIT> , <NUM_LIT> <EOL> self . fovy = <NUM_LIT> <EOL> self . zfar = <NUM_LIT> <EOL> width , height = self . size <EOL> self . aspect = width / float ( height ) <EOL> self . program = gloo . Program ( vert , frag ) <EOL> self . model = np . eye ( <NUM_LIT:4> , dtype = np . float32 ) <EOL> self . projection = np . eye ( <NUM_LIT:4> , dtype = np . float32 ) <EOL> self . view = translate ( ( <NUM_LIT:0> , <NUM_LIT:0> , - <NUM_LIT> ) ) <EOL> self . program [ '<STR_LIT>' ] = self . model <EOL> self . program [ '<STR_LIT>' ] = self . view <EOL> self . theta = <NUM_LIT:0> <EOL> self . phi = <NUM_LIT:0> <EOL> self . visible = True <EOL> self . _timer = app . Timer ( <NUM_LIT:1.0> / <NUM_LIT> ) <EOL> self . _timer . connect ( self . on_timer ) <EOL> self . _timer . start ( ) <EOL> gloo . set_clear_color ( ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> gloo . set_state ( '<STR_LIT>' ) <EOL> gloo . set_polygon_offset ( <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> def on_timer ( self , event ) : <EOL> self . theta += <NUM_LIT> <EOL> self . phi += <NUM_LIT> <EOL> self . model = np . dot ( rotate ( self . theta , ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) ) , <EOL> rotate ( self . phi , ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) ) ) <EOL> self . program [ '<STR_LIT>' ] = self . model <EOL> self . update ( ) <EOL> def on_resize ( self , event ) : <EOL> width , height = event . size <EOL> self . size = event . size <EOL> gloo . set_viewport ( <NUM_LIT:0> , <NUM_LIT:0> , width , height ) <EOL> self . aspect = width / float ( height ) <EOL> self . projection = perspective ( self . fovy , width / float ( height ) , <NUM_LIT:1.0> , <EOL> self . zfar ) <EOL> self . program [ '<STR_LIT>' ] = self . projection <EOL> def on_draw ( self , event ) : <EOL> gloo . clear ( ) <EOL> if self . visible : <EOL> gloo . set_state ( blend = False , depth_test = True , <EOL> polygon_offset_fill = True ) <EOL> self . program [ '<STR_LIT>' ] = <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> <EOL> self . program . draw ( '<STR_LIT>' , self . filled_buf ) <EOL> gloo . set_state ( blend = True , depth_test = True , <EOL> polygon_offset_fill = False ) <EOL> gloo . set_depth_mask ( False ) <EOL> self . program [ '<STR_LIT>' ] = <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> <EOL> self . program . draw ( '<STR_LIT>' , self . outline_buf ) <EOL> gloo . set_depth_mask ( True ) <EOL> def set_data ( self , vertices , filled , outline ) : <EOL> self . filled_buf = gloo . IndexBuffer ( filled ) <EOL> self . outline_buf = gloo . IndexBuffer ( outline ) <EOL> self . vertices_buff = gloo . VertexBuffer ( vertices ) <EOL> self . program . bind ( self . vertices_buff ) <EOL> self . update ( ) <EOL> class MainWindow ( QtGui . QMainWindow ) : <EOL> def __init__ ( self ) : <EOL> QtGui . QMainWindow . __init__ ( self ) <EOL> self . resize ( <NUM_LIT> , <NUM_LIT> ) <EOL> self . setWindowTitle ( '<STR_LIT>' ) <EOL> self . list_object = QtGui . QListWidget ( ) <EOL> self . list_object . setAlternatingRowColors ( True ) <EOL> self . list_object . itemSelectionChanged . connect ( self . list_objectChanged ) <EOL> self . list_object . addItems ( list ( OBJECT . keys ( ) ) ) <EOL> self . props_widget = ObjectWidget ( self ) <EOL> self . props_widget . signal_objet_changed . connect ( self . update_view ) <EOL> self . splitter_v = QtGui . QSplitter ( QtCore . Qt . Vertical ) <EOL> self . splitter_v . addWidget ( self . list_object ) <EOL> self . splitter_v . addWidget ( self . props_widget ) <EOL> self . canvas = Canvas ( ) <EOL> self . canvas . create_native ( ) <EOL> self . canvas . native . setParent ( self ) <EOL> self . canvas . measure_fps ( <NUM_LIT:0.1> , self . show_fps ) <EOL> splitter1 = QtGui . QSplitter ( QtCore . Qt . Horizontal ) <EOL> splitter1 . addWidget ( self . splitter_v ) <EOL> splitter1 . addWidget ( self . canvas . native ) <EOL> self . setCentralWidget ( splitter1 ) <EOL> self . status = self . statusBar ( ) <EOL> self . status . showMessage ( "<STR_LIT>" ) <EOL> self . mesh = MyMeshData ( ) <EOL> self . update_view ( self . props_widget . param ) <EOL> def list_objectChanged ( self ) : <EOL> row = self . list_object . currentIndex ( ) . row ( ) <EOL> name = self . list_object . currentIndex ( ) . data ( ) <EOL> if row != - <NUM_LIT:1> : <EOL> self . props_widget . deleteLater ( ) <EOL> self . props_widget = ObjectWidget ( self , param = ObjectParam ( name , <EOL> OBJECT [ name ] ) ) <EOL> self . splitter_v . addWidget ( self . props_widget ) <EOL> self . props_widget . signal_objet_changed . connect ( self . update_view ) <EOL> self . update_view ( self . props_widget . param ) <EOL> def show_fps ( self , fps ) : <EOL> nbr_tri = self . mesh . n_faces <EOL> self . status . showMessage ( "<STR_LIT>" % ( fps , nbr_tri ) ) <EOL> def update_view ( self , param ) : <EOL> cols = param . props [ '<STR_LIT>' ] <EOL> radius = param . props [ '<STR_LIT>' ] <EOL> if param . name == '<STR_LIT>' : <EOL> rows = param . props [ '<STR_LIT>' ] <EOL> mesh = gen . create_sphere ( cols , rows , radius = radius ) <EOL> elif param . name == '<STR_LIT>' : <EOL> length = param . props [ '<STR_LIT>' ] <EOL> mesh = gen . create_cone ( cols , radius = radius , length = length ) <EOL> elif param . name == '<STR_LIT>' : <EOL> rows = param . props [ '<STR_LIT>' ] <EOL> length = param . props [ '<STR_LIT>' ] <EOL> radius2 = param . props [ '<STR_LIT>' ] <EOL> mesh = gen . create_cylinder ( rows , cols , radius = [ radius , radius2 ] , <EOL> length = length ) <EOL> elif param . name == '<STR_LIT>' : <EOL> length = param . props [ '<STR_LIT>' ] <EOL> rows = param . props [ '<STR_LIT>' ] <EOL> cone_radius = param . props [ '<STR_LIT>' ] <EOL> cone_length = param . props [ '<STR_LIT>' ] <EOL> mesh = gen . create_arrow ( rows , cols , radius = radius , length = length , <EOL> cone_radius = cone_radius , <EOL> cone_length = cone_length ) <EOL> else : <EOL> return <EOL> self . canvas . visible = param . props [ '<STR_LIT>' ] <EOL> self . mesh . set_vertices ( mesh . get_vertices ( ) ) <EOL> self . mesh . set_faces ( mesh . get_faces ( ) ) <EOL> colors = np . tile ( DEFAULT_COLOR , ( self . mesh . n_vertices , <NUM_LIT:1> ) ) <EOL> self . mesh . set_vertex_colors ( colors ) <EOL> vertices , filled , outline = self . mesh . get_glTriangles ( ) <EOL> self . canvas . set_data ( vertices , filled , outline ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> appQt = QtGui . QApplication ( sys . argv ) <EOL> win = MainWindow ( ) <EOL> win . show ( ) <EOL> appQt . exec_ ( ) </s>
