44700501
pranathivemuri
program to genera...
|
1
2
3
4
|
#include <stdlib.h>
#include <string>
#include <fstream>
#include <algorithm>
|
44700501
pranathivemuri
program to genera...
|
5
|
|
627eed8d
David Mayerich
added a GUI for d...
|
6
7
8
9
10
11
12
13
14
15
|
//OpenGL includes
#include <GL/glut.h>
//STIM includes
#include <stim/visualization/gl_network.h>
#include <stim/visualization/gl_aabb.h>
#include <stim/parser/arguments.h>
#include <stim/visualization/camera.h>
//ANN includes
|
44700501
pranathivemuri
program to genera...
|
16
|
#include <ANN/ANN.h>
|
627eed8d
David Mayerich
added a GUI for d...
|
17
18
|
//BOOST includes
|
44700501
pranathivemuri
program to genera...
|
19
|
#include <boost/tuple/tuple.hpp>
|
03c5492b
pranathivemuri
networks and kd t...
|
20
|
|
627eed8d
David Mayerich
added a GUI for d...
|
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
|
stim::gl_aabb<float> bb;
stim::camera cam;
stim::gl_network<float> GT;
stim::gl_network<float> T;
//hard-coded parameters
float resample_rate = 0.5;
//mouse position tracking
int mouse_x;
int mouse_y;
void glut_render(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
stim::vec<float> eye = cam.getPosition();
stim::vec<float> focus = cam.getLookAt();
stim::vec<float> up = cam.getUp();
gluLookAt(eye[0], eye[1], eye[2], focus[0], focus[1], focus[2], up[0], up[1], up[2]);
// render the bounding box
glColor3f(0.0, 0.0, 1.0);
|
bbb519e6
David Mayerich
fixed AABB display
|
50
51
|
bb.glWire();
|
627eed8d
David Mayerich
added a GUI for d...
|
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
|
//render the GT network (red)
glColor3f(1.0, 0.0, 0.0);
GT.glCenterline();
//render the T network (green)
glColor3f(0.0, 1.0, 0.0);
T.glCenterline();
glutSwapBuffers();
}
// defines camera motion based on mouse dragging
void glut_motion(int x, int y){
float factor = 0.01;
float theta = factor * (mouse_x - x);
float phi = factor * (y - mouse_y);
cam.OrbitFocus(theta, phi);
mouse_x = x;
mouse_y = y;
glutPostRedisplay();
}
// sets the mouse position when clicked
void glut_mouse(int button, int state, int x, int y){
mouse_x = x;
mouse_y = y;
}
// re-calculates the projection matrix if the window is reshaped
void glut_reshape(int x, int y){
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, x, y);
float aspect = (float)x / (float)y;
gluPerspective(60, aspect, 0.1, 1000000);
}
void advertise(){
//output advertisement
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;
std::cout<<"Developers: Pranathi Vemuri, David Mayerich"<<std::endl;
std::cout<<"Source: https://git.stim.ee.uh.edu/segmentation/netmets"<<std::endl;
std::cout<<"========================================================================="<<std::endl<<std::endl;
std::cout<<"usage: netmets file1 file2 --sigma 10"<<std::endl;
std::cout<<" compare two files with a tolerance of 10 (units defined by the network)"<<std::endl;
std::cout<<" netmets file1 --gui"<<std::endl<<std::endl;
std::cout<<" load a file and display it using OpenGL"<<std::endl;
}
void compare(float sigma){
// compare ground truth with truth and viceversa
stim::network<float> cGT = GT.compare(T, sigma);
stim::network<float> cT = T.compare(GT, sigma);
//calculate the metrics
float FPR = cGT.average(1);
float FNR = cT.average(1);
// print false alarms and misses
std::cout << "FNR: " << FPR << std::endl;
std::cout << "FPR: " << FNR << std::endl;
}
void glut_initialize(){
float factor = 1.2;
// init GLUT and create Window
int myargc = 1;
char* myargv[1];
myargv [0]=strdup ("netmets");
glutInit(&myargc, myargv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,320);
glutCreateWindow("Lighthouse3D- GLUT Tutorial");
// register callbacks
glutDisplayFunc(glut_render);
glutMouseFunc(glut_mouse);
glutMotionFunc(glut_motion);
glutReshapeFunc(glut_reshape);
//set up the camera
stim::vec<float> c = bb.center();
//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, factor * std::max(bb.size()[0], bb.size()[1])));
cam.LookAt(c[0], c[1], c[2]); //look at the center
}
void display(){
//generate a bounding volume
bb = GT.boundingbox();
|
627eed8d
David Mayerich
added a GUI for d...
|
162
163
164
165
166
|
//create the GLUT window and set callback functions
glut_initialize();
glut_reshape(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
|
627eed8d
David Mayerich
added a GUI for d...
|
167
168
169
|
// enter GLUT event processing cycle
glutMainLoop();
}
|
44700501
pranathivemuri
program to genera...
|
170
171
172
|
int main(int argc, char* argv[])
{
|
627eed8d
David Mayerich
added a GUI for d...
|
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
//create an instance of arglist
stim::arglist args;
//add arguments
args.add("help", "prints this help");
args.add("sigma", "force a sigma value to specify the tolerance of the network comparison", "10");
args.add("gui", "display the network or network comparison using OpenGL");
//parse the user arguments
args.parse(argc, argv);
//test for help
if(args["help"].is_set() || args.nargs() == 0){
advertise();
std::cout<<args.str();
|
a0048e31
David Mayerich
added several tes...
|
188
189
190
|
exit(1);
}
|
627eed8d
David Mayerich
added a GUI for d...
|
191
192
193
194
|
//if one file is specified, load it as the ground truth
if(args.nargs() >= 1){
GT.load_obj(args.arg(0));
}
|
51c0cf6e
David Mayerich
cleaned up the me...
|
195
|
|
627eed8d
David Mayerich
added a GUI for d...
|
196
197
198
199
|
//if two files are provided, compare them
if(args.nargs() == 2){
float sigma = args["sigma"].as_float(); //get the sigma value from the user
T.load_obj(args.arg(1)); //load the second (test) network
|
51c0cf6e
David Mayerich
cleaned up the me...
|
200
|
|
627eed8d
David Mayerich
added a GUI for d...
|
201
202
|
GT = GT.resample(resample_rate * sigma); //resample both networks based on the sigma value
T = T.resample(resample_rate * sigma);
|
51c0cf6e
David Mayerich
cleaned up the me...
|
203
|
|
627eed8d
David Mayerich
added a GUI for d...
|
204
205
|
compare(sigma); //run the comparison algorithm
}
|
51c0cf6e
David Mayerich
cleaned up the me...
|
206
|
|
627eed8d
David Mayerich
added a GUI for d...
|
207
208
209
210
211
212
|
//if a GUI is requested, display the network using OpenGL
if(args["gui"].is_set())
display();
|
ed5edb3e
pranathivemuri
added function to...
|
213
|
}
|