forked from samuellab/mindcontrol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
228 lines (162 loc) · 6.03 KB
/
test.c
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
/*
* Copyright 2010 Andrew Leifer et al <[email protected]>
* This file is part of MindControl.
*
* MindControl is 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.
*
* MindControl s distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MindControl. If not, see <http://www.gnu.org/licenses/>.
*
* For the most up to date version of this software, see:
* https://github.com/samuellab/mindcontrol
*
*
*
* NOTE: If you use any portion of this code in your research, kindly cite:
* 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).
*/
/*
* This is a test program that performs some basic tests of the mindcontrol software.
* It is mostly useful for debugging.
*/
//Standard C headers
#include <stdio.h>
#include <ctime>
#include <time.h>
#include <conio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
//C++ header
#include <iostream>
#include <limits>
using namespace std;
//OpenCV Headers
#include <highgui.h>
#include <cv.h>
#include <cxcore.h>
//Andy's Headers
#include "MyLibs/AndysOpenCvLib.h"
#include "MyLibs/WormAnalysis.h"
#include "MyLibs/IllumWormProtocol.h"
#include "MyLibs/version.h"
//3rd Party Libraries
#include "3rdPartyLibs/tictoc.h"
Protocol* CreateTestProtocol(char* name){
Protocol* myP=CreateProtocolObject();
myP->Description="A test protocol.";
myP->Filename=name;
myP->GridSize=cvSize(21,99);
/** Create the Steps Object and Load it into the Protocol **/
myP->Steps=CreateStepsObject(myP->memory);
/** Create Some Polygons **/
WormPolygon* Head = CreateWormPolygon(myP->memory,myP->GridSize);
WormPolygon* Left = CreateWormPolygon(myP->memory,myP->GridSize);
WormPolygon* Right = CreateWormPolygon(myP->memory,myP->GridSize);
WormPolygon* Tail = CreateWormPolygon(myP->memory,myP->GridSize);
WormPolygon* Everything = CreateWormPolygon(myP->memory,myP->GridSize);
//(length along centerline,radius from centerline)
cvSeqPush(Head->Points,&cvPoint(-10,0));
cvSeqPush(Head->Points,&cvPoint(10,0));
cvSeqPush(Head->Points,&cvPoint(10,20));
cvSeqPush(Head->Points,&cvPoint(-10,20));
cvSeqPush(Left->Points,&cvPoint(0,30));
cvSeqPush(Left->Points,&cvPoint(-10,30));
cvSeqPush(Left->Points,&cvPoint(-10,70));
cvSeqPush(Left->Points,&cvPoint(0,70));
cvSeqPush(Right->Points,&cvPoint(0,30));
cvSeqPush(Right->Points,&cvPoint(10,30));
cvSeqPush(Right->Points,&cvPoint(10,70));
cvSeqPush(Right->Points,&cvPoint(0,70));
cvSeqPush(Tail->Points,&cvPoint(-10,80));
cvSeqPush(Tail->Points,&cvPoint(0,80));
cvSeqPush(Tail->Points,&cvPoint(0,99));
cvSeqPush(Tail->Points,&cvPoint(-10,99));
cvSeqPush(Everything->Points,&cvPoint(-10,0));
cvSeqPush(Everything->Points,&cvPoint(10,0));
cvSeqPush(Everything->Points,&cvPoint(10,99));
cvSeqPush(Everything->Points,&cvPoint(-10,99));
/** Create an Illumination Montage**/
CvSeq* FirstIllum=CreateIlluminationMontage(myP->memory);
CvSeq* SecondIllum=CreateIlluminationMontage(myP->memory);
CvSeq* ThirdIllum=CreateIlluminationMontage(myP->memory);
CvSeq* FourthIllum=CreateIlluminationMontage(myP->memory);
/** Let's load up the illumination montages with polygons**/
cvSeqPush(FirstIllum,&Head);
cvSeqPush(FirstIllum,&Tail);
cvSeqPush(FirstIllum,&Left);
cvSeqPush(FirstIllum,&Right);
printf("FirstIllum->total=%d\n",FirstIllum->total);
cvSeqPush(SecondIllum,&Head);
cvSeqPush(SecondIllum,&Right);
cvSeqPush(ThirdIllum,&Tail);
cvSeqPush(ThirdIllum,&Left);
cvSeqPush(FourthIllum,&Everything);
/** Let's Load the montages into a series of steps **/
cvSeqPush(myP->Steps,&FirstIllum);
cvSeqPush(myP->Steps,&SecondIllum);
cvSeqPush(myP->Steps,&ThirdIllum);
cvSeqPush(myP->Steps,&FourthIllum);
printf("Writing test protocol in file: %s\n",myP->Filename);
WriteProtocolToYAML(myP);
printf("Head->points->total=%d\n",Head->Points->total);
DestroyWormPolygon(&Head);
DestroyWormPolygon(&Tail);
DestroyWormPolygon(&Left);
DestroyWormPolygon(&Right);
return myP;
}
int main(){
//char* name = (char*) malloc(sizeof(char)*50);
printf(copyString("Hello you World\n"));
printf("Points between line test\n");
CvMemStorage* mem= cvCreateMemStorage();
CvSeq* test=cvCreateSeq(CV_SEQ_ELTYPE_POINT, sizeof(CvSeq), sizeof(CvPoint),mem);
GetLineFromEndPts(cvPoint(0,0),cvPoint(10,15),test);
return 0;
CvMemStorage* MyMem= cvCreateMemStorage();
CvFileStorage* fs=cvOpenFileStorage("appendTest.yaml",MyMem,CV_STORAGE_APPEND);
cvStartWriteStruct(fs,"Experiment",CV_NODE_MAP,NULL);
cvWriteInt(fs,"x",10);
cvWriteString(fs,"string","calvin And Hobbes");
cvEndWriteStruct(fs);
cvReleaseFileStorage(&fs);
return 0;
Protocol* myP=CreateTestProtocol("protocol.yml");
VerifyProtocol(myP);
WriteProtocolToYAML(myP);
DestroyProtocolObject(&myP);
printf("Done writing...\n\n");
Protocol* protocol2 = LoadProtocolFromFile("protocol.yml");
VerifyProtocol(protocol2);
protocol2->Filename="protoco2.yml";
printf("protocol2->Steps->total=%d\n",protocol2->Steps->total);
WriteProtocolToYAML(protocol2);
printf("GenerateRectangleWorm\n");
IplImage* rectWorm= GenerateRectangleWorm(protocol2->GridSize);
printf("ShowImage\n");
cvNamedWindow("RectWorm");
cvShowImage("RectWorm",rectWorm);
int k;
for (k = 0; k < protocol2->Steps->total; ++k) {
printf("====Step Number %d====\n",k);
cvZero(rectWorm);
TICTOC::timer().tic("IllumRectWorm()");
IllumRectWorm(rectWorm,protocol2,k,0);
TICTOC::timer().toc("IllumRectWorm()");
cvShowImage("RectWorm",rectWorm);
cvWaitKey(0);
}
printf("%s",TICTOC::timer().generateReportCstr());
return 0;
}