Jump to content

Programming Reference:ApplicationBase Class: Difference between revisions

From BCI2000 Wiki
Mellinger (talk | contribs)
 
(14 intermediate revisions by one other user not shown)
Line 5: Line 5:
The <tt>ApplicationBase</tt> class bundles base functionality which is useful for any BCI2000 application module. This base functionality comprises
The <tt>ApplicationBase</tt> class bundles base functionality which is useful for any BCI2000 application module. This base functionality comprises
*generation of random numbers,
*generation of random numbers,
*maintaining an application log file, and application log messages to the operator user,
*maintaining an application log file, and application log messages to the operator user.
*parameterization of application screen position and dimensions,
*display of a small copy of the application screen in an [[User_Reference:Operator_Module#Visualization_Windows|operator visualization window]].


==Usage==
==Usage==
An application module uses the <tt>ApplicationBase</tt> class by deriving its [[BCI2000Glossary:#task|task filter]] from <tt>ApplicationBase</tt> rather than <tt>GenericFilter</tt> directly. It has then access to the facilities explained below.
An application module uses the <tt>ApplicationBase</tt> class by deriving its [[BCI2000 Glossary#Task|task filter]] from <tt>ApplicationBase</tt> rather than <tt>GenericFilter</tt> directly. It has then access to the facilities explained below.
 
==Access to Application Windows==
The <tt>ApplicationBase</tt> class inherits from the [[Programming Reference:ApplicationWindowClient Class|<tt>ApplicationWindowClient</tt> class]], and thus provides access to framework-managed [[Programming Reference:ApplicationWindow Class|application windows]].
To access, and possibly create, the main application window from your <tt>ApplicationBase</tt>-derived application filter class, initialize an <tt>ApplicationWindow</tt> reference in its constructor with the <tt>ApplicationWindowClient::Window()</tt> function:
<pre>
class MyTaskFilter : public ApplicationBase
{
    ...
  private:
    ApplicationWindow& mrWindow;
    ...
};
 
MyTaskFilter::MyTaskFilter()
: mrWindow( ApplicationWindowClient::Window() )
{
  ...
}
 
MyTaskFilter::Initialize( ... )
{
  ...
  ImageStimulus* pImageStimulus = new ImageStimulus( mrWindow );
  ...
}
</pre>
You may also test windows for existence from the <tt>Preflight()</tt> function, and only use them when they already exist. This way, your code can adapt to the presence of certain filters in the application module. For more details, see the [[Programming Reference:ApplicationWindowClient Class|<tt>ApplicationWindowClient</tt> class]] reference page.


==RandomNumberGenerator==
==RandomNumberGenerator==
Line 24: Line 49:
The <tt>ApplicationBase</tt> class provides an object named <tt>AppLog</tt> as a convenient interface to write messages to screen, log file, or both at the same time. That <tt>AppLog</tt> object uses a [[Programming Reference:LogFile Class|<tt>LogFile</tt>]] object to write into a log file; it uses a [[Programming Reference:GenericVisualization Class|<tt>GenericVisualization</tt>]] object to write messages into an operator window.
The <tt>ApplicationBase</tt> class provides an object named <tt>AppLog</tt> as a convenient interface to write messages to screen, log file, or both at the same time. That <tt>AppLog</tt> object uses a [[Programming Reference:LogFile Class|<tt>LogFile</tt>]] object to write into a log file; it uses a [[Programming Reference:GenericVisualization Class|<tt>GenericVisualization</tt>]] object to write messages into an operator window.


The <tt>AppLog</tt> object is used as a <tt><std::ostream></tt> as in the following examples:
The <tt>AppLog</tt> object is a <tt><std::ostream></tt>, and may be used as in the following examples:
  // Write a message to the log file only:
  // Write a message to the log file only
  AppLog.File << "This message goes into the log file." << endl;
  AppLog.File << "This message goes into the log file." << endl;
  // Write a message to the screen only:
 
  // Write a message to the screen only
  AppLog.Screen << "This message goes into an operator window." << endl;
  AppLog.Screen << "This message goes into an operator window." << endl;
  // Write a message to both screen and file:
  // Write a message to both screen and file:
  AppLog << "This message is displayed by the operator module, and written into the log file." << endl;
  AppLog << "This message is displayed by the operator module, and written into the log file." << endl;
Make sure to include the "endl" as nothing is written until the AppLog receives a newline command.


The application log file is located in the current session directory, and named after the current session; it carries an '''.applog''' extension.
The application log file is located in the current session directory, and named after the current session; it carries an '''.applog''' extension.


Operator log window messages have ''APLG'' as their [[Technical Specification:BCI2000 messages|visualization source ID]].
Operator log window messages have ''APLG'' as their [[Technical Reference:BCI2000 Messages|visualization source ID]].
 
 
==Display Parameterization and Visualization==
Typically, a BCI2000 application module displays feedback or other stimuli in an application window. In the GUI abstraction layer of the BCI2000 framework, the application window's drawing area is represented as an object that inherits the [[Programming Reference:GUI:GraphDisplay Class|<tt>GUI::GraphDisplay</tt>]] interface.
 
When a derived class provides its underlying <tt>ApplicationBase</tt> with a <tt>GUI::GraphDisplay</tt> pointer at construction time, the <tt>ApplicationBase</tt> class will handle display visualization transparently.
The <tt>ApplicationBase</tt> class uses the <tt>GraphDisplay</tt>'s <tt>BitmapData</tt> method to obtain a copy of its contents, and to send these to the operator module for display in a visualization window using a message source ID of ''APSC''.
 
==Parameters==
===Application Window Properties===
{{ApplicationBaseParams}}
 
===Application Window Visualization===
Visualization parameters are available only if the descendant class provides a <tt>GUI::GraphDisplay</tt> pointer at construction time.
====VisualizeApplicationWindow====
Switches visualization display of a miniature copy of the application window on or off.
==== AppWindowSpatialDecimation====
A factor that determines resolution of visualized data in relation to the original window's size.
Enlarging the factor reduces the visualization window's resolution, and its initial size, and improves system timing by reducing the amount of data transferred.
====AppWindowTemporalDecimation====
A factor that determines the visualization window's update rate. A value of ''n'' results in each ''n''th sample being transferred.
 


==Remarks==
==Remarks==
Typically, a BCI2000 application will fall into one of two categories:
Typically, a BCI2000 application module will implement a paradigm that belongs to one of two categories:
*[[Programming Reference:StimulusPresentationTask Class|Stimulus Presentation]] (evoked potential paradigms), or
*evoking responses using stimulus presentation,
*[[Programming Reference:FeedbackTask Class|Feedback Presentation]] (continuous feedback paradigms).
*continuously presenting feedback of brain activity.
A BCI2000 task filter implementing one of these paradigms will not inherit from the <tt>ApplicationBase</tt> directly but either from the [[Programming Reference:StimulusPresentationTask Class|StimulusPresentationTask]] or [[Programming Reference:FeedbackTask Class|FeedbackTask]]. Still, such a task filter has access to all functionality provided by <tt>ApplicationBase</tt>.
A BCI2000 task filter implementing one of these paradigms will not inherit from the <tt>ApplicationBase</tt> directly but either from the [[Programming Reference:StimulusTask Class|StimulusTask]] or [[Programming Reference:FeedbackTask Class|FeedbackTask]].
Still, such a task filter has access to all functionality provided by <tt>ApplicationBase</tt>.


==See also==
==See also==
[[Programming Reference:StimulusPresentationTask Class]], [[Programming Reference:FeedbackTask Class]]
[[Programming Reference:StimulusTask Class]], [[Programming Reference:FeedbackTask Class]], [[Programming Reference:ApplicationWindowClient Class]]
 


[[Category:Framework API]][[Category:Development]]
[[Category:Framework API]][[Category:Development]]

Latest revision as of 18:39, 10 February 2012

Location

BCI2000/src/shared/modules/application

Synopsis

The ApplicationBase class bundles base functionality which is useful for any BCI2000 application module. This base functionality comprises

  • generation of random numbers,
  • maintaining an application log file, and application log messages to the operator user.

Usage

An application module uses the ApplicationBase class by deriving its task filter from ApplicationBase rather than GenericFilter directly. It has then access to the facilities explained below.

Access to Application Windows

The ApplicationBase class inherits from the ApplicationWindowClient class, and thus provides access to framework-managed application windows. To access, and possibly create, the main application window from your ApplicationBase-derived application filter class, initialize an ApplicationWindow reference in its constructor with the ApplicationWindowClient::Window() function:

 class MyTaskFilter : public ApplicationBase
 {
    ...
   private:
    ApplicationWindow& mrWindow;
    ...
 };

 MyTaskFilter::MyTaskFilter()
 : mrWindow( ApplicationWindowClient::Window() )
 {
   ...
 }

 MyTaskFilter::Initialize( ... )
 {
   ...
   ImageStimulus* pImageStimulus = new ImageStimulus( mrWindow );
   ...
 }

You may also test windows for existence from the Preflight() function, and only use them when they already exist. This way, your code can adapt to the presence of certain filters in the application module. For more details, see the ApplicationWindowClient class reference page.

RandomNumberGenerator

The ApplicationBase class provides an object of type RandomGenerator which may be used to obtain integer pseudo-random numbers uniformly distributed over a specified range:

int rnd = RandomNumberGenerator(10);

will assign a number between 0 and 9 to the variable named "rnd". Compared with other options to obtain pseudo-random numbers, the advantage of using ApplicationBase::RandomNumberGenerator object is that its behavior is governed by a global random seed value; this allows consistent, predictable BCI2000 behavior, e.g. for testing purposes. For more information, refer to the RandomGenerator reference page.

Application Log

Typically, a BCI2000 application module displays messages to the operator user to indicate that a new trial has started, a target has been hit or missed, or to display statistics about the current run. Often, this is information, in conjunction with additional, more detailed information is written into a log file, and that log file is maintained side-by-side with recorded data in the current session directory.

The ApplicationBase class provides an object named AppLog as a convenient interface to write messages to screen, log file, or both at the same time. That AppLog object uses a LogFile object to write into a log file; it uses a GenericVisualization object to write messages into an operator window.

The AppLog object is a <std::ostream>, and may be used as in the following examples:

// Write a message to the log file only
AppLog.File << "This message goes into the log file." << endl;
// Write a message to the screen only
AppLog.Screen << "This message goes into an operator window." << endl;
// Write a message to both screen and file:
AppLog << "This message is displayed by the operator module, and written into the log file." << endl;

Make sure to include the "endl" as nothing is written until the AppLog receives a newline command.

The application log file is located in the current session directory, and named after the current session; it carries an .applog extension.

Operator log window messages have APLG as their visualization source ID.

Remarks

Typically, a BCI2000 application module will implement a paradigm that belongs to one of two categories:

  • evoking responses using stimulus presentation,
  • continuously presenting feedback of brain activity.

A BCI2000 task filter implementing one of these paradigms will not inherit from the ApplicationBase directly but either from the StimulusTask or FeedbackTask. Still, such a task filter has access to all functionality provided by ApplicationBase.

See also

Programming Reference:StimulusTask Class, Programming Reference:FeedbackTask Class, Programming Reference:ApplicationWindowClient Class