[37] | 1 | /* |
---|
| 2 | |
---|
| 3 | Brian Curless |
---|
| 4 | |
---|
| 5 | Computer Graphics Laboratory |
---|
| 6 | Stanford University |
---|
| 7 | |
---|
| 8 | --------------------------------------------------------------------- |
---|
| 9 | |
---|
| 10 | Copyright (1997) The Board of Trustees of the Leland Stanford Junior |
---|
| 11 | University. Except for commercial resale, lease, license or other |
---|
| 12 | commercial transactions, permission is hereby given to use, copy, |
---|
| 13 | modify this software for academic purposes only. No part of this |
---|
| 14 | software or any derivatives thereof may be used in the production of |
---|
| 15 | computer models for resale or for use in a commercial |
---|
| 16 | product. STANFORD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND |
---|
| 17 | CONCERNING 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 | #include <sys/times.h> |
---|
| 28 | #include <sys/types.h> |
---|
| 29 | #include <sys/stat.h> |
---|
| 30 | #include <time.h> |
---|
| 31 | #include <errno.h> |
---|
| 32 | |
---|
| 33 | #include "vrip.h" |
---|
| 34 | #include "occFunc.h" |
---|
| 35 | #include "DepthMap.h" |
---|
| 36 | #include "vripRangeCmds.h" |
---|
| 37 | #include "vripGUICmds.h" |
---|
| 38 | #include "vripGlobals.h" |
---|
| 39 | #include "vripAux.h" |
---|
| 40 | |
---|
| 41 | #include "plyio.h" |
---|
| 42 | #include "DepthMapAux.h" |
---|
| 43 | #include "renderGeom.h" |
---|
| 44 | #include "configure.h" |
---|
| 45 | #include "scan.h" |
---|
| 46 | #include "scanRLE.h" |
---|
| 47 | #include "scanLinePerspRLE.h" |
---|
| 48 | #include "scanPerspRLE.h" |
---|
| 49 | #include "scanNormRLE.h" |
---|
| 50 | #include "Mesh.h" |
---|
| 51 | #include "rangePly.h" |
---|
| 52 | |
---|
| 53 | #include "defines.h" |
---|
| 54 | #include "linePersp.h" |
---|
| 55 | #include "perspective.h" |
---|
| 56 | |
---|
| 57 | static clock_t tm; |
---|
| 58 | static void start_time(); |
---|
| 59 | static void end_time(); |
---|
| 60 | static float time_elapsed(); |
---|
| 61 | |
---|
| 62 | static void parse_transformation(Mesh *mesh, Tcl_Interp *interp, |
---|
| 63 | int argc, const char**argv); |
---|
| 64 | |
---|
| 65 | //extern unsigned long TclGetClicks(); |
---|
| 66 | |
---|
| 67 | int |
---|
| 68 | Vrip_RangeScanCmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[]) |
---|
| 69 | { |
---|
| 70 | if (argc != 2 && argc != 3 && argc != 6 && argc != 9 ) { |
---|
| 71 | interp->result = "wrong number of args"; |
---|
| 72 | return TCL_ERROR; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | if (theGrid == NULL) { |
---|
| 76 | interp->result = "Grid not allocated."; |
---|
| 77 | return TCL_ERROR; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | if (!SuperQuiet) |
---|
| 81 | printf("Integrating mesh %s...", argv[1]); |
---|
| 82 | |
---|
| 83 | initOccFunc(); |
---|
| 84 | |
---|
| 85 | start_time(); |
---|
| 86 | |
---|
| 87 | Mesh *mesh = readMeshFromPly(argv[1], FALSE, FALSE); |
---|
| 88 | if (mesh == NULL) |
---|
| 89 | return TCL_ERROR; |
---|
| 90 | |
---|
| 91 | if (!mesh->hasConfidence) |
---|
| 92 | doConfidence(mesh); |
---|
| 93 | |
---|
| 94 | end_time(); |
---|
| 95 | |
---|
| 96 | TesselationTime = time_elapsed(); |
---|
| 97 | |
---|
| 98 | start_time(); |
---|
| 99 | |
---|
| 100 | parse_transformation(mesh, interp, argc, argv); |
---|
| 101 | |
---|
| 102 | Vec3f newdir; |
---|
| 103 | float angle; |
---|
| 104 | if (!mesh->isWarped) |
---|
| 105 | angle = 0; |
---|
| 106 | else if (mesh->isRightMirrorOpen) |
---|
| 107 | angle = 30; |
---|
| 108 | else |
---|
| 109 | angle = -30; |
---|
| 110 | |
---|
| 111 | Vec3f dir(-sin(RAD(angle)), 0, -cos(RAD(angle))); |
---|
| 112 | |
---|
| 113 | Matrix4f rot; |
---|
| 114 | mesh->quat.toMatrix(rot); |
---|
| 115 | |
---|
| 116 | rot.multVec(dir, newdir); |
---|
| 117 | |
---|
| 118 | if (Verbose) |
---|
| 119 | printf("View dir: [%f, %f, %f]\n", newdir.x, newdir.y, newdir.z); |
---|
| 120 | |
---|
| 121 | vec3f yuk; |
---|
| 122 | yuk[0] = newdir.x; |
---|
| 123 | yuk[1] = newdir.y; |
---|
| 124 | yuk[2] = newdir.z; |
---|
| 125 | |
---|
| 126 | OrthoShear *shear = computeShear(yuk); |
---|
| 127 | configureGrid(theGrid, shear); |
---|
| 128 | |
---|
| 129 | float sampleSpacing = sqrt(1 + shear->sx*shear->sx + shear->sy*shear->sy); |
---|
| 130 | |
---|
| 131 | if (UseEdgeLength) { |
---|
| 132 | MAX_DEPTH_DIFFERENCE = MaxEdgeLength/sampleSpacing; |
---|
| 133 | } |
---|
| 134 | else { |
---|
| 135 | MAX_DEPTH_DIFFERENCE = tan(acos(MinViewDot))* |
---|
| 136 | theGrid->resolution/sampleSpacing; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | BBox3f *gbbox = getBBox(theGrid); |
---|
| 140 | |
---|
| 141 | prepareRender(mesh, shear, gbbox, theGrid->resolution, |
---|
| 142 | theDepthMap, FALSE); |
---|
| 143 | softRenderConfidence(mesh); |
---|
| 144 | |
---|
| 145 | /* |
---|
| 146 | DepthMap *dm = renderDepthMap(mesh, shear, gbbox, |
---|
| 147 | theGrid->resolution, NULL); |
---|
| 148 | */ |
---|
| 149 | |
---|
| 150 | if (UseTails) { |
---|
| 151 | if (FillBackground) { |
---|
| 152 | fillBackground(theDepthMap); |
---|
| 153 | } else if (DoSilhouette) { |
---|
| 154 | makeSilhouette(theDepthMap); |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | end_time(); |
---|
| 159 | |
---|
| 160 | ResampleRangeTime = time_elapsed(); |
---|
| 161 | |
---|
| 162 | start_time(); |
---|
| 163 | |
---|
| 164 | if (UseTails) { |
---|
| 165 | scanConvertDragTails(theGrid, shear, theDepthMap); |
---|
| 166 | } |
---|
| 167 | else { |
---|
| 168 | scanConvert(theGrid, shear, theDepthMap); |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | end_time(); |
---|
| 172 | |
---|
| 173 | MergeTime = time_elapsed(); |
---|
| 174 | if (!SuperQuiet) |
---|
| 175 | printf("Time to process: %.2f sec\n", |
---|
| 176 | TesselationTime + ResampleRangeTime + MergeTime); |
---|
| 177 | |
---|
| 178 | delete shear; |
---|
| 179 | delete gbbox; |
---|
| 180 | |
---|
| 181 | return TCL_OK; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | int |
---|
| 185 | Vrip_RangeScanTreeCmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[]) |
---|
| 186 | { |
---|
| 187 | if (argc != 2 && argc != 3 && argc != 6 && argc != 9 ) { |
---|
| 188 | interp->result = "wrong number of args"; |
---|
| 189 | return TCL_ERROR; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | if (theGrid == NULL) { |
---|
| 193 | interp->result = "Grid not allocated."; |
---|
| 194 | return TCL_ERROR; |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | if (!SuperQuiet) |
---|
| 198 | printf("Integrating mesh %s...\n", argv[1]); |
---|
| 199 | |
---|
| 200 | initOccFunc(); |
---|
| 201 | |
---|
| 202 | start_time(); |
---|
| 203 | |
---|
| 204 | Mesh *mesh = readMeshFromPly(argv[1], FALSE, FALSE); |
---|
| 205 | if (mesh == NULL) |
---|
| 206 | return TCL_ERROR; |
---|
| 207 | |
---|
| 208 | if (!mesh->hasConfidence) |
---|
| 209 | doConfidence(mesh); |
---|
| 210 | |
---|
| 211 | end_time(); |
---|
| 212 | |
---|
| 213 | TesselationTime = time_elapsed(); |
---|
| 214 | |
---|
| 215 | start_time(); |
---|
| 216 | |
---|
| 217 | parse_transformation(mesh, interp, argc, argv); |
---|
| 218 | |
---|
| 219 | Vec3f newdir; |
---|
| 220 | float angle; |
---|
| 221 | if (!mesh->isWarped) |
---|
| 222 | angle = 0; |
---|
| 223 | else if (mesh->isRightMirrorOpen) |
---|
| 224 | angle = 30; |
---|
| 225 | else |
---|
| 226 | angle = -30; |
---|
| 227 | |
---|
| 228 | Vec3f dir(-sin(RAD(angle)), 0, -cos(RAD(angle))); |
---|
| 229 | |
---|
| 230 | Matrix4f rot; |
---|
| 231 | mesh->quat.toMatrix(rot); |
---|
| 232 | |
---|
| 233 | rot.multVec(dir, newdir); |
---|
| 234 | |
---|
| 235 | if (Verbose) |
---|
| 236 | printf("View dir: [%f, %f, %f]\n", newdir.x, newdir.y, newdir.z); |
---|
| 237 | vec3f yuk; |
---|
| 238 | yuk[0] = newdir.x; |
---|
| 239 | yuk[1] = newdir.y; |
---|
| 240 | yuk[2] = newdir.z; |
---|
| 241 | |
---|
| 242 | |
---|
| 243 | OrthoShear *shear = computeShear(yuk); |
---|
| 244 | configureGrid(theGrid, shear); |
---|
| 245 | |
---|
| 246 | float sampleSpacing = sqrt(1 + shear->sx*shear->sx + shear->sy*shear->sy); |
---|
| 247 | |
---|
| 248 | if (UseEdgeLength) { |
---|
| 249 | MAX_DEPTH_DIFFERENCE = MaxEdgeLength/sampleSpacing; |
---|
| 250 | } |
---|
| 251 | else { |
---|
| 252 | MAX_DEPTH_DIFFERENCE = tan(acos(MinViewDot))* |
---|
| 253 | theGrid->resolution/sampleSpacing; |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | BBox3f *gbbox = getBBox(theGrid); |
---|
| 257 | |
---|
| 258 | prepareRender(mesh, shear, gbbox, theGrid->resolution, |
---|
| 259 | theDepthMap, FALSE); |
---|
| 260 | softRenderConfidence(mesh); |
---|
| 261 | |
---|
| 262 | /* |
---|
| 263 | DepthMap *dm = renderDepthMap(mesh, shear, gbbox, |
---|
| 264 | theGrid->resolution, NULL); |
---|
| 265 | */ |
---|
| 266 | |
---|
| 267 | end_time(); |
---|
| 268 | |
---|
| 269 | ResampleRangeTime = time_elapsed(); |
---|
| 270 | |
---|
| 271 | start_time(); |
---|
| 272 | |
---|
| 273 | scanConvertTree(theGrid, shear, theDepthMap); |
---|
| 274 | |
---|
| 275 | end_time(); |
---|
| 276 | |
---|
| 277 | MergeTime = time_elapsed(); |
---|
| 278 | if (!SuperQuiet) |
---|
| 279 | printf("Time to process: %.2f sec\n", |
---|
| 280 | TesselationTime + ResampleRangeTime + MergeTime); |
---|
| 281 | |
---|
| 282 | delete shear; |
---|
| 283 | delete gbbox; |
---|
| 284 | |
---|
| 285 | return TCL_OK; |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | |
---|
| 289 | int |
---|
| 290 | Vrip_RangeScanNoTreeRLECmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[]) |
---|
| 291 | { |
---|
| 292 | if (argc != 2 && argc != 3 && argc != 6 && argc != 9 ) { |
---|
| 293 | interp->result = "wrong number of args"; |
---|
| 294 | return TCL_ERROR; |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | if (backRLEGrid == NULL || frontRLEGrid == NULL) { |
---|
| 298 | interp->result = "Grid not allocated."; |
---|
| 299 | return TCL_ERROR; |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | if (!SuperQuiet) |
---|
| 303 | printf("Integrating mesh %s...\n", argv[1]); |
---|
| 304 | |
---|
| 305 | initOccFunc(); |
---|
| 306 | |
---|
| 307 | start_time(); |
---|
| 308 | |
---|
| 309 | if (!Quiet) |
---|
| 310 | printf("Assiging confidences...\n"); |
---|
| 311 | |
---|
| 312 | fflush(stdout); |
---|
| 313 | |
---|
| 314 | Mesh *mesh; |
---|
| 315 | if (UseTails && FillGaps) { |
---|
| 316 | mesh = readMeshFromPly(argv[1], TRUE, FALSE); |
---|
| 317 | } |
---|
| 318 | else { |
---|
| 319 | mesh = readMeshFromPly(argv[1], FALSE, FALSE); |
---|
| 320 | } |
---|
| 321 | |
---|
| 322 | if (mesh == NULL) |
---|
| 323 | return TCL_ERROR; |
---|
| 324 | |
---|
| 325 | //fprintf(stderr, "Not assigning confidence!!\n"); |
---|
| 326 | if (!mesh->hasConfidence) |
---|
| 327 | doConfidence(mesh); |
---|
| 328 | |
---|
| 329 | end_time(); |
---|
| 330 | |
---|
| 331 | TesselationTime = time_elapsed(); |
---|
| 332 | |
---|
| 333 | start_time(); |
---|
| 334 | |
---|
| 335 | parse_transformation(mesh, interp, argc, argv); |
---|
| 336 | |
---|
| 337 | Vec3f newdir; |
---|
| 338 | float angle; |
---|
| 339 | if (!mesh->isWarped) |
---|
| 340 | angle = 0; |
---|
| 341 | else if (mesh->isRightMirrorOpen) |
---|
| 342 | angle = 30; |
---|
| 343 | else |
---|
| 344 | angle = -30; |
---|
| 345 | |
---|
| 346 | Vec3f dir(-sin(RAD(angle)), 0, -cos(RAD(angle))); |
---|
| 347 | |
---|
| 348 | Matrix4f rot; |
---|
| 349 | mesh->quat.toMatrix(rot); |
---|
| 350 | |
---|
| 351 | rot.multVec(dir, newdir); |
---|
| 352 | |
---|
| 353 | if (Verbose) |
---|
| 354 | printf("View dir: [%f, %f, %f]\n", newdir.x, newdir.y, newdir.z); |
---|
| 355 | vec3f yuk; |
---|
| 356 | yuk[0] = newdir.x; |
---|
| 357 | yuk[1] = newdir.y; |
---|
| 358 | yuk[2] = newdir.z; |
---|
| 359 | |
---|
| 360 | |
---|
| 361 | OrthoShear *shear = computeShear(yuk); |
---|
| 362 | |
---|
| 363 | float sampleSpacing = sqrt(1 + shear->sx*shear->sx + shear->sy*shear->sy); |
---|
| 364 | |
---|
| 365 | if (UseEdgeLength) { |
---|
| 366 | MAX_DEPTH_DIFFERENCE = MaxEdgeLength/sampleSpacing; |
---|
| 367 | } |
---|
| 368 | else { |
---|
| 369 | MAX_DEPTH_DIFFERENCE = tan(acos(MinViewDot))* |
---|
| 370 | backRLEGrid->resolution/sampleSpacing; |
---|
| 371 | } |
---|
| 372 | |
---|
| 373 | configureGrid(&frontRLEGrid, &backRLEGrid, shear); |
---|
| 374 | |
---|
| 375 | BBox3f *gbbox = getBBox(backRLEGrid); |
---|
| 376 | |
---|
| 377 | |
---|
| 378 | prepareRender(mesh, shear, gbbox, backRLEGrid->resolution, |
---|
| 379 | theDepthMap, FALSE); |
---|
| 380 | softRenderConfidence(mesh); |
---|
| 381 | |
---|
| 382 | updateRenderPhoto(theDepthMap); |
---|
| 383 | Tcl_Eval(interp, "update"); |
---|
| 384 | |
---|
| 385 | if (UseTails) { |
---|
| 386 | if (FillBackground) { |
---|
| 387 | fillBackground(theDepthMap); |
---|
| 388 | } else if (DoSilhouette) { |
---|
| 389 | makeSilhouette(theDepthMap); |
---|
| 390 | } |
---|
| 391 | } |
---|
| 392 | |
---|
| 393 | end_time(); |
---|
| 394 | |
---|
| 395 | ResampleRangeTime = time_elapsed(); |
---|
| 396 | |
---|
| 397 | start_time(); |
---|
| 398 | |
---|
| 399 | if (UseTails) { |
---|
| 400 | scanConvertDragTails(backRLEGrid, frontRLEGrid, shear, theDepthMap); |
---|
| 401 | } |
---|
| 402 | else { |
---|
| 403 | scanConvert(backRLEGrid, frontRLEGrid, shear, theDepthMap); |
---|
| 404 | } |
---|
| 405 | |
---|
| 406 | end_time(); |
---|
| 407 | |
---|
| 408 | MergeTime = time_elapsed(); |
---|
| 409 | if (!SuperQuiet) |
---|
| 410 | printf("Time to process: %.2f sec\n", |
---|
| 411 | TesselationTime + ResampleRangeTime + MergeTime); |
---|
| 412 | |
---|
| 413 | delete shear; |
---|
| 414 | delete gbbox; |
---|
| 415 | delete mesh; |
---|
| 416 | |
---|
| 417 | return TCL_OK; |
---|
| 418 | } |
---|
| 419 | |
---|
| 420 | |
---|
| 421 | int |
---|
| 422 | Vrip_RangeScanRLECmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[]) |
---|
| 423 | { |
---|
| 424 | if (argc != 2 && argc != 3 && argc != 6 && argc != 9 ) { |
---|
| 425 | interp->result = "wrong number of args"; |
---|
| 426 | return TCL_ERROR; |
---|
| 427 | } |
---|
| 428 | |
---|
| 429 | if (backRLEGrid == NULL || frontRLEGrid == NULL) { |
---|
| 430 | interp->result = "Grid not allocated."; |
---|
| 431 | return TCL_ERROR; |
---|
| 432 | } |
---|
| 433 | |
---|
| 434 | if (!SuperQuiet) |
---|
| 435 | printf("Integrating mesh %s...\n", argv[1]); |
---|
| 436 | |
---|
| 437 | initOccFunc(); |
---|
| 438 | |
---|
| 439 | start_time(); |
---|
| 440 | |
---|
| 441 | if (!Quiet) |
---|
| 442 | printf("Assiging confidences...\n"); |
---|
| 443 | |
---|
| 444 | fflush(stdout); |
---|
| 445 | |
---|
| 446 | Mesh *mesh; |
---|
| 447 | if (UseTails && FillGaps) { |
---|
| 448 | mesh = readMeshFromPly(argv[1], TRUE, FALSE); |
---|
| 449 | } |
---|
| 450 | else { |
---|
| 451 | mesh = readMeshFromPly(argv[1], FALSE, FALSE); |
---|
| 452 | } |
---|
| 453 | |
---|
| 454 | if (mesh == NULL) |
---|
| 455 | return TCL_ERROR; |
---|
| 456 | |
---|
| 457 | //fprintf(stderr, "Not assigning confidence!!\n"); |
---|
| 458 | if (!mesh->hasConfidence) |
---|
| 459 | doConfidence(mesh); |
---|
| 460 | |
---|
| 461 | end_time(); |
---|
| 462 | |
---|
| 463 | TesselationTime = time_elapsed(); |
---|
| 464 | |
---|
| 465 | start_time(); |
---|
| 466 | |
---|
| 467 | parse_transformation(mesh, interp, argc, argv); |
---|
| 468 | |
---|
| 469 | Vec3f newdir; |
---|
| 470 | float angle; |
---|
| 471 | if (!mesh->isWarped) |
---|
| 472 | angle = 0; |
---|
| 473 | else if (mesh->isRightMirrorOpen) |
---|
| 474 | angle = 30; |
---|
| 475 | else |
---|
| 476 | angle = -30; |
---|
| 477 | |
---|
| 478 | Vec3f dir(-sin(RAD(angle)), 0, -cos(RAD(angle))); |
---|
| 479 | |
---|
| 480 | Matrix4f rot; |
---|
| 481 | mesh->quat.toMatrix(rot); |
---|
| 482 | |
---|
| 483 | rot.multVec(dir, newdir); |
---|
| 484 | |
---|
| 485 | if (Verbose) |
---|
| 486 | printf("View dir: [%f, %f, %f]\n", newdir.x, newdir.y, newdir.z); |
---|
| 487 | vec3f yuk; |
---|
| 488 | yuk[0] = newdir.x; |
---|
| 489 | yuk[1] = newdir.y; |
---|
| 490 | yuk[2] = newdir.z; |
---|
| 491 | |
---|
| 492 | |
---|
| 493 | OrthoShear *shear = computeShear(yuk); |
---|
| 494 | |
---|
| 495 | float sampleSpacing = sqrt(1 + shear->sx*shear->sx + shear->sy*shear->sy); |
---|
| 496 | |
---|
| 497 | if (UseEdgeLength) { |
---|
| 498 | MAX_DEPTH_DIFFERENCE = MaxEdgeLength/sampleSpacing; |
---|
| 499 | } |
---|
| 500 | else { |
---|
| 501 | MAX_DEPTH_DIFFERENCE = tan(acos(MinViewDot))* |
---|
| 502 | backRLEGrid->resolution/sampleSpacing; |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | configureGrid(&frontRLEGrid, &backRLEGrid, shear); |
---|
| 506 | |
---|
| 507 | BBox3f *gbbox = getBBox(backRLEGrid); |
---|
| 508 | |
---|
| 509 | prepareRender(mesh, shear, gbbox, backRLEGrid->resolution, |
---|
| 510 | theDepthMap, FALSE); |
---|
| 511 | softRenderConfidence(mesh); |
---|
| 512 | |
---|
| 513 | updateRenderPhoto(theDepthMap); |
---|
| 514 | Tcl_Eval(interp, "update"); |
---|
| 515 | |
---|
| 516 | if (UseTails) { |
---|
| 517 | if (FillBackground) { |
---|
| 518 | fillBackground(theDepthMap); |
---|
| 519 | } else if (DoSilhouette) { |
---|
| 520 | makeSilhouette(theDepthMap); |
---|
| 521 | } |
---|
| 522 | } |
---|
| 523 | |
---|
| 524 | theDepthMap->tagCellsForResampling(); |
---|
| 525 | theDepthMap->fillTree(2); |
---|
| 526 | |
---|
| 527 | end_time(); |
---|
| 528 | |
---|
| 529 | ResampleRangeTime = time_elapsed(); |
---|
| 530 | |
---|
| 531 | start_time(); |
---|
| 532 | |
---|
| 533 | if (UseTails) { |
---|
| 534 | if (OneLineAtATime) { |
---|
| 535 | for (int zz = 0; zz < backRLEGrid->zdim; zz++) { |
---|
| 536 | printf("\rProcessing slice %d of %d...", |
---|
| 537 | zz+1, backRLEGrid->zdim); |
---|
| 538 | fflush(stdout); |
---|
| 539 | int somethingNew = |
---|
| 540 | scanConvertTreeDragTailsOneLine(backRLEGrid, frontRLEGrid, |
---|
| 541 | shear, theDepthMap, zz); |
---|
| 542 | if (somethingNew) { |
---|
| 543 | updatePhotoSlice(); |
---|
| 544 | Tcl_Eval(interp, "update"); |
---|
| 545 | } |
---|
| 546 | swapgrids(); |
---|
| 547 | } |
---|
| 548 | printf("\n"); |
---|
| 549 | } else { |
---|
| 550 | scanConvertTreeDragTails(backRLEGrid, frontRLEGrid, shear, theDepthMap); |
---|
| 551 | } |
---|
| 552 | } |
---|
| 553 | else { |
---|
| 554 | //scanConvert(backRLEGrid, frontRLEGrid, shear, theDepthMap); |
---|
| 555 | //scanConvertTree(backRLEGrid, frontRLEGrid, shear, theDepthMap); |
---|
| 556 | scanConvertTreeFast(backRLEGrid, frontRLEGrid, shear, theDepthMap); |
---|
| 557 | } |
---|
| 558 | |
---|
| 559 | end_time(); |
---|
| 560 | |
---|
| 561 | MergeTime = time_elapsed(); |
---|
| 562 | if (!SuperQuiet) |
---|
| 563 | printf("Time to process: %.2f sec\n", |
---|
| 564 | TesselationTime + ResampleRangeTime + MergeTime); |
---|
| 565 | |
---|
| 566 | delete shear; |
---|
| 567 | delete gbbox; |
---|
| 568 | delete mesh; |
---|
| 569 | |
---|
| 570 | return TCL_OK; |
---|
| 571 | } |
---|
| 572 | |
---|
| 573 | |
---|
| 574 | int |
---|
| 575 | Vrip_RangeScanEdgesRLECmd(ClientData, Tcl_Interp *interp, |
---|
| 576 | int argc, const char *argv[]) |
---|
| 577 | { |
---|
| 578 | if (argc != 2 && argc != 3 && argc != 6 && argc != 9 ) { |
---|
| 579 | interp->result = "wrong number of args"; |
---|
| 580 | return TCL_ERROR; |
---|
| 581 | } |
---|
| 582 | |
---|
| 583 | if (backRLEGrid == NULL || frontRLEGrid == NULL) { |
---|
| 584 | interp->result = "Grid not allocated."; |
---|
| 585 | return TCL_ERROR; |
---|
| 586 | } |
---|
| 587 | |
---|
| 588 | if (!SuperQuiet) |
---|
| 589 | printf("Integrating mesh %s...\n", argv[1]); |
---|
| 590 | |
---|
| 591 | initOccFunc(); |
---|
| 592 | |
---|
| 593 | start_time(); |
---|
| 594 | |
---|
| 595 | if (!Quiet) |
---|
| 596 | printf("Assiging confidences...\n"); |
---|
| 597 | |
---|
| 598 | fflush(stdout); |
---|
| 599 | |
---|
| 600 | Mesh *mesh; |
---|
| 601 | if (UseTails && FillGaps) { |
---|
| 602 | mesh = readMeshFromPly(argv[1], TRUE, FALSE); |
---|
| 603 | } |
---|
| 604 | else { |
---|
| 605 | mesh = readMeshFromPly(argv[1], FALSE, TRUE); |
---|
| 606 | } |
---|
| 607 | |
---|
| 608 | if (mesh == NULL) |
---|
| 609 | return TCL_ERROR; |
---|
| 610 | |
---|
| 611 | if (!mesh->hasConfidence) |
---|
| 612 | doConfidence(mesh); |
---|
| 613 | |
---|
| 614 | end_time(); |
---|
| 615 | |
---|
| 616 | TesselationTime = time_elapsed(); |
---|
| 617 | |
---|
| 618 | start_time(); |
---|
| 619 | |
---|
| 620 | parse_transformation(mesh, interp, argc, argv); |
---|
| 621 | |
---|
| 622 | Vec3f newdir; |
---|
| 623 | float angle; |
---|
| 624 | if (!mesh->isWarped) |
---|
| 625 | angle = 0; |
---|
| 626 | else if (mesh->isRightMirrorOpen) |
---|
| 627 | angle = 30; |
---|
| 628 | else |
---|
| 629 | angle = -30; |
---|
| 630 | |
---|
| 631 | Vec3f dir(-sin(RAD(angle)), 0, -cos(RAD(angle))); |
---|
| 632 | |
---|
| 633 | Matrix4f rot; |
---|
| 634 | mesh->quat.toMatrix(rot); |
---|
| 635 | |
---|
| 636 | rot.multVec(dir, newdir); |
---|
| 637 | |
---|
| 638 | if (Verbose) |
---|
| 639 | printf("View dir: [%f, %f, %f]\n", newdir.x, newdir.y, newdir.z); |
---|
| 640 | vec3f yuk; |
---|
| 641 | yuk[0] = newdir.x; |
---|
| 642 | yuk[1] = newdir.y; |
---|
| 643 | yuk[2] = newdir.z; |
---|
| 644 | |
---|
| 645 | |
---|
| 646 | OrthoShear *shear = computeShear(yuk); |
---|
| 647 | |
---|
| 648 | float sampleSpacing = sqrt(1 + shear->sx*shear->sx + shear->sy*shear->sy); |
---|
| 649 | |
---|
| 650 | if (UseEdgeLength) { |
---|
| 651 | MAX_DEPTH_DIFFERENCE = MaxEdgeLength/sampleSpacing; |
---|
| 652 | } |
---|
| 653 | else { |
---|
| 654 | MAX_DEPTH_DIFFERENCE = tan(acos(MinViewDot))* |
---|
| 655 | backRLEGrid->resolution/sampleSpacing; |
---|
| 656 | } |
---|
| 657 | |
---|
| 658 | configureGrid(&frontRLEGrid, &backRLEGrid, shear); |
---|
| 659 | |
---|
| 660 | BBox3f *gbbox = getBBox(backRLEGrid); |
---|
| 661 | |
---|
| 662 | |
---|
| 663 | prepareRender(mesh, shear, gbbox, backRLEGrid->resolution, |
---|
| 664 | theDepthMap, FALSE); |
---|
| 665 | |
---|
| 666 | softRenderEdgeSteps(mesh); |
---|
| 667 | theDepthMap->updateEdgeSteps(); |
---|
| 668 | |
---|
| 669 | updateRenderPhoto(theDepthMap); |
---|
| 670 | Tcl_Eval(interp, "update"); |
---|
| 671 | |
---|
| 672 | // sleep(5); |
---|
| 673 | |
---|
| 674 | softRenderConfidence(mesh); |
---|
| 675 | |
---|
| 676 | updateRenderPhoto(theDepthMap); |
---|
| 677 | Tcl_Eval(interp, "update"); |
---|
| 678 | |
---|
| 679 | if (UseTails) { |
---|
| 680 | if (FillBackground) { |
---|
| 681 | fillBackground(theDepthMap); |
---|
| 682 | } else if (DoSilhouette) { |
---|
| 683 | makeSilhouette(theDepthMap); |
---|
| 684 | } |
---|
| 685 | } |
---|
| 686 | |
---|
| 687 | theDepthMap->fillTree(2); |
---|
| 688 | |
---|
| 689 | end_time(); |
---|
| 690 | |
---|
| 691 | ResampleRangeTime = time_elapsed(); |
---|
| 692 | |
---|
| 693 | start_time(); |
---|
| 694 | |
---|
| 695 | if (UseTails) { |
---|
| 696 | scanConvertTreeDragTails(backRLEGrid, frontRLEGrid, shear, theDepthMap); |
---|
| 697 | } |
---|
| 698 | else { |
---|
| 699 | //scanConvert(backRLEGrid, frontRLEGrid, shear, theDepthMap); |
---|
| 700 | //scanConvertTree(backRLEGrid, frontRLEGrid, shear, theDepthMap); |
---|
| 701 | scanConvertTreeBiasEdgesEmpty(backRLEGrid, frontRLEGrid, shear, theDepthMap); |
---|
| 702 | } |
---|
| 703 | |
---|
| 704 | end_time(); |
---|
| 705 | |
---|
| 706 | MergeTime = time_elapsed(); |
---|
| 707 | if (!SuperQuiet) |
---|
| 708 | printf("Time to process: %.2f sec\n", |
---|
| 709 | TesselationTime + ResampleRangeTime + MergeTime); |
---|
| 710 | |
---|
| 711 | delete shear; |
---|
| 712 | delete gbbox; |
---|
| 713 | delete mesh; |
---|
| 714 | |
---|
| 715 | return TCL_OK; |
---|
| 716 | } |
---|
| 717 | |
---|
| 718 | |
---|
| 719 | |
---|
| 720 | int |
---|
| 721 | Vrip_RangeScanNormRLECmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[]) |
---|
| 722 | { |
---|
| 723 | if (argc != 2 && argc != 3 && argc != 6 && argc != 9 ) { |
---|
| 724 | interp->result = "wrong number of args"; |
---|
| 725 | return TCL_ERROR; |
---|
| 726 | } |
---|
| 727 | |
---|
| 728 | if (backRLEGridNorm == NULL || frontRLEGridNorm == NULL) { |
---|
| 729 | interp->result = "Grid not allocated."; |
---|
| 730 | return TCL_ERROR; |
---|
| 731 | } |
---|
| 732 | |
---|
| 733 | if (!SuperQuiet) |
---|
| 734 | printf("Integrating mesh %s...\n", argv[1]); |
---|
| 735 | |
---|
| 736 | initOccFunc(); |
---|
| 737 | |
---|
| 738 | start_time(); |
---|
| 739 | |
---|
| 740 | if (!Quiet) |
---|
| 741 | printf("Assiging confidences...\n"); |
---|
| 742 | fflush(stdout); |
---|
| 743 | |
---|
| 744 | Mesh *mesh; |
---|
| 745 | if (UseTails && FillGaps) { |
---|
| 746 | mesh = readMeshFromPly(argv[1], TRUE, FALSE); |
---|
| 747 | } |
---|
| 748 | else { |
---|
| 749 | mesh = readMeshFromPly(argv[1], FALSE, FALSE); |
---|
| 750 | } |
---|
| 751 | |
---|
| 752 | if (mesh == NULL) |
---|
| 753 | return TCL_ERROR; |
---|
| 754 | |
---|
| 755 | if (!mesh->hasConfidence) |
---|
| 756 | doConfidence(mesh); |
---|
| 757 | |
---|
| 758 | end_time(); |
---|
| 759 | |
---|
| 760 | TesselationTime = time_elapsed(); |
---|
| 761 | |
---|
| 762 | start_time(); |
---|
| 763 | |
---|
| 764 | parse_transformation(mesh, interp, argc, argv); |
---|
| 765 | |
---|
| 766 | Vec3f newdir; |
---|
| 767 | float angle; |
---|
| 768 | if (!mesh->isWarped) |
---|
| 769 | angle = 0; |
---|
| 770 | else if (mesh->isRightMirrorOpen) |
---|
| 771 | angle = 30; |
---|
| 772 | else |
---|
| 773 | angle = -30; |
---|
| 774 | |
---|
| 775 | Vec3f dir(-sin(RAD(angle)), 0, -cos(RAD(angle))); |
---|
| 776 | |
---|
| 777 | Matrix4f rot; |
---|
| 778 | mesh->quat.toMatrix(rot); |
---|
| 779 | |
---|
| 780 | rot.multVec(dir, newdir); |
---|
| 781 | |
---|
| 782 | if (Verbose) |
---|
| 783 | printf("View dir: [%f, %f, %f]\n", newdir.x, newdir.y, newdir.z); |
---|
| 784 | vec3f yuk; |
---|
| 785 | yuk[0] = newdir.x; |
---|
| 786 | yuk[1] = newdir.y; |
---|
| 787 | yuk[2] = newdir.z; |
---|
| 788 | |
---|
| 789 | |
---|
| 790 | OrthoShear *shear = computeShear(yuk); |
---|
| 791 | |
---|
| 792 | float sampleSpacing = sqrt(1 + shear->sx*shear->sx + shear->sy*shear->sy); |
---|
| 793 | |
---|
| 794 | if (UseEdgeLength) { |
---|
| 795 | MAX_DEPTH_DIFFERENCE = MaxEdgeLength/sampleSpacing; |
---|
| 796 | } |
---|
| 797 | else { |
---|
| 798 | MAX_DEPTH_DIFFERENCE = tan(acos(MinViewDot))* |
---|
| 799 | backRLEGrid->resolution/sampleSpacing; |
---|
| 800 | } |
---|
| 801 | |
---|
| 802 | configureGrid(&frontRLEGridNorm, &backRLEGridNorm, shear); |
---|
| 803 | |
---|
| 804 | BBox3f *gbbox = getBBox(backRLEGridNorm); |
---|
| 805 | |
---|
| 806 | prepareRender(mesh, shear, gbbox, backRLEGridNorm->resolution, |
---|
| 807 | theDepthMap, TRUE); |
---|
| 808 | softRenderNx(mesh); |
---|
| 809 | theDepthMap->updateNx(); |
---|
| 810 | updateRenderPhoto(theDepthMap); |
---|
| 811 | Tcl_Eval(interp, "update"); |
---|
| 812 | sleep(1); |
---|
| 813 | |
---|
| 814 | softRenderNy(mesh); |
---|
| 815 | theDepthMap->updateNy(); |
---|
| 816 | updateRenderPhoto(theDepthMap); |
---|
| 817 | Tcl_Eval(interp, "update"); |
---|
| 818 | sleep(1); |
---|
| 819 | |
---|
| 820 | softRenderNz(mesh); |
---|
| 821 | theDepthMap->updateNz(); |
---|
| 822 | updateRenderPhoto(theDepthMap); |
---|
| 823 | Tcl_Eval(interp, "update"); |
---|
| 824 | sleep(1); |
---|
| 825 | |
---|
| 826 | |
---|
| 827 | softRenderConfidence(mesh); |
---|
| 828 | updateRenderPhoto(theDepthMap); |
---|
| 829 | Tcl_Eval(interp, "update"); |
---|
| 830 | |
---|
| 831 | if (UseTails) { |
---|
| 832 | if (FillBackground) { |
---|
| 833 | fillBackground(theDepthMap); |
---|
| 834 | } else if (DoSilhouette) { |
---|
| 835 | makeSilhouette(theDepthMap); |
---|
| 836 | } |
---|
| 837 | } |
---|
| 838 | |
---|
| 839 | theDepthMap->fillTree(2); |
---|
| 840 | |
---|
| 841 | end_time(); |
---|
| 842 | |
---|
| 843 | ResampleRangeTime = time_elapsed(); |
---|
| 844 | |
---|
| 845 | start_time(); |
---|
| 846 | |
---|
| 847 | #if 0 |
---|
| 848 | if (UseTails) |
---|
| 849 | scanConvertTreeDragTails(backRLEGridNorm, frontRLEGridNorm, |
---|
| 850 | shear, theDepthMap); |
---|
| 851 | else |
---|
| 852 | scanConvertTree(backRLEGridNorm, frontRLEGridNorm, shear, theDepthMap); |
---|
| 853 | #else |
---|
| 854 | scanConvertTree(backRLEGridNorm, frontRLEGridNorm, shear, theDepthMap); |
---|
| 855 | #endif |
---|
| 856 | |
---|
| 857 | |
---|
| 858 | end_time(); |
---|
| 859 | |
---|
| 860 | MergeTime = time_elapsed(); |
---|
| 861 | if (!SuperQuiet) |
---|
| 862 | printf("Time to process: %.2f sec\n", |
---|
| 863 | TesselationTime + ResampleRangeTime + MergeTime); |
---|
| 864 | |
---|
| 865 | delete shear; |
---|
| 866 | delete gbbox; |
---|
| 867 | delete mesh; |
---|
| 868 | |
---|
| 869 | return TCL_OK; |
---|
| 870 | } |
---|
| 871 | |
---|
| 872 | |
---|
| 873 | |
---|
| 874 | int |
---|
| 875 | Vrip_RangeScanLinePerspCmd(ClientData, Tcl_Interp *interp, |
---|
| 876 | int argc, const char *argv[]) |
---|
| 877 | { |
---|
| 878 | Vec3f vec; |
---|
| 879 | |
---|
| 880 | if (argc != 2 && argc != 3 && argc != 6 && argc != 9 ) { |
---|
| 881 | interp->result = "wrong number of args"; |
---|
| 882 | return TCL_ERROR; |
---|
| 883 | } |
---|
| 884 | |
---|
| 885 | if (backRLEGrid == NULL || frontRLEGrid == NULL) { |
---|
| 886 | interp->result = "Grid not allocated."; |
---|
| 887 | return TCL_ERROR; |
---|
| 888 | } |
---|
| 889 | |
---|
| 890 | if (!SuperQuiet) |
---|
| 891 | printf("Integrating mesh %s...\n", argv[1]); |
---|
| 892 | |
---|
| 893 | initOccFunc(); |
---|
| 894 | |
---|
| 895 | start_time(); |
---|
| 896 | |
---|
| 897 | if (!Quiet) |
---|
| 898 | printf("Assiging confidences...\n"); |
---|
| 899 | fflush(stdout); |
---|
| 900 | |
---|
| 901 | |
---|
| 902 | Mesh *mesh; |
---|
| 903 | if (UseTails && FillGaps) { |
---|
| 904 | mesh = readMeshFromPly(argv[1], TRUE, FALSE); |
---|
| 905 | } |
---|
| 906 | else { |
---|
| 907 | mesh = readMeshFromPly(argv[1], FALSE, FALSE); |
---|
| 908 | } |
---|
| 909 | |
---|
| 910 | if (!mesh->hasConfidence) |
---|
| 911 | doConfidence(mesh); |
---|
| 912 | |
---|
| 913 | end_time(); |
---|
| 914 | |
---|
| 915 | TesselationTime = time_elapsed(); |
---|
| 916 | |
---|
| 917 | start_time(); |
---|
| 918 | |
---|
| 919 | parse_transformation(mesh, interp, argc, argv); |
---|
| 920 | |
---|
| 921 | |
---|
| 922 | float temp; |
---|
| 923 | int axis, flip; |
---|
| 924 | Vec3f center; |
---|
| 925 | center.setValue(frontRLEGrid->origin); |
---|
| 926 | |
---|
| 927 | if (frontRLEGrid->flip) |
---|
| 928 | center.z = -center.z; |
---|
| 929 | |
---|
| 930 | if (frontRLEGrid->axis == X_AXIS) { |
---|
| 931 | SWAP(center.x, center.z, temp); |
---|
| 932 | } |
---|
| 933 | else if (frontRLEGrid->axis == Y_AXIS) { |
---|
| 934 | SWAP(center.y, center.z, temp); |
---|
| 935 | } |
---|
| 936 | |
---|
| 937 | center.x += frontRLEGrid->resolution/2*frontRLEGrid->xdim; |
---|
| 938 | center.y += frontRLEGrid->resolution/2*frontRLEGrid->ydim; |
---|
| 939 | center.z += frontRLEGrid->resolution/2*frontRLEGrid->zdim; |
---|
| 940 | |
---|
| 941 | if (Verbose) { |
---|
| 942 | printf("Origin: (%f, %f, %f)\n", frontRLEGrid->origin[0], |
---|
| 943 | frontRLEGrid->origin[1], frontRLEGrid->origin[2]); |
---|
| 944 | printf("Center: (%f, %f, %f)\n", center.x, center.y, center.z); |
---|
| 945 | } |
---|
| 946 | |
---|
| 947 | OrthoShear *shear = initLinePersp(mesh->quat, mesh->trans, center, |
---|
| 948 | frontRLEGrid->resolution); |
---|
| 949 | |
---|
| 950 | float sampleSpacing = sqrt(1 + shear->sx*shear->sx + shear->sy*shear->sy); |
---|
| 951 | |
---|
| 952 | if (UseEdgeLength) { |
---|
| 953 | MAX_DEPTH_DIFFERENCE = MaxEdgeLength/sampleSpacing; |
---|
| 954 | } |
---|
| 955 | else { |
---|
| 956 | MAX_DEPTH_DIFFERENCE = tan(acos(MinViewDot))* |
---|
| 957 | backRLEGrid->resolution/sampleSpacing; |
---|
| 958 | } |
---|
| 959 | |
---|
| 960 | configureGridLinePersp(&frontRLEGrid, &backRLEGrid, shear); |
---|
| 961 | |
---|
| 962 | if (Verbose) { |
---|
| 963 | applyLinePersp(center, vec); |
---|
| 964 | printf("Transformed center: (%f, %f, %f)\n", vec.x, vec.y, vec.z); |
---|
| 965 | } |
---|
| 966 | |
---|
| 967 | int lineWidth; |
---|
| 968 | BBox3f *gbbox = getBBoxLinePersp(backRLEGrid, &lineWidth); |
---|
| 969 | if (Verbose) { |
---|
| 970 | printf("Line width = %d\n", lineWidth); |
---|
| 971 | } |
---|
| 972 | |
---|
| 973 | prepareRenderLinePersp(mesh, shear, gbbox, |
---|
| 974 | backRLEGrid->resolution, theDepthMap, FALSE); |
---|
| 975 | softRenderConfidence(mesh); |
---|
| 976 | |
---|
| 977 | updateRenderPhoto(theDepthMap); |
---|
| 978 | Tcl_Eval(interp, "update"); |
---|
| 979 | |
---|
| 980 | |
---|
| 981 | if (UseTails) { |
---|
| 982 | if (FillBackground) { |
---|
| 983 | fillBackground(theDepthMap); |
---|
| 984 | } else if (DoSilhouette) { |
---|
| 985 | makeSilhouette(theDepthMap); |
---|
| 986 | } |
---|
| 987 | } |
---|
| 988 | |
---|
| 989 | theDepthMap->fillTree(lineWidth); |
---|
| 990 | |
---|
| 991 | end_time(); |
---|
| 992 | |
---|
| 993 | ResampleRangeTime = time_elapsed(); |
---|
| 994 | |
---|
| 995 | start_time(); |
---|
| 996 | |
---|
| 997 | if (UseTails && !TailsOnly) { |
---|
| 998 | scanConvertLinePerspTreeDragTails(backRLEGrid, frontRLEGrid, |
---|
| 999 | shear, theDepthMap); |
---|
| 1000 | } else if (TailsOnly) { |
---|
| 1001 | #if 1 |
---|
| 1002 | scanConvertLinePerspTreeTailsOnly(backRLEGrid, frontRLEGrid, |
---|
| 1003 | shear, theDepthMap); |
---|
| 1004 | #else |
---|
| 1005 | printf("Using fast carver...\n"); |
---|
| 1006 | scanConvertLinePerspTreeTailsOnlyFast(backRLEGrid, frontRLEGrid, |
---|
| 1007 | shear, theDepthMap); |
---|
| 1008 | #endif |
---|
| 1009 | } |
---|
| 1010 | else { |
---|
| 1011 | scanConvertLinePerspTree(backRLEGrid, frontRLEGrid, shear, theDepthMap); |
---|
| 1012 | } |
---|
| 1013 | |
---|
| 1014 | end_time(); |
---|
| 1015 | |
---|
| 1016 | MergeTime = time_elapsed(); |
---|
| 1017 | if (!SuperQuiet) |
---|
| 1018 | printf("Time to process: %.2f sec\n", |
---|
| 1019 | TesselationTime + ResampleRangeTime + MergeTime); |
---|
| 1020 | |
---|
| 1021 | delete shear; |
---|
| 1022 | delete gbbox; |
---|
| 1023 | delete mesh; |
---|
| 1024 | |
---|
| 1025 | return TCL_OK; |
---|
| 1026 | } |
---|
| 1027 | |
---|
| 1028 | |
---|
| 1029 | int |
---|
| 1030 | Vrip_RangeScanPerspCmd(ClientData, Tcl_Interp *interp, |
---|
| 1031 | int argc, const char *argv[]) |
---|
| 1032 | { |
---|
| 1033 | Vec3f vec; |
---|
| 1034 | |
---|
| 1035 | if (argc != 2 && argc != 3 && argc != 6 && argc != 9 ) { |
---|
| 1036 | interp->result = "wrong number of args"; |
---|
| 1037 | return TCL_ERROR; |
---|
| 1038 | } |
---|
| 1039 | |
---|
| 1040 | if (backRLEGrid == NULL || frontRLEGrid == NULL) { |
---|
| 1041 | interp->result = "Grid not allocated."; |
---|
| 1042 | return TCL_ERROR; |
---|
| 1043 | } |
---|
| 1044 | |
---|
| 1045 | if (!SuperQuiet) |
---|
| 1046 | printf("Integrating mesh %s...\n", argv[1]); |
---|
| 1047 | |
---|
| 1048 | initOccFunc(); |
---|
| 1049 | |
---|
| 1050 | start_time(); |
---|
| 1051 | |
---|
| 1052 | if (!Quiet) |
---|
| 1053 | printf("Assiging confidences...\n"); |
---|
| 1054 | fflush(stdout); |
---|
| 1055 | |
---|
| 1056 | Mesh *mesh; |
---|
| 1057 | if (UseTails && FillGaps) { |
---|
| 1058 | mesh = readMeshFromPly(argv[1], TRUE, FALSE); |
---|
| 1059 | } |
---|
| 1060 | else { |
---|
| 1061 | mesh = readMeshFromPly(argv[1], FALSE, FALSE); |
---|
| 1062 | } |
---|
| 1063 | |
---|
| 1064 | if (!mesh->hasConfidence) |
---|
| 1065 | doConfidence(mesh, TRUE); |
---|
| 1066 | |
---|
| 1067 | end_time(); |
---|
| 1068 | |
---|
| 1069 | TesselationTime = time_elapsed(); |
---|
| 1070 | |
---|
| 1071 | if (!UsePerspectiveDir) { |
---|
| 1072 | mesh->computeBBox(); |
---|
| 1073 | Vec3f bboxCenter = mesh->bbox.fll + mesh->bbox.nur; |
---|
| 1074 | bboxCenter /= 2.0; |
---|
| 1075 | PerspectiveDir = bboxCenter - PerspectiveCOP; |
---|
| 1076 | PerspectiveDir.normalize(); |
---|
| 1077 | printf("Persp Dir: "); |
---|
| 1078 | PerspectiveDir.print(); |
---|
| 1079 | } |
---|
| 1080 | |
---|
| 1081 | start_time(); |
---|
| 1082 | |
---|
| 1083 | parse_transformation(mesh, interp, argc, argv); |
---|
| 1084 | |
---|
| 1085 | float temp; |
---|
| 1086 | int axis, flip; |
---|
| 1087 | Vec3f center; |
---|
| 1088 | center.setValue(frontRLEGrid->origin); |
---|
| 1089 | |
---|
| 1090 | if (frontRLEGrid->flip) |
---|
| 1091 | center.z = -center.z; |
---|
| 1092 | |
---|
| 1093 | if (frontRLEGrid->axis == X_AXIS) { |
---|
| 1094 | SWAP(center.x, center.z, temp); |
---|
| 1095 | } |
---|
| 1096 | else if (frontRLEGrid->axis == Y_AXIS) { |
---|
| 1097 | SWAP(center.y, center.z, temp); |
---|
| 1098 | } |
---|
| 1099 | |
---|
| 1100 | center.x += frontRLEGrid->resolution/2*frontRLEGrid->xdim; |
---|
| 1101 | center.y += frontRLEGrid->resolution/2*frontRLEGrid->ydim; |
---|
| 1102 | center.z += frontRLEGrid->resolution/2*frontRLEGrid->zdim; |
---|
| 1103 | |
---|
| 1104 | if (Verbose) { |
---|
| 1105 | printf("Origin: (%f, %f, %f)\n", frontRLEGrid->origin[0], |
---|
| 1106 | frontRLEGrid->origin[1], frontRLEGrid->origin[2]); |
---|
| 1107 | printf("Center: (%f, %f, %f)\n", center.x, center.y, center.z); |
---|
| 1108 | } |
---|
| 1109 | |
---|
| 1110 | OrthoShear *shear = initPersp(mesh->quat, mesh->trans, center, |
---|
| 1111 | frontRLEGrid->resolution); |
---|
| 1112 | |
---|
| 1113 | float sampleSpacing = sqrt(1 + shear->sx*shear->sx + shear->sy*shear->sy); |
---|
| 1114 | |
---|
| 1115 | if (UseEdgeLength) { |
---|
| 1116 | MAX_DEPTH_DIFFERENCE = MaxEdgeLength/sampleSpacing; |
---|
| 1117 | } |
---|
| 1118 | else { |
---|
| 1119 | MAX_DEPTH_DIFFERENCE = tan(acos(MinViewDot))* |
---|
| 1120 | backRLEGrid->resolution/sampleSpacing; |
---|
| 1121 | } |
---|
| 1122 | |
---|
| 1123 | configureGridPersp(&frontRLEGrid, &backRLEGrid, shear); |
---|
| 1124 | |
---|
| 1125 | if (Verbose) { |
---|
| 1126 | applyPersp(center, vec); |
---|
| 1127 | printf("Transformed center: (%f, %f, %f)\n", vec.x, vec.y, vec.z); |
---|
| 1128 | } |
---|
| 1129 | |
---|
| 1130 | int lineWidth; |
---|
| 1131 | BBox3f *gbbox = getBBoxPersp(backRLEGrid, &lineWidth); |
---|
| 1132 | if (Verbose) { |
---|
| 1133 | printf("Line width = %d\n", lineWidth); |
---|
| 1134 | } |
---|
| 1135 | |
---|
| 1136 | prepareRenderPersp(mesh, shear, gbbox, |
---|
| 1137 | backRLEGrid->resolution, theDepthMap, FALSE); |
---|
| 1138 | softRenderConfidence(mesh); |
---|
| 1139 | |
---|
| 1140 | updateRenderPhoto(theDepthMap); |
---|
| 1141 | Tcl_Eval(interp, "update"); |
---|
| 1142 | |
---|
| 1143 | |
---|
| 1144 | if (UseTails) { |
---|
| 1145 | if (FillBackground) { |
---|
| 1146 | fillBackground(theDepthMap); |
---|
| 1147 | } else if (DoSilhouette) { |
---|
| 1148 | makeSilhouette(theDepthMap); |
---|
| 1149 | } |
---|
| 1150 | } |
---|
| 1151 | |
---|
| 1152 | theDepthMap->fillTree(lineWidth); |
---|
| 1153 | |
---|
| 1154 | end_time(); |
---|
| 1155 | |
---|
| 1156 | ResampleRangeTime = time_elapsed(); |
---|
| 1157 | |
---|
| 1158 | start_time(); |
---|
| 1159 | |
---|
| 1160 | if (UseTails && !TailsOnly) { |
---|
| 1161 | scanConvertPerspTreeDragTails(backRLEGrid, frontRLEGrid, |
---|
| 1162 | shear, theDepthMap); |
---|
| 1163 | } else if (TailsOnly) { |
---|
| 1164 | #if 1 |
---|
| 1165 | scanConvertPerspTreeTailsOnly(backRLEGrid, frontRLEGrid, |
---|
| 1166 | shear, theDepthMap); |
---|
| 1167 | #else |
---|
| 1168 | printf("Using fast carver...\n"); |
---|
| 1169 | scanConvertPerspTreeTailsOnlyFast(backRLEGrid, frontRLEGrid, |
---|
| 1170 | shear, theDepthMap); |
---|
| 1171 | #endif |
---|
| 1172 | } |
---|
| 1173 | else { |
---|
| 1174 | scanConvertPerspTree(backRLEGrid, frontRLEGrid, shear, theDepthMap); |
---|
| 1175 | } |
---|
| 1176 | |
---|
| 1177 | end_time(); |
---|
| 1178 | |
---|
| 1179 | MergeTime = time_elapsed(); |
---|
| 1180 | if (!SuperQuiet) |
---|
| 1181 | printf("Time to process: %.2f sec\n", |
---|
| 1182 | TesselationTime + ResampleRangeTime + MergeTime); |
---|
| 1183 | |
---|
| 1184 | delete shear; |
---|
| 1185 | delete gbbox; |
---|
| 1186 | delete mesh; |
---|
| 1187 | |
---|
| 1188 | return TCL_OK; |
---|
| 1189 | } |
---|
| 1190 | |
---|
| 1191 | |
---|
| 1192 | static void |
---|
| 1193 | parse_transformation(Mesh *mesh, Tcl_Interp *interp, int argc, const char **argv) |
---|
| 1194 | { |
---|
| 1195 | Quaternion quat; |
---|
| 1196 | double xt,yt,zt; |
---|
| 1197 | double rot; |
---|
| 1198 | double q0,q1,q2,q3; |
---|
| 1199 | |
---|
| 1200 | /* parse the transformation info */ |
---|
| 1201 | |
---|
| 1202 | /* argc == 2, no transformation */ |
---|
| 1203 | /* argc == 3, <rot-about-y-axis> */ |
---|
| 1204 | /* argc == 6, <tx> <ty> <tz> <rot-about-y-axis> */ |
---|
| 1205 | /* argc == 9, <tx> <ty> <tz> <q0> <q1> <q2> <q3> */ |
---|
| 1206 | |
---|
| 1207 | |
---|
| 1208 | // First decide if a .xf file exists |
---|
| 1209 | int xfFileExists; |
---|
| 1210 | |
---|
| 1211 | // Awful code to create .xf filename |
---|
| 1212 | char filename[PATH_MAX]; |
---|
| 1213 | strcpy(filename, argv[1]); |
---|
| 1214 | char *dot = strrchr(filename, '.'); |
---|
| 1215 | *dot = 0; |
---|
| 1216 | strcat(filename, ".xf"); |
---|
| 1217 | struct stat sts; |
---|
| 1218 | if (stat(filename, &sts) == -1 && errno == ENOENT) { |
---|
| 1219 | xfFileExists = 0; |
---|
| 1220 | } else { |
---|
| 1221 | xfFileExists = 1; |
---|
| 1222 | } |
---|
| 1223 | |
---|
| 1224 | // If the .xf file exists and there are no overriding |
---|
| 1225 | // xform arguments, then go ahead and use the .xf file |
---|
| 1226 | if (argc == 2 && xfFileExists) { |
---|
| 1227 | float r1, r2, r3, t1, t2, t3; |
---|
| 1228 | Matrix4f mat; |
---|
| 1229 | mat.makeIdentity(); |
---|
| 1230 | FILE *fp = fopen(filename, "r"); |
---|
| 1231 | mat.read(fp); |
---|
| 1232 | t1 = mat.elem(0,3); |
---|
| 1233 | t2 = mat.elem(1,3); |
---|
| 1234 | t3 = mat.elem(2,3); |
---|
| 1235 | |
---|
| 1236 | /* |
---|
| 1237 | fscanf(fp, "%f %f %f %f", &r1, &r2, &r3, &t1); |
---|
| 1238 | mrot.setElem(0,0,r1); |
---|
| 1239 | mrot.setElem(1,0,r2); |
---|
| 1240 | mrot.setElem(2,0,r3); |
---|
| 1241 | fscanf(fp, "%f %f %f %f", &r1, &r2, &r3, &t2); |
---|
| 1242 | mrot.setElem(0,1,r1); |
---|
| 1243 | mrot.setElem(1,1,r2); |
---|
| 1244 | mrot.setElem(2,1,r3); |
---|
| 1245 | fscanf(fp, "%f %f %f %f", &r1, &r2, &r3, &t3); |
---|
| 1246 | mrot.setElem(0,2,r1); |
---|
| 1247 | mrot.setElem(1,2,r2); |
---|
| 1248 | mrot.setElem(2,2,r3); |
---|
| 1249 | */ |
---|
| 1250 | |
---|
| 1251 | mesh->quat.fromMatrix(mat); |
---|
| 1252 | mesh->trans.setValue(t1,t2,t3); |
---|
| 1253 | |
---|
| 1254 | return; |
---|
| 1255 | } |
---|
| 1256 | |
---|
| 1257 | /* translation */ |
---|
| 1258 | if (argc == 2 || argc == 3) { |
---|
| 1259 | mesh->trans.setValue(0,0,0); |
---|
| 1260 | } |
---|
| 1261 | else { |
---|
| 1262 | Tcl_GetDouble (interp, argv[2], &xt); |
---|
| 1263 | Tcl_GetDouble (interp, argv[3], &yt); |
---|
| 1264 | Tcl_GetDouble (interp, argv[4], &zt); |
---|
| 1265 | mesh->trans.setValue(xt, yt, zt); |
---|
| 1266 | } |
---|
| 1267 | |
---|
| 1268 | /* rotation */ |
---|
| 1269 | Matrix4f mrot; |
---|
| 1270 | mrot.makeIdentity(); |
---|
| 1271 | if (argc == 9) { |
---|
| 1272 | Tcl_GetDouble (interp, argv[5], &q0); |
---|
| 1273 | Tcl_GetDouble (interp, argv[6], &q1); |
---|
| 1274 | Tcl_GetDouble (interp, argv[7], &q2); |
---|
| 1275 | Tcl_GetDouble (interp, argv[8], &q3); |
---|
| 1276 | mesh->quat.q[0] = q0; |
---|
| 1277 | mesh->quat.q[1] = q1; |
---|
| 1278 | mesh->quat.q[2] = q2; |
---|
| 1279 | mesh->quat.q[3] = q3; |
---|
| 1280 | mesh->quat.toMatrix(mrot); |
---|
| 1281 | mrot.transpose(); |
---|
| 1282 | mesh->quat.fromMatrix(mrot); |
---|
| 1283 | } |
---|
| 1284 | else if (argc == 6) { |
---|
| 1285 | Tcl_GetDouble (interp, argv[5], &rot); |
---|
| 1286 | mrot.rotateY(RAD(rot)); |
---|
| 1287 | mesh->quat.fromMatrix(mrot); |
---|
| 1288 | } |
---|
| 1289 | else if (argc == 3) { |
---|
| 1290 | Tcl_GetDouble (interp, argv[2], &rot); |
---|
| 1291 | mrot.rotateY(RAD(rot)); |
---|
| 1292 | mesh->quat.fromMatrix(mrot); |
---|
| 1293 | } |
---|
| 1294 | else { |
---|
| 1295 | mesh->quat.fromMatrix(mrot); |
---|
| 1296 | } |
---|
| 1297 | } |
---|
| 1298 | |
---|
| 1299 | |
---|
| 1300 | static void |
---|
| 1301 | start_time() |
---|
| 1302 | { |
---|
| 1303 | struct tms buffer; |
---|
| 1304 | times(&buffer); |
---|
| 1305 | tm = buffer.tms_utime; |
---|
| 1306 | } |
---|
| 1307 | |
---|
| 1308 | static void |
---|
| 1309 | end_time() |
---|
| 1310 | { |
---|
| 1311 | struct tms buffer; |
---|
| 1312 | times(&buffer); |
---|
| 1313 | tm = buffer.tms_utime - tm; |
---|
| 1314 | } |
---|
| 1315 | |
---|
| 1316 | static float |
---|
| 1317 | time_elapsed() |
---|
| 1318 | { |
---|
| 1319 | return (double) tm / (double) CLOCKS_PER_SEC; |
---|
| 1320 | } |
---|
| 1321 | |
---|