[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 | #ifndef MIN |
---|
| 22 | #define MIN(x,y) ((x)<(y)?(x):(y)) |
---|
| 23 | #endif |
---|
| 24 | |
---|
| 25 | #ifndef MAX |
---|
| 26 | #define MAX(x,y) ((x)>(y)?(x):(y)) |
---|
| 27 | #endif |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | #include <limits.h> |
---|
| 31 | #include <stdlib.h> |
---|
| 32 | #include <math.h> |
---|
| 33 | #include <unistd.h> |
---|
| 34 | #include <sys/wait.h> |
---|
| 35 | |
---|
| 36 | #include "vrip.h" |
---|
| 37 | #include "vripGUICmds.h" |
---|
| 38 | #include "vripGlobals.h" |
---|
| 39 | |
---|
| 40 | #include <fstream> |
---|
| 41 | |
---|
| 42 | // Use c++-ified version!!! |
---|
| 43 | #include <tk.h> |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | static uchar *sliceBuf = NULL; |
---|
| 47 | static int sliceXdim = 0, sliceYdim = 0; |
---|
| 48 | |
---|
| 49 | static char *theRenderPhoto = NULL; |
---|
| 50 | static uchar *renderBuf = NULL; |
---|
| 51 | static int renderXdim = 0, renderYdim = 0; |
---|
| 52 | |
---|
| 53 | static int thePhotoSliceArgc; |
---|
| 54 | static const char **thePhotoSliceArgv = NULL; |
---|
| 55 | static Tcl_Interp *theInterp; |
---|
| 56 | |
---|
| 57 | // Allocate fog, bog only once, to avoid memory leakage |
---|
| 58 | // This has to be global, so that the multiple functions can all |
---|
| 59 | // use the same front/back buffer. Otherwise, changes from one |
---|
| 60 | // filter will not be reflected in the others... -lucas |
---|
| 61 | static OccGrid *fog=NULL; |
---|
| 62 | static OccGrid *bog=NULL; |
---|
| 63 | |
---|
| 64 | int |
---|
| 65 | Vrip_PhotoSliceCmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[]) |
---|
| 66 | { |
---|
| 67 | const char *axis; |
---|
| 68 | OccElement *slice; |
---|
| 69 | int sliceNum, xdim, ydim; |
---|
| 70 | |
---|
| 71 | if (argc != 4) { |
---|
| 72 | interp->result = "Usage: vrip_photoslice <photo-widget> <slice-num> <axis>"; |
---|
| 73 | return TCL_ERROR; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | if (theGrid == NULL) { |
---|
| 77 | interp->result = "Grid not allocated."; |
---|
| 78 | return TCL_ERROR; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | Tk_PhotoHandle handle = Tk_FindPhoto(theInterp, argv[1]); |
---|
| 82 | if (handle == NULL) |
---|
| 83 | return TCL_ERROR; |
---|
| 84 | |
---|
| 85 | sliceNum = atoi(argv[2]); |
---|
| 86 | axis = argv[3]; |
---|
| 87 | |
---|
| 88 | slice = theGrid->getSlice(axis, sliceNum, &xdim, &ydim); |
---|
| 89 | |
---|
| 90 | Tk_PhotoSetSize(handle, xdim, ydim); |
---|
| 91 | |
---|
| 92 | Tk_PhotoImageBlock block; |
---|
| 93 | // block.ptr = (uchar *)(slice + xdim*(ydim-1)); |
---|
| 94 | block.pixelPtr = (uchar *)(slice); |
---|
| 95 | block.width = xdim; |
---|
| 96 | block.height = ydim; |
---|
| 97 | |
---|
| 98 | block.pitch = -xdim*4; |
---|
| 99 | block.pixelSize = 4; |
---|
| 100 | |
---|
| 101 | #ifdef LINUX |
---|
| 102 | block.offset[0] = 1; |
---|
| 103 | block.offset[1] = 1; |
---|
| 104 | block.offset[2] = 1; |
---|
| 105 | #else |
---|
| 106 | block.offset[0] = 0; |
---|
| 107 | block.offset[1] = 0; |
---|
| 108 | block.offset[2] = 0; |
---|
| 109 | #endif |
---|
| 110 | |
---|
| 111 | Tk_PhotoPutBlock(handle, &block, 0, 0, xdim, ydim, TK_PHOTO_COMPOSITE_SET); |
---|
| 112 | |
---|
| 113 | return TCL_OK; |
---|
| 114 | |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | int |
---|
| 119 | Vrip_SetPhotoSliceCmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[]) |
---|
| 120 | { |
---|
| 121 | theInterp = interp; |
---|
| 122 | thePhotoSliceArgc = argc; |
---|
| 123 | |
---|
| 124 | thePhotoSliceArgv = argv; |
---|
| 125 | |
---|
| 126 | /* |
---|
| 127 | if (thePhotoSliceArgv == NULL) { |
---|
| 128 | thePhotoSliceArgv = new char*[10]; |
---|
| 129 | for (int i = 0; i < 10; i++) { |
---|
| 130 | thePhotoSliceArgv[i] = new char[PATH_MAX]; |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | for (int i = 0; i < argc; i++) { |
---|
| 135 | strcpy(thePhotoSliceArgv[i], argv[i]); |
---|
| 136 | } |
---|
| 137 | */ |
---|
| 138 | |
---|
| 139 | return TCL_OK; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | void |
---|
| 144 | updatePhotoSlice() |
---|
| 145 | { |
---|
| 146 | Vrip_PhotoSliceRLECmd(NULL, theInterp, thePhotoSliceArgc, |
---|
| 147 | thePhotoSliceArgv); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | int |
---|
| 151 | Vrip_VolSizeCmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[]) |
---|
| 152 | { |
---|
| 153 | sprintf(interp->result,"%d %d %d",frontRLEGrid->xdim,frontRLEGrid->ydim,frontRLEGrid->zdim); |
---|
| 154 | return TCL_OK; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | |
---|
| 158 | int |
---|
| 159 | Vrip_PhotoSliceRLECmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[]) |
---|
| 160 | { |
---|
| 161 | const char *axis; |
---|
| 162 | OccElement *slice; |
---|
| 163 | int sliceNum, xdim, ydim; |
---|
| 164 | float weight, weightScale, value; |
---|
| 165 | int offset, divisor; |
---|
| 166 | |
---|
| 167 | if (argc != 7) { |
---|
| 168 | interp->result = "Usage: vrip_photoslicerle <photo-widget> <slice-num> <axis> <weight-scale> <offset> <divisor>"; |
---|
| 169 | return TCL_ERROR; |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | if (frontRLEGrid == NULL) { |
---|
| 173 | interp->result = "Grid not allocated."; |
---|
| 174 | return TCL_ERROR; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | Tk_PhotoHandle handle = Tk_FindPhoto(theInterp, argv[1]); |
---|
| 178 | if (handle == NULL) |
---|
| 179 | return TCL_ERROR; |
---|
| 180 | |
---|
| 181 | sliceNum = atoi(argv[2]); |
---|
| 182 | axis = argv[3]; |
---|
| 183 | |
---|
| 184 | weightScale = atof(argv[4]); |
---|
| 185 | if (weightScale <= 0) { |
---|
| 186 | interp->result = "weight scale out of range"; |
---|
| 187 | return TCL_ERROR; |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | offset = atoi(argv[5]); |
---|
| 191 | divisor = atoi(argv[6]); |
---|
| 192 | |
---|
| 193 | slice = frontRLEGrid->getSlice(axis, sliceNum, &xdim, &ydim); |
---|
| 194 | |
---|
| 195 | if (sliceBuf == NULL) { |
---|
| 196 | sliceBuf = new uchar[3*xdim*ydim]; |
---|
| 197 | sliceXdim = xdim; |
---|
| 198 | sliceYdim = ydim; |
---|
| 199 | } |
---|
| 200 | else if (xdim*ydim > sliceXdim*sliceYdim) { |
---|
| 201 | delete sliceBuf; |
---|
| 202 | sliceBuf = new uchar[3*xdim*ydim]; |
---|
| 203 | sliceXdim = xdim; |
---|
| 204 | sliceYdim = ydim; |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | for (int i = 0; i < xdim*ydim; i++) { |
---|
| 208 | if (ShowConfSlice) { |
---|
| 209 | value = slice[i].value/255.0; |
---|
| 210 | if (value >= 255.5) value = 255; |
---|
| 211 | sliceBuf[3*i] = uchar(value+0.5); |
---|
| 212 | sliceBuf[3*i+1] = uchar(value+0.5); |
---|
| 213 | weight = (slice[i].totalWeight & ~OccGridRLE::FALSE_DATA_BIT) |
---|
| 214 | /weightScale; |
---|
| 215 | if (weight > 255.5) weight = 255; |
---|
| 216 | sliceBuf[3*i+2] = uchar(weight+0.5); |
---|
| 217 | #if 0 |
---|
| 218 | value = slice[i].value/255.0; |
---|
| 219 | if (value >= 255.5) value = 255; |
---|
| 220 | sliceBuf[3*i] = uchar(value+0.5); |
---|
| 221 | sliceBuf[3*i+1] = uchar(value+0.5); |
---|
| 222 | sliceBuf[3*i+2] = uchar(value+0.5); |
---|
| 223 | #elif 0 |
---|
| 224 | weight = 8*(slice[i].totalWeight & ~OccGridRLE::FALSE_DATA_BIT) |
---|
| 225 | /weightScale; |
---|
| 226 | if (weight > 255.5) weight = 255; |
---|
| 227 | sliceBuf[3*i] = uchar(weight+0.5); |
---|
| 228 | sliceBuf[3*i+1] = uchar(weight+0.5); |
---|
| 229 | sliceBuf[3*i+2] = 255; |
---|
| 230 | #endif |
---|
| 231 | } |
---|
| 232 | else if (ShowValueWeight) { |
---|
| 233 | if (slice[i].value == USHRT_MAX && |
---|
| 234 | (slice[i].totalWeight & ~OccGridRLE::FALSE_DATA_BIT) == 0) { |
---|
| 235 | #if 1 |
---|
| 236 | sliceBuf[3*i] = 145; |
---|
| 237 | sliceBuf[3*i+1] = 117; |
---|
| 238 | sliceBuf[3*i+2] = 74; |
---|
| 239 | #else |
---|
| 240 | sliceBuf[3*i] = 0; |
---|
| 241 | sliceBuf[3*i+1] = 0; |
---|
| 242 | sliceBuf[3*i+2] = 0; |
---|
| 243 | #endif |
---|
| 244 | } else { |
---|
| 245 | weight = (slice[i].totalWeight & ~OccGridRLE::FALSE_DATA_BIT) |
---|
| 246 | /weightScale; |
---|
| 247 | value = slice[i].value/256 - 128; |
---|
| 248 | value = value*weight/256 + 128; |
---|
| 249 | if (value >= 255.5) |
---|
| 250 | value = 255; |
---|
| 251 | else if (value < -0.5) |
---|
| 252 | value = 0; |
---|
| 253 | sliceBuf[3*i] = sliceBuf[3*i+1] = sliceBuf[3*i+2] = uchar(value+0.5); |
---|
| 254 | //sliceBuf[3*i] = sliceBuf[3*i+1] = sliceBuf[3*i+2] = uchar(weight/1.5+0.5); |
---|
| 255 | } |
---|
| 256 | } else { |
---|
| 257 | if (slice[i].value == USHRT_MAX && |
---|
| 258 | (slice[i].totalWeight & ~OccGridRLE::FALSE_DATA_BIT) == 0) { |
---|
| 259 | #if 1 |
---|
| 260 | sliceBuf[3*i] = 145; |
---|
| 261 | sliceBuf[3*i+1] = 117; |
---|
| 262 | sliceBuf[3*i+2] = 74; |
---|
| 263 | #else |
---|
| 264 | sliceBuf[3*i] = 0; |
---|
| 265 | sliceBuf[3*i+1] = 0; |
---|
| 266 | sliceBuf[3*i+2] = 0; |
---|
| 267 | #endif |
---|
| 268 | } else { |
---|
| 269 | |
---|
| 270 | value = (float(slice[i].value)-offset)/divisor+128; |
---|
| 271 | if (value <= 0.5) value = 0; |
---|
| 272 | |
---|
| 273 | //value = slice[i].value/255.0; |
---|
| 274 | if (value >= 255.5) value = 255; |
---|
| 275 | sliceBuf[3*i] = sliceBuf[3*i+1] = sliceBuf[3*i+2] = uchar(value+0.5); |
---|
| 276 | //sliceBuf[3*i] = sliceBuf[3*i+1] = sliceBuf[3*i+2] = uchar(weight/1.5+0.5); |
---|
| 277 | } |
---|
| 278 | } |
---|
| 279 | } |
---|
| 280 | |
---|
| 281 | Tk_PhotoSetSize(handle, xdim, ydim); |
---|
| 282 | |
---|
| 283 | Tk_PhotoImageBlock block; |
---|
| 284 | |
---|
| 285 | if (EQSTR(axis, "x")) { |
---|
| 286 | block.pixelPtr = sliceBuf + 3*xdim*(ydim-1); |
---|
| 287 | block.pitch = -xdim*3; |
---|
| 288 | } else if (EQSTR(axis, "y")) { |
---|
| 289 | block.pixelPtr = sliceBuf; |
---|
| 290 | block.pitch = xdim*3; |
---|
| 291 | } else if (EQSTR(axis, "z")) { |
---|
| 292 | block.pixelPtr = sliceBuf + 3*xdim*(ydim-1); |
---|
| 293 | block.pitch = -xdim*3; |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | block.pixelSize = 3; |
---|
| 297 | block.offset[0] = 0; |
---|
| 298 | block.offset[1] = 1; |
---|
| 299 | block.offset[2] = 2; |
---|
| 300 | block.width = xdim; |
---|
| 301 | block.height = ydim; |
---|
| 302 | |
---|
| 303 | Tk_PhotoPutBlock(handle, &block, 0, 0, xdim, ydim, TK_PHOTO_COMPOSITE_SET); |
---|
| 304 | |
---|
| 305 | return TCL_OK; |
---|
| 306 | |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | |
---|
| 310 | int |
---|
| 311 | Vrip_PhotoSliceNormRLECmd(ClientData, Tcl_Interp *interp, int argc, |
---|
| 312 | const char *argv[]) |
---|
| 313 | { |
---|
| 314 | const char *axis; |
---|
| 315 | OccNormElement *slice; |
---|
| 316 | int sliceNum, xdim, ydim; |
---|
| 317 | float weight, weightScale, value; |
---|
| 318 | |
---|
| 319 | if (argc != 5) { |
---|
| 320 | interp->result = "Usage: vrip_photoslicenormrle <photo-widget> <slice-num> <axis> <weight-scale>"; |
---|
| 321 | return TCL_ERROR; |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | if (frontRLEGridNorm == NULL) { |
---|
| 325 | interp->result = "Grid not allocated."; |
---|
| 326 | return TCL_ERROR; |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | Tk_PhotoHandle handle = Tk_FindPhoto(theInterp, argv[1]); |
---|
| 330 | if (handle == NULL) |
---|
| 331 | return TCL_ERROR; |
---|
| 332 | |
---|
| 333 | sliceNum = atoi(argv[2]); |
---|
| 334 | axis = argv[3]; |
---|
| 335 | |
---|
| 336 | weightScale = atof(argv[4]); |
---|
| 337 | if (weightScale <= 0) { |
---|
| 338 | interp->result = "weight scale out of range"; |
---|
| 339 | return TCL_ERROR; |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | slice = frontRLEGridNorm->getSlice(axis, sliceNum, &xdim, &ydim); |
---|
| 343 | |
---|
| 344 | if (sliceBuf == NULL) { |
---|
| 345 | sliceBuf = new uchar[3*xdim*ydim]; |
---|
| 346 | sliceXdim = xdim; |
---|
| 347 | sliceYdim = ydim; |
---|
| 348 | } |
---|
| 349 | else if (xdim*ydim > sliceXdim*sliceYdim) { |
---|
| 350 | delete sliceBuf; |
---|
| 351 | sliceBuf = new uchar[3*xdim*ydim]; |
---|
| 352 | sliceXdim = xdim; |
---|
| 353 | sliceYdim = ydim; |
---|
| 354 | } |
---|
| 355 | |
---|
| 356 | if (!ShowNormals) { |
---|
| 357 | for (int i = 0; i < xdim*ydim; i++) { |
---|
| 358 | value = slice[i].value/255.0; |
---|
| 359 | if (value >= 255.5) value = 255; |
---|
| 360 | sliceBuf[3*i] = uchar(value+0.5); |
---|
| 361 | weight = slice[i].totalWeight/weightScale; |
---|
| 362 | if (weight > 255.5) weight = 255; |
---|
| 363 | sliceBuf[3*i+1] = uchar(weight+0.5); |
---|
| 364 | } |
---|
| 365 | } else { |
---|
| 366 | for (int i = 0; i < xdim*ydim; i++) { |
---|
| 367 | sliceBuf[3*i] = uchar(int(slice[i].nx)+127); |
---|
| 368 | sliceBuf[3*i+1] = uchar(int(slice[i].ny)+127); |
---|
| 369 | sliceBuf[3*i+2] = uchar(int(slice[i].nz)+127); |
---|
| 370 | } |
---|
| 371 | } |
---|
| 372 | |
---|
| 373 | Tk_PhotoSetSize(handle, xdim, ydim); |
---|
| 374 | |
---|
| 375 | Tk_PhotoImageBlock block; |
---|
| 376 | |
---|
| 377 | if (EQSTR(axis, "x")) { |
---|
| 378 | block.pixelPtr = sliceBuf + 3*xdim*(ydim-1); |
---|
| 379 | block.pitch = -xdim*3; |
---|
| 380 | } else if (EQSTR(axis, "y")) { |
---|
| 381 | block.pixelPtr = sliceBuf; |
---|
| 382 | block.pitch = xdim*3; |
---|
| 383 | } else if (EQSTR(axis, "z")) { |
---|
| 384 | block.pixelPtr = sliceBuf + 3*xdim*(ydim-1); |
---|
| 385 | block.pitch = -xdim*3; |
---|
| 386 | } |
---|
| 387 | |
---|
| 388 | block.pixelSize = 3; |
---|
| 389 | |
---|
| 390 | if (!ShowNormals) { |
---|
| 391 | block.offset[0] = 0; |
---|
| 392 | block.offset[1] = 0; |
---|
| 393 | block.offset[2] = 1; |
---|
| 394 | } else { |
---|
| 395 | block.offset[0] = 0; |
---|
| 396 | block.offset[1] = 1; |
---|
| 397 | block.offset[2] = 2; |
---|
| 398 | } |
---|
| 399 | |
---|
| 400 | block.width = xdim; |
---|
| 401 | block.height = ydim; |
---|
| 402 | |
---|
| 403 | Tk_PhotoPutBlock(handle, &block, 0, 0, xdim, ydim, TK_PHOTO_COMPOSITE_SET); |
---|
| 404 | |
---|
| 405 | return TCL_OK; |
---|
| 406 | |
---|
| 407 | } |
---|
| 408 | |
---|
| 409 | |
---|
| 410 | |
---|
| 411 | int |
---|
| 412 | Vrip_GetVoxelRLECmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[]) |
---|
| 413 | { |
---|
| 414 | int ix, iy, iz; |
---|
| 415 | char buf[512]; |
---|
| 416 | |
---|
| 417 | if (argc != 4) { |
---|
| 418 | interp->result = "Usage: vrip_getvoxelrle <ix> <iy> <iz>"; |
---|
| 419 | return TCL_ERROR; |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | if (frontRLEGrid == NULL) { |
---|
| 423 | interp->result = "Grid not allocated."; |
---|
| 424 | return TCL_ERROR; |
---|
| 425 | } |
---|
| 426 | |
---|
| 427 | ix = atoi(argv[1]); |
---|
| 428 | iy = atoi(argv[2]); |
---|
| 429 | iz = atoi(argv[3]); |
---|
| 430 | |
---|
| 431 | if (ix >= 0 && ix < frontRLEGrid->xdim && |
---|
| 432 | iy >= 0 && iy < frontRLEGrid->ydim && |
---|
| 433 | iz >= 0 && iz < frontRLEGrid->zdim) { |
---|
| 434 | OccElement *el = frontRLEGrid->getElement(ix, iy, iz); |
---|
| 435 | sprintf(buf, "(%.3d, %.3d, %.3d): v = %+.5d, wt = %.5d", |
---|
| 436 | ix, iy, iz, (int) el->value + SHRT_MIN, el->totalWeight); |
---|
| 437 | } |
---|
| 438 | else |
---|
| 439 | sprintf(buf, "<index out of range>"); |
---|
| 440 | |
---|
| 441 | Tcl_SetResult(interp, buf, TCL_VOLATILE); |
---|
| 442 | |
---|
| 443 | return TCL_OK; |
---|
| 444 | } |
---|
| 445 | |
---|
| 446 | |
---|
| 447 | |
---|
| 448 | int |
---|
| 449 | Vrip_SetRenderPhotoCmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[]) |
---|
| 450 | { |
---|
| 451 | if (theRenderPhoto != NULL) |
---|
| 452 | delete [] theRenderPhoto; |
---|
| 453 | |
---|
| 454 | if (argc == 1) { |
---|
| 455 | theRenderPhoto = NULL; |
---|
| 456 | return TCL_OK; |
---|
| 457 | } |
---|
| 458 | else { |
---|
| 459 | theRenderPhoto = new char[strlen(argv[1])+1]; |
---|
| 460 | strcpy(theRenderPhoto, argv[1]); |
---|
| 461 | return TCL_OK; |
---|
| 462 | } |
---|
| 463 | } |
---|
| 464 | |
---|
| 465 | |
---|
| 466 | |
---|
| 467 | int |
---|
| 468 | updateRenderPhoto(DepthMap *dm) |
---|
| 469 | { |
---|
| 470 | int xdim, ydim; |
---|
| 471 | |
---|
| 472 | if (theRenderPhoto == NULL) |
---|
| 473 | return 0; |
---|
| 474 | |
---|
| 475 | Tk_PhotoHandle handle = Tk_FindPhoto(theInterp, theRenderPhoto); |
---|
| 476 | if (handle == NULL) |
---|
| 477 | return 0; |
---|
| 478 | |
---|
| 479 | xdim = dm->xdim; |
---|
| 480 | ydim = dm->ydim; |
---|
| 481 | |
---|
| 482 | if (renderBuf == NULL) { |
---|
| 483 | renderBuf = new uchar[xdim*ydim]; |
---|
| 484 | renderXdim = xdim; |
---|
| 485 | renderYdim = ydim; |
---|
| 486 | } |
---|
| 487 | else if (xdim*ydim > renderXdim*renderYdim) { |
---|
| 488 | delete renderBuf; |
---|
| 489 | renderBuf = new uchar[xdim*ydim]; |
---|
| 490 | renderXdim = xdim; |
---|
| 491 | renderYdim = ydim; |
---|
| 492 | } |
---|
| 493 | |
---|
| 494 | for (int i = 0; i < xdim*ydim; i++) { |
---|
| 495 | renderBuf[i] = uchar(fabs(dm->elems[i].conf*255+0.5)); |
---|
| 496 | } |
---|
| 497 | |
---|
| 498 | Tk_PhotoSetSize(handle, xdim, ydim); |
---|
| 499 | |
---|
| 500 | Tk_PhotoImageBlock block; |
---|
| 501 | |
---|
| 502 | block.pixelPtr = renderBuf + xdim*(ydim-1); |
---|
| 503 | block.pitch = -xdim; |
---|
| 504 | block.pixelSize = 1; |
---|
| 505 | block.offset[0] = 0; |
---|
| 506 | block.offset[1] = 0; |
---|
| 507 | block.offset[2] = 0; |
---|
| 508 | block.width = xdim; |
---|
| 509 | block.height = ydim; |
---|
| 510 | |
---|
| 511 | Tk_PhotoPutBlock(handle, &block, 0, 0, xdim, ydim, TK_PHOTO_COMPOSITE_SET); |
---|
| 512 | |
---|
| 513 | return 1; |
---|
| 514 | |
---|
| 515 | } |
---|
| 516 | |
---|
| 517 | |
---|