VisionEgg.PyroApps.SpinningDrumServer

Package VisionEgg :: Package PyroApps :: Module SpinningDrumServer |
[frames] | no frames]

# Source Code for Module VisionEgg.PyroApps.SpinningDrumServer

      1  #!/usr/bin/env python
      2  #
      3  # The Vision Egg: SpinningDrumServer
      4  #
      5  # Copyright (C) 2001-2003 Andrew Straw.
      6  # Author: Andrew Straw <astraw@users.sourceforge.net>
      7  # URL: <http://www.visionegg.org/>
      8  #
      9  # Distributed under the terms of the GNU Lesser General Public License
     10  # (LGPL). See LICENSE.TXT that came with this file.
     11  #
     12  # $Id$
     13
     14  import VisionEgg, string
     15  __version__ = VisionEgg.release_name
     16  __cvs__ = string.split('$Revision$')[1]
     17  __date__ = string.join(string.split('$Date$')[1:3], ' ')
     18  __author__ = 'Andrew Straw <astraw@users.sourceforge.net>'
     19
     20  import sys, os, math
     21  import VisionEgg.Core
     22  import VisionEgg.FlowControl
     23  import VisionEgg.Textures
     24  import VisionEgg.PyroHelpers
     25  import Pyro.core
     26
     27  from VisionEgg.PyroApps.ScreenPositionServer import ScreenPositionMetaController
     28  from VisionEgg.PyroApps.ScreenPositionGUI import ScreenPositionParameters
     29  from VisionEgg.PyroApps.SpinningDrumGUI import SpinningDrumMetaParameters
     30
     31 -class SpinningDrumExperimentMetaController( Pyro.core.ObjBase ):
     32 -    def __init__(self,screen,presentation,stimuli):
     33
     34          # get the instance of Stimulus that was created
     35          assert( stimuli[0][0] == '3d_perspective' )
     36          spinning_drum = stimuli[0][1]
     37
     38          Pyro.core.ObjBase.__init__(self)
     39          self.meta_params = SpinningDrumMetaParameters()
     40          if not isinstance(screen,VisionEgg.Core.Screen):
     41              raise ValueError("Expecting instance of VisionEgg.Core.Screen")
     42          if not isinstance(presentation,VisionEgg.FlowControl.Presentation):
     43              raise ValueError("Expecting instance of VisionEgg.FlowControl.Presentation")
     44          if not isinstance(spinning_drum,VisionEgg.Textures.SpinningDrum):
     45              raise ValueError("Expecting instance of VisionEgg.Textures.SpinningDrum")
     46          self.p = presentation
     47          self.stim = spinning_drum
     48
     49          screen.parameters.bgcolor = (0.5, 0.5, 0.5, 0.0)
     50
     51          self.p.add_controller(self.stim,'on',VisionEgg.FlowControl.FunctionController(
     52              during_go_func=self.on_function_during_go,
     53              between_go_func=self.on_function_between_go))
     54
     55          self.p.add_controller(self.stim,'angular_position',VisionEgg.FlowControl.FunctionController(
     56              during_go_func=self.angular_position_during_go,
     57              between_go_func=self.angular_position_between_go))
     58
     59 -    def __del__(self):
     60          self.p.remove_controller(self.stim,'on')
     61          self.p.remove_controller(self.stim,'angular_position')
     62          Pyro.core.ObjBase.__del__(self) # call base class
     63
     64 -    def on_function_during_go(self,t):
     65          if t <= self.meta_params.pre_stim_sec:
     66              return 0 # not on yet
     67          elif t <= (self.meta_params.pre_stim_sec + self.meta_params.stim_sec):
     68              return 1 # on
     69          else:
     70              return 0 # off again
     71
     72 -    def on_function_between_go(self):
     73          return 0 # off
     74
     75 -    def angular_position_during_go(self,t):
     76          adjusted_t = t - self.meta_params.pre_stim_sec
     77          return (adjusted_t * self.meta_params.velocity_dps) + self.meta_params.startpos_deg
     78
     79 -    def angular_position_between_go(self):
     80          return 0.0 # doesn't matter -- stimulus off
     81
     82 -    def get_parameters(self):
     83          return self.meta_params
     84
     85 -    def set_parameters(self, new_parameters):
     86          if isinstance(new_parameters, SpinningDrumMetaParameters):
     87              self.meta_params = new_parameters
     88          else:
     89              raise ValueError("Argument to set_parameters must be instance of SpinningDrumMetaParameters")
     90          self.update()
     91
     92 -    def update(self):
     93          stim_params = self.stim.parameters # shorthand
     94          meta_params = self.meta_params # shorthand
     95          stim_params.contrast = meta_params.contrast
     96          self.p.parameters.go_duration = ( meta_params.pre_stim_sec + meta_params.stim_sec + meta_params.post_stim_sec, 'seconds')
     97
     98 -    def go(self):
     99          self.p.parameters.enter_go_loop = 1
    100
    101 -    def quit_server(self):
    102          self.p.parameters.quit = 1
    103
    104 -def get_meta_controller_class():
    105      return SpinningDrumExperimentMetaController
    106
    107 -def make_stimuli():
    108      filename = os.path.join(VisionEgg.config.VISIONEGG_SYSTEM_DIR,"data/panorama.jpg")
    109      texture = VisionEgg.Textures.Texture(filename)
    110      stimulus = VisionEgg.Textures.SpinningDrum(texture=texture) # could add shrink_texture_ok=1
    111      return [('3d_perspective',stimulus)] # return ordered list of tuples
    112
    113 -def get_meta_controller_stimkey():
    114      return "spinning_drum_server"
    115
    116  # Don't do anything unless this script is being run
    117  if __name__ == '__main__':
    118
    119      pyro_server = VisionEgg.PyroHelpers.PyroServer()
    120
    121      screen = VisionEgg.Core.Screen.create_default()
    122
    123      # get Vision Egg stimulus ready to go
    124      stimuli = make_stimuli()
    125      stimulus = stimuli[0][1]
    126      temp = ScreenPositionParameters()
    127
    128      projection = VisionEgg.Core.PerspectiveProjection(temp.left,
    129                                                        temp.right,
    130                                                        temp.bottom,
    131                                                        temp.top,
    132                                                        temp.near,
    133                                                        temp.far)
    134      viewport = VisionEgg.Core.Viewport(screen=screen,stimuli=[stimulus],projection=projection)
    135      p = VisionEgg.FlowControl.Presentation(viewports=[viewport])
    136
    137      # now hand over control of projection to ScreenPositionMetaController
    138      projection_controller = ScreenPositionMetaController(p,projection)
    139      pyro_server.connect(projection_controller,"projection_controller")
    140
    141      # now hand over control of drum to SpinningDrumExperimentMetaController
    142      meta_controller = SpinningDrumExperimentMetaController(screen,p,stimuli)
    143      pyro_server.connect(meta_controller,get_meta_controller_stimkey())
    144
    145      # get listener controller and register it
    146      p.add_controller(None,None, pyro_server.create_listener_controller())
    147
    148      # enter endless loop
    149      p.run_forever()
    150