[visionegg] Re: simple RSVP scripts

Hi martin,

seems to work, thanks!

the code is as such (in case anybody else is interested)

btw... any idea on how to ensure all files are loaded into memory (first), besides doing some arbitrary wait loop?

cheers,

-=gabe

########################################################
#
#!usr/bin/pythonw
# based on Andrew Straw's demo code
# http://www.freelists.org/archives/visionegg/11-2002/msg00001.html

from VisionEgg import *
start_default_logging(); watch_exceptions()

from VisionEgg.Core import *
from VisionEgg.FlowControl import Presentation, FunctionController
from VisionEgg.Textures import *
from pygame.time import *
import OpenGL.GL as gl

import os

photoX = ("01.bmp",
          "02.bmp",
          "03.bmp",
          "04.bmp",
          "05.bmp",
          "06.bmp",
          "07.bmp",
          "08.bmp",
          "09.bmp",
          "10.bmp")

pwd = os.getcwd()

#duration_per_image = 0.1 # seconds
num_images = len(photoX)

screen = get_default_screen()

# Create list of stimuli
preloaded_stimulus_list = [] # empty at first

for i in range(num_images):
     # Read the texture file
     texture_name = os.path.join(pwd, 'data', photoX[i])
     texture = TextureFromFile(texture_name)

     # Load the texture to OpenGL, prepare for display
     stimulus = TextureStimulus(texture = texture,
                                size    = texture.size,
     #                           texture_min_filter=gl.GL_LINEAR
                                )
     # Add to list of stimuli
     preloaded_stimulus_list.append( stimulus )

###############################################
#
# <procedural_version>

viewport = Viewport(screen=screen)

frame_timer = FrameTimer()

num_loops = 100

# show images
for trialcounter in range(num_loops):
    for image_counter in range(num_images):
        viewport.parameters.stimuli =  [preloaded_stimulus_list[image_counter]]
        screen.clear()
        viewport.draw()
        swap_buffers()
        frame_timer.tick()

#
# </procedural_version>
#
###############################################

frame_timer.print_histogram()


Hi Gabriel,

Calling Viewport() creates a new viewport instance. I haven't tried this before but I'm pretty sure you could do the following instead:

viewport.stimuli = preloaded_stimulus_list

where viewport is your instance of Viewport().

Actually, the = assignment operator seems to (usually) work by reference in python, so if you were to subsequently update the contents of preloaded_stimulus_list such as:

preloaded_stimulus_list[2] = funstimulus

the viewport should be updated automatically. However, if you overwrite preloaded_stimulus_list completely with a new assignment, I think this assigns a new memory location for it, and viewport will still point to the old version of preloaded_stimulus_list.

Also, you can probably use various list methods like append() and remove() or just [bracketed indices] to modify viewport.stimuli directly.

Again, this is just how I *think* things might (or should) work, you'll have to try it out to make sure. I seem to be too lazy for that right now :)

Cheers,

Martin Spacek
PhD student, Swindale lab
Graduate Program in Neuroscience
Dept. of Ophthalmology and Visual Sciences
University of British Columbia, Vancouver, BC, Canada
+1-604-875-4555 ext. 66282
mspacek@xxxxxxxxxxxxxxx | http://swindale.ecc.ubc.ca

On 2005-01-24 10:24 AM, Gabriel Nevarez wrote:
Hi, andrew...

This version works... however, does calling the Viewport() method instantiate a *new* viewport object or simply reassign an existing one (preferrable)? In other words, what's the simplest way to designate the next texture in the "preloaded_stimulus_list[]" for presentation without allocating more resources (and, consequently, adding delays)?

Here is the guilty code snippet:

    viewport = Viewport(screen=screen,
                        stimuli = [preloaded_stimulus_list[image_counter]]) #


cheers, gabe

p.s. Below is the fully "functional" code... yes, it's REALLY ugly (thereby emphasizing, by contrast, the elegance of the Presentation object)

*********************************

#!usr/bin/pythonw
# based on Andrew Straw's demo code
# http://www.freelists.org/archives/visionegg/11-2002/msg00001.html

from VisionEgg import *
start_default_logging(); watch_exceptions()

from VisionEgg.Core import *
from VisionEgg.FlowControl import Presentation, FunctionController
from VisionEgg.Textures import *
from pygame.time import *
import OpenGL.GL as gl

photoX = ("crate.bmp", "glass.bmp", "mud.bmp", "nehe.bmp", "star.bmp")

duration_per_image = 0.1 # seconds
num_images = len(photoX)

screen = get_default_screen()

# Create list of stimuli
preloaded_stimulus_list = [] # empty at first

for i in range(num_images):
     # Read the texture file
     texture = TextureFromFile(photoX[i])

     # Load the texture to OpenGL, prepare for display
     stimulus = TextureStimulus(texture = texture,
                                size    = texture.size,
                                texture_min_filter=gl.GL_LINEAR,

position=(screen.size[0]/2.0,screen.size[1]/2.0),
                                shrink_texture_ok=1)

     # Add to list of stimuli
     preloaded_stimulus_list.append( stimulus )

     #<debug>
     print "preloaded_stimulus_list = "
     print preloaded_stimulus_list
     #</debug>


def image_selector( t ): i = int(t/duration_per_image) return [ preloaded_stimulus_list[i] ]

###############################################
#
# <controller_version>
    #uncomment this section this section for original, working version
"""

p = Presentation(go_duration=(duration_per_image *
                              num_images,'seconds'),viewports=[viewport])
p.add_controller(viewport,'stimuli',
                 FunctionController(during_go_func=image_selector) )

p.go()

"""
# </controller_version>

###############################################
# comment this section for "controller" version
#
# <procedural_version>

frame_timer = FrameTimer()
msec_timer = get_ticks()


done = False

# show image 1

for trialcounter in range(1000):

# code to modify for loading file as appropriate image_counter = 0
viewport = Viewport(screen=screen,
stimuli = [preloaded_stimulus_list[image_counter]]) # doesn't work


    screen.clear()
    viewport.draw()
    swap_buffers()
    frame_timer.tick()

    image_counter = image_counter + 1


#delay(1000) # show image 2


viewport = Viewport(screen=screen,
stimuli = [preloaded_stimulus_list[image_counter]]) # doesn't work


    screen.clear()
    viewport.draw()
    swap_buffers()
    frame_timer.tick()
    image_counter = image_counter + 1

    #delay(1000)

# show image 3
viewport = Viewport(screen=screen,
stimuli = [preloaded_stimulus_list[image_counter]]) # doesn't work


    screen.clear()
    viewport.draw()
    swap_buffers()
    frame_timer.tick()
    image_counter = image_counter + 1


#delay(1000)
#show image 4
viewport = Viewport(screen=screen,
stimuli = [preloaded_stimulus_list[image_counter]]) # doesn't work


    screen.clear()
    viewport.draw()
    swap_buffers()
    frame_timer.tick()
    image_counter = image_counter + 1


#delay(1000)
#show image 5
viewport = Viewport(screen=screen,
stimuli = [preloaded_stimulus_list[image_counter]]) # doesn't work


    screen.clear()
    viewport.draw()
    swap_buffers()
    frame_timer.tick()
    #image_counter = image_counter + 1

# </procedural_version>
#
########################################

frame_timer.print_histogram()




======================================
The Vision Egg mailing list
Archives: http://www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html

====================================== The Vision Egg mailing list Archives: http://www.freelists.org/archives/visionegg Website: http://www.visionegg.org/mailinglist.html

Other related posts: