drawing multiple objects on screen efficiently?

HI,

I'm a beginner of psychotoolbox. In my multiple-object-tracking
experiment, I need to draw multiple squares on the screen and make
them move smoothly on every frame (for a demo, please see
http://www.yale.edu/perception/Brian/demos/MOT-Basics.html).

Currently, I'm using the 'Screen('FillRect') ...)' function to draw
squares. It works pretty good when the number of squares is smaller
than 12. However, when the number of objects exceeds 12, the displays
slow down and are not smooth any more. It seems that within the
duration of a single frame (less than 20 ms), matlab on my computer
can not finish drawing more than 12 objects.

I'm wondering if there is any way to conquer this limitation. For
instance, instead of drawing 12 new squares during every frame,let
matlab draws 12 objects off-line and just put them into different
spatial locations. However, as a beginner of psychotoolbox, I can not
solve this problem myself. It will be great if someone around here can
give me some suggestions.

Thanks in advance!

Tao
The drawing functions accept lists as arguments, and with one
functional call you can quickly draw multiple objects. See the help
to the FillRect function, i.e. Screen('FillRect?')

keith

On Oct 13, 2008, at 6:41 PM, tao.gao wrote:

> HI,
>
> I'm a beginner of psychotoolbox. In my multiple-object-tracking
> experiment, I need to draw multiple squares on the screen and make
> them move smoothly on every frame (for a demo, please see
> http://www.yale.edu/perception/Brian/demos/MOT-Basics.html).
>
> Currently, I'm using the 'Screen('FillRect') ...)' function to draw
> squares. It works pretty good when the number of squares is smaller
> than 12. However, when the number of objects exceeds 12, the displays
> slow down and are not smooth any more. It seems that within the
> duration of a single frame (less than 20 ms), matlab on my computer
> can not finish drawing more than 12 objects.
>
> I'm wondering if there is any way to conquer this limitation. For
> instance, instead of drawing 12 new squares during every frame,let
> matlab draws 12 objects off-line and just put them into different
> spatial locations. However, as a beginner of psychotoolbox, I can not
> solve this problem myself. It will be great if someone around here can
> give me some suggestions.
>
> Thanks in advance!
>
> Tao
>
>
>
> ------------------------------------
>
> Post your message to: psychtoolbox@yahoogroups.com
> Please indicate OS9, OSX, or WIN version, and include your full name.
> Denis Pelli, David Brainard, and Allen Ingling.
> http://psychtoolbox.org
> Yahoo! Groups Links
>
>
>
>
Keith proposal is demonstrated in DrawingSpeedTest.

However, even without that, drawing 12 objects shouldn't
take more than some 12 * 40 microseconds < 0.5 msecs,
even on very slow, old hardware.

Overhead of Matlab on a modern system is less
than 10 microseconds per call.

Are you sure you have proper graphics drivers
installed? Are there any warnings output?

-mario

--- In psychtoolbox@yahoogroups.com, Keith Schneider <ks@...> wrote:
>
> The drawing functions accept lists as arguments, and with one
> functional call you can quickly draw multiple objects. See the help
> to the FillRect function, i.e. Screen('FillRect?')
>
> keith
>
> On Oct 13, 2008, at 6:41 PM, tao.gao wrote:
>
> > HI,
> >
> > I'm a beginner of psychotoolbox. In my multiple-object-tracking
> > experiment, I need to draw multiple squares on the screen and make
> > them move smoothly on every frame (for a demo, please see
> > http://www.yale.edu/perception/Brian/demos/MOT-Basics.html).
> >
> > Currently, I'm using the 'Screen('FillRect') ...)' function to draw
> > squares. It works pretty good when the number of squares is smaller
> > than 12. However, when the number of objects exceeds 12, the displays
> > slow down and are not smooth any more. It seems that within the
> > duration of a single frame (less than 20 ms), matlab on my computer
> > can not finish drawing more than 12 objects.
> >
> > I'm wondering if there is any way to conquer this limitation. For
> > instance, instead of drawing 12 new squares during every frame,let
> > matlab draws 12 objects off-line and just put them into different
> > spatial locations. However, as a beginner of psychotoolbox, I can not
> > solve this problem myself. It will be great if someone around here can
> > give me some suggestions.
> >
> > Thanks in advance!
> >
> > Tao
> >
> >
> >
> > ------------------------------------
> >
> > Post your message to: psychtoolbox@yahoogroups.com
> > Please indicate OS9, OSX, or WIN version, and include your full name.
> > Denis Pelli, David Brainard, and Allen Ingling.
> > http://psychtoolbox.org
> > Yahoo! Groups Links
> >
> >
> >
> >
>
Hi,

Thanks very much for Mario and Keith's replies. I had played around
with the screen function during the last few days. In my code code,
when drawing 12 squares during a single frame, I called ' screen
('FrameSquare') ' 12 times. Now, following Keith's suggestion, I put
all the squares in an array and only call the screen function once.
The speed of drawing is significantly increased! Thanks a lot.

However, I do have a new question. In my following experiment, I need
to draw multiple irregular polygons on the screen. The screen function
I'm using now is 'screen('FillPoly'..)'. As drawing multiple squares,
I tried to put all the polygons into an array and draw them by calling
the screen function only once. I have tried several different ways to
put the vertexes of multiple polygons into an array. However, the
'FillPoly' functions seems can not read these vertexes.

Is there anyone can give some suggestions on how to increase the
efficiency of the 'FillPoly' function?

Thanks in advance.

Cheers
Tao

P.S. Mario, I'm pretty sure that my video card is OK and my code works
the same way on several different PCs. So it is unlikely to be a
hardware problem, unless there are some tips about how to use the
video card appropriately that I do not know.


--- In psychtoolbox@yahoogroups.com, "Mario Kleiner"
<mario.kleiner@...> wrote:
>
> Keith proposal is demonstrated in DrawingSpeedTest.
>
> However, even without that, drawing 12 objects shouldn't
> take more than some 12 * 40 microseconds < 0.5 msecs,
> even on very slow, old hardware.
>
> Overhead of Matlab on a modern system is less
> than 10 microseconds per call.
>
> Are you sure you have proper graphics drivers
> installed? Are there any warnings output?
>
> -mario
>
> --- In psychtoolbox@yahoogroups.com, Keith Schneider <ks@> wrote:
> >
> > The drawing functions accept lists as arguments, and with one
> > functional call you can quickly draw multiple objects. See the help
> > to the FillRect function, i.e. Screen('FillRect?')
> >
> > keith
> >
> > On Oct 13, 2008, at 6:41 PM, tao.gao wrote:
> >
> > > HI,
> > >
> > > I'm a beginner of psychotoolbox. In my multiple-object-tracking
> > > experiment, I need to draw multiple squares on the screen and make
> > > them move smoothly on every frame (for a demo, please see
> > > http://www.yale.edu/perception/Brian/demos/MOT-Basics.html).
> > >
> > > Currently, I'm using the 'Screen('FillRect') ...)' function to draw
> > > squares. It works pretty good when the number of squares is smaller
> > > than 12. However, when the number of objects exceeds 12, the
displays
> > > slow down and are not smooth any more. It seems that within the
> > > duration of a single frame (less than 20 ms), matlab on my computer
> > > can not finish drawing more than 12 objects.
> > >
> > > I'm wondering if there is any way to conquer this limitation. For
> > > instance, instead of drawing 12 new squares during every frame,let
> > > matlab draws 12 objects off-line and just put them into different
> > > spatial locations. However, as a beginner of psychotoolbox, I
can not
> > > solve this problem myself. It will be great if someone around
here can
> > > give me some suggestions.
> > >
> > > Thanks in advance!
> > >
> > > Tao
> > >
> > >
> > >
> > > ------------------------------------
> > >
> > > Post your message to: psychtoolbox@yahoogroups.com
> > > Please indicate OS9, OSX, or WIN version, and include your full
name.
> > > Denis Pelli, David Brainard, and Allen Ingling.
> > > http://psychtoolbox.org
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> >
>
Hi again,

> The speed of drawing is significantly increased! Thanks a lot.

If you run the DrawingSpeedTest([],[],1) benchmark, it will
tell you how many microseconds it took per rectangle to
draw. If your system works correctly, you should see around
2 microseconds per drawn rectangle on about 3 years old
hardware. If you see something much more than that,
something is wrong.

The line ...
"PTB-INFO: OpenGL-Renderer is XXXX ...."
should say something like "ATI Technologies Inc." or
"NVidia corporation" etc. If it says something like
"Microsoft software renderer..." you can be sure that
you don't have the graphics drivers properly set up or
installed and the system is just using a slow software
renderer.

What is the output of DrawingSpeedTest([],[],1)?

> Is there anyone can give some suggestions on how to increase the
> efficiency of the 'FillPoly' function?

'FillPoly' only accepts one polygon per call. But if
your system is set up properly, that shouldn't be
a big problem.

The only other explanation for low performance would
be that you have very old or unsuitable graphics hardware
installed.

-mario
Hi,Mario

Thanks very much for your suggestions. Here is the outcome from
DrawingSpeedTest([],[],1):


PTB-INFO: Using NVidia's GL_TEXTURE_RECTANGLE_NV extension for
efficient high-performance texture mapping...
Rendered 1000 frames, each with 800 rectangles of size 80 x 80.
Total time 3.283449 seconds. Time per rectangle 0.004104 msecs.

It seems that the feedback are pretty good. Could you let me know
where I could find the code of DrawingSpeedTest?I hope to go through
it but failed to find a file named `DrawingSpeedTest'.

Thanks a lot!

Cheers
Tao



--- In psychtoolbox@yahoogroups.com, "Mario Kleiner"
<mario.kleiner@...> wrote:
>
> Hi again,
>
> > The speed of drawing is significantly increased! Thanks a lot.
>
> If you run the DrawingSpeedTest([],[],1) benchmark, it will
> tell you how many microseconds it took per rectangle to
> draw. If your system works correctly, you should see around
> 2 microseconds per drawn rectangle on about 3 years old
> hardware. If you see something much more than that,
> something is wrong.
>
> The line ...
> "PTB-INFO: OpenGL-Renderer is XXXX ...."
> should say something like "ATI Technologies Inc." or
> "NVidia corporation" etc. If it says something like
> "Microsoft software renderer..." you can be sure that
> you don't have the graphics drivers properly set up or
> installed and the system is just using a slow software
> renderer.
>
> What is the output of DrawingSpeedTest([],[],1)?
>
> > Is there anyone can give some suggestions on how to increase the
> > efficiency of the 'FillPoly' function?
>
> 'FillPoly' only accepts one polygon per call. But if
> your system is set up properly, that shouldn't be
> a big problem.
>
> The only other explanation for low performance would
> be that you have very old or unsuitable graphics hardware
> installed.
>
> -mario
>
To find the code just type
which('DrawingSpeedTest')
at the Matlab command line. A useful, although dangerous if you are not
careful elaboration of this idea is
edit(which('DrawingSpeedTest'))
that immediate opens the file in an editor (where, if you are not careful,
you can make changes and overwrite the original source!).

Ted Wright

On Fri, 31 Oct 2008, tao.gao wrote:

> Hi,Mario
>
> Thanks very much for your suggestions. Here is the outcome from
> DrawingSpeedTest([],[],1):
>
>
> PTB-INFO: Using NVidia's GL_TEXTURE_RECTANGLE_NV extension for
> efficient high-performance texture mapping...
> Rendered 1000 frames, each with 800 rectangles of size 80 x 80.
> Total time 3.283449 seconds. Time per rectangle 0.004104 msecs.
>
> It seems that the feedback are pretty good. Could you let me know
> where I could find the code of DrawingSpeedTest?I hope to go through
> it but failed to find a file named `DrawingSpeedTest'.
>
> Thanks a lot!
>
> Cheers
> Tao
>
>
>
> --- In psychtoolbox@yahoogroups.com, "Mario Kleiner"
> <mario.kleiner@...> wrote:
>>
>> Hi again,
>>
>>> The speed of drawing is significantly increased! Thanks a lot.
>>
>> If you run the DrawingSpeedTest([],[],1) benchmark, it will
>> tell you how many microseconds it took per rectangle to
>> draw. If your system works correctly, you should see around
>> 2 microseconds per drawn rectangle on about 3 years old
>> hardware. If you see something much more than that,
>> something is wrong.
>>
>> The line ...
>> "PTB-INFO: OpenGL-Renderer is XXXX ...."
>> should say something like "ATI Technologies Inc." or
>> "NVidia corporation" etc. If it says something like
>> "Microsoft software renderer..." you can be sure that
>> you don't have the graphics drivers properly set up or
>> installed and the system is just using a slow software
>> renderer.
>>
>> What is the output of DrawingSpeedTest([],[],1)?
>>
>>> Is there anyone can give some suggestions on how to increase the
>>> efficiency of the 'FillPoly' function?
>>
>> 'FillPoly' only accepts one polygon per call. But if
>> your system is set up properly, that shouldn't be
>> a big problem.
>>
>> The only other explanation for low performance would
>> be that you have very old or unsuitable graphics hardware
>> installed.
>>
>> -mario
>>
>
>
>
>

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Hi,

Thanks for your help. Now I have went through code of
DrawingSPeedTest. It seems to me that this code draws multiple objects
by assigning them into an array and then calls the screen function
once to draw all of them. In this way, multiple objects can be
generated with pretty good efficiency.

Unfortunately, as I mentioned in my previous email, this method only
works for FillRect, FrameRect, FillOval and FrameOval. To draw
multiple irregular polygons (which is critical to my experiment), one
still needs to call the screen function multiple times.

Is there anyway to improve the speed of the 'FillPoly' function? For
example, calling the screen function once to draw multiple polygons?

Thanks a lot.

Tao


P.S. I have already tested the speed of my computer with the
"DrawingSPeedTest", and the feedback is pretty good. Here is the
feedback. Still, I can not draw 12 polygons smoothly on each frame by
calling the screen function 12 times per frame.

PTB-INFO: Using NVidia's GL_TEXTURE_RECTANGLE_NV extension for
efficient high-performance texture mapping...
Rendered 1000 frames, each with 800 rectangles of size 80 x 80.
Total time 3.283449 seconds. Time per rectangle 0.004104 msecs.





--- In psychtoolbox@yahoogroups.com, "Charles E. (Ted) Wright"
<cewright@...> wrote:
>
> To find the code just type
> which('DrawingSpeedTest')
> at the Matlab command line. A useful, although dangerous if you are not
> careful elaboration of this idea is
> edit(which('DrawingSpeedTest'))
> that immediate opens the file in an editor (where, if you are not
careful,
> you can make changes and overwrite the original source!).
>
> Ted Wright
>
> On Fri, 31 Oct 2008, tao.gao wrote:
>
> > Hi,Mario
> >
> > Thanks very much for your suggestions. Here is the outcome from
> > DrawingSpeedTest([],[],1):
> >
> >
> > PTB-INFO: Using NVidia's GL_TEXTURE_RECTANGLE_NV extension for
> > efficient high-performance texture mapping...
> > Rendered 1000 frames, each with 800 rectangles of size 80 x 80.
> > Total time 3.283449 seconds. Time per rectangle 0.004104 msecs.
> >
> > It seems that the feedback are pretty good. Could you let me know
> > where I could find the code of DrawingSpeedTest?I hope to
go through
> > it but failed to find a file named `DrawingSpeedTest'.
> >
> > Thanks a lot!
> >
> > Cheers
> > Tao
> >
> >
> >
> > --- In psychtoolbox@yahoogroups.com, "Mario Kleiner"
> > <mario.kleiner@> wrote:
> >>
> >> Hi again,
> >>
> >>> The speed of drawing is significantly increased! Thanks a lot.
> >>
> >> If you run the DrawingSpeedTest([],[],1) benchmark, it will
> >> tell you how many microseconds it took per rectangle to
> >> draw. If your system works correctly, you should see around
> >> 2 microseconds per drawn rectangle on about 3 years old
> >> hardware. If you see something much more than that,
> >> something is wrong.
> >>
> >> The line ...
> >> "PTB-INFO: OpenGL-Renderer is XXXX ...."
> >> should say something like "ATI Technologies Inc." or
> >> "NVidia corporation" etc. If it says something like
> >> "Microsoft software renderer..." you can be sure that
> >> you don't have the graphics drivers properly set up or
> >> installed and the system is just using a slow software
> >> renderer.
> >>
> >> What is the output of DrawingSpeedTest([],[],1)?
> >>
> >>> Is there anyone can give some suggestions on how to increase the
> >>> efficiency of the 'FillPoly' function?
> >>
> >> 'FillPoly' only accepts one polygon per call. But if
> >> your system is set up properly, that shouldn't be
> >> a big problem.
> >>
> >> The only other explanation for low performance would
> >> be that you have very old or unsuitable graphics hardware
> >> installed.
> >>
> >> -mario
> >>
> >
> >
> >
> >
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>