[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 | |
---|
| 28 | #include "vrip.h" |
---|
| 29 | #include "vripFillCmds.h" |
---|
| 30 | #include "vripGlobals.h" |
---|
| 31 | #include "Mesh.h" |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | int |
---|
| 35 | Vrip_EllipseCmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[]) |
---|
| 36 | { |
---|
| 37 | int xx,yy,zz; |
---|
| 38 | float xlen,ylen,zlen; |
---|
| 39 | float a,b,c; |
---|
| 40 | float xpos,ypos,zpos; |
---|
| 41 | float res, fxyz; |
---|
| 42 | OccElement *buf; |
---|
| 43 | |
---|
| 44 | if (argc != 4) { |
---|
| 45 | interp->result = "Usage: vrip_ellipse <xlen> <ylen> <zlen>"; |
---|
| 46 | return TCL_ERROR; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | if (theGrid == NULL) { |
---|
| 50 | interp->result = "Grid not allocated."; |
---|
| 51 | return TCL_ERROR; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | xlen = atof(argv[1]); |
---|
| 55 | ylen = atof(argv[2]); |
---|
| 56 | zlen = atof(argv[3]); |
---|
| 57 | |
---|
| 58 | a = 1/xlen/xlen; |
---|
| 59 | b = 1/ylen/ylen; |
---|
| 60 | c = 1/zlen/zlen; |
---|
| 61 | |
---|
| 62 | res = theGrid->resolution; |
---|
| 63 | |
---|
| 64 | buf = theGrid->elems; |
---|
| 65 | |
---|
| 66 | zpos = -theGrid->zdim*theGrid->resolution/2; |
---|
| 67 | for (zz = 0; zz < theGrid->zdim; zz++, zpos+=res) { |
---|
| 68 | ypos = -theGrid->ydim*theGrid->resolution/2; |
---|
| 69 | for (yy = 0; yy < theGrid->ydim; yy++, ypos+=res) { |
---|
| 70 | xpos = -theGrid->xdim*theGrid->resolution/2; |
---|
| 71 | for (xx = 0; xx < theGrid->xdim; xx++, xpos+=res, buf++) { |
---|
| 72 | fxyz = a*xpos*xpos + b*ypos*ypos + c*zpos*zpos - 1; |
---|
| 73 | if (fxyz > 0) { |
---|
| 74 | buf->value = 0; |
---|
| 75 | buf->totalWeight = 0; |
---|
| 76 | } else { |
---|
| 77 | buf->value = USHRT_MAX/2; |
---|
| 78 | buf->totalWeight = USHRT_MAX/2; |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | return TCL_OK; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | int |
---|
| 89 | Vrip_EllipseRLECmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[]) |
---|
| 90 | { |
---|
| 91 | int xx,yy,zz; |
---|
| 92 | float xlen,ylen,zlen; |
---|
| 93 | float a,b,c; |
---|
| 94 | float xpos,ypos,zpos; |
---|
| 95 | float xposBump,yposBump,zposBump; |
---|
| 96 | float res, fxyz; |
---|
| 97 | OccElement *buf; |
---|
| 98 | float amplitude; |
---|
| 99 | float freq; |
---|
| 100 | float phase; |
---|
| 101 | |
---|
| 102 | amplitude = 0.517; |
---|
| 103 | freq = 0.3; |
---|
| 104 | phase = 0.123; |
---|
| 105 | |
---|
| 106 | if (argc != 4) { |
---|
| 107 | interp->result = "Usage: vrip_ellipse <xlen> <ylen> <zlen>"; |
---|
| 108 | return TCL_ERROR; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | if (frontRLEGrid == NULL) { |
---|
| 112 | interp->result = "Grid not allocated."; |
---|
| 113 | return TCL_ERROR; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | xlen = atof(argv[1]); |
---|
| 117 | ylen = atof(argv[2]); |
---|
| 118 | zlen = atof(argv[3]); |
---|
| 119 | |
---|
| 120 | a = 5/xlen/xlen; |
---|
| 121 | b = 5/ylen/ylen; |
---|
| 122 | c = 5/zlen/zlen; |
---|
| 123 | |
---|
| 124 | res = frontRLEGrid->resolution; |
---|
| 125 | |
---|
| 126 | OccElement *scanline = new OccElement[frontRLEGrid->xdim]; |
---|
| 127 | frontRLEGrid->reset(); |
---|
| 128 | |
---|
| 129 | zpos = -frontRLEGrid->zdim*frontRLEGrid->resolution/2; |
---|
| 130 | for (zz = 0; zz < frontRLEGrid->zdim; zz++, zpos+=res) { |
---|
| 131 | ypos = -frontRLEGrid->ydim*frontRLEGrid->resolution/2; |
---|
| 132 | for (yy = 0; yy < frontRLEGrid->ydim; yy++, ypos+=res) { |
---|
| 133 | xpos = -frontRLEGrid->xdim*frontRLEGrid->resolution/2; |
---|
| 134 | buf = scanline; |
---|
| 135 | for (xx = 0; xx < frontRLEGrid->xdim; xx++, xpos+=res, buf++) { |
---|
| 136 | float amp = amplitude*exp(-float(yy)/frontRLEGrid->ydim*3); |
---|
| 137 | xposBump = xpos + |
---|
| 138 | amp*frontRLEGrid->resolution*sin(2*M_PI*freq*xx+0.123); |
---|
| 139 | yposBump = ypos + |
---|
| 140 | amp*frontRLEGrid->resolution*sin(2*M_PI*freq*yy+6.788); |
---|
| 141 | zposBump = zpos + |
---|
| 142 | amp*frontRLEGrid->resolution*sin(2*M_PI*freq*zz+2.97); |
---|
| 143 | fxyz = a*xposBump*xposBump + b*yposBump*yposBump |
---|
| 144 | + c*zposBump*zposBump - 1; |
---|
| 145 | fxyz = 2*exp(-(a*xposBump*xposBump + |
---|
| 146 | b*yposBump*yposBump + c*zposBump*zposBump)); |
---|
| 147 | if (fxyz > 0.99) { |
---|
| 148 | buf->value = USHRT_MAX; |
---|
| 149 | buf->totalWeight = 0; |
---|
| 150 | } |
---|
| 151 | else if (fxyz < 0.01) { |
---|
| 152 | buf->value = 0; |
---|
| 153 | buf->totalWeight = 0; |
---|
| 154 | } else { |
---|
| 155 | buf->value = ushort(USHRT_MAX*fxyz); |
---|
| 156 | buf->totalWeight = USHRT_MAX; |
---|
| 157 | } |
---|
| 158 | } |
---|
| 159 | frontRLEGrid->putScanline(scanline, yy, zz); |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | delete [] scanline; |
---|
| 164 | |
---|
| 165 | return TCL_OK; |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | int |
---|
| 170 | Vrip_ChairRLECmd(ClientData, Tcl_Interp *interp, |
---|
| 171 | int argc, const char *argv[]) |
---|
| 172 | { |
---|
| 173 | int xx,yy,zz; |
---|
| 174 | float a,b,k; |
---|
| 175 | float xpos,ypos,zpos; |
---|
| 176 | float res, fxyz; |
---|
| 177 | OccElement *buf; |
---|
| 178 | |
---|
| 179 | if (argc != 4) { |
---|
| 180 | interp->result = "Usage: vrip_chair <a> <b> <k>"; |
---|
| 181 | return TCL_ERROR; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | if (frontRLEGrid == NULL) { |
---|
| 185 | interp->result = "Grid not allocated."; |
---|
| 186 | return TCL_ERROR; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | a = atof(argv[1]); |
---|
| 190 | b = atof(argv[2]); |
---|
| 191 | k = atof(argv[3]); |
---|
| 192 | |
---|
| 193 | res = frontRLEGrid->resolution; |
---|
| 194 | |
---|
| 195 | OccElement *scanline = new OccElement[frontRLEGrid->xdim]; |
---|
| 196 | frontRLEGrid->reset(); |
---|
| 197 | |
---|
| 198 | zpos = -frontRLEGrid->zdim*frontRLEGrid->resolution/2; |
---|
| 199 | for (zz = 0; zz < frontRLEGrid->zdim; zz++, zpos+=res) { |
---|
| 200 | ypos = -frontRLEGrid->ydim*frontRLEGrid->resolution/2; |
---|
| 201 | for (yy = 0; yy < frontRLEGrid->ydim; yy++, ypos+=res) { |
---|
| 202 | xpos = -frontRLEGrid->xdim*frontRLEGrid->resolution/2; |
---|
| 203 | buf = scanline; |
---|
| 204 | for (xx = 0; xx < frontRLEGrid->xdim; xx++, xpos+=res, buf++) { |
---|
| 205 | fxyz = -(pow((xpos*xpos+ypos*ypos+zpos*zpos-a*k*k),2) - |
---|
| 206 | b*((zpos-k)*(zpos-k)-2*xpos*xpos)* |
---|
| 207 | ((zpos+k)*(zpos+k)-2*ypos*ypos))*0.01+0.5; |
---|
| 208 | if (fxyz > 1) { |
---|
| 209 | buf->value = USHRT_MAX; |
---|
| 210 | buf->totalWeight = 0; |
---|
| 211 | } |
---|
| 212 | else if (fxyz < 0) { |
---|
| 213 | buf->value = 0; |
---|
| 214 | buf->totalWeight = 0; |
---|
| 215 | } else { |
---|
| 216 | buf->value = ushort(USHRT_MAX*fxyz); |
---|
| 217 | buf->totalWeight = USHRT_MAX; |
---|
| 218 | } |
---|
| 219 | } |
---|
| 220 | frontRLEGrid->putScanline(scanline, yy, zz); |
---|
| 221 | } |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | delete [] scanline; |
---|
| 225 | |
---|
| 226 | return TCL_OK; |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | |
---|
| 230 | int |
---|
| 231 | Vrip_SinewaveRLECmd(ClientData, Tcl_Interp *interp, |
---|
| 232 | int argc, const char *argv[]) |
---|
| 233 | { |
---|
| 234 | int xx,yy,zz; |
---|
| 235 | float frequency,amplitude; |
---|
| 236 | float xpos,ypos,zpos; |
---|
| 237 | float res, fxyz; |
---|
| 238 | OccElement *buf; |
---|
| 239 | |
---|
| 240 | if (argc != 3) { |
---|
| 241 | interp->result = "Usage: vrip_sinewave <amplitude> <frequency>"; |
---|
| 242 | return TCL_ERROR; |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | if (frontRLEGrid == NULL) { |
---|
| 246 | interp->result = "Grid not allocated."; |
---|
| 247 | return TCL_ERROR; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | amplitude = atof(argv[1]); |
---|
| 251 | frequency = atof(argv[2]); |
---|
| 252 | |
---|
| 253 | res = frontRLEGrid->resolution; |
---|
| 254 | |
---|
| 255 | OccElement *scanline = new OccElement[frontRLEGrid->xdim]; |
---|
| 256 | frontRLEGrid->reset(); |
---|
| 257 | |
---|
| 258 | zpos = -frontRLEGrid->zdim*frontRLEGrid->resolution/2; |
---|
| 259 | for (zz = 0; zz < frontRLEGrid->zdim; zz++, zpos+=res) { |
---|
| 260 | ypos = -frontRLEGrid->ydim*frontRLEGrid->resolution/2; |
---|
| 261 | for (yy = 0; yy < frontRLEGrid->ydim; yy++, ypos+=res) { |
---|
| 262 | xpos = -frontRLEGrid->xdim*frontRLEGrid->resolution/2; |
---|
| 263 | buf = scanline; |
---|
| 264 | for (xx = 0; xx < frontRLEGrid->xdim; xx++, xpos+=res, buf++) { |
---|
| 265 | fxyz = -zpos + amplitude*cos(2*M_PI*frequency*xpos) + 0.5; |
---|
| 266 | if (fxyz > 1) { |
---|
| 267 | buf->value = USHRT_MAX; |
---|
| 268 | buf->totalWeight = 0; |
---|
| 269 | } |
---|
| 270 | else if (fxyz < 0) { |
---|
| 271 | buf->value = 0; |
---|
| 272 | buf->totalWeight = 0; |
---|
| 273 | } else { |
---|
| 274 | buf->value = ushort(USHRT_MAX*fxyz); |
---|
| 275 | buf->totalWeight = USHRT_MAX; |
---|
| 276 | } |
---|
| 277 | } |
---|
| 278 | frontRLEGrid->putScanline(scanline, yy, zz); |
---|
| 279 | } |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | delete [] scanline; |
---|
| 283 | |
---|
| 284 | return TCL_OK; |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | |
---|
| 288 | int |
---|
| 289 | Vrip_GumdropTorusRLECmd(ClientData, Tcl_Interp *interp, |
---|
| 290 | int argc, const char *argv[]) |
---|
| 291 | { |
---|
| 292 | int xx,yy,zz; |
---|
| 293 | float xpos,ypos,zpos; |
---|
| 294 | float res, fxyz; |
---|
| 295 | OccElement *buf; |
---|
| 296 | |
---|
| 297 | if (argc != 1) { |
---|
| 298 | interp->result = "Usage: vrip_gumdrop_torus"; |
---|
| 299 | return TCL_ERROR; |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | if (frontRLEGrid == NULL) { |
---|
| 303 | interp->result = "Grid not allocated."; |
---|
| 304 | return TCL_ERROR; |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | res = frontRLEGrid->resolution; |
---|
| 308 | |
---|
| 309 | OccElement *scanline = new OccElement[frontRLEGrid->xdim]; |
---|
| 310 | frontRLEGrid->reset(); |
---|
| 311 | |
---|
| 312 | zpos = -frontRLEGrid->zdim*frontRLEGrid->resolution/2; |
---|
| 313 | for (zz = 0; zz < frontRLEGrid->zdim; zz++, zpos+=res) { |
---|
| 314 | ypos = -frontRLEGrid->ydim*frontRLEGrid->resolution/2; |
---|
| 315 | for (yy = 0; yy < frontRLEGrid->ydim; yy++, ypos+=res) { |
---|
| 316 | xpos = -frontRLEGrid->xdim*frontRLEGrid->resolution/2; |
---|
| 317 | buf = scanline; |
---|
| 318 | for (xx = 0; xx < frontRLEGrid->xdim; xx++, xpos+=res, buf++) { |
---|
| 319 | fxyz = 4*pow(xpos,4)+4*pow(ypos,4)+8*ypos*ypos*zpos*zpos |
---|
| 320 | +4*pow(zpos,4)+17*xpos*xpos*ypos*ypos+17*xpos*xpos*zpos*zpos |
---|
| 321 | -20*xpos*xpos-20*ypos*ypos-20*zpos*zpos+17+0.5; |
---|
| 322 | fxyz = (1-fxyz)*0.1; |
---|
| 323 | if (fxyz > 1) { |
---|
| 324 | buf->value = USHRT_MAX; |
---|
| 325 | buf->totalWeight = 0; |
---|
| 326 | } |
---|
| 327 | else if (fxyz < 0) { |
---|
| 328 | buf->value = 0; |
---|
| 329 | buf->totalWeight = 0; |
---|
| 330 | } else { |
---|
| 331 | buf->value = ushort(USHRT_MAX*fxyz); |
---|
| 332 | buf->totalWeight = USHRT_MAX; |
---|
| 333 | } |
---|
| 334 | } |
---|
| 335 | frontRLEGrid->putScanline(scanline, yy, zz); |
---|
| 336 | } |
---|
| 337 | } |
---|
| 338 | |
---|
| 339 | delete [] scanline; |
---|
| 340 | |
---|
| 341 | return TCL_OK; |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | |
---|
| 345 | int |
---|
| 346 | Vrip_CylinderRLECmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[]) |
---|
| 347 | { |
---|
| 348 | int xx,yy,zz; |
---|
| 349 | float radius, c; |
---|
| 350 | float xpos,ypos,zpos; |
---|
| 351 | float res, fxyz; |
---|
| 352 | OccElement *buf; |
---|
| 353 | |
---|
| 354 | if (argc != 2) { |
---|
| 355 | interp->result = "Usage: vrip_cylinder <radius>"; |
---|
| 356 | return TCL_ERROR; |
---|
| 357 | } |
---|
| 358 | |
---|
| 359 | if (frontRLEGrid == NULL) { |
---|
| 360 | interp->result = "Grid not allocated."; |
---|
| 361 | return TCL_ERROR; |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | radius = atof(argv[1]); |
---|
| 365 | c = 1/radius/radius; |
---|
| 366 | |
---|
| 367 | res = frontRLEGrid->resolution; |
---|
| 368 | |
---|
| 369 | OccElement *scanline = new OccElement[frontRLEGrid->xdim]; |
---|
| 370 | frontRLEGrid->reset(); |
---|
| 371 | |
---|
| 372 | zpos = -frontRLEGrid->zdim*frontRLEGrid->resolution/2; |
---|
| 373 | for (zz = 0; zz < frontRLEGrid->zdim; zz++, zpos+=res) { |
---|
| 374 | ypos = -frontRLEGrid->ydim*frontRLEGrid->resolution/2; |
---|
| 375 | for (yy = 0; yy < frontRLEGrid->ydim; yy++, ypos+=res) { |
---|
| 376 | xpos = -frontRLEGrid->xdim*frontRLEGrid->resolution/2; |
---|
| 377 | buf = scanline; |
---|
| 378 | for (xx = 0; xx < frontRLEGrid->xdim; xx++, xpos+=res, buf++) { |
---|
| 379 | fxyz = exp(-(c*(xpos*xpos+zpos*zpos))); |
---|
| 380 | if (fxyz > 0.75 || fxyz < 0.25) { |
---|
| 381 | buf->value = 0; |
---|
| 382 | buf->totalWeight = 0; |
---|
| 383 | } else { |
---|
| 384 | buf->value = ushort(USHRT_MAX*fxyz); |
---|
| 385 | buf->totalWeight = USHRT_MAX; |
---|
| 386 | } |
---|
| 387 | } |
---|
| 388 | frontRLEGrid->putScanline(scanline, yy, zz); |
---|
| 389 | } |
---|
| 390 | } |
---|
| 391 | |
---|
| 392 | delete [] scanline; |
---|
| 393 | |
---|
| 394 | return TCL_OK; |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | |
---|
| 398 | int |
---|
| 399 | Vrip_FillRLECmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[]) |
---|
| 400 | { |
---|
| 401 | int xx,yy,zz; |
---|
| 402 | float value, weight; |
---|
| 403 | |
---|
| 404 | if (argc != 3) { |
---|
| 405 | interp->result = "Usage: vrip_fillrle <value> <weight>"; |
---|
| 406 | return TCL_ERROR; |
---|
| 407 | } |
---|
| 408 | |
---|
| 409 | if (frontRLEGrid == NULL) { |
---|
| 410 | interp->result = "Grid not allocated."; |
---|
| 411 | return TCL_ERROR; |
---|
| 412 | } |
---|
| 413 | |
---|
| 414 | value = atof(argv[1]); |
---|
| 415 | weight = atof(argv[2]); |
---|
| 416 | |
---|
| 417 | OccElement *scanline = new OccElement[frontRLEGrid->xdim]; |
---|
| 418 | for (xx = 0; xx < frontRLEGrid->xdim; xx++) { |
---|
| 419 | scanline[xx].value = ushort(USHRT_MAX*value); |
---|
| 420 | scanline[xx].totalWeight = ushort(UCHAR_MAX*weight); |
---|
| 421 | } |
---|
| 422 | |
---|
| 423 | /* |
---|
| 424 | scanline[0].value = scanline[0].totalWeight = 0; |
---|
| 425 | scanline[frontRLEGrid->xdim-1].value = |
---|
| 426 | scanline[frontRLEGrid->xdim-1].totalWeight = 0; |
---|
| 427 | */ |
---|
| 428 | |
---|
| 429 | frontRLEGrid->reset(); |
---|
| 430 | |
---|
| 431 | for (zz = 0; zz < frontRLEGrid->zdim; zz++) { |
---|
| 432 | for (yy = 0; yy < frontRLEGrid->ydim; yy++) { |
---|
| 433 | frontRLEGrid->putScanline(scanline, yy, zz); |
---|
| 434 | } |
---|
| 435 | } |
---|
| 436 | |
---|
| 437 | |
---|
| 438 | /* |
---|
| 439 | |
---|
| 440 | for (xx = 0; xx < frontRLEGrid->xdim; xx++) { |
---|
| 441 | scanline[xx].value = 0; |
---|
| 442 | scanline[xx].totalWeight = 0; |
---|
| 443 | } |
---|
| 444 | |
---|
| 445 | zz = 0; |
---|
| 446 | for (yy = 0; yy < frontRLEGrid->ydim; yy++) { |
---|
| 447 | frontRLEGrid->putScanline(scanline, yy, zz); |
---|
| 448 | } |
---|
| 449 | zz = frontRLEGrid->zdim-1; |
---|
| 450 | for (yy = 0; yy < frontRLEGrid->ydim; yy++) { |
---|
| 451 | frontRLEGrid->putScanline(scanline, yy, zz); |
---|
| 452 | } |
---|
| 453 | |
---|
| 454 | yy = 0; |
---|
| 455 | for (zz = 0; zz < frontRLEGrid->zdim; zz++) { |
---|
| 456 | frontRLEGrid->putScanline(scanline, yy, zz); |
---|
| 457 | } |
---|
| 458 | yy = frontRLEGrid->ydim-1; |
---|
| 459 | for (zz = 0; zz < frontRLEGrid->zdim; zz++) { |
---|
| 460 | frontRLEGrid->putScanline(scanline, yy, zz); |
---|
| 461 | } |
---|
| 462 | */ |
---|
| 463 | |
---|
| 464 | |
---|
| 465 | delete [] scanline; |
---|
| 466 | |
---|
| 467 | return TCL_OK; |
---|
| 468 | } |
---|
| 469 | |
---|
| 470 | |
---|
| 471 | int |
---|
| 472 | Vrip_CubeCmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[]) |
---|
| 473 | { |
---|
| 474 | int xx,yy,zz; |
---|
| 475 | float xlen,ylen,zlen; |
---|
| 476 | float xpos,ypos,zpos; |
---|
| 477 | float res; |
---|
| 478 | OccElement *buf; |
---|
| 479 | |
---|
| 480 | if (argc != 4) { |
---|
| 481 | interp->result = "Usage: vrip_cube <xlen> <ylen> <zlen>"; |
---|
| 482 | return TCL_ERROR; |
---|
| 483 | } |
---|
| 484 | |
---|
| 485 | if (theGrid == NULL) { |
---|
| 486 | interp->result = "Grid not allocated."; |
---|
| 487 | return TCL_ERROR; |
---|
| 488 | } |
---|
| 489 | |
---|
| 490 | xlen = atof(argv[1]); |
---|
| 491 | ylen = atof(argv[2]); |
---|
| 492 | zlen = atof(argv[3]); |
---|
| 493 | |
---|
| 494 | res = theGrid->resolution; |
---|
| 495 | |
---|
| 496 | buf = theGrid->elems; |
---|
| 497 | |
---|
| 498 | zpos = -theGrid->zdim*theGrid->resolution/2; |
---|
| 499 | |
---|
| 500 | for (zz = 0; zz < theGrid->zdim; zz++, zpos+=res) { |
---|
| 501 | |
---|
| 502 | ypos = -theGrid->ydim*theGrid->resolution/2; |
---|
| 503 | |
---|
| 504 | for (yy = 0; yy < theGrid->ydim; yy++, ypos+=res) { |
---|
| 505 | |
---|
| 506 | xpos = -theGrid->xdim*theGrid->resolution/2; |
---|
| 507 | |
---|
| 508 | for (xx = 0; xx < theGrid->xdim; xx++, xpos+=res, buf++) { |
---|
| 509 | |
---|
| 510 | if (fabs(xpos) < xlen/2 && fabs(ypos) < ylen/2 |
---|
| 511 | && fabs(zpos) < zlen/2) { |
---|
| 512 | buf->value = USHRT_MAX; |
---|
| 513 | buf->totalWeight = USHRT_MAX; |
---|
| 514 | } else { |
---|
| 515 | buf->value = 0; |
---|
| 516 | buf->totalWeight = USHRT_MAX; |
---|
| 517 | } |
---|
| 518 | |
---|
| 519 | } |
---|
| 520 | } |
---|
| 521 | } |
---|
| 522 | |
---|
| 523 | return TCL_OK; |
---|
| 524 | } |
---|
| 525 | |
---|
| 526 | |
---|
| 527 | int |
---|
| 528 | Vrip_CubeRLECmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[]) |
---|
| 529 | { |
---|
| 530 | int xx,yy,zz; |
---|
| 531 | float xlen,ylen,zlen; |
---|
| 532 | |
---|
| 533 | float xpos,ypos,zpos; |
---|
| 534 | float res, fxyz; |
---|
| 535 | OccElement *buf; |
---|
| 536 | |
---|
| 537 | if (argc != 4) { |
---|
| 538 | interp->result = "Usage: vrip_cuberle <xlen> <ylen> <zlen>"; |
---|
| 539 | return TCL_ERROR; |
---|
| 540 | } |
---|
| 541 | |
---|
| 542 | if (frontRLEGrid == NULL) { |
---|
| 543 | interp->result = "Grid not allocated."; |
---|
| 544 | return TCL_ERROR; |
---|
| 545 | } |
---|
| 546 | |
---|
| 547 | xlen = atof(argv[1]); |
---|
| 548 | ylen = atof(argv[2]); |
---|
| 549 | zlen = atof(argv[3]); |
---|
| 550 | |
---|
| 551 | res = frontRLEGrid->resolution; |
---|
| 552 | |
---|
| 553 | OccElement *scanline = new OccElement[frontRLEGrid->xdim]; |
---|
| 554 | frontRLEGrid->reset(); |
---|
| 555 | |
---|
| 556 | zpos = -frontRLEGrid->zdim*frontRLEGrid->resolution/2; |
---|
| 557 | for (zz = 0; zz < frontRLEGrid->zdim; zz++, zpos+=res) { |
---|
| 558 | ypos = -frontRLEGrid->ydim*frontRLEGrid->resolution/2; |
---|
| 559 | for (yy = 0; yy < frontRLEGrid->ydim; yy++, ypos+=res) { |
---|
| 560 | xpos = -frontRLEGrid->xdim*frontRLEGrid->resolution/2; |
---|
| 561 | buf = scanline; |
---|
| 562 | for (xx = 0; xx < frontRLEGrid->xdim; xx++, xpos+=res, buf++) { |
---|
| 563 | if (fabs(xpos) < xlen/2 && fabs(ypos) < ylen/2 |
---|
| 564 | && fabs(zpos) < zlen/2) { |
---|
| 565 | buf->value = USHRT_MAX; |
---|
| 566 | buf->totalWeight = USHRT_MAX; |
---|
| 567 | } else { |
---|
| 568 | buf->value = 0; |
---|
| 569 | buf->totalWeight = USHRT_MAX; |
---|
| 570 | } |
---|
| 571 | |
---|
| 572 | } |
---|
| 573 | frontRLEGrid->putScanline(scanline, yy, zz); |
---|
| 574 | } |
---|
| 575 | } |
---|
| 576 | |
---|
| 577 | delete [] scanline; |
---|
| 578 | |
---|
| 579 | return TCL_OK; |
---|
| 580 | } |
---|