source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/vrippack-0.31/src/vrip/vripMiscCmds.cc @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 17.1 KB
Line 
1/*
2
3Brian Curless
4
5Computer Graphics Laboratory
6Stanford University
7
8---------------------------------------------------------------------
9
10Copyright (1997) The Board of Trustees of the Leland Stanford Junior
11University. Except for commercial resale, lease, license or other
12commercial transactions, permission is hereby given to use, copy,
13modify this software for academic purposes only.  No part of this
14software or any derivatives thereof may be used in the production of
15computer models for resale or for use in a commercial
16product. STANFORD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND
17CONCERNING THIS SOFTWARE.  No support is implied or provided.
18
19*/
20
21
22#include <limits.h>
23#include <stdlib.h>
24#include <math.h>
25#include <unistd.h>
26#include <sys/wait.h>
27
28#include "vrip.h"
29#include "vripMiscCmds.h"
30#include "vripGlobals.h"
31#include "configure.h"
32#include "occFunc.h"
33
34
35
36int
37Vrip_ParamCmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[])
38{
39    int ival, count;
40    uchar ucval;
41    float fval;
42
43    if (argc == 1) {
44        printf("Command: vrip_param [-option value]\n");
45        printf("  -verbose <boolean> (%d)\n", Verbose);
46        printf("  -warn <boolean> (%d)\n", Warn);
47        printf("  -quiet <boolean> (%d)\n", Quiet);
48
49        printf("  -show_norm <boolean> (%d)\n", ShowNormals);
50        printf("  -show_weight_slice <boolean> (%d)\n", ShowConfSlice);
51        printf("  -show_value_weight <boolean> (%d)\n", ShowValueWeight);
52
53        printf("  -use_tails <boolean> (%d)\n", UseTails);
54        printf("  -tails_only <boolean> (%d)\n", TailsOnly);
55
56        printf("  -fill_gaps <boolean> (%d)\n", FillGaps);
57        printf("  -fill_bg <boolean> (%d)\n", FillBackground);
58        printf("  -do_silhouette <boolean> (%d)\n", DoSilhouette);
59        printf("  -extend_boundary_steps <byte> (%d)\n", EdgeExtensionSamples);
60        //printf("  -mesh_resolution <int> (%d)\n", MeshResolution);
61
62        printf("  -line_persp_center <float> <float> <float> (%f, %f, %f)\n", 
63               LASER_LINE_AT_T0_X, LASER_LINE_AT_T0_Y, LASER_LINE_AT_T0_Z);
64        printf("  -line_persp_dir <float> <float> <float> (%f, %f, %f)\n", 
65               LASER_LINE_DIR_X, LASER_LINE_DIR_Y, LASER_LINE_DIR_Z);
66
67        printf("  -persp_center <float> <float> <float> (%f, %f, %f)\n", 
68               PerspectiveCOP.x, PerspectiveCOP.y, PerspectiveCOP.z);
69        printf("  -persp_dir <float> <float> <float> (%f, %f, %f)\n", 
70               PerspectiveDir.x, PerspectiveDir.y, PerspectiveDir.z);
71        printf("  -use_persp_dir <boolean> (%d)\n", UsePerspectiveDir);
72
73        printf("  -use_length <boolean> (%d)\n", UseEdgeLength);
74        printf("  -min_view_dot <float> (%f)\n", MinViewDot);
75        printf("  -max_edge_length <float> (%f)\n", MaxEdgeLength);
76        printf("  -min_color <char> (%d)\n", MinColor);
77
78        printf("  -vert_weight_bias <byte> (%d)\n", ConfidenceBias);
79
80        printf("  -view_weight_exp <float> (%f)\n", ConfidenceExponent);
81
82        printf("  -boundary_weight_exp <float> (%f)\n", EdgeConfExponent);
83        printf("  -max_boundary_steps <int> (%d)\n", EdgeConfSteps);
84        printf("  -min_boundary_weight <byte> (%d)\n", MinEdgeConfidence);
85        printf("  -min_vertex_confidence float (%f)\n", MinVertexConfidence);
86
87        printf("  -ramp_width <float> (%f)\n", OccupancyRampWidth);
88        printf("  -w1 <float> (%f)\n", WeightPos1);
89        printf("  -w2 <float> (%f)\n", WeightPos2);
90        printf("  -w3 <float> (%f)\n", WeightPos3);
91        printf("  -w4 <float> (%f)\n", WeightPos4);
92        printf("  -w5 <float> (%f)\n", WeightPos5);
93        printf("  -min_voxel_weight <byte> (%d)\n", MinWeight);
94
95        return TCL_OK;
96    }
97
98    count = 1;
99    while (count < argc) {
100        if (EQSTR(argv[count], "-verbose")) {
101            count++;
102            ival = atoi(argv[count]);
103            Verbose = ival != 0;
104        } 
105        else if (EQSTR(argv[count], "-warn")) {
106            count++;
107            ival = atoi(argv[count]);
108            Warn = ival != 0;
109        }
110        else if (EQSTR(argv[count], "-line_persp_center")) {
111            count++;
112            fval = atof(argv[count]);
113            LASER_LINE_AT_T0_X = fval;
114            count++;
115            fval = atof(argv[count]);
116            LASER_LINE_AT_T0_Y = fval;
117            count++;
118            fval = atof(argv[count]);
119            LASER_LINE_AT_T0_Z = fval;
120        }
121        else if (EQSTR(argv[count], "-line_persp_dir")) {
122            count++;
123            fval = atof(argv[count]);
124            LASER_LINE_DIR_X = fval;
125            count++;
126            fval = atof(argv[count]);
127            LASER_LINE_DIR_Y = fval;
128            count++;
129            fval = atof(argv[count]);
130            LASER_LINE_DIR_Z = fval;
131        }
132        else if (EQSTR(argv[count], "-persp_center")) {
133            count++;
134            fval = atof(argv[count]);
135            PerspectiveCOP.x = fval;
136            count++;
137            fval = atof(argv[count]);
138            PerspectiveCOP.y = fval;
139            count++;
140            fval = atof(argv[count]);
141            PerspectiveCOP.z = fval;
142        }
143        else if (EQSTR(argv[count], "-persp_dir")) {
144            count++;
145            fval = atof(argv[count]);
146            PerspectiveDir.x = fval;
147            count++;
148            fval = atof(argv[count]);
149            PerspectiveDir.y = fval;
150            count++;
151            fval = atof(argv[count]);
152            PerspectiveDir.z = fval;
153        }
154        else if (EQSTR(argv[count], "-use_tails")) {
155            count++;
156            ival = atoi(argv[count]);
157            UseTails = ival != 0;
158        }
159        else if (EQSTR(argv[count], "-tails_only")) {
160            count++;
161            ival = atoi(argv[count]);
162            TailsOnly = ival != 0;
163        }
164        else if (EQSTR(argv[count], "-fill_gaps")) {
165            count++;
166            ival = atoi(argv[count]);
167            FillGaps = ival != 0;
168        }
169        else if (EQSTR(argv[count], "-fill_bg")) {
170            count++;
171            ival = atoi(argv[count]);
172            FillBackground = ival != 0;
173        }
174        else if (EQSTR(argv[count], "-do_silhouette")) {
175            count++;
176            ival = atoi(argv[count]);
177            DoSilhouette = ival != 0;
178        }
179        else if (EQSTR(argv[count], "-show_norm")) {
180            count++;
181            ival = atoi(argv[count]);
182            ShowNormals = ival != 0;
183        }
184        else if (EQSTR(argv[count], "-show_value_weight")) {
185            count++;
186            ival = atoi(argv[count]);
187            ShowValueWeight = ival != 0;
188        }
189        else if (EQSTR(argv[count], "-show_weight_slice") ||
190           EQSTR(argv[count], "-show_conf_slice")) {
191            count++;
192            ival = atoi(argv[count]);
193            ShowConfSlice = ival != 0;
194        }
195        else if (EQSTR(argv[count], "-quiet")) {
196            count++;
197            ival = atoi(argv[count]);
198            Quiet = ival != 0;
199        }
200        else if (EQSTR(argv[count], "-superQuiet")) {
201            count++;
202            ival = atoi(argv[count]);
203            SuperQuiet = ival != 0;
204        }
205        else if (EQSTR(argv[count], "-mesh_resolution")) {
206            count++;
207            ival = atoi(argv[count]);
208            MeshResolution = ival;
209        }
210        else if (EQSTR(argv[count], "-vert_weight_bias") ||
211           EQSTR(argv[count], "-confbias")) {
212            count++;
213            ival = atoi(argv[count]);
214            ConfidenceBias = ival;
215        }
216        else if (EQSTR(argv[count], "-min_boundary_weight") ||
217           EQSTR(argv[count], "-minedgeconf")) {
218            count++;
219            ival = atoi(argv[count]);
220            MinEdgeConfidence = ival;
221        }
222        else if (EQSTR(argv[count], "-min_vertex_confidence")) {
223            count++;
224            fval = atof(argv[count]);
225            MinVertexConfidence = fval;
226        }
227        else if (EQSTR(argv[count], "-max_boundary_steps") ||
228           EQSTR(argv[count], "-edgeconfsteps")) {
229            count++;
230            ival = atoi(argv[count]);
231            EdgeConfSteps = ival;
232        }
233        else if (EQSTR(argv[count], "-min_voxel_weight") ||
234           EQSTR(argv[count], "-minweight")) {
235            count++;
236            ival = atoi(argv[count]);
237            MinWeight = ival;
238        }
239        else if (EQSTR(argv[count], "-extend_boundary_steps") ||
240           EQSTR(argv[count], "-extedge")) {
241            count++;
242            ival = atoi(argv[count]);
243            EdgeExtensionSamples = ival;
244        }
245        else if (EQSTR(argv[count], "-max_edge_length") ||
246           EQSTR(argv[count], "-maxedge")) {
247            count++;
248            fval = atof(argv[count]);
249            MaxEdgeLength = fval;
250        }
251        else if (EQSTR(argv[count], "-min_color") ||
252           EQSTR(argv[count], "-mincolor")) {
253            count++;
254            ucval = atoi(argv[count]);
255            MinColor = ucval;
256        }
257        else if (EQSTR(argv[count], "-use_length") ||
258           EQSTR(argv[count], "-uselength")) {
259            count++;
260            ival = atoi(argv[count]);
261            UseEdgeLength = ival;
262        }
263        else if (EQSTR(argv[count], "-min_view_dot") ||
264           EQSTR(argv[count], "-minviewdot")) {
265            count++;
266            fval = atof(argv[count]);
267            MinViewDot = fval;
268        }
269        else if (EQSTR(argv[count], "-ramp_width") ||
270           EQSTR(argv[count], "-rampwidth")) {
271            count++;
272            fval = atof(argv[count]);
273            OccupancyRampWidth = fval;
274        }
275        else if (EQSTR(argv[count], "-w1")) {
276            count++;
277            fval = atof(argv[count]);
278            WeightPos1 = fval;
279        }
280        else if (EQSTR(argv[count], "-w2")) {
281            count++;
282            fval = atof(argv[count]);
283            WeightPos2 = fval;
284        }
285        else if (EQSTR(argv[count], "-w3")) {
286            count++;
287            fval = atof(argv[count]);
288            WeightPos3 = fval;
289        }
290        else if (EQSTR(argv[count], "-w4")) {
291            count++;
292            fval = atof(argv[count]);
293            WeightPos4 = fval;
294        }
295        else if (EQSTR(argv[count], "-w5")) {
296            count++;
297            fval = atof(argv[count]);
298            WeightPos5 = fval;
299        }
300        else if (EQSTR(argv[count], "-boundary_weight_exp") ||
301           EQSTR(argv[count], "-edgeconfexp")) {
302            count++;
303            fval = atof(argv[count]);
304            EdgeConfExponent = fval;
305        }
306        else if (EQSTR(argv[count], "-view_weight_exp") ||
307           EQSTR(argv[count], "-confexp")) {
308            count++;
309            fval = atof(argv[count]);
310            ConfidenceExponent = fval;
311        } else {
312           Tcl_AppendResult(interp, "vrip_param: No such parameter, `", 
313                            argv[count], "'", (char *)NULL);
314           return TCL_ERROR;
315        }
316        count++;
317    }
318
319    return TCL_OK;
320}
321
322
323
324int
325Vrip_MergeTimeCmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[])
326{
327   char time[PATH_MAX];
328
329   sprintf(time, "%f", MergeTime);
330   Tcl_SetResult(interp, time, TCL_VOLATILE);
331
332   return TCL_OK;
333}
334
335
336int
337Vrip_TessTimeCmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[])
338{
339   char time[PATH_MAX];
340
341   sprintf(time, "%f", TesselationTime);
342   Tcl_SetResult(interp, time, TCL_VOLATILE);
343
344   return TCL_OK;
345}
346
347
348int
349Vrip_ResampleRangeTimeCmd(ClientData, Tcl_Interp *interp, 
350                          int argc, const char *argv[])
351{
352   char time[PATH_MAX];
353
354   sprintf(time, "%f", ResampleRangeTime);
355   Tcl_SetResult(interp, time, TCL_VOLATILE);
356
357   return TCL_OK;
358}
359
360
361int
362Vrip_CopyrightCmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[])
363{
364   printf("\n");
365   printf("Copyright (2001)\n");
366   printf("\n");
367   printf("The Board of Regents of the University of Washington (UW)\n");
368   printf("The Board of Trustees of the Leland Stanford Junior University (Stanford)\n");
369   printf("\n");
370   printf("Except for commercial resale, lease, license or other\n");
371   printf("commercial transactions, permission is hereby given to use, copy,\n");
372   printf("modify this software for academic purposes only.  No part of this\n");
373   printf("software or any derivatives thereof may be used in the production of\n");
374   printf("computer models for resale or for use in a commercial product.\n");
375   printf("UW AND STANFORD MAKE NO REPRESENTATIONS OR WARRANTIES OF ANY\n");
376   printf("KIND CONCERNING THIS SOFTWARE.  No support is implied or provided.\n");
377   printf("\n");
378
379   return TCL_OK;
380}
381
382
383int
384PcreateCmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[])
385{
386   // This used to mean something under IRIX...
387
388   /*   char newArgv[100][PATH_MAX];
389    char path[PATH_MAX];
390    int result;
391
392    if (argc == 1) {
393        interp->result = "wrong # of args";
394        return TCL_ERROR;
395    }
396
397    strcpy(path,argv[1]);
398    for (int i = 1; i < argc; i++) {
399        strcpy(newArgv[i-1],argv[i]);
400    }
401    newArgv[argc-1] = NULL;
402
403#ifndef LINUX
404    result = pcreatevp(path, newArgv);
405
406    wait(NULL);
407#endif
408   */
409
410    return TCL_OK;
411}
412
413int
414Vrip_CalibrateRotationCmd(ClientData, Tcl_Interp *interp, 
415                          int argc, const char *argv[])
416{
417   FILE *fp = fopen(argv[1], "r");
418   
419   int i, count = 0;
420   float t0, t1, t2, q0, q1, q2, q3, norm;
421   float inAngles[1000], angles[1000], angle;
422   Quaternion quats[1000];
423   Vec3f trans[1000], axes[1000], center[1000], axis;
424   while (fscanf(fp, "%f %f %f %f %f %f %f %f", 
425                &angle, &t0, &t1, &t2, &q0, &q1, &q2, &q3) > 0) {
426      inAngles[count] = angle;
427      quats[count].setValue(q0, q1, q2, q3);
428      quats[count].normalize();
429      trans[count].setValue(t0,t1,t2);
430      count++;
431   }
432
433   fclose(fp);
434
435   Matrix4f mbase, mbaseinv, mrot, newMat, mat;
436   Quaternion quat, quatAccum;
437   Vec3f transAccum;
438
439   printf("\nXforms relative to origin:\n\n");
440
441   mbase.makeIdentity();
442   quats[0].toMatrix(mbase);
443   mbase.setTranslate(trans[0]);
444   mbaseinv = mbase.inverse();
445
446   for (i = 1; i < count; i++) {
447      mat.makeIdentity();
448      quats[i].toMatrix(mat);
449      mat.setTranslate(trans[i]);
450      mat.multLeft(mbaseinv);
451      quat.fromMatrix(mat);
452      quat.toAxisAngle(angles[i], axes[i]);
453     
454      if (axes[i][1] > 0) {
455         angles[i] = 360 - angles[i];
456         axes[i].negate();
457      }
458      printf("Angle = %f, Axis = (%f, %f, %f)\n", angles[i],
459             axes[i][0], axes[i][1], axes[i][2]);
460
461      newMat.setValue(mat);
462      newMat.setElem(0,0,1-newMat.elem(0,0));
463      newMat.setElem(1,1,1-newMat.elem(1,1));
464      newMat.setElem(2,2,1-newMat.elem(2,2));
465      newMat.inverse();
466
467      printf("Center = (%g, %g, %g)\n", 
468             -newMat.elem(0,3), -newMat.elem(1,3), -newMat.elem(2,3));
469   }
470
471   printf("\nXforms relative to previous scan:\n\n");
472
473   quatAccum.setValue(0,0,0,0);
474   transAccum.setValue(0,0,0);
475
476   for (i = 1; i < count; i++) {
477      mbase.makeIdentity();
478      quats[i-1].toMatrix(mbase);
479      mbase.setTranslate(trans[i-1]);
480      mbaseinv = mbase.inverse();
481
482      mat.makeIdentity();
483      quats[i].toMatrix(mat);
484      mat.setTranslate(trans[i]);
485      mat.multLeft(mbaseinv);
486      quat.fromMatrix(mat);
487
488      quat.normalize();
489
490      quatAccum.q[0] += quat.q[0];
491      quatAccum.q[1] += quat.q[1];
492      quatAccum.q[2] += quat.q[2];
493      quatAccum.q[3] += quat.q[3];
494
495      quat.toAxisAngle(angles[i], axes[i]);
496     
497      if (axes[i][1] > 0) {
498         angles[i] = 360 - angles[i];
499         axes[i].negate();
500      }
501      printf("Angle = %f, Axis = (%f, %f, %f)\n", angles[i],
502             axes[i][0], axes[i][1], axes[i][2]);
503
504      newMat.setValue(mat);
505      newMat.setElem(0,0,1-newMat.elem(0,3));
506      newMat.setElem(1,1,1-newMat.elem(1,3));
507      newMat.setElem(2,2,1-newMat.elem(2,3));
508      newMat.inverse();
509
510      Vec3f center(newMat.elem(0,3), newMat.elem(1,3), newMat.elem(2,3));
511      center.negate();
512
513      transAccum += center;
514
515      printf("Center = (%g, %g, %g)\n", center[0], center[1], center[2]);
516   }
517   
518   transAccum /= -(count-1);
519
520   quatAccum.q[0] /= (count-1);
521   quatAccum.q[1] /= (count-1);
522   quatAccum.q[2] /= (count-1);
523   quatAccum.q[3] /= (count-1);
524   quatAccum.normalize();
525
526   quatAccum.toAxisAngle(angle, axis);
527
528   printf("\nRotation axis and translation based on pairwise:\n\n");
529   printf("Angle = %f, Axis = (%f, %f, %f)\n", angle,
530          axis[0], axis[1], axis[2]);
531   printf("Center = (%g, %g, %g)\n", 
532          transAccum[0], transAccum[1], transAccum[2]);
533
534   return TCL_OK;
535   
536}
537
538int
539Vrip_TestVAScannerCmd(ClientData, Tcl_Interp *interp, 
540                          int argc, const char *argv[])
541{
542   int i;
543   int numPairs;
544   int doHorizontal;
545   float triangAngle;
546   float tiltAngle;
547   FILE *fp;
548   char filename[PATH_MAX];
549   Matrix4f mview1, mview1inv, mview2, mview2inv;
550
551   numPairs = atoi(argv[1]);
552   triangAngle = atof(argv[2])*M_PI/180;
553   tiltAngle = atof(argv[3])*M_PI/180;
554   doHorizontal = !strcmp(argv[4],"horiz");
555   
556   // compute viewing transformations
557   for (i = 0; i < numPairs; i++) {
558      float pairAngle = 360/numPairs * i * M_PI/180; 
559
560      if (doHorizontal) {
561         mview1.makeIdentity();
562         mview1.setRotateY(pairAngle);
563         mview1.rotateX(-tiltAngle);
564         
565         sprintf(filename, "view%d-A.xf", i);
566         fp = fopen(filename, "w");
567         mview1.write(fp);
568         fclose(fp);
569         
570         mview2.makeIdentity();
571         mview2.setRotateY(pairAngle+triangAngle);
572         mview2.rotateX(-tiltAngle);
573         
574         mview1inv = mview1.inverse();
575         mview1inv.multLeft(mview2);
576         
577         sprintf(filename, "view%d-A-to-B.xf", i);
578         fp = fopen(filename, "w");
579         mview1inv.write(fp);
580         fclose(fp);
581         
582         mview2inv = mview2.inverse();
583         
584         sprintf(filename, "align%d-B.xf", i);
585         fp = fopen(filename, "w");
586         mview2inv.write(fp);
587         fclose(fp);     
588      } else {
589         mview1.makeIdentity();
590         mview1.setRotateY(pairAngle);
591         mview1.rotateX(-tiltAngle-triangAngle/2);
592         
593         sprintf(filename, "view%d-A.xf", i);
594         fp = fopen(filename, "w");
595         mview1.write(fp);
596         fclose(fp);
597         
598         mview2.makeIdentity();
599         mview2.setRotateY(pairAngle);
600         mview2.rotateX(-tiltAngle+triangAngle/2);
601         
602         mview1inv = mview1.inverse();
603         mview1inv.multLeft(mview2);
604         
605         sprintf(filename, "view%d-A-to-B.xf", i);
606         fp = fopen(filename, "w");
607         mview1inv.write(fp);
608         fclose(fp);
609         
610         mview2inv = mview2.inverse();
611         
612         sprintf(filename, "align%d-B.xf", i);
613         fp = fopen(filename, "w");
614         mview2inv.write(fp);
615         fclose(fp);
616      }
617   }
618
619   return TCL_OK;
620}
Note: See TracBrowser for help on using the repository browser.