Stimulus Position
-
dsteines
- Posts: 16
- Joined: 23 Jan 2010, 17:19
Stimulus Position
Hello,
I am creating an application that positions the stimulus at a random location on the screen at each presentation of a new stimulus.
I am trying to modify the StimulusPresentation application to do this. Where is the position of the stimulus set?
Thank you for your help.
David
I am creating an application that positions the stimulus at a random location on the screen at each presentation of a new stimulus.
I am trying to modify the StimulusPresentation application to do this. Where is the position of the stimulus set?
Thank you for your help.
David
-
mellinger
- Posts: 1341
- Joined: 12 Feb 2003, 11:06
David,
for the StimulusPresentation task, stimuli are centered on the screen. The respective code is located in
src/core/Application/StimulusPresentation/StimulusPresentationTask.cpp,
function StimulusPresentationTask::OnInitialize().
There, in lines 348 to 352, a rectangle is defined for captions, and in line 369 to 373, one for icons, which is then applied in line 359 and 378, respectively.
The rectangle is defined by {left, top, right, bottom}, given in coordinate values between 0 and 1, where 0 is the feedback screen's left/top, and 1 is the feedback screen's right/bottom.
In addition to the stimulus' enclosing rectangle, there is an "AspectRatioMode" defined for each stimulus, which can be one of
AdjustNone,
AdjustWidth,
AdjustHeight,
AdjustBoth.
This defines whether width or height are adjusted to obtain the stimulus' original aspect ratio, or whether both are adjusted to obtain its original pixel size. Adjustment is done such that the original stimulus borders and the adjusted stimulus border share a common center.
For captions, the rectangle's left and right positions are both set to 0.5, which in conjunction with the aspect ratio mode of AdjustWidth leads to a centered stimulus. For icons, height is adjusted in a similar way.
More details may be found in the description of the ImageStimulus class at
http://www.bci2000.org/wiki/index.php/P ... ulus_Class
For your task at hand, it is probably best to override the OnStimulusBegin() method in the StimulusTask class, by adding a method declaration
to the StimulusPresentationTask class, and to provide an implementation that sets stimulus position to a random value:
More information can be found in the BCI2000 wiki describing the various C++ classes interacting in the StimulusPresentation module:
http://www.bci2000.org/wiki/index.php/P ... Task_Class
http://www.bci2000.org/wiki/index.php/P ... ulus_Class
http://www.bci2000.org/wiki/index.php/P ... nMap_Class
http://www.bci2000.org/wiki/index.php/P ... ulus_Class
HTH,
Juergen
for the StimulusPresentation task, stimuli are centered on the screen. The respective code is located in
src/core/Application/StimulusPresentation/StimulusPresentationTask.cpp,
function StimulusPresentationTask::OnInitialize().
There, in lines 348 to 352, a rectangle is defined for captions, and in line 369 to 373, one for icons, which is then applied in line 359 and 378, respectively.
The rectangle is defined by {left, top, right, bottom}, given in coordinate values between 0 and 1, where 0 is the feedback screen's left/top, and 1 is the feedback screen's right/bottom.
In addition to the stimulus' enclosing rectangle, there is an "AspectRatioMode" defined for each stimulus, which can be one of
AdjustNone,
AdjustWidth,
AdjustHeight,
AdjustBoth.
This defines whether width or height are adjusted to obtain the stimulus' original aspect ratio, or whether both are adjusted to obtain its original pixel size. Adjustment is done such that the original stimulus borders and the adjusted stimulus border share a common center.
For captions, the rectangle's left and right positions are both set to 0.5, which in conjunction with the aspect ratio mode of AdjustWidth leads to a centered stimulus. For icons, height is adjusted in a similar way.
More details may be found in the description of the ImageStimulus class at
http://www.bci2000.org/wiki/index.php/P ... ulus_Class
For your task at hand, it is probably best to override the OnStimulusBegin() method in the StimulusTask class, by adding a method declaration
Code: Select all
virtual void OnStimulusBegin( int stimulusCode );Code: Select all
void StimulusPresentationTask::OnStimulusBegin( int inStimulusCode )
{
// Use the BCI2000 RandomNumberGenerator to obtain random coordinates.
float x = RandomNumberGenerator( 1000 ) / 1000.0,
y = RandomNumberGenerator( 1000 ) / 1000.0;
// Create an empty rectangle at the desired position.
GUI::Rect rect = { x, y, x, y };
// Obtain the set of stimuli associated with the current stimulus code.
SetOfStimuli stimuli = Associations()[ inStimulusCode ].Stimuli();
// Iterate over the set to find the icon stimulus.
for( SetOfStimuli::iterator i = stimuli.begin(); i != stimuli.end(); ++i )
{
// Check whether the current stimulus is an image.
ImageStimulus* pImage = dynamic_cast<ImageStimulus*>( *i );
if( pImage != NULL )
// If it is an image, set its position to the desired one.
pImage->SetAspectRatioMode( GUI::AspectRatioModes::AdjustBoth )
.SetDisplayRect( rect );
}
StimulusTask::OnStimulusBegin( inStimulusCode );
}
http://www.bci2000.org/wiki/index.php/P ... Task_Class
http://www.bci2000.org/wiki/index.php/P ... ulus_Class
http://www.bci2000.org/wiki/index.php/P ... nMap_Class
http://www.bci2000.org/wiki/index.php/P ... ulus_Class
HTH,
Juergen
Last edited by mellinger on 03 Feb 2010, 11:38, edited 3 times in total.
-
dsteines
- Posts: 16
- Joined: 23 Jan 2010, 17:19
Thank you for the help, but I am still having some trouble with this. I override the OnStimulusBegin() method as you suggested using the code that you provided. Everything compiled fine, but the stimulus never appears. I added a call to pImage->Show() after I set the DisplayRect but that did not paint the object. I also tried calls to Invalidate and Paint. How do I get the image to appear?
Thanks,
David
Thanks,
David
-
mellinger
- Posts: 1341
- Joined: 12 Feb 2003, 11:06
David,
I forgot to call the ancestor class' OnStimulusBegin() at the end of the overridden method. Stimulus presentation is done there, by calling SetOfStimuli::Present().
I fixed the above code example.
Sorry,
Juergen
I forgot to call the ancestor class' OnStimulusBegin() at the end of the overridden method. Stimulus presentation is done there, by calling SetOfStimuli::Present().
I fixed the above code example.
Sorry,
Juergen
Last edited by mellinger on 03 Feb 2010, 10:50, edited 1 time in total.
-
dsteines
- Posts: 16
- Joined: 23 Jan 2010, 17:19
-
doug.davies
- Posts: 12
- Joined: 09 Jun 2011, 13:07
Re: Stimulus Position
Hi all,
I am currently working on an application which has the same functionality as described above, and the solution described in these posts does not seem to work for me. When I make the alterations to the StimulusPresentationTask code and run the module,the icons are not displayed on the screen but the audio stimuli continue to play. This is the only change I have made so far to the code downloaded to the repository, and the module functions correctly if I remove the two code statements from this post. Could something have changed in the code since the posts here that invalidates this solution?
Thank you,
Doug Davies
UC Berkeley
I am currently working on an application which has the same functionality as described above, and the solution described in these posts does not seem to work for me. When I make the alterations to the StimulusPresentationTask code and run the module,the icons are not displayed on the screen but the audio stimuli continue to play. This is the only change I have made so far to the code downloaded to the repository, and the module functions correctly if I remove the two code statements from this post. Could something have changed in the code since the posts here that invalidates this solution?
Thank you,
Doug Davies
UC Berkeley
-
mellinger
- Posts: 1341
- Joined: 12 Feb 2003, 11:06
Re: Stimulus Position
Hi,
there are more changes to the code suggested in my post above than just two statements. Rather, a new method declaration needs to be added to the StimulusPresentationTask header file, and the respective method definition needs to be added to the cpp file. The method definition consists of a number of statements.
Could this be a misunderstanding?
Regards,
Juergen
there are more changes to the code suggested in my post above than just two statements. Rather, a new method declaration needs to be added to the StimulusPresentationTask header file, and the respective method definition needs to be added to the cpp file. The method definition consists of a number of statements.
Could this be a misunderstanding?
Regards,
Juergen
-
doug.davies
- Posts: 12
- Joined: 09 Jun 2011, 13:07
Re: Stimulus Position
Juergen,
Thanks for you reply.
I do not believe that is the issue, I have made additions to both the header and source files as described here. The code compiles and runs correctly, except that the icon stimuli are not displayed. Audio stimuli and the captions are displayed correctly, however.
Any further thoughts are greatly appreciated.
Doug
Thanks for you reply.
I do not believe that is the issue, I have made additions to both the header and source files as described here. The code compiles and runs correctly, except that the icon stimuli are not displayed. Audio stimuli and the captions are displayed correctly, however.
Any further thoughts are greatly appreciated.
Doug
Who is online
Users browsing this forum: No registered users and 0 guests
