This repository has been archived by the owner on Oct 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
StandardStimuli.h
300 lines (251 loc) · 10.1 KB
/
StandardStimuli.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/**
* StandardStimuli.h
*
* Description:
*
* NOTE: All objects that inherit from Stimulus and contain pointer data
* must implement a copy constructor and a destructor. It is also advised to
* make a private = operator.
*
* History:
* Dave Cox on ??/??/?? - Created.
* Paul Jankunas on 05/23/05 - Fixed spacing. Added copy constructors,
* destructors, and = operator to object that are
* added to ExpandableLists.
*
* Copyright 2005 MIT. All rights reserved.
*/
#ifndef _STANDARD_STIMULI_H
#define _STANDARD_STIMULI_H
#include "Stimulus.h"
#include "Experiment.h"
#include "ComponentFactory.h"
namespace mw {
// a stimulus object with a position stored
// may still be an error here TODO because no destructor and copy
// constructor does nothing
class OffsetStimulusContainer : public Stimulus {
protected:
shared_ptr<Stimulus> stim;
shared_ptr<Variable> xoffset;
shared_ptr<Variable> yoffset;
public:
/**
* Constructor
*/
OffsetStimulusContainer(std::string _tag, shared_ptr<Stimulus> _stim);
OffsetStimulusContainer(std::string _tag, shared_ptr<Stimulus> _stim,
shared_ptr<Variable> _xdeg,
shared_ptr<Variable> _ydeg);
OffsetStimulusContainer(OffsetStimulusContainer& copy);
~OffsetStimulusContainer();
virtual Stimulus * frozenClone();
virtual void draw(StimulusDisplay * display, float x, float y);
virtual void draw(StimulusDisplay * display, float x, float y,
float sizex, float sizey);
private:
// do not use the assignment operator, it does nothing
// useful. I made it private to hide it from users and to
// prevent a default version from being used.
void operator=(const OffsetStimulusContainer& l) { }
};
// a stimulus object with a position stored
// this is the base object from which many others should derive
class BasicTransformStimulus : public Stimulus {
protected:
shared_ptr<Variable> xoffset;
shared_ptr<Variable> yoffset;
shared_ptr<Variable> xscale;
shared_ptr<Variable> yscale;
shared_ptr<Variable> rotation; // planar rotation added in for free
shared_ptr<Variable> alpha_multiplier;
// JJD added these July 2006 to keep track of what was actually done for announcing things
float last_posx, last_posy, last_sizex, last_sizey, last_rot;
public:
BasicTransformStimulus(std::string _tag,
shared_ptr<Variable> _xoffset,
shared_ptr<Variable> _yoffset,
shared_ptr<Variable> _xscale,
shared_ptr<Variable> _yscale,
shared_ptr<Variable> _rot,
shared_ptr<Variable> _alpha);
BasicTransformStimulus(const BasicTransformStimulus& tocopy);
~BasicTransformStimulus();
virtual Stimulus * frozenClone();
virtual void setTranslation(shared_ptr<Variable> _x,
shared_ptr<Variable> _y);
virtual void setScale(shared_ptr<Variable> _scale);
virtual void setScale(shared_ptr<Variable> _xscale,
shared_ptr<Variable> _yscale);
virtual void setRotation(shared_ptr<Variable> rot);
virtual void draw(StimulusDisplay * display);
virtual void draw(StimulusDisplay * display,float x, float y,
float sizex, float sizey);
virtual Datum getCurrentAnnounceDrawData();
virtual shared_ptr<Variable> getXScale(){ return xscale; }
virtual shared_ptr<Variable> getYScale(){ return yscale; }
virtual shared_ptr<Variable> getXOffset(){ return xoffset; }
virtual shared_ptr<Variable> getYOffset(){ return yoffset; }
};
class OpenGLImageLoader {
protected:
public:
static bool initialized;
static Lockable *lock;
static void initialize();
static GLuint load(std::string filename, StimulusDisplay *display,
int *width, int *height);
};
// Image file based stimulus
class ImageStimulus : public BasicTransformStimulus {
protected:
std::string filename;
vector<GLuint> texture_maps;
int width, height;
// for debugging
ConstantVariable *const0, *const2;
public:
ImageStimulus(std::string _tag, std::string filename,
shared_ptr<Variable> _xoffset,
shared_ptr<Variable> _yoffset,
shared_ptr<Variable> _xscale,
shared_ptr<Variable> _yscale,
shared_ptr<Variable> _rot,
shared_ptr<Variable> _alpha);
// constructor for cloning an existing image stimulus
ImageStimulus(std::string _tag, std::string _filename,
const vector<GLuint>& _texture_maps,
int _width,
int _height,
shared_ptr<Variable> _xoffset,
shared_ptr<Variable> _yoffset,
shared_ptr<Variable> _xscale,
shared_ptr<Variable> _yscale,
shared_ptr<Variable> _rot,
shared_ptr<Variable> _alpha);
ImageStimulus(ImageStimulus& copy);
virtual ~ImageStimulus();
virtual Stimulus * frozenClone();
std::string getFilename();
virtual void drawInUnitSquare(StimulusDisplay *display);
virtual void load(StimulusDisplay *display);
virtual Datum getCurrentAnnounceDrawData();
};
class ImageStimulusFactory : public ComponentFactory {
virtual shared_ptr<mw::Component> createObject(std::map<std::string, std::string> parameters,
ComponentRegistry *reg);
};
// Simple point (e.g. for fixation) - JJD started, but not clear how to implement JJD TODO
// the x and y units are in the ambient open GL space
// how to specify size ???
class PointStimulus : public BasicTransformStimulus {
protected:
shared_ptr<Variable> r;
shared_ptr<Variable> g;
shared_ptr<Variable> b;
float last_r,last_g,last_b;
public:
PointStimulus(std::string _tag, shared_ptr<Variable> _xoffset,
shared_ptr<Variable> _yoffset,
shared_ptr<Variable> _xscale,
shared_ptr<Variable> _yscale,
shared_ptr<Variable> _rot,
shared_ptr<Variable> _alpha,
shared_ptr<Variable> _r,
shared_ptr<Variable> _g,
shared_ptr<Variable> _b);
PointStimulus(const PointStimulus &tocopy);
~PointStimulus();
virtual Stimulus * frozenClone();
virtual void drawInUnitSquare(StimulusDisplay *display);
virtual Datum getCurrentAnnounceDrawData();
};
// default copy constructor is ok here even though we are managing
// a pointer to an Experiment. It is not needed to copy the entire
// experiment because there should only be one copy in memory
/*class FreeRunningMovieStimulus : public BasicTransformStimulus {
protected:
// needs to know what experiment it belongs to (kludgey but true!)
Experiment *experiment;
long nframes; // how many frames? negative numbers loop
long frame_interval_ms; // how long between frames?
int current_frame; // what frame are we on now?
long start_time;
// called internally to set the frame number before
// other draw functions are called
void setCurrentFrame();
bool running;
ScheduleTask *schedule_node;
public:
FreeRunningMovieStimulus(char *_tag, long nframes=1, long frame_interval=16,
float _xoffset=0, float _yoffset=0,
float _xscale=1.0, float _yscale = 1.0,
float _rot = 0.0);
// set the frame and then go on as normal
virtual void draw(StimulusDisplay * display);
// overload this to provide teeth
virtual void drawInUnitSquare(shared_ptr<StimulusDisplay> display);
virtual void draw(StimulusDisplay * display,float x, float y,
float sizex, float sizey);
// start/stop rolling when this is called
virtual void setVisible(bool vis);
};*/
// CompoundStimulus: a stimulus made up of several registered sub-stimuli
// ExpandableList being private means that you cannot call any of the
// expandable list methods outside of the implementation.
class CompoundStimulus : public Stimulus {
protected:
ExpandableList<OffsetStimulusContainer> *stimList;
std::string currentSubTag;
public:
CompoundStimulus(std::string _tag);
~CompoundStimulus();
virtual Stimulus * frozenClone();
void addStimulus(shared_ptr<Stimulus> stim);
void addStimulus(shared_ptr<Stimulus> stim,
shared_ptr<Variable> _xloc,
shared_ptr<Variable> _yloc);
virtual void draw(StimulusDisplay * display,
float xdeg, float ydeg);
void makeSubTag();
virtual void announceStimulusDraw(MWTime now); // override of base class method
};
class BlankScreen : public Stimulus{
// the default copy constructor is ok for this object.
// Variable(const Param& that) : r(that.r), g(that.g), b(that.b) { }
protected:
shared_ptr<Variable> r;
shared_ptr<Variable> g;
shared_ptr<Variable> b;
float last_r,last_g,last_b;
public:
BlankScreen(std::string _tag,
shared_ptr<Variable> r,
shared_ptr<Variable> g,
shared_ptr<Variable> b);
virtual ~BlankScreen();
virtual Stimulus * frozenClone();
virtual void drawInUnitSquare(StimulusDisplay *display);
virtual Datum getCurrentAnnounceDrawData();
};
class BlankScreenFactory : public ComponentFactory {
virtual shared_ptr<mw::Component> createObject(std::map<std::string, std::string> parameters,
ComponentRegistry *reg);
};
/*class VideoRequest {
protected:
StimID stimtodraw;
Datum xloc;
Datum yloc;
public:
VideoRequest(StimID _stim, Datum _x, Datum _y) {
stimtodraw = _stim;
xloc = _x;
yloc = _y;
}
virtual ~VideoRequest() { }
virtual void service();
};
void videoInterruptService();*/
}
#endif