Blame view

main.cu 27.5 KB
7c1b82bc   Jiaming Guo   test for 00_GT.swc
1
  #include <stdlib.h>
db598823   David Mayerich   fixed GCC errors ...
2
3
  #include <string>
  #include <fstream>
f001495e   Jiaming Guo   fix minor errors ...
4
  #include <algorithm> 
db598823   David Mayerich   fixed GCC errors ...
5
6
7
8
9
10
11
12
13
14
15
16
  
  //OpenGL includes
  #include <GL/glut.h>
  #include <GL/freeglut.h>
  
  //STIM includes
  #include <stim/visualization/gl_network.h>
  #include <stim/biomodels/network.h>
  #include <stim/visualization/gl_aaboundingbox.h>
  #include <stim/parser/arguments.h>
  #include <stim/visualization/camera.h>
  
f86a38d3   Jiaming Guo   add device choice...
17
18
19
20
21
  #ifdef __CUDACC__
  //CUDA includes
  #include <cuda.h>
  #endif
  
db598823   David Mayerich   fixed GCC errors ...
22
23
24
25
26
27
28
  //BOOST includes
  #include <boost/tuple/tuple.hpp>
  
  //visualization objects
  stim::gl_aaboundingbox<float> bb;			//axis-aligned bounding box object
  stim::camera cam;					//camera object
  
f001495e   Jiaming Guo   fix minor errors ...
29
  // number of networks
db598823   David Mayerich   fixed GCC errors ...
30
  unsigned num_nets = 0;
f001495e   Jiaming Guo   fix minor errors ...
31
32
  
  // networks
db598823   David Mayerich   fixed GCC errors ...
33
34
  stim::gl_network<float> GT;			//ground truth network
  stim::gl_network<float> T;			//test network
9627c6e6   Jiaming Guo   add splitting and...
35
36
37
  stim::gl_network<float> _GT;		//splitted GT
  stim::gl_network<float> _T;			//splitted T
  
f001495e   Jiaming Guo   fix minor errors ...
38
  // indicator
9627c6e6   Jiaming Guo   add splitting and...
39
  unsigned ind = 0;						//indicator of mapping
9627c6e6   Jiaming Guo   add splitting and...
40
  
f001495e   Jiaming Guo   fix minor errors ...
41
  // relationships
9627c6e6   Jiaming Guo   add splitting and...
42
43
  std::vector<unsigned> _gt_t;								// store indices of nearest edge points in _T for _GT
  std::vector<unsigned> _t_gt;								// store indices of nearest edge points in _GT for _T
db598823   David Mayerich   fixed GCC errors ...
44
45
  
  //hard-coded parameters
f86a38d3   Jiaming Guo   add device choice...
46
47
48
  float resample_rate = 0.5f;			//sample rate for the network (fraction of sigma used as the maximum sample rate)
  float camera_factor = 1.2f;			//start point of the camera as a function of X and Y size
  float orbit_factor = 0.01f;			//degrees per pixel used to orbit the camera
4d23da9c   Jiaming Guo   add 00_GT.swc,now...
49
50
  float zoom_factor = 10.0f;
  float radius_factor = 0.5f;
db598823   David Mayerich   fixed GCC errors ...
51
  
9627c6e6   Jiaming Guo   add splitting and...
52
53
54
55
  //mouse click
  bool LButtonDown = false;			// true when left button down
  bool RButtonDown = false;
  
db598823   David Mayerich   fixed GCC errors ...
56
57
58
59
  //mouse position tracking
  int mouse_x;
  int mouse_y;
  
f001495e   Jiaming Guo   fix minor errors ...
60
  // render modes
9627c6e6   Jiaming Guo   add splitting and...
61
62
63
  bool compareMode = true;			// default mode is compare mode
  bool mappingMode = false;
  
5ac53c9e   Jiaming Guo   add keyboardfunc
64
  // random color set
9627c6e6   Jiaming Guo   add splitting and...
65
66
  std::vector<float> colormap;
  
5ac53c9e   Jiaming Guo   add keyboardfunc
67
68
69
  // special key indicator
  int mods;
  
db598823   David Mayerich   fixed GCC errors ...
70
71
72
  //OpenGL objects
  GLuint cmap_tex = 0;				//texture name for the color map
  
4d23da9c   Jiaming Guo   add 00_GT.swc,now...
73
  float delta;
7c1b82bc   Jiaming Guo   test for 00_GT.swc
74
  float sigma = 3;					//default sigma
4d23da9c   Jiaming Guo   add 00_GT.swc,now...
75
  float radius = 3;					//equals to radius
19ec4731   Jiaming Guo   add light
76
  int adjoint_fac = 0;
e1700dd0   Jiaming Guo   fixed bugs when i...
77
  int light_fac = 0;
7c1b82bc   Jiaming Guo   test for 00_GT.swc
78
  
db598823   David Mayerich   fixed GCC errors ...
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
  //sets an OpenGL viewport taking up the entire window
  void glut_render_single_projection(){
  
  	glMatrixMode(GL_PROJECTION);					//load the projection matrix for editing
  	glLoadIdentity();								//start with the identity matrix
  	int X = glutGet(GLUT_WINDOW_WIDTH);				//use the whole screen for rendering
  	int Y = glutGet(GLUT_WINDOW_HEIGHT);
  	glViewport(0, 0, X, Y);							//specify a viewport for the entire window
  	float aspect = (float)X / (float)Y;				//calculate the aspect ratio
  	gluPerspective(60, aspect, 0.1, 1000000);		//set up a perspective projection
  }
  
  //sets an OpenGL viewport taking up the left half of the window
  void glut_render_left_projection(){
  
  	glMatrixMode(GL_PROJECTION);					//load the projection matrix for editing
  	glLoadIdentity();								//start with the identity matrix
  	int X = glutGet(GLUT_WINDOW_WIDTH) / 2;			//only use half of the screen for the viewport
  	int Y = glutGet(GLUT_WINDOW_HEIGHT);
  	glViewport(0, 0, X, Y);							//specify the viewport on the left
  	float aspect = (float)X / (float)Y;				//calculate the aspect ratio
  	gluPerspective(60, aspect, 0.1, 1000000);		//set up a perspective projection
  }
  
  //sets an OpenGL viewport taking up the right half of the window
  void glut_render_right_projection(){
  
  	glMatrixMode(GL_PROJECTION);					//load the projection matrix for editing
  	glLoadIdentity();								//start with the identity matrix
  	int X = glutGet(GLUT_WINDOW_WIDTH) / 2;			//only use half of the screen for the viewport
  	int Y = glutGet(GLUT_WINDOW_HEIGHT);
  	glViewport(X, 0, X, Y);							//specify the viewport on the right
  	float aspect = (float)X / (float)Y;				//calculate the aspect ratio
  	gluPerspective(60, aspect, 0.1, 1000000);		//set up a perspective projection
  }
  
  void glut_render_modelview(){
  
  	glMatrixMode(GL_MODELVIEW);						//load the modelview matrix for editing
  	glLoadIdentity();								//start with the identity matrix
  	stim::vec3<float> eye = cam.getPosition();		//get the camera position (eye point)
  	stim::vec3<float> focus = cam.getLookAt();		//get the camera focal point
  	stim::vec3<float> up = cam.getUp();				//get the camera "up" orientation
  
db598823   David Mayerich   fixed GCC errors ...
123
124
125
  	gluLookAt(eye[0], eye[1], eye[2], focus[0], focus[1], focus[2], up[0], up[1], up[2]);	//set up the OpenGL camera
  }
  
db598823   David Mayerich   fixed GCC errors ...
126
127
128
  //draws the network(s)
  void glut_render(void) {
  
f85b1b3a   Jiaming Guo   add proper light
129
  	stim::vec3<float> eye = cam.getPosition();		//get the camera position (eye point)
dea61e7f   Jiaming Guo   some tests
130
131
132
  	stim::vec3<float> focus = cam.getLookAt();		//get the camera focal point
  	stim::vec3<float> up = cam.getUp();				//get the camera "up" orientation
  
a1ce3752   David Mayerich   fixed minor light...
133
134
  	stim::vec3<float> v = focus - eye;				//calculate a vector from the camera to the center
  	stim::vec3<float> v1 = v.cross(up);				
dea61e7f   Jiaming Guo   some tests
135
136
137
138
139
  	stim::vec3<float> v2 = up.cross(v);
  	v1 = v1.norm();
  	v2 = v2.norm();
  	stim::vec3<float> l1 = v1 + up;
  	stim::vec3<float> l2 = v2 + -up;
b97049a6   Jiaming Guo   add moving light ...
140
  	stim::vec3<float> s = bb.size();
dea61e7f   Jiaming Guo   some tests
141
142
  	float r = s.len();
  
a1ce3752   David Mayerich   fixed minor light...
143
144
145
146
  	//stim::vec3<float> p1 = focus + l1*r/5;
  	//stim::vec3<float> p2 = focus + l2*r/5;
  	stim::vec3<float> p1 = focus + cam.getUp() * 100000;
  	stim::vec3<float> p2 = cam.getPosition();
dea61e7f   Jiaming Guo   some tests
147
148
149
  
  	// light	
  	GLfloat global_ambient[] = { 0.5, 0.5, 0.5, 1.0 };
f85b1b3a   Jiaming Guo   add proper light
150
  	GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0 };
dea61e7f   Jiaming Guo   some tests
151
  	GLfloat diffuse1[] = { 1.0, 1.0, 1.0, 1.0 };
f85b1b3a   Jiaming Guo   add proper light
152
  	GLfloat diffuse2[] = { 0.4, 0.4, 0.4, 1.0 };
dea61e7f   Jiaming Guo   some tests
153
154
155
  	GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 };
  	GLfloat position1[] = { p1[0], p1[1], p1[2], 1.0 };		// upper right light source
  	GLfloat position2[] = { p2[0], p2[1], p2[2], 1.0 };		// lower left light source
f85b1b3a   Jiaming Guo   add proper light
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
  
  	glClearColor(0.0, 0.0, 0.0, 1.0);
  	glShadeModel(GL_SMOOTH);
  
  	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);
  
  	glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
  	glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse1);
  	glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
  	glLightfv(GL_LIGHT0, GL_POSITION, position1);
  
  	glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
  	glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse2);
  	glLightfv(GL_LIGHT1, GL_SPECULAR, specular);
  	glLightfv(GL_LIGHT1, GL_POSITION, position2);
f85b1b3a   Jiaming Guo   add proper light
171
  
21f03d55   Jiaming Guo   add functions for...
172
173
  	//no mapping, just comparing
  	if (ind == 0) {	
7c1b82bc   Jiaming Guo   test for 00_GT.swc
174
175
176
177
178
179
  		if (num_nets == 1) {										//if a single network is loaded
  			glEnable(GL_DEPTH_TEST);								//enable depth
  			glut_render_single_projection();						//fill the entire viewport
  			glut_render_modelview();								//set up the modelview matrix with camera details
  			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		//clear the screen
  			GT.glCenterline0();										//render the GT network (the only one loaded)
c62540c7   Jiaming Guo   normalization
180
  			glDisable(GL_DEPTH_TEST);
7c1b82bc   Jiaming Guo   test for 00_GT.swc
181
182
183
  		}
  
  		if (num_nets == 2) {										//if two networks are loaded	
7c1b82bc   Jiaming Guo   test for 00_GT.swc
184
  			glEnable(GL_TEXTURE_1D);										//enable texture mapping
c62540c7   Jiaming Guo   normalization
185
  			if (light_fac == 0)
19ec4731   Jiaming Guo   add light
186
  				glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);	//texture map will be used as the network color
e1700dd0   Jiaming Guo   fixed bugs when i...
187
  			else
19ec4731   Jiaming Guo   add light
188
  				glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
7c1b82bc   Jiaming Guo   test for 00_GT.swc
189
  			glBindTexture(GL_TEXTURE_1D, cmap_tex);							//bind the Brewer texture map
c62540c7   Jiaming Guo   normalization
190
191
192
193
194
  			
  			glEnable(GL_DEPTH_TEST);								//enable depth
  			glut_render_left_projection();							//set up a projection for the left half of the window
  			glut_render_modelview();								//set up the modelview matrix using camera details
  			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		//clear the screen
7c1b82bc   Jiaming Guo   test for 00_GT.swc
195
  
4d23da9c   Jiaming Guo   add 00_GT.swc,now...
196
  			GT.glCylinder(sigma, radius);							//render the GT network
19ec4731   Jiaming Guo   add light
197
  			if (adjoint_fac == 1) {
e1700dd0   Jiaming Guo   fixed bugs when i...
198
  				glDisable(GL_TEXTURE_1D);							//disable texture in order to render in other color
8b30eb84   Jiaming Guo   add SPACE keyboar...
199
200
  				glEnable(GL_BLEND);									//enable color blend
  				glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);	//set blend function
e1700dd0   Jiaming Guo   fixed bugs when i...
201
  				glDisable(GL_DEPTH_TEST);							//should disable depth to render transparancy
19ec4731   Jiaming Guo   add light
202
203
  				glColor4f(0.0f, 0.3f, 0.0f, 0.2f);
  				T.glAdjointCylinder(sigma, radius);
8b30eb84   Jiaming Guo   add SPACE keyboar...
204
205
  				glDisable(GL_BLEND);
  				glEnable(GL_DEPTH_TEST);
19ec4731   Jiaming Guo   add light
206
207
  				glEnable(GL_TEXTURE_1D);
  				glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
8b30eb84   Jiaming Guo   add SPACE keyboar...
208
  			}
7c1b82bc   Jiaming Guo   test for 00_GT.swc
209
210
211
  
  			glut_render_right_projection();							//set up a projection for the right half of the window
  			glut_render_modelview();								//set up the modelview matrix using camera details
19ec4731   Jiaming Guo   add light
212
  
4d23da9c   Jiaming Guo   add 00_GT.swc,now...
213
  			T.glCylinder(sigma, radius);							//render the T network
19ec4731   Jiaming Guo   add light
214
  
4d23da9c   Jiaming Guo   add 00_GT.swc,now...
215
  			sigma = radius;											// set sigma equal to radius
7c1b82bc   Jiaming Guo   test for 00_GT.swc
216
217
  		}
  	}
f7d360df   Jiaming Guo   resoloved conflicts
218
  
7c1b82bc   Jiaming Guo   test for 00_GT.swc
219
220
221
222
223
224
225
226
  	//do comparing and mapping
  	else {	
  		if (num_nets == 1) {											//if a single network is loaded
  			std::cout << "You should have at least two networks to do mapping." << std::endl;	//exit program because there isn't enough network
  			exit(1);
  		}
  		if (num_nets == 2) {											//if two networks are loaded
  			if (compareMode) {
9627c6e6   Jiaming Guo   add splitting and...
227
  				glEnable(GL_TEXTURE_1D);										//enable texture mapping
e1700dd0   Jiaming Guo   fixed bugs when i...
228
  				if (light_fac == 0)
19ec4731   Jiaming Guo   add light
229
  					glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);	//texture map will be used as the network color
e1700dd0   Jiaming Guo   fixed bugs when i...
230
  				else
19ec4731   Jiaming Guo   add light
231
  					glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);//map light to texture
9627c6e6   Jiaming Guo   add splitting and...
232
  				glBindTexture(GL_TEXTURE_1D, cmap_tex);							//bind the Brewer texture map
c62540c7   Jiaming Guo   normalization
233
234
  				
  				glEnable(GL_DEPTH_TEST);								//enable depth
dea61e7f   Jiaming Guo   some tests
235
  				glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		//clear the screen
c62540c7   Jiaming Guo   normalization
236
237
  				glut_render_left_projection();							//set up a projection for the left half of the window
  				glut_render_modelview();								//set up the modelview matrix using camera details
dea61e7f   Jiaming Guo   some tests
238
239
240
241
242
243
244
245
246
  
  				glPushMatrix();
  				glTranslatef(p1[0], p1[1], p1[2]);
  				glColor3f(0.0, 1.0, 0.0);
  				glutSolidSphere(10, 10, 10);
  				glPopMatrix();
  				glPushMatrix();
  				glTranslatef(p2[0], p2[1], p2[2]);
  				glColor3f(0.0, 0.0, 1.0);
a1ce3752   David Mayerich   fixed minor light...
247
  				//glutSolidSphere(10, 10, 10);
dea61e7f   Jiaming Guo   some tests
248
249
  				glPopMatrix();
  				glColor3f(1, 1, 1);
9627c6e6   Jiaming Guo   add splitting and...
250
  
4d23da9c   Jiaming Guo   add 00_GT.swc,now...
251
  				_GT.glCylinder(sigma, radius);							//render the GT network
dea61e7f   Jiaming Guo   some tests
252
  
19ec4731   Jiaming Guo   add light
253
254
  				if (adjoint_fac == 1) {
  					glDisable(GL_TEXTURE_1D);							//temporarily disable texture
8b30eb84   Jiaming Guo   add SPACE keyboar...
255
256
257
  					glEnable(GL_BLEND);									//enable color blend
  					glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);	//set blend function
  					glDisable(GL_DEPTH_TEST);							//should disable depth
19ec4731   Jiaming Guo   add light
258
259
  					glColor4f(0.0f, 0.3f, 0.0f, 0.2f);
  					_T.glAdjointCylinder(sigma, radius);
8b30eb84   Jiaming Guo   add SPACE keyboar...
260
261
  					glDisable(GL_BLEND);
  					glEnable(GL_DEPTH_TEST);
19ec4731   Jiaming Guo   add light
262
263
  					glEnable(GL_TEXTURE_1D);							//re-enable texture
  					glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
8b30eb84   Jiaming Guo   add SPACE keyboar...
264
  				}
9627c6e6   Jiaming Guo   add splitting and...
265
266
267
  
  				glut_render_right_projection();							//set up a projection for the right half of the window
  				glut_render_modelview();								//set up the modelview matrix using camera details
19ec4731   Jiaming Guo   add light
268
  
4d23da9c   Jiaming Guo   add 00_GT.swc,now...
269
  				_T.glCylinder(sigma, radius);							//render the T network
19ec4731   Jiaming Guo   add light
270
  
4d23da9c   Jiaming Guo   add 00_GT.swc,now...
271
  				sigma = radius;											//set sigma equal to radius
7c1b82bc   Jiaming Guo   test for 00_GT.swc
272
273
  			}
  			else {
dea61e7f   Jiaming Guo   some tests
274
  				glEnable(GL_COLOR_MATERIAL);
f001495e   Jiaming Guo   fix minor errors ...
275
  				glEnable(GL_DEPTH_TEST);								//enable depth
dea61e7f   Jiaming Guo   some tests
276
  				glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		//clear the screen
f7d360df   Jiaming Guo   resoloved conflicts
277
278
  				glut_render_left_projection();							//set up a projection for the left half of the window
  				glut_render_modelview();								//set up the modelview matrix using camera details
8b30eb84   Jiaming Guo   add SPACE keyboar...
279
  						
19ec4731   Jiaming Guo   add light
280
  				_GT.glRandColorCylinder(0, _gt_t, colormap, sigma, radius);
9627c6e6   Jiaming Guo   add splitting and...
281
282
283
  
  				glut_render_right_projection();							//set up a projection for the right half of the window
  				glut_render_modelview();								//set up the modelview matrix using camera details
8b30eb84   Jiaming Guo   add SPACE keyboar...
284
  																		
19ec4731   Jiaming Guo   add light
285
286
  				_T.glRandColorCylinder(1, _t_gt, colormap, sigma, radius);
  
4d23da9c   Jiaming Guo   add 00_GT.swc,now...
287
  				sigma = radius;											//set sigma equal to radius
9627c6e6   Jiaming Guo   add splitting and...
288
289
  			}
  		}
db598823   David Mayerich   fixed GCC errors ...
290
  	}
c62540c7   Jiaming Guo   normalization
291
292
  	glDisable(GL_DEPTH_TEST);
  	glDisable(GL_TEXTURE_1D);
e1700dd0   Jiaming Guo   fixed bugs when i...
293
294
295
296
297
298
299
300
  
  	if (num_nets == 2) {											// works only with two networks
  		std::ostringstream ss;
  		if (mappingMode)											// if it is in mapping mode
  			ss << "Mapping Mode";
  		else
  			ss << "Compare Mode";									// default mode is compare mode
  
e1700dd0   Jiaming Guo   fixed bugs when i...
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
  		if (light_fac == 1)
  			glDisable(GL_LIGHTING);
  		glMatrixMode(GL_PROJECTION);								// set up the 2d viewport for mode text printing
  		glPushMatrix();
  		glLoadIdentity();
  		int X = glutGet(GLUT_WINDOW_WIDTH);							// get the current window width
  		int Y = glutGet(GLUT_WINDOW_HEIGHT);						// get the current window height
  		glViewport(0, 0, X / 2, Y);									// locate to left bottom corner
  		gluOrtho2D(0, X, 0, Y);										// define othogonal aspect
  		glColor3f(0.8, 0.0, 0.0);									// using red to show mode
  
  		glMatrixMode(GL_MODELVIEW);
  		glPushMatrix();
  		glLoadIdentity();
  
  		glRasterPos2f(0, 5);										//print text in the left bottom corner
  		glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)(ss.str().c_str()));
  
  		glPopMatrix();
  		glMatrixMode(GL_PROJECTION);
  		glPopMatrix();
  		glColor3f(1.0, 1.0, 1.0);									//clear red color
  		if (light_fac == 1)
  			glEnable(GL_LIGHTING);
  	}
  
f85b1b3a   Jiaming Guo   add proper light
327
328
  	glDisable(GL_COLOR_MATERIAL);
  
db598823   David Mayerich   fixed GCC errors ...
329
330
331
332
333
334
  	glutSwapBuffers();
  }
  
  // defines camera motion based on mouse dragging
  void glut_motion(int x, int y){
  	
5ac53c9e   Jiaming Guo   add keyboardfunc
335
  	if(LButtonDown == true && RButtonDown == false && mods != GLUT_ACTIVE_CTRL){
db598823   David Mayerich   fixed GCC errors ...
336
337
338
339
340
341
342
343
344
345
  
  	float theta = orbit_factor * (mouse_x - x);		//determine the number of degrees along the x-axis to rotate
  	float phi = orbit_factor * (y - mouse_y);		//number of degrees along the y-axis to rotate
  
  	cam.OrbitFocus(theta, phi);						//rotate the camera around the focal point
  
  	mouse_x = x;									//update the mouse position
  	mouse_y = y;
  		
  	glutPostRedisplay();							//re-draw the visualization
9627c6e6   Jiaming Guo   add splitting and...
346
  	}
db598823   David Mayerich   fixed GCC errors ...
347
348
  }
  
f001495e   Jiaming Guo   fix minor errors ...
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
  // sets the menu options
  void glut_menu(int value) {
  	if (value == 1) {								// menu 1 represents comparing mode
  		compareMode = true;
  		mappingMode = false;
  	}
  	if (value == 2) {								// menu 2 represents mapping mode
  		compareMode = false;
  		mappingMode = true;
  	}
  	if (value == 3) {
  		exit(0);
  	}
  	glutPostRedisplay();
  }
  
db598823   David Mayerich   fixed GCC errors ...
365
366
  // sets the mouse position when clicked
  void glut_mouse(int button, int state, int x, int y){
9627c6e6   Jiaming Guo   add splitting and...
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
  	
  	if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
  		mouse_x = x;
  		mouse_y = y;
  		LButtonDown = true;
  	}
  	else if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN){
  		mouse_x = x;
  		mouse_y = y;
  		RButtonDown = true;
  	}
  	else if(button == GLUT_LEFT_BUTTON && state == GLUT_UP){
  		mouse_x = x;
  		mouse_y = y;
  		LButtonDown = false;
  	}
  	else if(button == GLUT_RIGHT_BUTTON && state == GLUT_UP){
  		mouse_x = x;
  		mouse_y = y;
  		RButtonDown = false;
  	}
5ac53c9e   Jiaming Guo   add keyboardfunc
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
  
  	/// implementation of mouse click mapping feedback
  	mods = glutGetModifiers();											// get modifier keys
  	if (mods == GLUT_ACTIVE_CTRL) 										// if the CTRL key is pressed
  		if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
  			std::cout << "( " << x << ", " << y << " )" << std::endl;	// if the CTRL key is pressed and LEFT BUTTON is DOWN, print the window coordinates
  
  			GLint    viewport[4];
  			GLdouble modelview[16];
  			GLdouble projection[16];
  			GLdouble winX, winY, winZ;
  			GLdouble posX, posY, posZ;
  
  			glGetIntegerv(GL_VIEWPORT, viewport);
  			glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
  			glGetDoublev(GL_PROJECTION_MATRIX, projection);
  
  			winX = (GLdouble)x;
  			winY = viewport[3] - (GLdouble)y;
  			glReadPixels((GLint)winX, (GLint)winY, (GLsizei)1, (GLsizei)1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);		// need frame buffer FBO
  			gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);						// not sure why it should add 1 to the winZ
  			
  			std::cout << "( " << posX << ", " << posY << ", "<< posZ <<" )" << std::endl;
  		}
9627c6e6   Jiaming Guo   add splitting and...
412
413
  }
  
f001495e   Jiaming Guo   fix minor errors ...
414
415
  // define camera move based on mouse wheel move(actually we can combine this with glut_mouse)
  void glut_wheel(int wheel, int direction, int x, int y) {
b31bfd7d   David Mayerich   added SWC files a...
416
  
4d23da9c   Jiaming Guo   add 00_GT.swc,now...
417
  	if (direction > 0)								// if it is button 3(up), move closer
b31bfd7d   David Mayerich   added SWC files a...
418
  		delta = zoom_factor;
4d23da9c   Jiaming Guo   add 00_GT.swc,now...
419
  	else											// if it is button 4(down), leave farther
7c1b82bc   Jiaming Guo   test for 00_GT.swc
420
  		delta = -zoom_factor;
b31bfd7d   David Mayerich   added SWC files a...
421
422
  
  	cam.Push(delta);
f001495e   Jiaming Guo   fix minor errors ...
423
424
425
426
  	glutPostRedisplay();
  }
  
  // define keyboard inputs
9627c6e6   Jiaming Guo   add splitting and...
427
  void glut_keyboard(unsigned char key, int x, int y){
4d23da9c   Jiaming Guo   add 00_GT.swc,now...
428
429
430
431
432
  	
  	// register different keyboard operation
  	switch (key) {
  		
  		// change render mode
19ec4731   Jiaming Guo   add light
433
434
  		case 'm':															// if keyboard 'm' is pressed, then change render mode
  			if (compareMode && !mappingMode && ind && !adjoint_fac) {		// if current mode is comparing mode
4d23da9c   Jiaming Guo   add 00_GT.swc,now...
435
436
437
  				compareMode = false;
  				mappingMode = true;
  			}
19ec4731   Jiaming Guo   add light
438
  			else if (!compareMode && mappingMode && ind && !adjoint_fac) {	// if current mode is mapping mode
4d23da9c   Jiaming Guo   add 00_GT.swc,now...
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
  				compareMode = true;
  				mappingMode = false;
  			}
  			break;
  
  		// zooming
  		case 'w':						// if keyboard 'w' is pressed, then move closer
  			delta = zoom_factor;
  			cam.Push(delta);
  			break;
  		case 's':						// if keyboard 's' is pressed, then leave farther
  			delta = -zoom_factor;
  			cam.Push(delta);
  			break;
  
  		// resample and re-render the cylinder in different radius
  		case 'd':						// if keyboard 'd' is pressed, then increase radius by radius_factor
  			radius += radius_factor;
  			break;
  		case 'a':						// if keyboard 'a' is pressed, then decrease radius by radius_factor
  			radius -= radius_factor;
  			// get rid of the degenerated case when radius decrease below 0
  			if (radius < 0.001f)
  				radius = 0.2;
  			break;
19ec4731   Jiaming Guo   add light
464
  
e1700dd0   Jiaming Guo   fixed bugs when i...
465
466
467
468
469
470
471
  		// turn on/off the light
  		case 'l':						// if keyboard 'l' is pressed, then change the light
  			if (!light_fac && !adjoint_fac) {
  				light_fac = 1;
  				glEnable(GL_LIGHTING);
  				glEnable(GL_LIGHT0);
  				glEnable(GL_LIGHT1);
e1700dd0   Jiaming Guo   fixed bugs when i...
472
473
474
475
476
477
  			}
  			else if (light_fac && !adjoint_fac) {
  				light_fac = 0;
  				glDisable(GL_LIGHTING);
  				glDisable(GL_LIGHT0);
  				glDisable(GL_LIGHT1);
e1700dd0   Jiaming Guo   fixed bugs when i...
478
479
480
  			}
  			break;
  
19ec4731   Jiaming Guo   add light
481
482
  		// render a transparant T very close to GT in compare mode
  		case 32:						// if keyboard 'SPACE' is pressed, then change the adjoint_fac
e1700dd0   Jiaming Guo   fixed bugs when i...
483
  			if (!adjoint_fac && compareMode && !light_fac)
19ec4731   Jiaming Guo   add light
484
  				adjoint_fac = 1;
e1700dd0   Jiaming Guo   fixed bugs when i...
485
  			else if(adjoint_fac && compareMode && !light_fac)
19ec4731   Jiaming Guo   add light
486
  				adjoint_fac = 0;
8b30eb84   Jiaming Guo   add SPACE keyboar...
487
  			break;
4d23da9c   Jiaming Guo   add 00_GT.swc,now...
488
489
490
491
  
  		// close window and exit application
  		case 27:						// if keyboard 'ESC' is pressed, then exit
  			exit(0);
f001495e   Jiaming Guo   fix minor errors ...
492
  	}
9627c6e6   Jiaming Guo   add splitting and...
493
  	glutPostRedisplay();
db598823   David Mayerich   fixed GCC errors ...
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
  }
  
  #define BREWER_CTRL_PTS 11							//number of control points in the Brewer map
  void texture_initialize(){
  
  	//define the colormap
  	static float  brewer_map[BREWER_CTRL_PTS][3] = {			//generate a Brewer color map (blue to red)
  		{0.192157f, 0.211765f, 0.584314f},
  		{0.270588f, 0.458824f, 0.705882f},
  		{0.454902f, 0.678431f, 0.819608f},
  		{0.670588f, 0.85098f, 0.913725f},
  		{0.878431f, 0.952941f, 0.972549f},
  		{1.0f, 1.0f, 0.74902f},
  		{0.996078f, 0.878431f, 0.564706f},
  		{0.992157f, 0.682353f, 0.380392f},
  		{0.956863f, 0.427451f, 0.262745f},
  		{0.843137f, 0.188235f, 0.152941f},
  		{0.647059f, 0.0f, 0.14902f}
  	};
  
  	glGenTextures(1, &cmap_tex);								//generate a texture map name
  	glBindTexture(GL_TEXTURE_1D, cmap_tex);						//bind the texture map
  
  	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);		//enable linear interpolation
  	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);			//clamp the values at the minimum and maximum
  	glTexImage1D(GL_TEXTURE_1D, 0, 3, BREWER_CTRL_PTS, 0, GL_RGB, GL_FLOAT,	//upload the texture map to the GPU
  					brewer_map);
  }
  
  //Initialize the OpenGL (GLUT) window, including starting resolution, callbacks, texture maps, and camera
  void glut_initialize(){
  	
  	int myargc = 1;					//GLUT requires arguments, so create some bogus ones
  	char* myargv[1];
  	myargv [0]=strdup ("netmets");
  
  	glutInit(&myargc, myargv);									//pass bogus arguments to glutInit()
f001495e   Jiaming Guo   fix minor errors ...
532
  	glutSetOption(GLUT_MULTISAMPLE, 8);
7c1b82bc   Jiaming Guo   test for 00_GT.swc
533
  	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);	//generate a color buffer, depth buffer, and enable double buffering
db598823   David Mayerich   fixed GCC errors ...
534
  	glutInitWindowPosition(100,100);							//set the initial window position
5ac53c9e   Jiaming Guo   add keyboardfunc
535
  	glutInitWindowSize(320, 320);								//set the initial window size
db598823   David Mayerich   fixed GCC errors ...
536
  	glutCreateWindow("NetMets - STIM Lab, UH");					//set the dialog box title
db598823   David Mayerich   fixed GCC errors ...
537
  	
db598823   David Mayerich   fixed GCC errors ...
538
539
540
541
  	// register callback functions
  	glutDisplayFunc(glut_render);			//function executed for rendering - renders networks
  	glutMouseFunc(glut_mouse);				//executed on a mouse click - sets starting mouse positions for rotations
  	glutMotionFunc(glut_motion);			//executed when the mouse is moved while a button is pressed
f001495e   Jiaming Guo   fix minor errors ...
542
  	if (ind == 1) {							//only in mapping mode, keyboard will be used
f001495e   Jiaming Guo   fix minor errors ...
543
  		glutCreateMenu(glut_menu);			//register menu option callback
4d23da9c   Jiaming Guo   add 00_GT.swc,now...
544
545
546
547
548
549
  		glutAddMenuEntry("Comparing Mode", 1);	//register menu 1 as comparing mode
  		glutAddMenuEntry("Mapping Mode", 2);	//register menu 2 as mapping mode
  		glutAddMenuEntry("Exit", 3);			//register menu 3 as exiting
  		glutAttachMenu(GLUT_RIGHT_BUTTON);		//register right mouse to open menu option
  	}		
  	glutKeyboardFunc(glut_keyboard);		//register keyboard callback
b31bfd7d   David Mayerich   added SWC files a...
550
  	glutMouseWheelFunc(glut_wheel);		
db598823   David Mayerich   fixed GCC errors ...
551
  
9627c6e6   Jiaming Guo   add splitting and...
552
  	texture_initialize();									//set up texture mapping (create texture maps, enable features)
db598823   David Mayerich   fixed GCC errors ...
553
554
555
556
557
558
  
  	stim::vec3<float> c = bb.center();		//get the center of the network bounding box
  
  	//place the camera along the z-axis at a distance determined by the network size along x and y
  	cam.setPosition(c + stim::vec<float>(0, 0, camera_factor * std::max(bb.size()[0], bb.size()[1])));
  	cam.LookAt(c[0], c[1], c[2]);						//look at the center of the network
db598823   David Mayerich   fixed GCC errors ...
559
560
  }
  
f86a38d3   Jiaming Guo   add device choice...
561
  #ifdef __CUDACC__
f001495e   Jiaming Guo   fix minor errors ...
562
  // set specific device to work on
f86a38d3   Jiaming Guo   add device choice...
563
564
565
566
567
568
569
570
571
572
  void setdevice(int &device){
  	int count;
  	cudaGetDeviceCount(&count);				// numbers of device that are available
  	if(count < device + 1){
  	std::cout<<"No such device available, please set another device"<<std::endl;
  	exit(1);
  	}
  }
  #else
  void setdevice(int &device){
f001495e   Jiaming Guo   fix minor errors ...
573
  	device = -1;							// set to default -1
f86a38d3   Jiaming Guo   add device choice...
574
575
576
  }
  #endif
  
db598823   David Mayerich   fixed GCC errors ...
577
  //compare both networks and fill the networks with error information
f86a38d3   Jiaming Guo   add device choice...
578
  void compare(float sigma, int device){
db598823   David Mayerich   fixed GCC errors ...
579
  
f86a38d3   Jiaming Guo   add device choice...
580
581
  	GT = GT.compare(T, sigma, device);						//compare the ground truth to the test case - store errors in GT
      T = T.compare(GT, sigma, device);						//compare the test case to the ground truth - store errors in T
db598823   David Mayerich   fixed GCC errors ...
582
583
  
  	//calculate the metrics
691fa079   David Mayerich   initial pass adap...
584
585
  	float FPR = GT.average();						//calculate the metrics
  	float FNR = T.average();
db598823   David Mayerich   fixed GCC errors ...
586
587
588
589
590
  	
  	std::cout << "FNR: " << FPR << std::endl;		//print false alarms and misses
  	std::cout << "FPR: " << FNR << std::endl;
  }
  
f001495e   Jiaming Guo   fix minor errors ...
591
  //split and map two networks and fill the networks' R with metric information
21f03d55   Jiaming Guo   add functions for...
592
  void map(float sigma, int device, float threshold){
9627c6e6   Jiaming Guo   add splitting and...
593
  
f001495e   Jiaming Guo   fix minor errors ...
594
  	// compare and split two networks
21f03d55   Jiaming Guo   add functions for...
595
596
  	_GT.split(GT, T, sigma, device, threshold);
  	_T.split(T, GT, sigma, device, threshold);
9627c6e6   Jiaming Guo   add splitting and...
597
  
f001495e   Jiaming Guo   fix minor errors ...
598
  	// mapping two new splitted networks and get their edge relation
21f03d55   Jiaming Guo   add functions for...
599
600
  	_GT.mapping(_T, _gt_t, device, threshold);
  	_T.mapping(_GT, _t_gt, device, threshold);
9627c6e6   Jiaming Guo   add splitting and...
601
  
f001495e   Jiaming Guo   fix minor errors ...
602
  	// generate random color set based on the number of edges in GT
9627c6e6   Jiaming Guo   add splitting and...
603
  	size_t num = _gt_t.size();							// also create random color for unmapping edge, but won't be used though
5ac53c9e   Jiaming Guo   add keyboardfunc
604
605
  	colormap.resize(3 * num);							// 3 portions compound RGB
  	for(int i = 0; i < 3 * num; i++)
f001495e   Jiaming Guo   fix minor errors ...
606
  		colormap[i] = rand()/(float)RAND_MAX;			// set to [0, 1]
9627c6e6   Jiaming Guo   add splitting and...
607
608
609
610
611
612
613
614
615
  	
  	//calculate the metrics
  	float FPR = _GT.average(0);						//calculate the metrics
  	float FNR = _T.average(0);
  	
  	std::cout << "FNR: " << FPR << std::endl;		//print false alarms and misses
  	std::cout << "FPR: " << FNR << std::endl;
  }
  
db598823   David Mayerich   fixed GCC errors ...
616
617
618
  // writes features of the networks i.e average segment length, tortuosity, branching index, contraction, fractal dimension, number of end and branch points to a csv file
  // Pranathi wrote this - saves network features to a CSV file
  void features(std::string filename){
f86a38d3   Jiaming Guo   add device choice...
619
  		double avgL_t, avgL_gt, avgT_t, avgT_gt, avgB_t, avgB_gt, avgC_t, avgC_gt, avgFD_t, avgFD_gt;
db598823   David Mayerich   fixed GCC errors ...
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
  		unsigned int e_t, e_gt, b_gt, b_t;
  		avgL_gt = GT.Lengths();
  		avgT_gt = GT.Tortuosities();
  		avgL_t = T.Lengths();
  		avgT_t = T.Tortuosities();
  		avgB_gt = GT.BranchingIndex();
  		avgB_t = T.BranchingIndex();
  		avgC_gt = GT.Contractions();
  		avgFD_gt = GT.FractalDimensions();
  		avgC_t = T.Contractions();
  		avgFD_t = T.FractalDimensions();
  		e_gt = GT.EndP();
  		e_t = T.EndP();
  		b_gt = GT.BranchP();
  		b_t = T.BranchP();
  		std::ofstream myfile;
  		myfile.open (filename.c_str());
  		myfile << "Length, Tortuosity, Contraction, Fractal Dimension, Branch Points, End points, Branching Index, \n";
  		myfile << avgL_gt << "," << avgT_gt << "," << avgC_gt << "," << avgFD_gt << "," << b_gt << "," << e_gt << "," << avgB_gt <<std::endl;
  		myfile << avgL_t << "," << avgT_t << "," << avgC_t << "," << avgFD_t << "," << b_t << "," << e_t << "," << avgB_t <<std::endl;
  		myfile.close();
  }
  
  // Output an advertisement for the lab, authors, and usage information
  void advertise(){
  	std::cout<<std::endl<<std::endl;
  	std::cout<<"========================================================================="<<std::endl;
  	std::cout<<"Thank you for using the NetMets network comparison tool!"<<std::endl;
  	std::cout<<"Scalable Tissue Imaging and Modeling (STIM) Lab, University of Houston"<<std::endl;
21f03d55   Jiaming Guo   add functions for...
649
  	std::cout<<"Developers: Pranathi Vemuri, David Mayerich, Jiaming Guo"<<std::endl;
9627c6e6   Jiaming Guo   add splitting and...
650
  	std::cout<<"Source: https://git.stim.ee.uh.edu/segmentation/netmets" <<std::endl;
db598823   David Mayerich   fixed GCC errors ...
651
652
  	std::cout<<"========================================================================="<<std::endl<<std::endl;
  
f86a38d3   Jiaming Guo   add device choice...
653
  	std::cout<<"usage: netmets file1 file2 --sigma 3"<<std::endl;
f001495e   Jiaming Guo   fix minor errors ...
654
  	std::cout<<"            compare two .obj files with a tolerance of 3 (units defined by the network)"<<std::endl<<std::endl;
f86a38d3   Jiaming Guo   add device choice...
655
656
657
658
  	std::cout<<"       netmets file1 --gui"<<std::endl;
  	std::cout<<"            load a file and display it using OpenGL"<<std::endl<<std::endl;
  	std::cout<<"       netmets file1 file2 --device 0"<<std::endl;
  	std::cout<<"            compare two files using device 0 (if there isn't a gpu, use cpu)"<<std::endl<<std::endl;
21f03d55   Jiaming Guo   add functions for...
659
660
  	std::cout<<"       netmets file1 file2 --mapping value"<<std::endl;
  	std::cout<<"            mapping two files in random colors with a threshold of value"<<std::endl<<std::endl;
db598823   David Mayerich   fixed GCC errors ...
661
662
663
664
665
666
667
668
  }
  
  int main(int argc, char* argv[])
  {
  	stim::arglist args;						//create an instance of arglist
  
  	//add arguments
  	args.add("help", "prints this help");
f86a38d3   Jiaming Guo   add device choice...
669
  	args.add("sigma", "force a sigma value to specify the tolerance of the network comparison", "3");
db598823   David Mayerich   fixed GCC errors ...
670
  	args.add("gui", "display the network or network comparison using OpenGL");
f86a38d3   Jiaming Guo   add device choice...
671
  	args.add("device", "choose specific device to run", "0");
db598823   David Mayerich   fixed GCC errors ...
672
  	args.add("features", "save features to a CSV file, specify file name");
9627c6e6   Jiaming Guo   add splitting and...
673
  	args.add("mapping", "mapping input according to similarity");
db598823   David Mayerich   fixed GCC errors ...
674
675
676
677
678
679
680
681
682
  
  	args.parse(argc, argv);					//parse the user arguments
  
  	if(args["help"].is_set() || args.nargs() == 0){			//test for help
  		advertise();										//output the advertisement
  		std::cout<<args.str();								//output arguments
  		exit(1);											//exit
  	}
  	
f001495e   Jiaming Guo   fix minor errors ...
683
684
685
  	if (args.nargs() >= 1) {			// if at least one network file is specified
  		num_nets = 1;					// set the number of networks to one
  		std::vector<std::string> tmp = stim::parser::split(args.arg(0), '.');	// split the filename at '.'
95850378   Jiaming Guo   add two good test...
686
  		if ("swc" == tmp[1]) 			// loading swc file
f001495e   Jiaming Guo   fix minor errors ...
687
  			GT.load_swc(args.arg(0));	// load the specified file as the ground truth
f001495e   Jiaming Guo   fix minor errors ...
688
689
690
691
692
693
694
695
  		else if ("obj" == tmp[1])		// loading obj file
  			GT.load_obj(args.arg(0));	// load the specified file as the ground truth
  		else {
  			std::cout << "Invalid loading file" << std::endl;
  			exit(1);
  		}	
  	}
  
540379da   Jiaming Guo   rewrite loading f...
696
697
698
699
700
  	if (args.nargs() == 2) {								//if two files are specified, they will be displayed in neighboring viewports and compared
  		int device = args["device"].as_int();				//get the device value from the user
  		num_nets = 2;										//set the number of networks to two
  		sigma = args["sigma"].as_float();					//get the sigma value from the user
  		radius = sigma;
95850378   Jiaming Guo   add two good test...
701
702
  		std::vector<std::string> tmp = stim::parser::split(args.arg(1), '.');	// split the filename at '.'
  		if ("swc" == tmp[1]) 								//loading swc files
540379da   Jiaming Guo   rewrite loading f...
703
  			T.load_swc(args.arg(1));                        //load the second (test) network
95850378   Jiaming Guo   add two good test...
704
705
706
707
708
709
  		else if ("obj" == tmp[1])							//loading obj files
  			T.load_obj(args.arg(1));
  		else {
  			std::cout << "Invalid loading file" << std::endl;
  			exit(1);
  		}
540379da   Jiaming Guo   rewrite loading f...
710
711
712
713
714
715
716
717
  		if (args["features"].is_set())						//if the user wants to save features
  			features(args["features"].as_string());
  		//does it need to be resampled??
  		GT = GT.resample(resample_rate * sigma);			//resample both networks based on the sigma value
  		T = T.resample(resample_rate * sigma);
  		if (args["mapping"].is_set()) {
  			float threshold = args["mapping"].as_float();
  			map(sigma, device, threshold);
21f03d55   Jiaming Guo   add functions for...
718
  		}
540379da   Jiaming Guo   rewrite loading f...
719
720
  		else
  			compare(sigma, device);							//run the comparison algorithm
9627c6e6   Jiaming Guo   add splitting and...
721
  		}
db598823   David Mayerich   fixed GCC errors ...
722
723
  
  	//if a GUI is requested, display the network using OpenGL
9627c6e6   Jiaming Guo   add splitting and...
724
  	if(args["gui"].is_set()){
21f03d55   Jiaming Guo   add functions for...
725
726
  		if (args["mapping"].is_set()) {
  			ind = 1;								//set indicator of mapping to 1(true)
9627c6e6   Jiaming Guo   add splitting and...
727
728
  			bb = _GT.boundingbox();					//generate a bounding volume		
  			glut_initialize();						//create the GLUT window and set callback functions		
21f03d55   Jiaming Guo   add functions for...
729
  			glutMainLoop();							//enter GLUT event processing cycle
9627c6e6   Jiaming Guo   add splitting and...
730
  		}
21f03d55   Jiaming Guo   add functions for...
731
  		else {
9627c6e6   Jiaming Guo   add splitting and...
732
733
  			bb = GT.boundingbox();					//generate a bounding volume		
  			glut_initialize();						//create the GLUT window and set callback functions		
21f03d55   Jiaming Guo   add functions for...
734
  			glutMainLoop();							//enter GLUT event processing cycle
9627c6e6   Jiaming Guo   add splitting and...
735
736
  		}
  	}
db598823   David Mayerich   fixed GCC errors ...
737
  }