Commit 998eff30c0d58164de22da84bdd36218dbdd1a23
1 parent
f37cf039
modified to use with the new random.h and modified spharmonics.pdf classes
Showing
1 changed file
with
45 additions
and
26 deletions
Show diff stats
main.cpp
... | ... | @@ -8,6 +8,7 @@ |
8 | 8 | #include <stim/visualization/obj.h> |
9 | 9 | #include <stim/visualization/gl_spharmonics.h> |
10 | 10 | #include <stim/math/constants.h> |
11 | +#include <stim/math/random.h> | |
11 | 12 | |
12 | 13 | #define theta_scale 0.01 |
13 | 14 | #define phi_scale 0.01 |
... | ... | @@ -95,6 +96,18 @@ void display(){ |
95 | 96 | glVertex3f(0.0, 0.0, 0.0); |
96 | 97 | glVertex3f(0.0, 0.0, 100.0); |
97 | 98 | glEnd(); |
99 | + | |
100 | + glColor3f(1.0f, 0.0f, 0.0f); | |
101 | + glBegin(GL_LINES); | |
102 | + glVertex3f(0.0, 0.0, 0.0); | |
103 | + glVertex3f(100.0, 0.0, 0.0); | |
104 | + glEnd(); | |
105 | + | |
106 | + glColor3f(0.0f, 0.0f, 1.0f); | |
107 | + glBegin(GL_LINES); | |
108 | + glVertex3f(0.0, 0.0, 0.0); | |
109 | + glVertex3f(0.0, 100.0, 0.0); | |
110 | + glEnd(); | |
98 | 111 | } |
99 | 112 | |
100 | 113 | //flush commands on the GPU |
... | ... | @@ -153,7 +166,7 @@ void mouse_drag(int x, int y){ |
153 | 166 | |
154 | 167 | glutPostRedisplay(); |
155 | 168 | } |
156 | - | |
169 | +/* | |
157 | 170 | float uniformRandom() |
158 | 171 | { |
159 | 172 | return ( (float)(rand()))/( (float)(RAND_MAX)); |
... | ... | @@ -207,7 +220,7 @@ sample_sphere(int num_samples, float radius = 1.0) |
207 | 220 | |
208 | 221 | return samples; |
209 | 222 | } |
210 | - | |
223 | +*/ | |
211 | 224 | void process_arguments(int argc, char* argv[]){ |
212 | 225 | |
213 | 226 | args.add("help", "prints this help"); |
... | ... | @@ -219,6 +232,7 @@ void process_arguments(int argc, char* argv[]){ |
219 | 232 | args.add("zaxis", "render the z-axis as a green line"); |
220 | 233 | args.add("pdf", "outputs the PDF if an OBJ files is given"); |
221 | 234 | args.add("interp", "interpolates between two specified sets of coefficients", "", "[c0 c1 c2 c3 ...]"); |
235 | + args.add("center", "the center of the model given with --obj", "[x y z]"); | |
222 | 236 | |
223 | 237 | //process the command line arguments |
224 | 238 | args.parse(argc, argv); |
... | ... | @@ -315,12 +329,29 @@ void process_arguments(int argc, char* argv[]){ |
315 | 329 | } |
316 | 330 | else if(args["obj"].is_set()){ |
317 | 331 | |
318 | - std::string filename = args["obj"].as_string(0); | |
319 | - unsigned int l = args["obj"].as_int(1); | |
320 | - int p = args["obj"].as_int(2); | |
321 | - std::cout << p << std::endl; | |
322 | - std::vector<stim::vec3<float> > sphere = sample_sphere(p); | |
323 | - p = p+3; | |
332 | + std::string filename = args["obj"].as_string(0); ///Read Filename | |
333 | + unsigned int l = args["obj"].as_int(1); ///l value | |
334 | + int p = args["obj"].as_int(2); ///number of samples | |
335 | + stim::obj<double> object(filename); ///Open the file | |
336 | + stim::vec3<double> c; ///read the center | |
337 | + if(args["center"].is_set()) | |
338 | + stim::vec3<double> c(args["center"].as_float(0), args["center"].as_float(1), args["center"].as_float(2)); | |
339 | + else | |
340 | + c = stim::vec3<double>(0,0,0); | |
341 | + | |
342 | + unsigned int nV = object.numV(); | |
343 | + std::vector< stim::vec3<double> > points; ///redo the points such that they are in a stim::vec3 array, not stim::vec array | |
344 | +// points.resize(nV); | |
345 | + | |
346 | + for(int i = 0; i < nV; i++) | |
347 | + { | |
348 | + stim::vec<double> temp = object.getV(i); | |
349 | + points.push_back(stim::vec3<double>(temp[0], temp[1], temp[2])); | |
350 | + } | |
351 | + S.pdf(points, l, l, c, p); | |
352 | + | |
353 | +/* | |
354 | + std::vector<stim::vec3<double> > sphere = stim::Random<double>::sample_sphere(p, 1.0, stim::TAU); | |
324 | 355 | |
325 | 356 | //create an obj object |
326 | 357 | stim::obj<double> object(filename); |
... | ... | @@ -334,8 +365,8 @@ void process_arguments(int argc, char* argv[]){ |
334 | 365 | |
335 | 366 | //for each vertex in the model, create an MC sample |
336 | 367 | std::vector< stim::vec<double> > spherical; |
337 | - stim::vec<float> sample; | |
338 | - stim::vec<float> centered; | |
368 | + stim::vec<double> sample; | |
369 | + stim::vec<double> centered; | |
339 | 370 | for(unsigned int i = 0; i < nV; i++){ |
340 | 371 | |
341 | 372 | sample = object.getV(i); //get a vertex in cartesian coordinates |
... | ... | @@ -346,7 +377,7 @@ void process_arguments(int argc, char* argv[]){ |
346 | 377 | //generate the spherical PDF |
347 | 378 | stim::spharmonics<double> P; |
348 | 379 | P.pdf(spherical, l, l); |
349 | - std::vector<float> weights; ///array of weights | |
380 | + std::vector<double> weights; ///array of weights | |
350 | 381 | if(args["pdf"].is_set()) |
351 | 382 | { |
352 | 383 | // S.pdf(spherical, l, l); |
... | ... | @@ -355,7 +386,7 @@ void process_arguments(int argc, char* argv[]){ |
355 | 386 | float val = 0; ///value starts with 0 |
356 | 387 | for(int j = 0; j < nV; j++) ///for each point on surface |
357 | 388 | { |
358 | - stim::vec3<float> star(object.getV(j)[0] - c[0], | |
389 | + stim::vec3<double> star(object.getV(j)[0] - c[0], | |
359 | 390 | object.getV(j)[1] - c[1], |
360 | 391 | object.getV(j)[2] - c[2]); ///center each point on the model |
361 | 392 | // val += abs(star.dot(sphere[i])); ///sum the dot product of the centered point and the sphere. |
... | ... | @@ -368,20 +399,7 @@ void process_arguments(int argc, char* argv[]){ |
368 | 399 | S.mcBegin(l,l); |
369 | 400 | for(int i = 0; i < p; i++) |
370 | 401 | { |
371 | - if(sphere[i] == stim::vec3<float>(0., 0., 1.)) | |
372 | - { | |
373 | - std::cout << i << sphere[i] << " " << weights[i] << std::endl; | |
374 | - } | |
375 | - if(sphere[i] == stim::vec3<float>(0., 1., 0.)) | |
376 | - { | |
377 | - std::cout << i << sphere[i] << " " << weights[i] << std::endl; | |
378 | - } | |
379 | - if(sphere[i] == stim::vec3<float>(0., -1., 0.)) | |
380 | - { | |
381 | - std::cout << i << sphere[i] << " " << weights[i] << std::endl; | |
382 | - } | |
383 | - //std::cout << i << sphere[i] << " " << weights[i] << std::endl; | |
384 | - stim::vec3<float> sph = sphere[i].cart2sph(); | |
402 | + stim::vec3<double> sph = sphere[i].cart2sph(); | |
385 | 403 | S.mcSample(sph[1], sph[2], weights[i]); |
386 | 404 | } |
387 | 405 | S.mcEnd(); |
... | ... | @@ -400,6 +418,7 @@ void process_arguments(int argc, char* argv[]){ |
400 | 418 | } |
401 | 419 | S.mcEnd(); |
402 | 420 | } |
421 | +*/ | |
403 | 422 | } |
404 | 423 | |
405 | 424 | //if the user specifies an SH basis function | ... | ... |