-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
282 lines (226 loc) · 5.72 KB
/
main.cpp
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
/*
* Copyright 2018 Wenbin Yang <bysin7@gmail.com>
* This file is part of BLITZ (Behavioral Learning In The Zebrafish),
* which is adapted from MindControl (Andrew Leifer et al <leifer@fas.harvard.edu>
* Leifer, A.M., Fang-Yen, C., Gershow, M., Alkema, M., and Samuel A. D.T.,
* "Optogenetic manipulation of neural activity with high spatial resolution in
* freely moving Caenorhabditis elegans," Nature Methods, Submitted (2010).
*
* BLITZ is a free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the license, or
* (at your option) any later version.
*
* Filename: main.cpp
* Abstract: this file contains all functions used in constructing final
* behavioral learning experiment in zebrafish
*
* Current Version: 2.0
* Author: Wenbin Yang <bysin7@gmail.com>
* Modified on: Apr. 28, 2018
* Replaced Version: 1.1
* Author: Wenbin Yang <bysin7@gmail.com>
* Created on: Jan. 1, 2018
*/
// Include 3rd party libraries
#include "3rdPartyLibs/Utilities/Timer.h"
// Include user-defined libraries
#include "MyLibs/experiment.h"
#include "MyLibs/talk2screen.h"
#include "MyLibs/talk2camera.h"
// Include standard libraries
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
/*TODO:
1. degrade load_image_to_buffers to a method of AreaData
2. put all positions and patterns coordinates into ScreenData
3. do a similar update to the FishData class.
4. reduce unnecessary data-type conversions
5. remove unnecessary code
*/
//vector<const char*> CS_patterns =
//{
// "Images/redBlackCheckerboard.jpg",
// "Images/whiteBlackCheckerboard.jpg",
// "Images/fullBlue.jpg"
//};
/*
Mat I = imread("Images/fullBlue.jpg");
namedWindow("Display", 1);
imshow("Display", I);
waitKey(0);
*/
string pathName = "F:/FishExpData/";
ExperimentData exp(pathName);
if (!exp.initialize())
{
cout << "Experiment Initialization Failed." << endl;
exit(0);
}
else {
cout << "Experiment initialized." << endl;
}
exp.runOLexp();
/* The block for the real experiment
string pathName = "F:/FishExpData/";
vector<string> CS_Patterns;
CS_Patterns.push_back("redBlackCheckerboard");
CS_Patterns.push_back("whiteBlackCheckerboard");
CS_Patterns.push_back("fullBlue");
//string CS_Pattern = "redBlackCheckerboard";
ExperimentData exp(CS_Patterns,pathName);
if (!exp.initialize())
{
cout << "Experiment Initialization Failed." << endl;
exit(0);
}
else {
cout << "Experiment initialized." << endl;
}
exp.runOLexp();
*/
/*
string CS_Pattern = "RGB96";
ExperimentData exp(CS_Pattern);
if (!exp.initialize())
{
cout << "Experiment Initialization Failed." << endl;
exit(0);
}
else {
cout << "Experiment initialized." << endl;
}
exp.runOLexp();
The real main function */
/* Test serial port
string CS_Pattern = "redBlackCheckerboard";
ExperimentData exp(CS_Pattern);
if (!exp.thePort.initialize(COM_NUM)) {
cout << "Initialize failed" << endl;
return false;
}
int flag;
cout << endl; // separated with an empty line
for (int i = 0; i < 12; i++)
{
flag = exp.thePort.givePulse(i);
waitKey(100);
cout << "Give shock:" << i << endl;
if (flag = 0)
{
cout << "Failed" << endl;
}
}
*/
/* main function
string CS_Pattern = "redBlackCheckerboard";
ExperimentData exp(CS_Pattern);
if (!exp.initialize())
{
cout << "Experiment Initialization Failed." << endl;
exit(0);
}
else {
cout << "Experiment initialized." << endl;
}
exp.runOLexp();
*/
/* Test screen function
Timer expTimer;
ScreenData myScreen;
vector<const char*> CSpatterns =
{
"Images/redBlackCheckerboard.jpg",
"Images/whiteBlackCheckerboard.jpg",
"Images/fullBlue.jpg"
};
myScreen.initialize(CSpatterns);
expTimer.start();
while (1)
{
int timeInSec = expTimer.getElapsedTimeInSec();
cout << "Time (s) : " << timeInSec << endl;
int areaIdx = rand() % 3;
if (timeInSec % 10 == 0)
myScreen.allAreas[areaIdx].allPatches[0].pIdx = !myScreen.allAreas[areaIdx].allPatches[0].pIdx;
myScreen.allAreas[areaIdx].allPatches[0].updatePattern();
myScreen.renderTexture();
}
*/
/* Test OL Procedure
ExperimentData exp;
const char imgName[] = "Images/redCheckerBoard.jpg";
try {
exp.initialize(imgName);
exp.prepareBgImg();
exp.runOLexp();
}
catch (const GenericException &e)
{
// Error handling
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
}
*/
/*
int testVar = 10;
vector<int> headVec(4, 0);
headVec[1] = 1;
headVec[2] = 2;
headVec[3] = 3;
fs << "Frame" << "[";
string vName; // variable name
for (int i = 0; i < headVec.size(); i++)
{
vName = "Head" + to_string(i);
fs << "{:" << vName << headVec[i] << "}";
}
fs << "]";
*/
//yaml << "Frames" << "[";
//writeOutVarInline<int>(fs, testVar, "testVar");
/* Timer.start can be used as reset
Timer expTimer;
expTimer.start();
while (1)
{
int timeInSec = expTimer.getElapsedTimeInSec();
cout << "Time (s): " << timeInSec << endl;
if (timeInSec > 10)
expTimer.start();
}
*/
/* Test camera function
Timer expTimer;
expTimer.start();
CameraData cams;
cams.initialize();
while (cams.grabPylonImg())
{
cout << "Time (s) : " << expTimer.getElapsedTimeInSec() << endl;
#ifdef PYLON_WIN_BUILD
// Display the grabbed image.
Pylon::DisplayImage(1, cams.ptrGrabResult);
#endif
}
*/
// Enquire how many cameras to use
// and enter filenames respectively
/*
try{ // Handle with missing frames of Pylon cameras
ExperimentData myExp;
myExp.initialize();
myExp.prepareBgImg();
myExp.runOLexp(); // run operant learning experiment
}
catch (const GenericException &e)
{
// Error handling
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
}
*/
}