gaze  0.1.0
Perform gaze tracking with common webcams.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
Public Member Functions | Static Public Member Functions | List of all members
wpl::Experiment Class Reference

Implements an experiment flow for Judd et al. (2009) Judd2009. More...

#include "where_people_look/experiment.h"

Public Member Functions

 Experiment (GtkImage *const image, Config *const config)
 
Configget_config ()
 
Experiment usage
void prepare ()
 
void start ()
 
You should not call this manually.
Todo:
shoeffner: Maybe this should become private?
bool trial ()
 

Static Public Member Functions

static gboolean experiment_calibrate (gpointer experiment)
 
static gboolean experiment_trial (gpointer experiment)
 
static gboolean experiment_quit_program (gpointer experiment)
 
static bool experiment_prepare (const GtkWidget *const assistant, Experiment *const experiment)
 
static bool experiment_start (const GtkWidget *const window, const GdkEventKey *const event_key, Experiment *const experiment)
 

Detailed Description

Implements an experiment flow for Judd et al. (2009) Judd2009.

The data acquisition experiment can be prepared, started, quitted, and is divided into trials.

Using this class

The experiment should first be prepared (prepare()), then started (start()). After that, it will go through each available trial, recalibrate every 50 trials, and stop after all trials are done.

Each trial lasts three seconds and there are pauses of one second between the trials, during which a gray screen is shown.

Before the first and after the last trial there is another two seconds break.

Note
Many static functions are just created to allow G_CALLBACK to call them with appropriate Experiment instances. For example, Experiment::experiment_trial calls trial() on the provided experiment. However, some do extra checking: Experiment::experiment_start will only start the experiment if the space key was pressed and the experiment is not yet running.

Definition at line 45 of file experiment.h.

Constructor & Destructor Documentation

wpl::Experiment::Experiment ( GtkImage *const  image,
Config *const  config 
)

Constructs an experiment.

Parameters
imageThe GtkImage* to be updated for each trial.
configThe configuration. It is used to find the stimuli.

Definition at line 48 of file experiment.cpp.

49  : config(config),
50  gaze_tracker(new gaze::GazeTracker()),
51  image(image) {
52 }
This class wraps the gaze tracking process.
Definition: gaze_tracker.h:24

Member Function Documentation

gboolean wpl::Experiment::experiment_calibrate ( gpointer  experiment)
static

Calibrates the GazeTracker of the specified experiment.

Parameters
experimentMust be a gpointer to an Experiment.
Returns
false

Definition at line 104 of file experiment.cpp.

Referenced by trial().

104  {
105  Experiment* exp = static_cast<Experiment*>(experiment);
106  exp->is_calibrating = false;
107  exp->gaze_tracker->calibrate();
108  return false;
109 }
Experiment(GtkImage *const image, Config *const config)
Definition: experiment.cpp:48
complex< _Tp > exp(const complex< _Tp > &)
bool wpl::Experiment::experiment_prepare ( const GtkWidget *const  assistant,
Experiment *const  experiment 
)
static

Calls prepare() on the given experiment.

Parameters
assistantThis widget is ignored but needed to bind the G_CALLBACK properly.
experimentMust be a gpointer to an Experiment.
Returns
false

Definition at line 123 of file experiment.cpp.

References prepare().

124  {
125  experiment->prepare();
126  return false;
127 }
gboolean wpl::Experiment::experiment_quit_program ( gpointer  experiment)
static

Gets the ancestor window of the experiment's image (see Experiment(GtkImage*,Config*)) and issues a destroy signal.

Parameters
experimentMust be a gpointer to an Experiment.
Returns
false

Definition at line 111 of file experiment.cpp.

Referenced by trial().

111  {
112  Experiment* exp = static_cast<Experiment*>(experiment);
113  GtkWidget* window = gtk_widget_get_ancestor(GTK_WIDGET(exp->image),
114  GTK_TYPE_WINDOW);
115  g_signal_emit_by_name(window, "destroy");
116  return false;
117 }
Experiment(GtkImage *const image, Config *const config)
Definition: experiment.cpp:48
complex< _Tp > exp(const complex< _Tp > &)
bool wpl::Experiment::experiment_start ( const GtkWidget *const  window,
const GdkEventKey *const  event_key,
Experiment *const  experiment 
)
static

Calls start() on the given experiment if the space key is event_key's keyval and the experiment is not started.

Parameters
windowThis widget is ignored but needed to bind the G_CALLBACK properly.
event_keyThe event key to process.
experimentMust be a gpointer to an Experiment.
Returns
false

Definition at line 129 of file experiment.cpp.

References start().

131  {
132  if (event_key->keyval == GDK_KEY_space) {
133  if (!experiment->is_started) {
134  experiment->start();
135  }
136  }
137  return false;
138 }
gboolean wpl::Experiment::experiment_trial ( gpointer  experiment)
static

Calls trial() on the given experiment.

Parameters
experimentMust be a gpointer to an Experiment.
Returns
false

Definition at line 119 of file experiment.cpp.

References trial().

Referenced by start(), and trial().

119  {
120  return static_cast<Experiment*>(experiment)->trial();
121 }
Experiment(GtkImage *const image, Config *const config)
Definition: experiment.cpp:48
Config * wpl::Experiment::get_config ( )
Returns
a pointer to this experiment's config.

Definition at line 57 of file experiment.cpp.

57  {
58  return this->config;
59 }
void wpl::Experiment::prepare ( )

Prepares the experiment.

Preparations performed are

  • GazeTracker initialization
  • Stimuli list generation

Definition at line 61 of file experiment.cpp.

References lock().

Referenced by experiment_prepare().

61  {
62  std::lock_guard<std::mutex> lock(this->mutex);
63  if (this->is_prepared) {
64  return;
65  }
66  this->init_gaze_tracker();
67  this->read_stimuli_list();
68  this->is_prepared = true;
69 }
void lock(_L1 &__l1, _L2 &__l2, _L3 &...__l3)
void wpl::Experiment::start ( )

Starts the experiment. After a warmup time, the first trial starts.

If this function is called on a started experiment, it simply returns.

Definition at line 71 of file experiment.cpp.

References experiment_trial(), and lock().

Referenced by experiment_start().

71  {
72  std::lock_guard<std::mutex> lock(this->mutex);
73  if (this->is_started) {
74  return;
75  }
76  g_timeout_add(this->warmup, Experiment::experiment_trial, this);
77  this->is_started = true;
78 }
static gboolean experiment_trial(gpointer experiment)
Definition: experiment.cpp:119
void lock(_L1 &__l1, _L2 &__l2, _L3 &...__l3)
bool wpl::Experiment::trial ( )

Handles trials.

This function should not be called manually.

If a calibration is needed (because of the 50-trials-then-recalibrate setting), this calls the calibration function and polls itself every 500 millisecondss to try to continue the experiment with the next trial.

If a calibration is already (or still) in progress, this simply returns true to trigger another test.

If there are no trials left, this issues a program quit after two seconds.

Only if no calibration needs to be done or is in progress, and there are still trials left, an actual trial is started: A stimulus is presented for three seconds, followed by a one second pause. This trial function issues a new trial to be performed afterwards and returns false to not poll itself again.

Returns
true for retries during calibration, false otherwise.

Definition at line 80 of file experiment.cpp.

References experiment_calibrate(), experiment_quit_program(), experiment_trial(), and lock().

Referenced by experiment_trial().

80  {
81  std::lock_guard<std::mutex> lock(this->mutex);
82  if (this->is_calibrating) {
83  return true;
84  }
85  if (this->calibration_countdown-- == 0) {
86  this->is_calibrating = true;
87  this->calibration_countdown = this->calibration_after;
88  g_timeout_add(0, Experiment::experiment_calibrate, this);
89  g_timeout_add(500, Experiment::experiment_trial, this);
90  } else {
91  if (!this->trials.empty()) {
92  g_timeout_add(0, Experiment::experiment_start_trial, this);
93  g_timeout_add(this->trial_duration, Experiment::experiment_stop_trial,
94  this);
95  g_timeout_add(this->trial_duration + this->pause_duration,
97  } else {
98  g_timeout_add(this->cooldown, Experiment::experiment_quit_program, this);
99  }
100  }
101  return false;
102 }
static gboolean experiment_trial(gpointer experiment)
Definition: experiment.cpp:119
void lock(_L1 &__l1, _L2 &__l2, _L3 &...__l3)
static gboolean experiment_calibrate(gpointer experiment)
Definition: experiment.cpp:104
static gboolean experiment_quit_program(gpointer experiment)
Definition: experiment.cpp:111

The documentation for this class was generated from the following files: