Blame view

NetworkComparison.cpp 8.85 KB
ebb721c7   David Mayerich   new repository fo...
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
  #include "rts/rtsPoint3d.h"
  #include <vector>
  #include <string>
  
  //AnyOption library for parsing command-line options:
  //http://www.hackorama.com/anyoption/
  #include "anyoption.h"
  
  //#include "ImplicitCalculations.h"
  #include "rts/objJedi.h"
  #include "DrawingFunctions.h"
  #include "rts/rtsGraph.h"
  #include "rts/rtsFilename.h"
  
  #define PRINT_LOG	1
  
  
  using namespace std;
  
  bool displayGui = false;
  bool displayVerbose = false;
  
  rtsFiberNetwork* goldNetwork;
  GLint goldNodeDL;
  
  rtsFiberNetwork* testNetwork;
  
  //standard deviation of the gaussian envelope surrounding the networks
  float sigmaG, sigmaC;
  
  int glutwindow_id;
  
  void GlutMenuCallback(int option);
  
  void LoadNetworks(string gold_filename, string test_filename)
  {
  
  	goldNetwork = new rtsFiberNetwork();
  	testNetwork = new rtsFiberNetwork();
  
  	cout<<endl;
  	cout<<"Gold Standard:"<<endl;
  	goldNetwork->LoadSWC(gold_filename);
  	cout<<"Nodes: "<<goldNetwork->NodeList.size()<<endl;
  	cout<<"Fibers: "<<goldNetwork->FiberList.size()<<endl;
  	cout<<"Total Length: "<<goldNetwork->getTotalLength()<<endl;
  
  	cout<<endl;
  
  	cout<<"Test Network:"<<endl;
  	testNetwork->LoadSWC(test_filename);
  	cout<<"Nodes: "<<testNetwork->NodeList.size()<<endl;
  	cout<<"Fibers: "<<testNetwork->FiberList.size()<<endl;
  	cout<<"Total Length: "<<testNetwork->getTotalLength()<<endl;
  
  	cout<<endl;
  
  	//focusNetwork = testNetwork;
  }
  
  void SpecialKeys(int key, int x, int y)
  {
  	if(key == GLUT_KEY_LEFT)
  		IncrementSelectedFiber(-1);
  	if(key == GLUT_KEY_RIGHT)
  		IncrementSelectedFiber(1);
  }
  
  void PrintHelp()
  {
  	cout<<"'.' = Center Camera"<<endl;
  	cout<<"'z' = Reduce Radius"<<endl;
  	cout<<"'x' = Increase Radius"<<endl;
  	cout<<"'c' = Color Segments"<<endl;
  }
  
  void KeyboardFunction(unsigned char key, int x, int y)
  {
  	if(key == '.')
  		RecenterCamera();
  	if(key == '?')
  		PrintHelp();
  	if(key == 'z')
  	{
  		fiber_radius_factor += 0.1;
  		node_radius_factor += 0.1;
  		CreateDisplayLists();
  	}
  	if(key == 'x')
  	{
  		fiber_radius_factor -= 0.1;
  		node_radius_factor -= 0.1;
  		CreateDisplayLists();
  	}
  	if(key == 'c')
  	{
  		ColorFibers();
  		CreateDisplayLists();
  	}
  	if(key == 'q')
  	{
  		exit(1);
  	}
  
  }
  
  void InitializeOpenGL()
  {
      //GLUT stuff
  	//menus
  	rts_glutInitialize("Network Comparison", 1000, 500);
  
  	int mnuMain = glutCreateMenu(GlutMenuCallback);
  	int mnuColormap = glutCreateMenu(GlutMenuCallback);
  
  	glutSetMenu(mnuMain);
  	glutAddMenuEntry("Network", DISPLAY_NETWORK);
  	glutAddMenuEntry("Graph", DISPLAY_GRAPH);
  	glutAddMenuEntry("Connected", DISPLAY_CONNECTED);
  	glutAddMenuEntry("Selected", DISPLAY_SELECTED);
  
  	//create the colormap menu
  	glutAddSubMenu("Colormap", mnuColormap);
  	glutSetMenu(mnuColormap);
  	glutAddMenuEntry("Isoluminant", COLORMAP_ISOLUMINANT);
  	glutAddMenuEntry("Black Body", COLORMAP_BLACKBODY);
  	glutAddMenuEntry("Brewer", COLORMAP_BREWER);
  	glutAddMenuEntry("Rainbow", COLORMAP_RAINBOW);
  
  	glutSetMenu(mnuMain);
  	glutAddMenuEntry("Exit", NETCOMP_EXIT);
  	glutAddMenuEntry("Cull Test-Case", CULL_TEST_CASE);
  	glutAddMenuEntry("Recompute NetMets", RECOMPUTE_METRIC);
  	glutAttachMenu(GLUT_RIGHT_BUTTON);
  
  	//keyboard stuff
  	glutSpecialFunc(SpecialKeys);
  	glutKeyboardFunc(KeyboardFunction);
  
  	//camera
  	point3D<float> min_point0 = goldNetwork->min_pos;
  	point3D<float> min_point1 = testNetwork->min_pos;
  
  	point3D<float> max_point0 = goldNetwork->max_pos;
  	point3D<float> max_point1 = testNetwork->max_pos;
  
  	point3D<float> min_point(min(min_point0.x, min_point1.x), min(min_point0.y, min_point1.y), min(min_point0.z, min_point1.z));
  	point3D<float> max_point(max(max_point0.x, max_point1.x), max(max_point0.y, max_point1.y), max(max_point0.z, max_point1.z));
  	point3D<float> center_point = min_point + 0.5*(max_point - min_point);
  	network_span = (max_point - point3D<float>(0, 0, 0)).Length();
  	rts_glut_camera.setPosition(0, 0, 3*network_span);
  	rts_glut_camera.LookAt(center_point, vector3D<float>(0.0, 1.0, 0.0));
  
  
  	//load the shaders
  	makeColormap();
  	//create strings for all of the shader filenames
  	string SmoothShaderVertexFilename = "";
  		SmoothShaderVertexFilename += "SmoothShader_Vertex.glsl";
  	string SmoothShaderFragmentFilename = "";
  		SmoothShaderFragmentFilename += "SmoothShader_Fragment.glsl";
  	string ErrorMapFragmentFilename = "";
  		ErrorMapFragmentFilename += "ErrorMap_Fragment.glsl";
  
  	//Edge_ErrorShader.Init();
  	//ErrorShader.Clean();
  
  	Edge_ErrorShader.AttachShader(GL_VERTEX_SHADER, SmoothShaderVertexFilename.c_str());
  
  	//Edge_ErrorShader.AttachShader(GL_FRAGMENT_SHADER, "ErrorShader_Fragment.glsl");
  	Edge_ErrorShader.AttachShader(GL_FRAGMENT_SHADER, ErrorMapFragmentFilename.c_str());
  	Edge_ErrorShader.Compile();
  
  	//cout<<"Edge Error Shader Log-------------------------"<<endl;
  	Edge_ErrorShader.PrintLog();
  	Edge_ErrorShader.Link();
  	Edge_ErrorShader.PrintLog();
  	Edge_ErrorShader.AttachGlobalUniform("L1_pos", L1_pos);
  	Edge_ErrorShader.AttachTextureMap("colorMap", texColorMap);
  
  
  	Node_ErrorShader.AttachShader(GL_VERTEX_SHADER, SmoothShaderVertexFilename.c_str());
  	Node_ErrorShader.AttachShader(GL_FRAGMENT_SHADER, ErrorMapFragmentFilename.c_str());
  	Node_ErrorShader.Compile();
  	Node_ErrorShader.PrintLog();
  	Node_ErrorShader.Link();
  	Node_ErrorShader.PrintLog();
  	Node_ErrorShader.AttachGlobalUniform("L1_pos", L1_pos);
  	Node_ErrorShader.AttachTextureMap("colorMap", texColorMap);
  
  	Smooth_Shader.AttachShader(GL_VERTEX_SHADER, SmoothShaderVertexFilename.c_str());
  	Smooth_Shader.AttachShader(GL_FRAGMENT_SHADER, SmoothShaderFragmentFilename.c_str());
  	Smooth_Shader.Compile();
  	Smooth_Shader.PrintLog();
  	Smooth_Shader.Link();
  	Smooth_Shader.PrintLog();
  	Smooth_Shader.AttachGlobalUniform("L0_pos", L0_pos);
  	Smooth_Shader.AttachGlobalUniform("L1_pos", L1_pos);
  
  }
  
  void ComputeNetMets()
  {
  
  	testNetwork->Resample(sigmaG);
  	testNetwork->SubdivideNetwork(sigmaG);
  
  	goldNetwork->Resample(sigmaG);
  	goldNetwork->SubdivideNetwork(sigmaG);
  
  
  	//compare the two networks and get the core graph
  	float gFPR, gFNR, cFPR, cFNR;
  	coreGraph = goldNetwork->CompareNetworks(testNetwork, sigmaG, sigmaC, gFPR, gFNR, cFPR, cFNR);
  
  	//output error metrics
  	if(displayVerbose)
  	{
          cout<<"GEOMETRY++++++++++++"<<endl;
          cout<<"False Positive Rate: "<<gFPR<<endl;
          cout<<"False Negative Rate: "<<gFNR<<endl;
          cout<<"CONNECTIVITY++++++++"<<endl;
          cout<<"False Positive Rate: "<<cFPR<<endl;
          cout<<"False Negative Rate: "<<cFNR<<endl;
      }
      else
      {
          cout<<gFPR<<'\t'<<gFNR<<'\t'<<cFPR<<'\t'<<cFNR<<endl;
      }
  
  	//color each of the core graph fiber sequences
  	ColorFibers();
  
  }
  
  #include <stdio.h>
  #include <errno.h>
  int main(int argc, char* argv[])
  {
      //Create an AnyOption object
      AnyOption* opt = new AnyOption();
      opt->addUsage( "" );
      opt->addUsage( "Usage: NetMets [OPTION]... [GROUND TRUTH FILE] [TEST CASE FILE]" );
      opt->addUsage( "" );
      opt->addUsage( " -h  --help         Prints this help " );
      opt->addUsage( " -s  --sigma        Input sigma value (default = 25)");
      opt->addUsage( " -g  --gui          Display NetMets GUI " );
      opt->addUsage( " -v  --verbose      Verbose output " );
      opt->addUsage( "" );
  
      opt->setFlag(  "help", 'h' );   /* a flag (takes no argument), supporting long and short form */
      opt->setFlag(  "gui", 'g' );
      opt->setOption("sigma", 's');
      opt->setFlag( "verbose", 'v');
  
      /* go through the command line and get the options  */
      opt->processCommandArgs( argc, argv );
  
      //display the help
      if( opt->getFlag( "help" ) || opt->getFlag( 'h' ) )
      {
                  opt->printUsage();
                  return 0;
      }
  
      //set a flag to display the GUI if requested
      if( opt->getFlag( "gui" ) || opt->getFlag( 'g' ) )
                  displayGui = true;
      if( opt->getFlag("verbose") || opt->getFlag('v'))
                  displayVerbose = true;
  
      //set the sigma value based on user input
      sigmaG = 25;
  	sigmaC = 25;
  
  	if( opt->getValue( 's' ) != NULL  || opt->getValue( "sigma" ) != NULL  )
  	{
          sigmaG = atof(opt->getValue("sigma"));
          sigmaC = sigmaG;
  
      }
          	//cout << "size = " << atof(opt->getValue("sigma")) << endl ;
  
      //get the filename arguments
      int nArgs = opt->getArgc();
      char** sArgs = (char**)malloc(nArgs);
      for(int a=0; a<nArgs; a++)
          sArgs[a] = opt->getArgv(a);
  
  
  	string gold_filename;
  	string test_filename;
  
  	int resolution = 512;
  	float epsilon = 0.1;
  	if(nArgs < 2)
  	{
  		gold_filename = "00_GT.obj"; test_filename = "00_T.obj"; sigmaG = sigmaC = 25.0;
  		//sigmaG = 25; sigmaC = 25.0;
  
  	}
  	else
  	{
          gold_filename = sArgs[0];
  		test_filename = sArgs[1];
  	}
  
  
  	//load the network files
  	testNetwork = new rtsFiberNetwork();
  	testNetwork->LoadFile(test_filename);
  
  	goldNetwork = new rtsFiberNetwork();
  	goldNetwork->LoadFile(gold_filename);
  
  
  
  
  
  
  	//compute the metric
  	ComputeNetMets();
  
  
  
  	//if the user does not want the GUI displayed, just return
      if(!displayGui) return 0;
  
      //initialize OpenGL
  	InitializeOpenGL();
  
      //create display lists
  	CreateDisplayLists();
  
  
      //set up GLUT and start
  	rts_glutStart(MyDisplayFunction);
  
  	return 0;
  
  }