-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNeuronGraphics.cpp
443 lines (317 loc) · 11.1 KB
/
NeuronGraphics.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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
#include "stdafx.h"
#include "NeuralNet.h"
// define colors
double NeuronColor[4]={0.0,0.0,0.0,1.0};
double NormalColorTriangulated[4]={0.8,0.6,0.6,1.0};
double NormalColorNonManifold[4]={1.0,0.0,1.0,1.0};
double PointColorUsed[4]={0.0,0.0,0.6,1.0};
double PointColorNotUsed[4]={0.0,0.0,1.0,1.0};
// added for patch classification
double NeuronBaseColor[4]={0.3,0.3,0.3,0.99};
double NeuronPatchAdditionColor[4]={0.2,0.35,0.2,0.0};
double EdgeColorDiscrimination[4] = {0.225,0.325,0.425,0.0};
double EdgeColorUDir[4]={1.0,0.0,0.0,1.0};
double EdgeColorVDir[4]={0.0,0.8,0.0,1.0};
double EdgeColor[4]={0.5,1.0,0.0,1.0};
double EdgeColorNew[4]={1.0,1.0,0.0,1.0};
double EdgeColorInside[4]={1.0,0.0,0.0,1.0};
double EdgeColorBoundary[4]={0.0,1.0,1.0,1.0};
double EdgeColorNonManifold[4]={1.0,0.0,1.0,1.0};
double EdgeColorNotConsistantInDirection[4]={1.0,1.0,1.0,1.0};
double NormalColor[4]={0.0,0.0,0.0,1.0};
double FaceColorTransperant[4]={0.0,1.0,0.0,0.5};
double FaceColorNew[4]={0.0,1.0,0.0,1.0};
float FaceMaterialColorFront[4]={0.0f,1.0f,0.0f,1.0f};
float FaceMaterialColorBack[4]={1.0f,0.6f,0.0f,1.0f};
float MaterialSpecularColor[4]={1.0f,1.0f,1.0f,1.0f};
float MaterialShininess[1]={8.0f};
void MyPoint::Draw (RealType PointSize){
glBegin(GL_LINES);
glVertex3d(Pos[0]-PointSize,Pos[1],Pos[2]);
glVertex3d(Pos[0]+PointSize,Pos[1],Pos[2]);
glVertex3d(Pos[0],Pos[1]-PointSize,Pos[2]);
glVertex3d(Pos[0],Pos[1]+PointSize,Pos[2]);
glVertex3d(Pos[0],Pos[1],Pos[2]-PointSize);
glVertex3d(Pos[0],Pos[1],Pos[2]+PointSize);
glEnd();
}
void Neuron::Draw (RealType PointSize, RealType NormalSize){
glLineWidth(2.0);
glColor4dv(NeuronColor);
this->MyPoint::Draw(PointSize);
if (NormalSize>0.0){
glLineWidth(4.0);
glPushName ( (GLint) this);
glBegin(GL_LINES);
if (NonManifoldNeuron>0)
glColor4dv(NormalColorNonManifold);
else if (TriDist<0 || Tags & NEURON_ON_BOUNDARY)
glColor4dv(NormalColorTriangulated);
else
glColor4dv(NormalColor);
glVertex3d(Pos[0],Pos[1],Pos[2]);
glVertex3d(Normal.Pos[0]*NormalSize+Pos[0],Normal.Pos[1]*NormalSize+Pos[1],Normal.Pos[2]*NormalSize+Pos[2]);
glEnd();
}
glPopName();
glLineWidth(1.0);
}
/* edges with different colors by patches version
void Edge::Draw(){
double ThisNeuronColor[4];
if (Tag & EDGE_V_DIR)
glLineWidth(4.0);
else
glLineWidth(2.0);
glBegin(GL_LINES);
for (int i=0;i<4;i++){
ThisNeuronColor[i]=Neuron1->PatchClassification * NeuronPatchAdditionColor[i];
if (Tag & EDGE_U_DIR) ThisNeuronColor[i] += EdgeColorDiscrimination[i];
if (Tag & EDGE_V_DIR) ThisNeuronColor[i] += EdgeColorDiscrimination[i]+EdgeColorDiscrimination[i];
ThisNeuronColor[i] = NeuronBaseColor[i] + fabs( ThisNeuronColor[i] - (int) ThisNeuronColor[i]) *(1.0 - NeuronBaseColor[i]);
}
//if (Tag & EDGE_U_DIR)
// glColor4dv(EdgeColorUDir);
//else
glColor4dv(ThisNeuronColor);
glVertex3d(Neuron1->Pos[0],Neuron1->Pos[1],Neuron1->Pos[2]);
for (i=0;i<4;i++){
ThisNeuronColor[i]=Neuron2->PatchClassification * NeuronPatchAdditionColor[i];
if (Tag & EDGE_U_DIR) ThisNeuronColor[i] += EdgeColorDiscrimination[i];
if (Tag & EDGE_V_DIR) ThisNeuronColor[i] += EdgeColorDiscrimination[i]+EdgeColorDiscrimination[i];
ThisNeuronColor[i] = NeuronBaseColor[i] + fabs( ThisNeuronColor[i] - (int) ThisNeuronColor[i]) *(1.0 - NeuronBaseColor[i]);
}
//if (Tag & EDGE_U_DIR)
// glColor4dv(EdgeColorUDir);
//else
glColor4dv(ThisNeuronColor);
glVertex3d(Neuron2->Pos[0],Neuron2->Pos[1],Neuron2->Pos[2]);
glEnd();
glLineWidth(1.0);
}
*/
void Edge::Draw(){
glBegin(GL_LINES);
glVertex3d(Neuron1->Pos[0],Neuron1->Pos[1],Neuron1->Pos[2]);
glVertex3d(Neuron2->Pos[0],Neuron2->Pos[1],Neuron2->Pos[2]);
glEnd();
}
void PointList::DrawList (RealType PointSize, int ChunkSize, int BaseIteration){
if (!DispListNumber) return; // list not initialized
glNewList(DispListNumber,GL_COMPILE);
for(int i=0; i<Size; i++){
// first points after index (cyclic) are purple all others are blue
/*
if ( ((i-(BaseIteration % Size)) % Size) < ChunkSize)
glColor4dv(PointColorUsed);
else
glColor4dv(PointColorNotUsed);
Array[i]->Draw(PointSize*Array[i]->Weight);
*/
/*
if ( Array[i]->Weight == 1.0)
glColor4dv(PointColorUsed);
else
glColor4dv(PointColorNotUsed);
Array[i]->Draw(PointSize);//*Array[i]->Weight);
*/
double ThisNeuronColor[4];
if (Array[i]->Classification != NULL){
for (int j=0;j<4;j++){
ThisNeuronColor[j] = Array[i]->Classification->NeuronId * NeuronPatchAdditionColor[j];
ThisNeuronColor[j] = NeuronBaseColor[j] + fabs( ThisNeuronColor[j] - (int) ThisNeuronColor[j]) *(1.0 - NeuronBaseColor[j]);
}
glColor4dv(ThisNeuronColor);
}
else
glColor4dv(PointColorUsed);
Array[i]->Draw(PointSize);//*Array[i]->Weight);
}
glEndList();
RecalcForDisplay=false;
MyGLErrorMessage("building point list");
}
void PointList::Draw(){
if (!DispListNumber) return; // list not initialized
glCallList(DispListNumber);
}
void NeuralNet::DrawList(RealType PointSize, RealType NormalSize ){
if (!DispListNumber) return; // list not initialized
int i=0,
NetSize=Neurons.Size;
glNewList(DispListNumber,GL_COMPILE);
Neuron *It=Neurons.Head;
if (Neurons.Head!=NULL) do{
//glColor4dv(NeuronColor);
It->Draw(PointSize, NormalSize);
It=It->Next;
i++; //just count to see that there is no missing point at the end
} while (It!=Neurons.Head);
if (i != Neurons.Size) MyFatalError ("NeuralNet::DrawList - inconsistency detected in size of list");
glEndList();
MyGLErrorMessage("building NN list");
}
void NeuralNet::Draw(){
if (!DispListNumber) return; // list not initialized
glCallList(DispListNumber);
}
int MyGLErrorMessage(char *ErrorMessage){
int err=glGetError();
if (err){
const unsigned char *ErrStr = gluErrorString(err);
TRACE ("GL error: %s - %s\n",ErrorMessage,ErrStr);
ASSERT(0);
exit(0);
}
return err;
}
void NeuralNet::InitDispList(){
DispListNumber = glGenLists(1);
MyGLErrorMessage("NN init value");
// we assume no glerror is created... add warning later in here
// we create the an empty list...
glNewList(DispListNumber,GL_COMPILE);
glRectf(0.0,0.0,1.0,1.0);
glEndList();
MyGLErrorMessage("NN init list");
}
void PointList::InitDispList(){
DispListNumber = glGenLists(1);
MyGLErrorMessage("Ptlist init value");
// we assume no glerror is created... add warning later in here
// we create the an empty list...
glNewList(DispListNumber,GL_COMPILE);
glRectf(0.0,0.0,1.0,1.0);
glEndList();
MyGLErrorMessage("Ptlist init list");
}
void EdgeList::Draw(){
if (!DispListNumber) return; // list not initialized
glCallList(DispListNumber);
}
void EdgeList::DrawList(int DrawEdgeNew){
if (!DispListNumber) return; // list not initialized
int i=0;
glNewList(DispListNumber,GL_COMPILE);
Edge *TempEdge=Head;
if (Head!=NULL) do {
// TempEdge->Draw();
if (TempEdge->Tag & EDGE_U_DIR){
glLineWidth(2);
glColor4dv(EdgeColorUDir);
}
else if (TempEdge->Tag & EDGE_V_DIR){
glLineWidth(2);
glColor4dv(EdgeColorVDir);
}
else if (TempEdge->NotConsistantInDirection){
glLineWidth(8);
glColor4dv(EdgeColorNotConsistantInDirection);
}
else if (TempEdge->FaceCounter ==1 )
glColor4dv(EdgeColorBoundary);
else if (TempEdge->FaceCounter ==2 )
glColor4dv(EdgeColorInside);
else if (TempEdge->FaceCounter >2 ){
glLineWidth(8);
glColor4dv(EdgeColorNonManifold);
}
else
glColor4dv(EdgeColor);
if (TempEdge->Tag & EDGE_ADDED_FOR_TRIANGULATION){
glEnable (GL_LINE_STIPPLE);
glLineStipple(1,0x0f0f);
TempEdge->Draw();
glDisable (GL_LINE_STIPPLE);
}
else
TempEdge->Draw();
// return line width to original
glLineWidth(1);
TempEdge=TempEdge->Next;
i++; //just count to see that there is no missing point at the end
} while (TempEdge!=Head);
#ifdef MY_DEBUG
// debug check
if (i != Size) MyFatalError("EdgeList::DrawList - inconsistency in list size was detected");
#endif
glEndList();
MyGLErrorMessage("building Edge list");
}
void EdgeList::InitDispList(){
DispListNumber = glGenLists(1);
MyGLErrorMessage("Edgelist init value");
// we assume no glerror is created... add warning later in here
// we create the an empty list...
glNewList(DispListNumber,GL_COMPILE);
glRectf(0.0,0.0,1.0,1.0);
glEndList();
MyGLErrorMessage("Edgelist init list");
}
void FaceList::Draw(){
if (!DispListNumber) return; // list not initialized
glCallList(DispListNumber);
}
void FaceList::DrawList(){
// this function draws all the edges, the first DrawEdgeNew edges are drawn in a different color.
// for rectangular topology grids, the U direction edges are drawn with a different color from V direction edges
if (!DispListNumber) return; // list not initialized
int i=0;
glNewList(DispListNumber,GL_COMPILE);
Face *TempFace=Head;
if (Head!=NULL) do {
//glColor4dv(FaceColorTransperant);
//glColor4d(0.0,1.0-(double)TempFace->PatchNumber/5.0,(double)TempFace->PatchNumber/5.0,1.0);//0.5);
//glColor4d(0.0,1.0-(double)TempFace->Tag/5.0,(double)TempFace->Tag/5.0,1.0);//0.5);
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,MaterialSpecularColor);
glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,MaterialShininess);
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE , FaceMaterialColorFront);
glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE , FaceMaterialColorBack);
//glColor4fv(FaceMaterialColor);
TempFace->Draw();
TempFace=TempFace->Next;
i++; //just count to see that there is no missing point at the end
} while (TempFace!=Head);
#ifdef MY_DEBUG
// debug check
if (i != Size) MyFatalError("FaceList::DrawList - inconsistency in list size was detected");
#endif
glEndList();
MyGLErrorMessage("building Face list");
}
void FaceList::InitDispList(){
DispListNumber = glGenLists(1);
MyGLErrorMessage("Edgelist init value");
// we assume no glerror is created... add warning later in here
// we create the an empty list...
glNewList(DispListNumber,GL_COMPILE);
glRectf(0.0,0.0,1.0,1.0);
glEndList();
MyGLErrorMessage("Facelist init list");
}
void Face::Draw(){
Neuron *Neuron1,*Neuron2,*Neuron3;
GetFaceNeurons(&Neuron1,&Neuron2,&Neuron3);
glPushName ( (GLint) this);
if (!FlipDirection){
glBegin(GL_POLYGON);
glNormal3d(Neuron1->Normal.Pos[0],Neuron1->Normal.Pos[1],Neuron1->Normal.Pos[2]);
glVertex3d(Neuron1->Pos[0],Neuron1->Pos[1],Neuron1->Pos[2]);
glNormal3d(Neuron2->Normal.Pos[0],Neuron2->Normal.Pos[1],Neuron2->Normal.Pos[2]);
glVertex3d(Neuron2->Pos[0],Neuron2->Pos[1],Neuron2->Pos[2]);
glNormal3d(Neuron3->Normal.Pos[0],Neuron3->Normal.Pos[1],Neuron3->Normal.Pos[2]);
glVertex3d(Neuron3->Pos[0],Neuron3->Pos[1],Neuron3->Pos[2]);
glEnd();
}
else{
glBegin(GL_POLYGON);
glNormal3d(Neuron3->Normal.Pos[0],Neuron3->Normal.Pos[1],Neuron3->Normal.Pos[2]);
glVertex3d(Neuron3->Pos[0],Neuron3->Pos[1],Neuron3->Pos[2]);
glNormal3d(Neuron2->Normal.Pos[0],Neuron2->Normal.Pos[1],Neuron2->Normal.Pos[2]);
glVertex3d(Neuron2->Pos[0],Neuron2->Pos[1],Neuron2->Pos[2]);
glNormal3d(Neuron1->Normal.Pos[0],Neuron1->Normal.Pos[1],Neuron1->Normal.Pos[2]);
glVertex3d(Neuron1->Pos[0],Neuron1->Pos[1],Neuron1->Pos[2]);
glEnd();
}
glPopName ();
}