input.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. #ifndef _HPP_INPUT
  2. #define _HPP_INPUT
  3. #include "libcsim.hpp"
  4. #include "layer.hpp"
  5. #include "objmovie.hpp"
  6. #include "stimulussequence.hpp"
  7. #include "tinyxml.h"
  8. enum InputMode {
  9. csimInputDefault,
  10. csimInputTest,
  11. csimInputRemote,
  12. csimInputRandom,
  13. csimInputRandomSequence,
  14. csimInputDirect,
  15. csimInputSaccades,
  16. csimInputSaccTest,
  17. csimInputSlideWinPic,
  18. csimInputPlayMovie,
  19. csimInputSequence
  20. };
  21. InputMode InputModeFromString(std::string modeString);
  22. class InputSynchronizer; // forward declaration
  23. /*! \brief input is a base class for input objects
  24. *
  25. *
  26. *
  27. */
  28. class input : public SimElement {
  29. protected:
  30. layer *Target;
  31. string FileName;
  32. int *RecordBuffer;
  33. csimInputChannel InputNumber;
  34. StimulusSequence* StimSeq;
  35. float *InputPointer;
  36. float Strength;
  37. int Size, Start, Stop;
  38. int CurStimNr; // is used for indexing stimulus arrays, starts with 0
  39. bool ResetToBeDone;
  40. InputMode mode;
  41. InputSynchronizer* inpsync;
  42. bool mSilent;
  43. public:
  44. input(layer* tg, csimInputChannel InputNumber=csimInputChannel_AMPA, float strength=1.0, int size=100, int start=0);
  45. ~input();
  46. virtual int proceede(int TotalTime=0);
  47. virtual int prepare(int StepNum=0);
  48. virtual int GetCurStimNr();
  49. virtual int GetLastStim(); // returns CurStimNr+1 or 0 for isi
  50. virtual int GetNStimuli();
  51. virtual int SetInputSync(InputSynchronizer* _inpsync);
  52. virtual void SetMode(InputMode _mode);
  53. virtual int WriteSimInfo(fstream &fw);
  54. virtual int WriteSimInfo(fstream &fw, const string &ChildInfo);
  55. virtual void SetInputStrength(float _Strength) {Strength=_Strength;};
  56. virtual void setSilent(bool Silent) {mSilent=Silent;}
  57. bool isi;
  58. };
  59. typedef map<int,int> ResponseMap;
  60. class InputSynchronizer {
  61. input* Master;
  62. ResponseMap* rmap;
  63. public:
  64. InputSynchronizer(input* _Master, ResponseMap* _rmap=0);
  65. int GetRemoteStimNr();
  66. };
  67. // for linear input sequences that can run in two directions (forward and backward)
  68. class BidirSequenceInput {
  69. protected:
  70. int Direction;
  71. public:
  72. BidirSequenceInput();
  73. void RandomDir();
  74. void ChangeDir();
  75. };
  76. class SequenceInput: public input, public BidirSequenceInput {
  77. float Overlap;
  78. int Duration;
  79. int NumPatterns;
  80. int PtPointer, Hold, PtShift;
  81. public:
  82. SequenceInput(layer* tg, csimInputChannel InputNumber=csimInputChannel_AMPA, float strength=1, int size=10, int numpt=10, float ov=0.5, int dur=100);
  83. ~SequenceInput();
  84. virtual int proceede(int TotalTime=0);
  85. };
  86. class PatternSequenceInput: public input, public BidirSequenceInput {
  87. float Overlap;
  88. int Duration;
  89. int NumPatterns;
  90. int PatternSize;
  91. int PtPointer, Hold, PtShift;
  92. int **PatternArray;
  93. public:
  94. PatternSequenceInput(layer* tg, csimInputChannel InputNumber=csimInputChannel_AMPA, float strength=1, int size=10, int _PtStart=0, int numpt=10, float ov=0.5, int dur=100);
  95. ~PatternSequenceInput();
  96. virtual int proceede(int TotalTime=0);
  97. virtual void Jump();
  98. };
  99. class PictureSequenceInput: public input, public BidirSequenceInput {
  100. private:
  101. int Npictures;
  102. float **PictureArray;
  103. int StimDuration, Isi1Duration, Isi2Duration;;
  104. int StimHold, IsiHold;
  105. int NoJumpHold, NoJumpDuration;
  106. bool TestMode;
  107. float mBackgroundStrength;
  108. public:
  109. PictureSequenceInput(layer* tg,
  110. csimInputChannel InputNumber=csimInputChannel_AMPA,
  111. float strength=1,
  112. float _StimDur=10,
  113. float _Isi1Dur=10,
  114. float _NoJumpDur=5,
  115. float _Isi2Dur=0,
  116. float _BackgroundStrength=0.);
  117. ~PictureSequenceInput();
  118. virtual int proceede(int TotalTime=0);
  119. void SetGaussPictureArray(const vector<vector2d> &mpList, float Sigma, float Cut=2);
  120. void SetCirclePictureArray(const vector<vector2d> &mpList, float Radius, float Background=0);
  121. void SetPictureArray(int _Npic, float _mpy=0.5, float Sigma=0.5);
  122. void SetPictureArray(vector<vector<float> > &paVec);
  123. void SetPictureArray(ObjMovie *Movie);
  124. void SetCirclePictureArray(int _Npic, float _mpy=0.5, float Radius=0.2, float Background=0);
  125. void SetLinearPictureArray(int _Npic, int _mpy, int _NumSeq, float Sigma=0.25);
  126. void SetTwoPointArray(float distance=0.2, float Radius=0.2);
  127. void SetTestMode(float _StimDuration=20, float _IsiDuration=1000);
  128. void ClearPictureArray();
  129. void SetBackgroundStrength(float BgStrength) {mBackgroundStrength=BgStrength;};
  130. virtual int Show(int TotalTime=0);
  131. virtual void Jump();
  132. };
  133. class SpikeTrainInput: public input {
  134. private:
  135. float *Picture;
  136. int SpikeHold, InterSpikeHold, SpikeDuration, InterSpikeDuration;
  137. float SpikeFrequency, SpikeWidth;
  138. int DelayDuration;
  139. int *SyncStimNr;
  140. public:
  141. SpikeTrainInput(layer* tg, csimInputChannel InputNumber=csimInputChannel_AMPA, float strength=1, float _SpikeFreq=10, float SpikeDuration=1.);
  142. ~SpikeTrainInput();
  143. void SetPictureCircle();
  144. void SetPictureAll(); // all neurons are activated equally
  145. void SetSpikeFrequency(float _SpikeFreq);
  146. virtual int proceede(int TotalTime=0);
  147. virtual int prepare(int=0);
  148. virtual int SetInputSync(InputSynchronizer* _inpsync, float _delay=0);
  149. };
  150. class MultiSequenceInput: public input {
  151. private:
  152. vector<PatternSequenceInput*> SequenceList;
  153. int NumSeq;
  154. int CurInputNr;
  155. int SwitchTime;
  156. int SwitchHold;
  157. int MinStimTime;
  158. int AddStimTime;
  159. int StimHold;
  160. public:
  161. MultiSequenceInput(layer* tg, int Nseq, csimInputChannel InputNumber=csimInputChannel_AMPA, float strength=1, int size=10, int _PtStart=0, int numpt=10, float ov=0.5, int dur=100);
  162. virtual int proceede(int TotalTime=0);
  163. };
  164. class MultiPictureSequenceInput: public input {
  165. private:
  166. vector<PictureSequenceInput*> SequenceList;
  167. vector<int> StimNumStart;
  168. int NumSeq;
  169. int CurInputNr;
  170. int SwitchTime;
  171. int SwitchHold;
  172. int MinStimTime;
  173. int AddStimTime;
  174. int StimHold;
  175. int StimTime;
  176. int SeqTime;
  177. int SeqHold;
  178. int IsiDuration, IsiHold;
  179. public:
  180. MultiPictureSequenceInput(layer* tg, csimInputChannel InputNumber=csimInputChannel_AMPA, int Nseq=3, float strength=1, float _StimTime=50, float _IsiTime=20);
  181. virtual int proceede(int TotalTime=0);
  182. int SetupGaussPictureArrays(
  183. vector<vector<vector2d> > mpList,
  184. float _StimDur=10, float Sigma=0.2, float Cut=2);
  185. int SetupCirclePictureArrays(
  186. vector<vector<vector2d> > mpList,
  187. float _StimDur=10, float Radius=0.2);
  188. int SetupPictureArrays(float _StimDur=10);
  189. int SetupLinearPictureArrays(float _StimDur=10, float Sigma=0.1);
  190. void SetTestMode(float _StimDuration=20, float _IsiDuration=1000);
  191. void Jump();
  192. };
  193. class LearnTestInput: public input {
  194. int delay;
  195. int hold, isi;
  196. int phase;
  197. public:
  198. LearnTestInput(layer*, csimInputChannel , float, float =10, float=20);
  199. ~LearnTestInput();
  200. int proceede(int TotalTime=0);
  201. };
  202. ////////////////////////////////////////
  203. /*! \brief ObjMovieInput
  204. *
  205. */
  206. class ObjMovieInput: public input {
  207. protected:
  208. ObjMovie* MovieFile;
  209. int FilterNr;
  210. int StimDuration, TestStimDuration, IsiDuration;
  211. int TestIsiDuration;
  212. int StimHold, IsiHold;
  213. int FrameSize;
  214. float *Data;
  215. bool SwitchMaster;
  216. bool RandomNext;
  217. bool TestMode;
  218. bool PositiveInput;
  219. input* SwitchMasterObj;
  220. public:
  221. ObjMovieInput(layer* tg, csimInputChannel InputNumber=csimInputChannel_AMPA, ObjMovie* _Movie=0, int FilterNr=0, float strength=1, float _StimDur=20, float _IsiDur=5);
  222. virtual int proceede(int TotalTime=0);
  223. void SetRandomNext(bool);
  224. void SetStimDuration(int _stimdur);
  225. void SetTestMode(bool tm);
  226. void InitializeTestMode(float _StimDuration, float _IsiDuration);
  227. virtual int GetNStimuli();
  228. int GetNFrames();
  229. void SetMovieFile(ObjMovie* _Movie, int FilterNr);
  230. };
  231. struct XYpair {
  232. XYpair(int _x, int _y): x(_x), y(_y) {};
  233. int x, y;
  234. };
  235. typedef vector<XYpair> XYpairList;
  236. /*! \brief ScanObjMovieInput is used in som01 and som02.
  237. ScanObjMovieInput interprets the idlmov format as a container for a set of pictures
  238. which are used as inputs in a certain order and with certain rules.
  239. The rules can be changed by setting a different input mode.
  240. New behaviour can be implemented
  241. First it was used for movies with scanned objects, generated with Crystal Space.
  242. In Crystal Space for every viewing angle of the object a picture was taken.
  243. The same was done for every object.
  244. \author fm
  245. */
  246. class ScanObjMovieInput: public ObjMovieInput {
  247. protected:
  248. int Xpara, Ypara, NXpara, NYpara;
  249. bool XContinous, XCircle, YCircle, XRandomChange ;
  250. int direction;
  251. int Isi2Duration;
  252. int NextX();
  253. int NextY();
  254. int NextRandom();
  255. int NextY_RandomDir();
  256. int NextRandomX();
  257. int NextObjpos();
  258. int NextRandomObjpos();
  259. int NextJitterX();
  260. int testiffirstrunever;
  261. int Xparacounter;
  262. int dirchangecounter;
  263. int testiffirsttestrunever;
  264. int NoJumpHold, NoJumpDuration, NoJumpDurationTest;
  265. XYpairList *TestStimList;
  266. vector<XYpair>::iterator TestIt;
  267. StimulusSequence mStimSequence;
  268. public:
  269. ScanObjMovieInput(layer* tg, csimInputChannel InputNumber=csimInputChannel_AMPA, ObjMovie* _Movie=0, int FilterNr=0, float strength=1, float _StimDur=20, int _NXpara=30, int _NYpara=30, bool _XContinous=true, int _NoJumpHold=20, float _IsiDur=20, float _Isi2Dur=0,int _NoJumpDurationTest=15);
  270. virtual int proceede(int TotalTime=0);
  271. void InitializeTestMode(
  272. XYpairList* StimList, float _StimDuration=20, float _IsiDuration=1000);
  273. ResponseMap* GetTestStimMap();
  274. void SetXCircle(bool);
  275. void SetXRandomChange(bool);
  276. void SetYCircle(bool);
  277. void loadStimulusSequence(const char* FileName);
  278. virtual void SetMode(InputMode _mode);
  279. virtual int WriteSimInfo(fstream &fw);
  280. };
  281. ///////
  282. class SequenceObjMovieInput: public ObjMovieInput {
  283. protected:
  284. int direction;
  285. // StimulusSequence* StimSeq;
  286. int NoJumpHold, NoJumpDuration;
  287. public:
  288. SequenceObjMovieInput(layer* tg, csimInputChannel InputNumber=csimInputChannel_AMPA, ObjMovie* _Movie=0, StimulusSequence* seq=0, int FilterNr=0, float strength=1, float _StimDur=20, int _NoJumpHold=20);
  289. virtual int proceede(int TotalTime=0);
  290. };
  291. ////////
  292. class VarSequenceInput: public input {
  293. private:
  294. vector<vector<float> >* Pictures;
  295. vector<int*> Sequence; //[SequenceDuration,PictureNumber]
  296. int steps;
  297. vector<int*>::const_iterator SequenceIterator;
  298. public:
  299. VarSequenceInput(layer* tg,csimInputChannel InputNumber=csimInputChannel_AMPA);
  300. ~VarSequenceInput();
  301. virtual int proceede(int TotalTime=0);
  302. void addPicture(vector<float>& );
  303. void changePicture(int ,vector<float>& );
  304. void addSequence(int ,int );
  305. void setSequenceIterator();
  306. bool changeSequence(int ,int ,int );
  307. void printSequences();
  308. };
  309. class ShiftObjMovieInput: public ObjMovieInput {
  310. public:
  311. ShiftObjMovieInput(layer* tg, csimInputChannel InputNumber=csimInputChannel_AMPA, ObjMovie* _Movie=0, int FilterNr=0, float strength=1, float _StimDur=20, float _IsiDur=5);
  312. virtual int proceede(int TotalTime=0);
  313. };
  314. //////////////////////////////////
  315. vector<float> CirclePicture(
  316. int SizeX,
  317. int SizeY,
  318. float MpX,
  319. float MpY,
  320. float Radius,
  321. float Amplitude,
  322. float Background,
  323. bool NormPos=false);
  324. #endif /*_HPP_INPUT */