-
Notifications
You must be signed in to change notification settings - Fork 2
/
miniproject.cpp
315 lines (293 loc) · 10.6 KB
/
miniproject.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#include <GL\glut.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <conio.h>
#include "iostream"
#include <time.h>
using namespace std;
bool flag = true;
GLfloat xRotated, yRotated, zRotated;
void check(int value)
{
if (flag == true)
{
flag = false;
}
else if (flag == false)
{
flag = true;
}
cout << flag << "\n";
glutPostRedisplay();
glutTimerFunc(1000, check, 0);
}
void highlight_lines(float x, float y, float z, float live_transparency_line)
{
float a, b, c;
for (a = 0; a <= 0.5; a = a + 0.1)
{
for (b = 0; b <= 0.5; b = b + 0.1)
{
for (c = 0; c <= 0.5; c = c + 0.1)
{
//First Hidden Layer Plane 1
glPointSize(3.0);
glBegin(GL_POINTS);
glColor4f(1.0, 1.0, 1.0, 0.05);
glVertex3f(0.1 + b, 0.1 + c, 0.4);
glVertex3f(0.1 + b, 0.1 + c, 0.4);
glEnd();
glBegin(GL_LINE_LOOP);
glColor4f(1.0, 1.0, 1.0, live_transparency_line);
glVertex3f(x, y, z);
glVertex3f(0.1 + b, 0.1 + c, 0.4);
glVertex3f(0.1 + b, 0.1 + c, 0.4);
glEnd();
//First Hidden Layer Plane 4
if (c < 0.44)
{
glPointSize(3.0);
glBegin(GL_POINTS);
glVertex3f(x, y, z);
glVertex3f(0.17 + b, 0.16 + c, 0.44);
glVertex3f(0.17 + b, 0.16 + c, 0.44);
glEnd();
glBegin(GL_LINE_LOOP);
glColor4f(1.0, 1.0, 1.0, live_transparency_line);
glVertex3f(x, y, z);
glVertex3f(0.17 + b, 0.16 + c, 0.44);
glVertex3f(0.17 + b, 0.16 + c, 0.44);
glEnd();
}
//Second Hidden Layer Plane 1
glPointSize(3.0);
glBegin(GL_POINTS);
glColor4f(1.0, 1.0, 1.0, 0.05);
glVertex3f(0.1 + b, 0.1 + c, 0.8);
glVertex3f(0.1 + b, 0.1 + c, 0.8);
glEnd();
glBegin(GL_LINE_LOOP);
glColor4f(1.0, 1.0, 1.0, live_transparency_line);
glVertex3f(0.1 + b, 0.1 + a, 0.4);
glVertex3f(0.1 + b, 0.1 + c, 0.8);
glVertex3f(0.1 + b, 0.1 + c, 0.8);
glEnd();
//output layer
glPointSize(20.0);
glBegin(GL_POINTS);
glColor4f(0.0, 0.0, 1.0, 1.0);
glVertex3f(0.2, 0.35, 1.2);
glEnd();
glBegin(GL_LINE_LOOP);
glColor4f(1.0, 1.0, 1.0, live_transparency_line);
glVertex3f(0.1 + b, 0.1 + a, 0.8);
glVertex3f(0.2, 0.35, 1.2);
glVertex3f(0.2, 0.35, 1.2);
glEnd();
}
}
}
}
void displaynetwork(void)
{
glMatrixMode(GL_MODELVIEW);
// clear the drawing buffer.
glClear(GL_COLOR_BUFFER_BIT);
// clear the identity matrix.
glLoadIdentity();
// traslate the draw by z = -4.0
// Note this when you decrease z like -8.0 the drawing will looks far , or smaller.
glTranslatef(-1.0, -0.75, -3.5); // -1.6 for scaling of 2.3
// Red color used to draw.
glColor3f(0.8, 0.2, 0.1);
glRotatef(yRotated, 0.0, 1.0, 0.0);
glScalef(2.0, 2.0, 2.0);
float dead_transparency_line = 0.08;
float live_transparency_line = 0.15;
float a, b, c;
for (a = 0; a <= 0.5; a = a + 0.1)
{
for (b = 0; b <= 0.5; b = b + 0.1)
{
for (c = 0; c <= 0.5; c = c + 0.1)
{
//Input Layer
glPointSize(15.0);
glBegin(GL_POINTS);
glColor4f(1.0, 1.0, 1.0, 0.05);
glVertex3f(0.1 + b, 0.1 + a, 0.0);
glEnd();
//First Hidden Layer Plane 1
glPointSize(3.0);
glBegin(GL_POINTS);
glColor4f(1.0, 1.0, 1.0, 0.05);
glVertex3f(0.1 + b, 0.1 + c, 0.4);
glEnd();
glBegin(GL_LINE_LOOP);
glColor4f(1.0, 1.0, 1.0, dead_transparency_line);
glVertex3f(0.1 + b, 0.1 + a, 0.0);
glVertex3f(0.1 + b, 0.1 + c, 0.4);
glVertex3f(0.1 + b, 0.1 + c, 0.4);
glEnd();
//First Hidden Layer Plane 2
if (c < 0.47)
{
glPointSize(3.0);
glBegin(GL_POINTS);
glVertex3f(0.1 + b, 0.1 + a, 0.0);
glVertex3f(0.13 + b, 0.13 + c, 0.42);
glEnd();
glBegin(GL_LINE_LOOP);
glColor4f(1.0, 1.0, 1.0, dead_transparency_line);
glVertex3f(0.1 + b, 0.1 + a, 0.0);
glVertex3f(0.13 + b, 0.13 + c, 0.42);
glVertex3f(0.13 + b, 0.13 + c, 0.42);
glEnd();
}
//First Hidden Layer Plane 3
glPointSize(3.0);
glBegin(GL_POINTS);
glVertex3f(0.1 + b, 0.1 + a, 0.0);
glVertex3f(0.07 + b, 0.07 + c, 0.42);
glVertex3f(0.07 + b, 0.07 + c, 0.42);
glEnd();
glBegin(GL_LINE_LOOP);
glColor4f(1.0, 1.0, 1.0, dead_transparency_line);
glVertex3f(0.1 + b, 0.1 + a, 0.0);
glVertex3f(0.07 + b, 0.07 + c, 0.42);
glVertex3f(0.07 + b, 0.07 + c, 0.42);
glEnd();
//First Hidden Layer Plane 4
if (c < 0.44)
{
glPointSize(3.0);
glBegin(GL_POINTS);
glVertex3f(0.1 + b, 0.1 + a, 0.0);
glVertex3f(0.17 + b, 0.16 + c, 0.44);
glVertex3f(0.17 + b, 0.16 + c, 0.44);
glEnd();
glBegin(GL_LINE_LOOP);
glColor4f(1.0, 1.0, 1.0, dead_transparency_line);
glVertex3f(0.1 + b, 0.1 + a, 0.0);
glVertex3f(0.17 + b, 0.16 + c, 0.44);
glVertex3f(0.17 + b, 0.16 + c, 0.44);
glEnd();
}
//Second Hidden Layer Plane 1
glPointSize(3.0);
glBegin(GL_POINTS);
glColor4f(1.0, 1.0, 1.0, 0.05);
glVertex3f(0.1 + b, 0.1 + c, 0.8);
glVertex3f(0.1 + b, 0.1 + c, 0.8);
glEnd();
glBegin(GL_LINE_LOOP);
glColor4f(1.0, 1.0, 1.0, dead_transparency_line);
glVertex3f(0.1 + b, 0.1 + a, 0.4);
glVertex3f(0.1 + b, 0.1 + c, 0.8);
glVertex3f(0.1 + b, 0.1 + c, 0.8);
glEnd();
//Second Hidden Layer Plane 2
if (c < 0.47)
{
glPointSize(3.0);
glBegin(GL_POINTS);
glVertex3f(0.1 + b, 0.1 + a, 0.42);
glVertex3f(0.13 + b, 0.13 + c, 0.82);
glVertex3f(0.13 + b, 0.13 + c, 0.82);
glEnd();
glBegin(GL_LINE_LOOP);
glColor4f(1.0, 1.0, 1.0, dead_transparency_line);
glVertex3f(0.1 + b, 0.1 + a, 0.0);
glVertex3f(0.13 + b, 0.13 + c, 0.82);
glVertex3f(0.13 + b, 0.13 + c, 0.82);
glEnd();
}
//Output Layer
glPointSize(3.0);
glBegin(GL_POINTS);
glColor4f(1.0, 1.0, 1.0, 0.05);
glVertex3f(0.1 + b, 0.35, 1.2);
glVertex3f(0.1 + b, 0.35, 1.2);
glEnd();
glBegin(GL_LINE_LOOP);
glColor4f(1.0, 1.0, 1.0, dead_transparency_line);
glVertex3f(0.1 + b, 0.1 + c, 0.8);
glVertex3f(0.1 + a, 0.35, 1.2);
glVertex3f(0.1 + a, 0.35, 1.2);
glEnd();
}
}
}
if (flag == true)
{
//Inut image '1'
glPointSize(15.0);
glBegin(GL_POINTS);
glColor4f(0.0, 0.0, 1.0, 1.0);
glVertex3f(0.3, 0.2, 0.0);
glVertex3f(0.3, 0.3, 0.0);
glVertex3f(0.3, 0.4, 0.0);
glVertex3f(0.3, 0.5, 0.0);
glVertex3f(0.3, 0.6, 0.0);
glVertex3f(0.4, 0.5, 0.0);
glVertex3f(0.2, 0.2, 0.0);
glVertex3f(0.3, 0.2, 0.0);
glVertex3f(0.4, 0.2, 0.0);
glEnd();
//Highlighting the active neurons
highlight_lines(0.3, 0.2, 0.0, live_transparency_line);
highlight_lines(0.3, 0.3, 0.0, live_transparency_line);
highlight_lines(0.3, 0.4, 0.0, live_transparency_line);
highlight_lines(0.3, 0.5, 0.0, live_transparency_line);
highlight_lines(0.3, 0.6, 0.0, live_transparency_line);
highlight_lines(0.4, 0.5, 0.0, live_transparency_line);
highlight_lines(0.2, 0.2, 0.0, live_transparency_line);
highlight_lines(0.3, 0.2, 0.0, live_transparency_line);
highlight_lines(0.4, 0.2, 0.0, live_transparency_line);
}
//Flushing the whole output
glFlush();
// sawp buffers called because we are using double buffering
glutSwapBuffers();
}
void reshapenetwork(int x, int y)
{
if (y == 0 || x == 0) return; //Nothing is visible then, so return
//Set a new projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//Angle of view:40 degrees
gluPerspective(40.0, (GLdouble)x / (GLdouble)y, 0.5, 20.0);
glViewport(0, 0, x, y); //Use the whole window for rendering
}
void idlenetwork(void)
{
yRotated += 0.05;
displaynetwork();
}
int main(int argc, char** argv)
{
//Initialize GLUT
glutInit(&argc, argv);
//double buffering used to avoid flickering problem in animation
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
// window size
glutInitWindowSize(1350, 950);
glutInitWindowPosition(0, 0);
// create the window
glutCreateWindow("network Rotating Animation");
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
yRotated = 40;
glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//Assign the function used in events
glutDisplayFunc(displaynetwork);
glutReshapeFunc(reshapenetwork);
glutIdleFunc(idlenetwork);
//Let start glut loop
glutTimerFunc(100, check, 0);
glutMainLoop();
return 0;
}