[visionegg] Re: RDS with gratings
- From: Inna Tsirlin <innkat@xxxxxxxxx>
- To: visionegg@xxxxxxxxxxxxx
- Date: Thu, 12 May 2005 11:00:01 -0400
Hi, thank you for your reply,
> Dear Inna, It's difficult to guess what exactly is going on unless you
> post the code...
Yes of course :). Below is the code of the modified class. It is
pretty simple. In addition to _init_() and draw() methods I added
shift() which shifts the dots by a certain amount which can be a
double ( so that a shift by 1.5 pixels is possible). The class which
is using GratingRDS is too long to add here, but all it does is
displays the GratingRDS object on a viewport and then on a key stroke
shifts the objects by a certain amount.
Thank you again,
Inna.
class GratingRDS(VisionEgg.Core.Stimulus):
parameters_and_defaults = {
'on' : ( True,
ve_types.Boolean ),
'position' : ( ( 512, 384 ), # in eye coordinates, for 1024x768
ve_types.Sequence2(ve_types.UnsignedInteger) ),
'anchor' : ('center',
ve_types.String),
'size' : ( ( 300, 300 ), # in eye coordinates
ve_types.Sequence2(ve_types.UnsignedInteger) ),
'color' : ((1.0,1.0,1.0),
ve_types.AnyOf(ve_types.Sequence3(ve_types.Real),
ve_types.Sequence4(ve_types.Real))),
'dot_size' : (4, # pixels
ve_types.UnsignedInteger),
'depth' : ( None, # set for depth testing
ve_types.Real ),
'center' : (None, # DEPRECATED -- don't use
ve_types.Sequence2(ve_types.Real),
"",
VisionEgg.ParameterDefinition.DEPRECATED),
'num_dots' : ( 100,
ve_types.UnsignedInteger ),
}
__slots__ = (
'x_positions',
'y_positions',
'dots',
'_gave_alpha_warning',
)
def __init__(self, **kw):
VisionEgg.Core.Stimulus.__init__(self,**kw)
num_dots = self.parameters.num_dots # shorthand
self.dots = []
dot_size = self.parameters.dot_size # shorthand
self.x_positions = zeros((num_dots,))
self.y_positions = zeros((num_dots,))
self.x_orig = zeros((num_dots,)) # before adding disparity.
self.y_orig = zeros((num_dots,)) # added by Yuichi Sakano
self._gave_alpha_warning = 0
for i in range (num_dots):
grating = SinGrating2D(
position = (
self.x_positions[i], self.y_positions[i] ),
size =
(dot_size+2 , dot_size),
phase_at_t0 = -30.0,
spatial_freq =
1.0/(dot_size*2),
temporal_freq_hz = 0.0,
orientation = 180.0)
self.dots.append(grating)
def shift(self, amount):
initial_phase = -30
parts = math.modf(amount)
final_parts = [parts[0], parts[1]]
if parts[0] != 0:
pixel_phase = 180/self.parameters.dot_size
curr_shift = abs(initial_phase -
self.dots[0].parameters.phase_at_t0)
future_shift = curr_shift + parts[0]*pixel_phase
if future_shift >= pixel_phase:
shift_parts = [future_shift -
int(future_shift/pixel_phase)*pixel_phase,
int(future_shift/pixel_phase)]
final_parts[0], final_parts[1] =
shift_parts[0], parts[1] + shift_parts[1]
for x in self.dots:
x.set(phase_at_t0 = initial_phase +
final_parts[0]*pixel_phase)
print final_parts
self.parameters.position = [self.parameters.position[0]
+ int(final_parts[1]), self.parameters.position[1]]
def draw(self):
p = self.parameters # shorthand
if p.center is not None:
p.anchor = 'center'
p.position = p.center[0], p.center[1] # copy
values (don't copy ref to tuple)
if p.on:
center =
VisionEgg._get_center(p.position,p.anchor,p.size)
num_dots = self.parameters.num_dots # shorthand
i = 0
xs = self.x_positions + center[0] - p.size[0]/2
ys = self.y_positions + center[1] - p.size[1]/2
for x in self.dots:
x.set(position = [xs[i], ys[i]])
i = i +1
x.draw()
=====================================The Vision Egg mailing list
Archives: http://www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html
- Follow-Ups:
- [visionegg] Re: RDS with gratings
- From: Andrew Straw
- References:
- [visionegg] RDS with gratings
- From: Inna Tsirlin
- [visionegg] Re: RDS with gratings
- From: Andrew Straw
Other related posts:
- » [visionegg] RDS with gratings
- » [visionegg] Re: RDS with gratings
- » [visionegg] Re: RDS with gratings
- » [visionegg] Re: RDS with gratings
- » [visionegg] Re: RDS with gratings
- [visionegg] Re: RDS with gratings
- From: Andrew Straw
- [visionegg] RDS with gratings
- From: Inna Tsirlin
- [visionegg] Re: RDS with gratings
- From: Andrew Straw