| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | #include <osg/Node> |
|---|
| 20 | #include <osg/Geometry> |
|---|
| 21 | #include <osg/Notify> |
|---|
| 22 | #include <osg/Texture3D> |
|---|
| 23 | #include <osg/Texture1D> |
|---|
| 24 | #include <osg/ImageSequence> |
|---|
| 25 | #include <osg/TexGen> |
|---|
| 26 | #include <osg/Geode> |
|---|
| 27 | #include <osg/Billboard> |
|---|
| 28 | #include <osg/PositionAttitudeTransform> |
|---|
| 29 | #include <osg/ClipNode> |
|---|
| 30 | #include <osg/AlphaFunc> |
|---|
| 31 | #include <osg/TexGenNode> |
|---|
| 32 | #include <osg/TexEnv> |
|---|
| 33 | #include <osg/TexEnvCombine> |
|---|
| 34 | #include <osg/Material> |
|---|
| 35 | #include <osg/PrimitiveSet> |
|---|
| 36 | #include <osg/Endian> |
|---|
| 37 | #include <osg/BlendFunc> |
|---|
| 38 | #include <osg/BlendEquation> |
|---|
| 39 | #include <osg/TransferFunction> |
|---|
| 40 | #include <osg/MatrixTransform> |
|---|
| 41 | |
|---|
| 42 | #include <osgDB/Registry> |
|---|
| 43 | #include <osgDB/ReadFile> |
|---|
| 44 | #include <osgDB/WriteFile> |
|---|
| 45 | #include <osgDB/FileUtils> |
|---|
| 46 | #include <osgDB/FileNameUtils> |
|---|
| 47 | |
|---|
| 48 | #include <osgGA/EventVisitor> |
|---|
| 49 | #include <osgGA/TrackballManipulator> |
|---|
| 50 | #include <osgGA/FlightManipulator> |
|---|
| 51 | #include <osgGA/KeySwitchMatrixManipulator> |
|---|
| 52 | |
|---|
| 53 | #include <osgUtil/CullVisitor> |
|---|
| 54 | |
|---|
| 55 | #include <osgViewer/Viewer> |
|---|
| 56 | #include <osgViewer/ViewerEventHandlers> |
|---|
| 57 | |
|---|
| 58 | #include <osgManipulator/TabBoxDragger> |
|---|
| 59 | #include <osgManipulator/TabPlaneTrackballDragger> |
|---|
| 60 | #include <osgManipulator/TrackballDragger> |
|---|
| 61 | |
|---|
| 62 | #include <osg/io_utils> |
|---|
| 63 | |
|---|
| 64 | #include <algorithm> |
|---|
| 65 | #include <iostream> |
|---|
| 66 | |
|---|
| 67 | #include <osg/ImageUtils> |
|---|
| 68 | #include <osgVolume/Volume> |
|---|
| 69 | #include <osgVolume/VolumeTile> |
|---|
| 70 | #include <osgVolume/RayTracedTechnique> |
|---|
| 71 | #include <osgVolume/FixedFunctionTechnique> |
|---|
| 72 | |
|---|
| 73 | typedef std::vector< osg::ref_ptr<osg::Image> > ImageList; |
|---|
| 74 | |
|---|
| 75 | enum ShadingModel |
|---|
| 76 | { |
|---|
| 77 | Standard, |
|---|
| 78 | Light, |
|---|
| 79 | Isosurface, |
|---|
| 80 | MaximumIntensityProjection |
|---|
| 81 | }; |
|---|
| 82 | |
|---|
| 83 | struct PassThroughTransformFunction |
|---|
| 84 | { |
|---|
| 85 | unsigned char operator() (unsigned char c) const { return c; } |
|---|
| 86 | }; |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | struct ProcessRow |
|---|
| 90 | { |
|---|
| 91 | virtual ~ProcessRow() {} |
|---|
| 92 | |
|---|
| 93 | virtual void operator() (unsigned int num, |
|---|
| 94 | GLenum source_pixelFormat, unsigned char* source, |
|---|
| 95 | GLenum dest_pixelFormat, unsigned char* dest) const |
|---|
| 96 | { |
|---|
| 97 | switch(source_pixelFormat) |
|---|
| 98 | { |
|---|
| 99 | case(GL_LUMINANCE): |
|---|
| 100 | case(GL_ALPHA): |
|---|
| 101 | switch(dest_pixelFormat) |
|---|
| 102 | { |
|---|
| 103 | case(GL_LUMINANCE): |
|---|
| 104 | case(GL_ALPHA): A_to_A(num, source, dest); break; |
|---|
| 105 | case(GL_LUMINANCE_ALPHA): A_to_LA(num, source, dest); break; |
|---|
| 106 | case(GL_RGB): A_to_RGB(num, source, dest); break; |
|---|
| 107 | case(GL_RGBA): A_to_RGBA(num, source, dest); break; |
|---|
| 108 | } |
|---|
| 109 | break; |
|---|
| 110 | case(GL_LUMINANCE_ALPHA): |
|---|
| 111 | switch(dest_pixelFormat) |
|---|
| 112 | { |
|---|
| 113 | case(GL_LUMINANCE): |
|---|
| 114 | case(GL_ALPHA): LA_to_A(num, source, dest); break; |
|---|
| 115 | case(GL_LUMINANCE_ALPHA): LA_to_LA(num, source, dest); break; |
|---|
| 116 | case(GL_RGB): LA_to_RGB(num, source, dest); break; |
|---|
| 117 | case(GL_RGBA): LA_to_RGBA(num, source, dest); break; |
|---|
| 118 | } |
|---|
| 119 | break; |
|---|
| 120 | case(GL_RGB): |
|---|
| 121 | switch(dest_pixelFormat) |
|---|
| 122 | { |
|---|
| 123 | case(GL_LUMINANCE): |
|---|
| 124 | case(GL_ALPHA): RGB_to_A(num, source, dest); break; |
|---|
| 125 | case(GL_LUMINANCE_ALPHA): RGB_to_LA(num, source, dest); break; |
|---|
| 126 | case(GL_RGB): RGB_to_RGB(num, source, dest); break; |
|---|
| 127 | case(GL_RGBA): RGB_to_RGBA(num, source, dest); break; |
|---|
| 128 | } |
|---|
| 129 | break; |
|---|
| 130 | case(GL_RGBA): |
|---|
| 131 | switch(dest_pixelFormat) |
|---|
| 132 | { |
|---|
| 133 | case(GL_LUMINANCE): |
|---|
| 134 | case(GL_ALPHA): RGBA_to_A(num, source, dest); break; |
|---|
| 135 | case(GL_LUMINANCE_ALPHA): RGBA_to_LA(num, source, dest); break; |
|---|
| 136 | case(GL_RGB): RGBA_to_RGB(num, source, dest); break; |
|---|
| 137 | case(GL_RGBA): RGBA_to_RGBA(num, source, dest); break; |
|---|
| 138 | } |
|---|
| 139 | break; |
|---|
| 140 | case(GL_BGR): |
|---|
| 141 | switch(dest_pixelFormat) |
|---|
| 142 | { |
|---|
| 143 | case(GL_LUMINANCE): |
|---|
| 144 | case(GL_ALPHA): BGR_to_A(num, source, dest); break; |
|---|
| 145 | case(GL_LUMINANCE_ALPHA): BGR_to_LA(num, source, dest); break; |
|---|
| 146 | case(GL_RGB): BGR_to_RGB(num, source, dest); break; |
|---|
| 147 | case(GL_RGBA): BGR_to_RGBA(num, source, dest); break; |
|---|
| 148 | } |
|---|
| 149 | break; |
|---|
| 150 | case(GL_BGRA): |
|---|
| 151 | switch(dest_pixelFormat) |
|---|
| 152 | { |
|---|
| 153 | case(GL_LUMINANCE): |
|---|
| 154 | case(GL_ALPHA): BGRA_to_A(num, source, dest); break; |
|---|
| 155 | case(GL_LUMINANCE_ALPHA): BGRA_to_LA(num, source, dest); break; |
|---|
| 156 | case(GL_RGB): BGRA_to_RGB(num, source, dest); break; |
|---|
| 157 | case(GL_RGBA): BGRA_to_RGBA(num, source, dest); break; |
|---|
| 158 | } |
|---|
| 159 | break; |
|---|
| 160 | } |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | virtual void A_to_A(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 166 | { |
|---|
| 167 | for(unsigned int i=0;i<num;++i) |
|---|
| 168 | { |
|---|
| 169 | *dest++ = *source++; |
|---|
| 170 | } |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | virtual void A_to_LA(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 174 | { |
|---|
| 175 | for(unsigned int i=0;i<num;++i) |
|---|
| 176 | { |
|---|
| 177 | *dest++ = *source; |
|---|
| 178 | *dest++ = *source++; |
|---|
| 179 | } |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | virtual void A_to_RGB(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 183 | { |
|---|
| 184 | for(unsigned int i=0;i<num;++i) |
|---|
| 185 | { |
|---|
| 186 | *dest++ = *source; |
|---|
| 187 | *dest++ = *source; |
|---|
| 188 | *dest++ = *source++; |
|---|
| 189 | } |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | virtual void A_to_RGBA(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 193 | { |
|---|
| 194 | for(unsigned int i=0;i<num;++i) |
|---|
| 195 | { |
|---|
| 196 | *dest++ = *source; |
|---|
| 197 | *dest++ = *source; |
|---|
| 198 | *dest++ = *source; |
|---|
| 199 | *dest++ = *source++; |
|---|
| 200 | } |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | virtual void LA_to_A(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 206 | { |
|---|
| 207 | for(unsigned int i=0;i<num;++i) |
|---|
| 208 | { |
|---|
| 209 | ++source; |
|---|
| 210 | *dest++ = *source++; |
|---|
| 211 | } |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | virtual void LA_to_LA(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 215 | { |
|---|
| 216 | for(unsigned int i=0;i<num;++i) |
|---|
| 217 | { |
|---|
| 218 | *dest++ = *source++; |
|---|
| 219 | *dest++ = *source++; |
|---|
| 220 | } |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | virtual void LA_to_RGB(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 224 | { |
|---|
| 225 | for(unsigned int i=0;i<num;++i) |
|---|
| 226 | { |
|---|
| 227 | *dest++ = *source; |
|---|
| 228 | *dest++ = *source; |
|---|
| 229 | *dest++ = *source; |
|---|
| 230 | source+=2; |
|---|
| 231 | } |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | virtual void LA_to_RGBA(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 235 | { |
|---|
| 236 | for(unsigned int i=0;i<num;++i) |
|---|
| 237 | { |
|---|
| 238 | *dest++ = *source; |
|---|
| 239 | *dest++ = *source; |
|---|
| 240 | *dest++ = *source++; |
|---|
| 241 | *dest++ = *source++; |
|---|
| 242 | } |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | virtual void RGB_to_A(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 248 | { |
|---|
| 249 | for(unsigned int i=0;i<num;++i) |
|---|
| 250 | { |
|---|
| 251 | unsigned char val = *source; |
|---|
| 252 | *dest++ = val; |
|---|
| 253 | source += 3; |
|---|
| 254 | } |
|---|
| 255 | } |
|---|
| 256 | |
|---|
| 257 | virtual void RGB_to_LA(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 258 | { |
|---|
| 259 | for(unsigned int i=0;i<num;++i) |
|---|
| 260 | { |
|---|
| 261 | unsigned char val = *source; |
|---|
| 262 | *dest++ = val; |
|---|
| 263 | *dest++ = val; |
|---|
| 264 | source += 3; |
|---|
| 265 | } |
|---|
| 266 | } |
|---|
| 267 | |
|---|
| 268 | virtual void RGB_to_RGB(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 269 | { |
|---|
| 270 | for(unsigned int i=0;i<num;++i) |
|---|
| 271 | { |
|---|
| 272 | *dest++ = *source++; |
|---|
| 273 | *dest++ = *source++; |
|---|
| 274 | *dest++ = *source++; |
|---|
| 275 | } |
|---|
| 276 | } |
|---|
| 277 | |
|---|
| 278 | virtual void RGB_to_RGBA(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 279 | { |
|---|
| 280 | for(unsigned int i=0;i<num;++i) |
|---|
| 281 | { |
|---|
| 282 | unsigned char val = *source; |
|---|
| 283 | *dest++ = *source++; |
|---|
| 284 | *dest++ = *source++; |
|---|
| 285 | *dest++ = *source++; |
|---|
| 286 | *dest++ = val; |
|---|
| 287 | } |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | virtual void RGBA_to_A(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 293 | { |
|---|
| 294 | for(unsigned int i=0;i<num;++i) |
|---|
| 295 | { |
|---|
| 296 | source += 3; |
|---|
| 297 | *dest++ = *source++; |
|---|
| 298 | } |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | virtual void RGBA_to_LA(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 302 | { |
|---|
| 303 | for(unsigned int i=0;i<num;++i) |
|---|
| 304 | { |
|---|
| 305 | unsigned char val = *source; |
|---|
| 306 | source += 3; |
|---|
| 307 | *dest++ = val; |
|---|
| 308 | *dest++ = *source++; |
|---|
| 309 | } |
|---|
| 310 | } |
|---|
| 311 | |
|---|
| 312 | virtual void RGBA_to_RGB(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 313 | { |
|---|
| 314 | for(unsigned int i=0;i<num;++i) |
|---|
| 315 | { |
|---|
| 316 | *dest++ = *source++; |
|---|
| 317 | *dest++ = *source++; |
|---|
| 318 | *dest++ = *source++; |
|---|
| 319 | ++source; |
|---|
| 320 | } |
|---|
| 321 | } |
|---|
| 322 | |
|---|
| 323 | virtual void RGBA_to_RGBA(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 324 | { |
|---|
| 325 | for(unsigned int i=0;i<num;++i) |
|---|
| 326 | { |
|---|
| 327 | *dest++ = *source++; |
|---|
| 328 | *dest++ = *source++; |
|---|
| 329 | *dest++ = *source++; |
|---|
| 330 | *dest++ = *source++; |
|---|
| 331 | } |
|---|
| 332 | } |
|---|
| 333 | |
|---|
| 334 | |
|---|
| 335 | |
|---|
| 336 | virtual void BGR_to_A(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 337 | { |
|---|
| 338 | for(unsigned int i=0;i<num;++i) |
|---|
| 339 | { |
|---|
| 340 | unsigned char val = *source; |
|---|
| 341 | *dest++ = val; |
|---|
| 342 | source += 3; |
|---|
| 343 | } |
|---|
| 344 | } |
|---|
| 345 | |
|---|
| 346 | virtual void BGR_to_LA(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 347 | { |
|---|
| 348 | for(unsigned int i=0;i<num;++i) |
|---|
| 349 | { |
|---|
| 350 | unsigned char val = *source; |
|---|
| 351 | *dest++ = val; |
|---|
| 352 | *dest++ = val; |
|---|
| 353 | source += 3; |
|---|
| 354 | } |
|---|
| 355 | } |
|---|
| 356 | |
|---|
| 357 | virtual void BGR_to_RGB(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 358 | { |
|---|
| 359 | for(unsigned int i=0;i<num;++i) |
|---|
| 360 | { |
|---|
| 361 | unsigned char blue = *source++; |
|---|
| 362 | unsigned char green = *source++; |
|---|
| 363 | unsigned char red = *source++; |
|---|
| 364 | *dest++ = red; |
|---|
| 365 | *dest++ = green; |
|---|
| 366 | *dest++ = blue; |
|---|
| 367 | } |
|---|
| 368 | } |
|---|
| 369 | |
|---|
| 370 | virtual void BGR_to_RGBA(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 371 | { |
|---|
| 372 | for(unsigned int i=0;i<num;++i) |
|---|
| 373 | { |
|---|
| 374 | unsigned char blue = *source++; |
|---|
| 375 | unsigned char green = *source++; |
|---|
| 376 | unsigned char red = *source++; |
|---|
| 377 | unsigned char val = (unsigned char)((int(red)+int(green)+int(blue))/3); |
|---|
| 378 | *dest++ = red; |
|---|
| 379 | *dest++ = green; |
|---|
| 380 | *dest++ = blue; |
|---|
| 381 | *dest++ = val; |
|---|
| 382 | } |
|---|
| 383 | } |
|---|
| 384 | |
|---|
| 385 | |
|---|
| 386 | |
|---|
| 387 | virtual void BGRA_to_A(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 388 | { |
|---|
| 389 | for(unsigned int i=0;i<num;++i) |
|---|
| 390 | { |
|---|
| 391 | source += 3; |
|---|
| 392 | *dest++ = *source++; |
|---|
| 393 | } |
|---|
| 394 | } |
|---|
| 395 | |
|---|
| 396 | virtual void BGRA_to_LA(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 397 | { |
|---|
| 398 | for(unsigned int i=0;i<num;++i) |
|---|
| 399 | { |
|---|
| 400 | unsigned char val = *source; |
|---|
| 401 | source += 3; |
|---|
| 402 | *dest++ = val; |
|---|
| 403 | *dest++ = *source++; |
|---|
| 404 | } |
|---|
| 405 | } |
|---|
| 406 | |
|---|
| 407 | virtual void BGRA_to_RGB(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 408 | { |
|---|
| 409 | for(unsigned int i=0;i<num;++i) |
|---|
| 410 | { |
|---|
| 411 | unsigned char blue = *source++; |
|---|
| 412 | unsigned char green = *source++; |
|---|
| 413 | unsigned char red = *source++; |
|---|
| 414 | *dest++ = red; |
|---|
| 415 | *dest++ = green; |
|---|
| 416 | *dest++ = blue; |
|---|
| 417 | ++source; |
|---|
| 418 | } |
|---|
| 419 | } |
|---|
| 420 | |
|---|
| 421 | virtual void BGRA_to_RGBA(unsigned int num, unsigned char* source, unsigned char* dest) const |
|---|
| 422 | { |
|---|
| 423 | for(unsigned int i=0;i<num;++i) |
|---|
| 424 | { |
|---|
| 425 | unsigned char blue = *source++; |
|---|
| 426 | unsigned char green = *source++; |
|---|
| 427 | unsigned char red = *source++; |
|---|
| 428 | unsigned char alpha = *source++; |
|---|
| 429 | *dest++ = red; |
|---|
| 430 | *dest++ = green; |
|---|
| 431 | *dest++ = blue; |
|---|
| 432 | *dest++ = alpha; |
|---|
| 433 | } |
|---|
| 434 | } |
|---|
| 435 | |
|---|
| 436 | }; |
|---|
| 437 | |
|---|
| 438 | |
|---|
| 439 | void clampToNearestValidPowerOfTwo(int& sizeX, int& sizeY, int& sizeZ, int s_maximumTextureSize, int t_maximumTextureSize, int r_maximumTextureSize) |
|---|
| 440 | { |
|---|
| 441 | |
|---|
| 442 | int s_nearestPowerOfTwo = 1; |
|---|
| 443 | while(s_nearestPowerOfTwo<sizeX && s_nearestPowerOfTwo<s_maximumTextureSize) s_nearestPowerOfTwo*=2; |
|---|
| 444 | |
|---|
| 445 | int t_nearestPowerOfTwo = 1; |
|---|
| 446 | while(t_nearestPowerOfTwo<sizeY && t_nearestPowerOfTwo<t_maximumTextureSize) t_nearestPowerOfTwo*=2; |
|---|
| 447 | |
|---|
| 448 | int r_nearestPowerOfTwo = 1; |
|---|
| 449 | while(r_nearestPowerOfTwo<sizeZ && r_nearestPowerOfTwo<r_maximumTextureSize) r_nearestPowerOfTwo*=2; |
|---|
| 450 | |
|---|
| 451 | sizeX = s_nearestPowerOfTwo; |
|---|
| 452 | sizeY = t_nearestPowerOfTwo; |
|---|
| 453 | sizeZ = r_nearestPowerOfTwo; |
|---|
| 454 | } |
|---|
| 455 | |
|---|
| 456 | osg::Image* createTexture3D(ImageList& imageList, ProcessRow& processRow, |
|---|
| 457 | unsigned int numComponentsDesired, |
|---|
| 458 | int s_maximumTextureSize, |
|---|
| 459 | int t_maximumTextureSize, |
|---|
| 460 | int r_maximumTextureSize, |
|---|
| 461 | bool resizeToPowerOfTwo) |
|---|
| 462 | { |
|---|
| 463 | int max_s = 0; |
|---|
| 464 | int max_t = 0; |
|---|
| 465 | unsigned int max_components = 0; |
|---|
| 466 | int total_r = 0; |
|---|
| 467 | ImageList::iterator itr; |
|---|
| 468 | for(itr=imageList.begin(); |
|---|
| 469 | itr!=imageList.end(); |
|---|
| 470 | ++itr) |
|---|
| 471 | { |
|---|
| 472 | osg::Image* image = itr->get(); |
|---|
| 473 | GLenum pixelFormat = image->getPixelFormat(); |
|---|
| 474 | if (pixelFormat==GL_ALPHA || |
|---|
| 475 | pixelFormat==GL_INTENSITY || |
|---|
| 476 | pixelFormat==GL_LUMINANCE || |
|---|
| 477 | pixelFormat==GL_LUMINANCE_ALPHA || |
|---|
| 478 | pixelFormat==GL_RGB || |
|---|
| 479 | pixelFormat==GL_RGBA || |
|---|
| 480 | pixelFormat==GL_BGR || |
|---|
| 481 | pixelFormat==GL_BGRA) |
|---|
| 482 | { |
|---|
| 483 | max_s = osg::maximum(image->s(), max_s); |
|---|
| 484 | max_t = osg::maximum(image->t(), max_t); |
|---|
| 485 | max_components = osg::maximum(osg::Image::computeNumComponents(pixelFormat), max_components); |
|---|
| 486 | total_r += image->r(); |
|---|
| 487 | } |
|---|
| 488 | else |
|---|
| 489 | { |
|---|
| 490 | osg::notify(osg::NOTICE)<<"Image "<<image->getFileName()<<" has unsuitable pixel format 0x"<< std::hex<< pixelFormat << std::dec << std::endl; |
|---|
| 491 | } |
|---|
| 492 | } |
|---|
| 493 | |
|---|
| 494 | if (max_components==3) |
|---|
| 495 | { |
|---|
| 496 | |
|---|
| 497 | max_components = 4; |
|---|
| 498 | } |
|---|
| 499 | |
|---|
| 500 | if (numComponentsDesired!=0) max_components = numComponentsDesired; |
|---|
| 501 | |
|---|
| 502 | GLenum desiredPixelFormat = 0; |
|---|
| 503 | switch(max_components) |
|---|
| 504 | { |
|---|
| 505 | case(1): |
|---|
| 506 | osg::notify(osg::NOTICE)<<"desiredPixelFormat = GL_LUMINANCE" << std::endl; |
|---|
| 507 | desiredPixelFormat = GL_LUMINANCE; |
|---|
| 508 | break; |
|---|
| 509 | case(2): |
|---|
| 510 | osg::notify(osg::NOTICE)<<"desiredPixelFormat = GL_LUMINANCE_ALPHA" << std::endl; |
|---|
| 511 | desiredPixelFormat = GL_LUMINANCE_ALPHA; |
|---|
| 512 | break; |
|---|
| 513 | case(3): |
|---|
| 514 | osg::notify(osg::NOTICE)<<"desiredPixelFormat = GL_RGB" << std::endl; |
|---|
| 515 | desiredPixelFormat = GL_RGB; |
|---|
| 516 | break; |
|---|
| 517 | case(4): |
|---|
| 518 | osg::notify(osg::NOTICE)<<"desiredPixelFormat = GL_RGBA" << std::endl; |
|---|
| 519 | desiredPixelFormat = GL_RGBA; |
|---|
| 520 | break; |
|---|
| 521 | } |
|---|
| 522 | if (desiredPixelFormat==0) return 0; |
|---|
| 523 | |
|---|
| 524 | |
|---|
| 525 | |
|---|
| 526 | int s_nearestPowerOfTwo = 1; |
|---|
| 527 | int t_nearestPowerOfTwo = 1; |
|---|
| 528 | int r_nearestPowerOfTwo = 1; |
|---|
| 529 | |
|---|
| 530 | if (resizeToPowerOfTwo) |
|---|
| 531 | { |
|---|
| 532 | while(s_nearestPowerOfTwo<max_s && s_nearestPowerOfTwo<s_maximumTextureSize) s_nearestPowerOfTwo*=2; |
|---|
| 533 | while(t_nearestPowerOfTwo<max_t && t_nearestPowerOfTwo<t_maximumTextureSize) t_nearestPowerOfTwo*=2; |
|---|
| 534 | while(r_nearestPowerOfTwo<total_r && r_nearestPowerOfTwo<r_maximumTextureSize) r_nearestPowerOfTwo*=2; |
|---|
| 535 | |
|---|
| 536 | osg::notify(osg::NOTICE)<<"max image width = "<<max_s<<" nearest power of two = "<<s_nearestPowerOfTwo<<std::endl; |
|---|
| 537 | osg::notify(osg::NOTICE)<<"max image height = "<<max_t<<" nearest power of two = "<<t_nearestPowerOfTwo<<std::endl; |
|---|
| 538 | osg::notify(osg::NOTICE)<<"max image depth = "<<total_r<<" nearest power of two = "<<r_nearestPowerOfTwo<<std::endl; |
|---|
| 539 | } |
|---|
| 540 | else |
|---|
| 541 | { |
|---|
| 542 | s_nearestPowerOfTwo = max_s; |
|---|
| 543 | t_nearestPowerOfTwo = max_t; |
|---|
| 544 | r_nearestPowerOfTwo = total_r; |
|---|
| 545 | } |
|---|
| 546 | |
|---|
| 547 | |
|---|
| 548 | osg::ref_ptr<osg::Image> image_3d = new osg::Image; |
|---|
| 549 | image_3d->allocateImage(s_nearestPowerOfTwo,t_nearestPowerOfTwo,r_nearestPowerOfTwo, |
|---|
| 550 | desiredPixelFormat,GL_UNSIGNED_BYTE); |
|---|
| 551 | |
|---|
| 552 | |
|---|
| 553 | unsigned int r_offset = (total_r<r_nearestPowerOfTwo) ? r_nearestPowerOfTwo/2 - total_r/2 : 0; |
|---|
| 554 | |
|---|
| 555 | int curr_dest_r = r_offset; |
|---|
| 556 | |
|---|
| 557 | |
|---|
| 558 | for(itr=imageList.begin(); |
|---|
| 559 | itr!=imageList.end(); |
|---|
| 560 | ++itr) |
|---|
| 561 | { |
|---|
| 562 | osg::Image* image = itr->get(); |
|---|
| 563 | GLenum pixelFormat = image->getPixelFormat(); |
|---|
| 564 | if (pixelFormat==GL_ALPHA || |
|---|
| 565 | pixelFormat==GL_LUMINANCE || |
|---|
| 566 | pixelFormat==GL_INTENSITY || |
|---|
| 567 | pixelFormat==GL_LUMINANCE_ALPHA || |
|---|
| 568 | pixelFormat==GL_RGB || |
|---|
| 569 | pixelFormat==GL_RGBA || |
|---|
| 570 | pixelFormat==GL_BGR || |
|---|
| 571 | pixelFormat==GL_BGRA) |
|---|
| 572 | { |
|---|
| 573 | |
|---|
| 574 | int num_r = osg::minimum(image->r(), (image_3d->r() - curr_dest_r)); |
|---|
| 575 | int num_t = osg::minimum(image->t(), image_3d->t()); |
|---|
| 576 | int num_s = osg::minimum(image->s(), image_3d->s()); |
|---|
| 577 | |
|---|
| 578 | unsigned int s_offset_dest = (image->s()<s_nearestPowerOfTwo) ? s_nearestPowerOfTwo/2 - image->s()/2 : 0; |
|---|
| 579 | unsigned int t_offset_dest = (image->t()<t_nearestPowerOfTwo) ? t_nearestPowerOfTwo/2 - image->t()/2 : 0; |
|---|
| 580 | |
|---|
| 581 | for(int r=0;r<num_r;++r, ++curr_dest_r) |
|---|
| 582 | { |
|---|
| 583 | for(int t=0;t<num_t;++t) |
|---|
| 584 | { |
|---|
| 585 | unsigned char* dest = image_3d->data(s_offset_dest,t+t_offset_dest,curr_dest_r); |
|---|
| 586 | unsigned char* source = image->data(0,t,r); |
|---|
| 587 | |
|---|
| 588 | processRow(num_s, image->getPixelFormat(), source, image_3d->getPixelFormat(), dest); |
|---|
| 589 | } |
|---|
| 590 | } |
|---|
| 591 | } |
|---|
| 592 | } |
|---|
| 593 | return image_3d.release(); |
|---|
| 594 | } |
|---|
| 595 | |
|---|
| 596 | |
|---|
| 597 | struct ScaleOperator |
|---|
| 598 | { |
|---|
| 599 | ScaleOperator():_scale(1.0f) {} |
|---|
| 600 | ScaleOperator(float scale):_scale(scale) {} |
|---|
| 601 | ScaleOperator(const ScaleOperator& so):_scale(so._scale) {} |
|---|
| 602 | |
|---|
| 603 | ScaleOperator& operator = (const ScaleOperator& so) { _scale = so._scale; return *this; } |
|---|
| 604 | |
|---|
| 605 | float _scale; |
|---|
| 606 | |
|---|
| 607 | inline void luminance(float& l) const { l*= _scale; } |
|---|
| 608 | inline void alpha(float& a) const { a*= _scale; } |
|---|
| 609 | inline void luminance_alpha(float& l,float& a) const { l*= _scale; a*= _scale; } |
|---|
| 610 | inline void rgb(float& r,float& g,float& b) const { r*= _scale; g*=_scale; b*=_scale; } |
|---|
| 611 | inline void rgba(float& r,float& g,float& b,float& a) const { r*= _scale; g*=_scale; b*=_scale; a*=_scale; } |
|---|
| 612 | }; |
|---|
| 613 | |
|---|
| 614 | struct RecordRowOperator |
|---|
| 615 | { |
|---|
| 616 | RecordRowOperator(unsigned int num):_colours(num),_pos(0) {} |
|---|
| 617 | |
|---|
| 618 | mutable std::vector<osg::Vec4> _colours; |
|---|
| 619 | mutable unsigned int _pos; |
|---|
| 620 | |
|---|
| 621 | inline void luminance(float l) const { rgba(l,l,l,1.0f); } |
|---|
| 622 | inline void alpha(float a) const { rgba(1.0f,1.0f,1.0f,a); } |
|---|
| 623 | inline void luminance_alpha(float l,float a) const { rgba(l,l,l,a); } |
|---|
| 624 | inline void rgb(float r,float g,float b) const { rgba(r,g,b,1.0f); } |
|---|
| 625 | inline void rgba(float r,float g,float b,float a) const { _colours[_pos++].set(r,g,b,a); } |
|---|
| 626 | }; |
|---|
| 627 | |
|---|
| 628 | struct WriteRowOperator |
|---|
| 629 | { |
|---|
| 630 | WriteRowOperator():_pos(0) {} |
|---|
| 631 | WriteRowOperator(unsigned int num):_colours(num),_pos(0) {} |
|---|
| 632 | |
|---|
| 633 | std::vector<osg::Vec4> _colours; |
|---|
| 634 | mutable unsigned int _pos; |
|---|
| 635 | |
|---|
| 636 | inline void luminance(float& l) const { l = _colours[_pos++].r(); } |
|---|
| 637 | inline void alpha(float& a) const { a = _colours[_pos++].a(); } |
|---|
| 638 | inline void luminance_alpha(float& l,float& a) const { l = _colours[_pos].r(); a = _colours[_pos++].a(); } |
|---|
| 639 | inline void rgb(float& r,float& g,float& b) const { r = _colours[_pos].r(); g = _colours[_pos].g(); b = _colours[_pos].b(); } |
|---|
| 640 | inline void rgba(float& r,float& g,float& b,float& a) const { r = _colours[_pos].r(); g = _colours[_pos].g(); b = _colours[_pos].b(); a = _colours[_pos++].a(); } |
|---|
| 641 | }; |
|---|
| 642 | |
|---|
| 643 | osg::Image* readRaw(int sizeX, int sizeY, int sizeZ, int numberBytesPerComponent, int numberOfComponents, const std::string& endian, const std::string& raw_filename) |
|---|
| 644 | { |
|---|
| 645 | osgDB::ifstream fin(raw_filename.c_str(), std::ifstream::binary); |
|---|
| 646 | if (!fin) return 0; |
|---|
| 647 | |
|---|
| 648 | GLenum pixelFormat; |
|---|
| 649 | switch(numberOfComponents) |
|---|
| 650 | { |
|---|
| 651 | case 1 : pixelFormat = GL_LUMINANCE; break; |
|---|
| 652 | case 2 : pixelFormat = GL_LUMINANCE_ALPHA; break; |
|---|
| 653 | case 3 : pixelFormat = GL_RGB; break; |
|---|
| 654 | case 4 : pixelFormat = GL_RGBA; break; |
|---|
| 655 | default : |
|---|
| 656 | osg::notify(osg::NOTICE)<<"Error: numberOfComponents="<<numberOfComponents<<" not supported, only 1,2,3 or 4 are supported."<<std::endl; |
|---|
| 657 | return 0; |
|---|
| 658 | } |
|---|
| 659 | |
|---|
| 660 | |
|---|
| 661 | GLenum dataType; |
|---|
| 662 | switch(numberBytesPerComponent) |
|---|
| 663 | { |
|---|
| 664 | case 1 : dataType = GL_UNSIGNED_BYTE; break; |
|---|
| 665 | case 2 : dataType = GL_UNSIGNED_SHORT; break; |
|---|
| 666 | case 4 : dataType = GL_UNSIGNED_INT; break; |
|---|
| 667 | default : |
|---|
| 668 | osg::notify(osg::NOTICE)<<"Error: numberBytesPerComponent="<<numberBytesPerComponent<<" not supported, only 1,2 or 4 are supported."<<std::endl; |
|---|
| 669 | return 0; |
|---|
| 670 | } |
|---|
| 671 | |
|---|
| 672 | int s_maximumTextureSize=256, t_maximumTextureSize=256, r_maximumTextureSize=256; |
|---|
| 673 | |
|---|
| 674 | int sizeS = sizeX; |
|---|
| 675 | int sizeT = sizeY; |
|---|
| 676 | int sizeR = sizeZ; |
|---|
| 677 | clampToNearestValidPowerOfTwo(sizeS, sizeT, sizeR, s_maximumTextureSize, t_maximumTextureSize, r_maximumTextureSize); |
|---|
| 678 | |
|---|
| 679 | osg::ref_ptr<osg::Image> image = new osg::Image; |
|---|
| 680 | image->allocateImage(sizeS, sizeT, sizeR, pixelFormat, dataType); |
|---|
| 681 | |
|---|
| 682 | |
|---|
| 683 | bool endianSwap = (osg::getCpuByteOrder()==osg::BigEndian) ? (endian!="big") : (endian=="big"); |
|---|
| 684 | |
|---|
| 685 | unsigned int r_offset = (sizeZ<sizeR) ? sizeR/2 - sizeZ/2 : 0; |
|---|
| 686 | |
|---|
| 687 | int offset = endianSwap ? numberBytesPerComponent : 0; |
|---|
| 688 | int delta = endianSwap ? -1 : 1; |
|---|
| 689 | for(int r=0;r<sizeZ;++r) |
|---|
| 690 | { |
|---|
| 691 | for(int t=0;t<sizeY;++t) |
|---|
| 692 | { |
|---|
| 693 | char* data = (char*) image->data(0,t,r+r_offset); |
|---|
| 694 | for(int s=0;s<sizeX;++s) |
|---|
| 695 | { |
|---|
| 696 | if (!fin) return 0; |
|---|
| 697 | |
|---|
| 698 | for(int c=0;c<numberOfComponents;++c) |
|---|
| 699 | { |
|---|
| 700 | char* ptr = data+offset; |
|---|
| 701 | for(int b=0;b<numberBytesPerComponent;++b) |
|---|
| 702 | { |
|---|
| 703 | fin.read((char*)ptr, 1); |
|---|
| 704 | ptr += delta; |
|---|
| 705 | } |
|---|
| 706 | data += numberBytesPerComponent; |
|---|
| 707 | } |
|---|
| 708 | } |
|---|
| 709 | } |
|---|
| 710 | } |
|---|
| 711 | |
|---|
| 712 | |
|---|
| 713 | |
|---|
| 714 | { |
|---|
| 715 | |
|---|
| 716 | osg::Vec4 minValue, maxValue; |
|---|
| 717 | osg::computeMinMax(image.get(), minValue, maxValue); |
|---|
| 718 | osg::modifyImage(image.get(),ScaleOperator(1.0f/maxValue.r())); |
|---|
| 719 | } |
|---|
| 720 | |
|---|
| 721 | |
|---|
| 722 | fin.close(); |
|---|
| 723 | |
|---|
| 724 | if (dataType!=GL_UNSIGNED_BYTE) |
|---|
| 725 | { |
|---|
| 726 | |
|---|
| 727 | |
|---|
| 728 | osg::ref_ptr<osg::Image> new_image = new osg::Image; |
|---|
| 729 | new_image->allocateImage(sizeS, sizeT, sizeR, pixelFormat, GL_UNSIGNED_BYTE); |
|---|
| 730 | |
|---|
| 731 | RecordRowOperator readOp(sizeS); |
|---|
| 732 | WriteRowOperator writeOp; |
|---|
| 733 | |
|---|
| 734 | for(int r=0;r<sizeR;++r) |
|---|
| 735 | { |
|---|
| 736 | for(int t=0;t<sizeT;++t) |
|---|
| 737 | { |
|---|
| 738 | |
|---|
| 739 | readOp._pos = 0; |
|---|
| 740 | writeOp._pos = 0; |
|---|
| 741 | |
|---|
| 742 | |
|---|
| 743 | osg::readRow(sizeS, pixelFormat, dataType, image->data(0,t,r), readOp); |
|---|
| 744 | |
|---|
| 745 | |
|---|
| 746 | writeOp._colours.swap(readOp._colours); |
|---|
| 747 | |
|---|
| 748 | osg::modifyRow(sizeS, pixelFormat, GL_UNSIGNED_BYTE, new_image->data(0,t,r), writeOp); |
|---|
| 749 | |
|---|
| 750 | |
|---|
| 751 | writeOp._colours.swap(readOp._colours); |
|---|
| 752 | } |
|---|
| 753 | } |
|---|
| 754 | |
|---|
| 755 | image = new_image; |
|---|
| 756 | } |
|---|
| 757 | |
|---|
| 758 | return image.release(); |
|---|
| 759 | |
|---|
| 760 | |
|---|
| 761 | } |
|---|
| 762 | |
|---|
| 763 | enum ColourSpaceOperation |
|---|
| 764 | { |
|---|
| 765 | NO_COLOUR_SPACE_OPERATION, |
|---|
| 766 | MODULATE_ALPHA_BY_LUMINANCE, |
|---|
| 767 | MODULATE_ALPHA_BY_COLOUR, |
|---|
| 768 | REPLACE_ALPHA_WITH_LUMINANCE, |
|---|
| 769 | REPLACE_RGB_WITH_LUMINANCE |
|---|
| 770 | }; |
|---|
| 771 | |
|---|
| 772 | struct ModulateAlphaByLuminanceOperator |
|---|
| 773 | { |
|---|
| 774 | ModulateAlphaByLuminanceOperator() {} |
|---|
| 775 | |
|---|
| 776 | inline void luminance(float&) const {} |
|---|
| 777 | inline void alpha(float&) const {} |
|---|
| 778 | inline void luminance_alpha(float& l,float& a) const { a*= l; } |
|---|
| 779 | inline void rgb(float&,float&,float&) const {} |
|---|
| 780 | inline void rgba(float& r,float& g,float& b,float& a) const { float l = (r+g+b)*0.3333333; a *= l;} |
|---|
| 781 | }; |
|---|
| 782 | |
|---|
| 783 | struct ModulateAlphaByColourOperator |
|---|
| 784 | { |
|---|
| 785 | ModulateAlphaByColourOperator(const osg::Vec4& colour):_colour(colour) { _lum = _colour.length(); } |
|---|
| 786 | |
|---|
| 787 | osg::Vec4 _colour; |
|---|
| 788 | float _lum; |
|---|
| 789 | |
|---|
| 790 | inline void luminance(float&) const {} |
|---|
| 791 | inline void alpha(float&) const {} |
|---|
| 792 | inline void luminance_alpha(float& l,float& a) const { a*= l*_lum; } |
|---|
| 793 | inline void rgb(float&,float&,float&) const {} |
|---|
| 794 | inline void rgba(float& r,float& g,float& b,float& a) const { a = (r*_colour.r()+g*_colour.g()+b*_colour.b()+a*_colour.a()); } |
|---|
| 795 | }; |
|---|
| 796 | |
|---|
| 797 | struct ReplaceAlphaWithLuminanceOperator |
|---|
| 798 | { |
|---|
| 799 | ReplaceAlphaWithLuminanceOperator() {} |
|---|
| 800 | |
|---|
| 801 | inline void luminance(float&) const {} |
|---|
| 802 | inline void alpha(float&) const {} |
|---|
| 803 | inline void luminance_alpha(float& l,float& a) const { a= l; } |
|---|
| 804 | inline void rgb(float&,float&,float&) const { } |
|---|
| 805 | inline void rgba(float& r,float& g,float& b,float& a) const { float l = (r+g+b)*0.3333333; a = l; } |
|---|
| 806 | }; |
|---|
| 807 | |
|---|
| 808 | osg::Image* doColourSpaceConversion(ColourSpaceOperation op, osg::Image* image, osg::Vec4& colour) |
|---|
| 809 | { |
|---|
| 810 | switch(op) |
|---|
| 811 | { |
|---|
| 812 | case (MODULATE_ALPHA_BY_LUMINANCE): |
|---|
| 813 | { |
|---|
| 814 | std::cout<<"doing conversion MODULATE_ALPHA_BY_LUMINANCE"<<std::endl; |
|---|
| 815 | osg::modifyImage(image,ModulateAlphaByLuminanceOperator()); |
|---|
| 816 | return image; |
|---|
| 817 | } |
|---|
| 818 | case (MODULATE_ALPHA_BY_COLOUR): |
|---|
| 819 | { |
|---|
| 820 | std::cout<<"doing conversion MODULATE_ALPHA_BY_COLOUR"<<std::endl; |
|---|
| 821 | osg::modifyImage(image,ModulateAlphaByColourOperator(colour)); |
|---|
| 822 | return image; |
|---|
| 823 | } |
|---|
| 824 | case (REPLACE_ALPHA_WITH_LUMINANCE): |
|---|
| 825 | { |
|---|
| 826 | std::cout<<"doing conversion REPLACE_ALPHA_WITH_LUMINANCE"<<std::endl; |
|---|
| 827 | osg::modifyImage(image,ReplaceAlphaWithLuminanceOperator()); |
|---|
| 828 | return image; |
|---|
| 829 | } |
|---|
| 830 | case (REPLACE_RGB_WITH_LUMINANCE): |
|---|
| 831 | { |
|---|
| 832 | std::cout<<"doing conversion REPLACE_ALPHA_WITH_LUMINANCE"<<std::endl; |
|---|
| 833 | osg::Image* newImage = new osg::Image; |
|---|
| 834 | newImage->allocateImage(image->s(), image->t(), image->r(), GL_LUMINANCE, image->getDataType()); |
|---|
| 835 | osg::copyImage(image, 0, 0, 0, image->s(), image->t(), image->r(), |
|---|
| 836 | newImage, 0, 0, 0, false); |
|---|
| 837 | return newImage; |
|---|
| 838 | } |
|---|
| 839 | default: |
|---|
| 840 | return image; |
|---|
| 841 | } |
|---|
| 842 | } |
|---|
| 843 | |
|---|
| 844 | |
|---|
| 845 | osg::TransferFunction1D* readTransferFunctionFile(const std::string& filename) |
|---|
| 846 | { |
|---|
| 847 | std::string foundFile = osgDB::findDataFile(filename); |
|---|
| 848 | if (foundFile.empty()) |
|---|
| 849 | { |
|---|
| 850 | std::cout<<"Error: could not find transfer function file : "<<filename<<std::endl; |
|---|
| 851 | return 0; |
|---|
| 852 | } |
|---|
| 853 | |
|---|
| 854 | std::cout<<"Reading transfer function "<<filename<<std::endl; |
|---|
| 855 | |
|---|
| 856 | osg::TransferFunction1D::ColorMap colorMap; |
|---|
| 857 | osgDB::ifstream fin(foundFile.c_str()); |
|---|
| 858 | while(fin) |
|---|
| 859 | { |
|---|
| 860 | float value, red, green, blue, alpha; |
|---|
| 861 | fin >> value >> red >> green >> blue >> alpha; |
|---|
| 862 | if (fin) |
|---|
| 863 | { |
|---|
| 864 | std::cout<<"value = "<<value<<" ("<<red<<", "<<green<<", "<<blue<<", "<<alpha<<")"<<std::endl; |
|---|
| 865 | colorMap[value] = osg::Vec4(red,green,blue,alpha); |
|---|
| 866 | } |
|---|
| 867 | } |
|---|
| 868 | |
|---|
| 869 | if (colorMap.empty()) |
|---|
| 870 | { |
|---|
| 871 | std::cout<<"Error: No values read from transfer function file: "<<filename<<std::endl; |
|---|
| 872 | return 0; |
|---|
| 873 | } |
|---|
| 874 | |
|---|
| 875 | osg::TransferFunction1D* tf = new osg::TransferFunction1D; |
|---|
| 876 | tf->assign(colorMap); |
|---|
| 877 | |
|---|
| 878 | return tf; |
|---|
| 879 | } |
|---|
| 880 | |
|---|
| 881 | |
|---|
| 882 | class TestSupportOperation: public osg::GraphicsOperation |
|---|
| 883 | { |
|---|
| 884 | public: |
|---|
| 885 | |
|---|
| 886 | TestSupportOperation(): |
|---|
| 887 | osg::GraphicsOperation("TestSupportOperation",false), |
|---|
| 888 | supported(true), |
|---|
| 889 | errorMessage(), |
|---|
| 890 | maximumTextureSize(256) {} |
|---|
| 891 | |
|---|
| 892 | virtual void operator () (osg::GraphicsContext* gc) |
|---|
| 893 | { |
|---|
| 894 | OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mutex); |
|---|
| 895 | |
|---|
| 896 | glGetIntegerv( GL_MAX_3D_TEXTURE_SIZE, &maximumTextureSize ); |
|---|
| 897 | |
|---|
| 898 | osg::notify(osg::NOTICE)<<"Max texture size="<<maximumTextureSize<<std::endl; |
|---|
| 899 | } |
|---|
| 900 | |
|---|
| 901 | OpenThreads::Mutex mutex; |
|---|
| 902 | bool supported; |
|---|
| 903 | std::string errorMessage; |
|---|
| 904 | GLint maximumTextureSize; |
|---|
| 905 | }; |
|---|
| 906 | |
|---|
| 907 | class DraggerVolumeTileCallback : public osgManipulator::DraggerCallback |
|---|
| 908 | { |
|---|
| 909 | public: |
|---|
| 910 | |
|---|
| 911 | DraggerVolumeTileCallback(osgVolume::VolumeTile* volume, osgVolume::Locator* locator): |
|---|
| 912 | _volume(volume), |
|---|
| 913 | _locator(locator) {} |
|---|
| 914 | |
|---|
| 915 | |
|---|
| 916 | virtual bool receive(const osgManipulator::MotionCommand& command); |
|---|
| 917 | |
|---|
| 918 | |
|---|
| 919 | osg::observer_ptr<osgVolume::VolumeTile> _volume; |
|---|
| 920 | osg::ref_ptr<osgVolume::Locator> _locator; |
|---|
| 921 | |
|---|
| 922 | osg::Matrix _startMotionMatrix; |
|---|
| 923 | |
|---|
| 924 | osg::Matrix _localToWorld; |
|---|
| 925 | osg::Matrix _worldToLocal; |
|---|
| 926 | |
|---|
| 927 | }; |
|---|
| 928 | |
|---|
| 929 | bool DraggerVolumeTileCallback::receive(const osgManipulator::MotionCommand& command) |
|---|
| 930 | { |
|---|
| 931 | if (!_locator) return false; |
|---|
| 932 | |
|---|
| 933 | switch (command.getStage()) |
|---|
| 934 | { |
|---|
| 935 | case osgManipulator::MotionCommand::START: |
|---|
| 936 | { |
|---|
| 937 | |
|---|
| 938 | _startMotionMatrix = _locator->getTransform(); |
|---|
| 939 | |
|---|
| 940 | |
|---|
| 941 | osg::NodePath nodePathToRoot; |
|---|
| 942 | osgManipulator::computeNodePathToRoot(*_volume,nodePathToRoot); |
|---|
| 943 | _localToWorld = _startMotionMatrix * osg::computeLocalToWorld(nodePathToRoot); |
|---|
| 944 | _worldToLocal = osg::Matrix::inverse(_localToWorld); |
|---|
| 945 | |
|---|
| 946 | return true; |
|---|
| 947 | } |
|---|
| 948 | case osgManipulator::MotionCommand::MOVE: |
|---|
| 949 | { |
|---|
| 950 | |
|---|
| 951 | osg::Matrix localMotionMatrix = _localToWorld * command.getWorldToLocal() |
|---|
| 952 | * command.getMotionMatrix() |
|---|
| 953 | * command.getLocalToWorld() * _worldToLocal; |
|---|
| 954 | |
|---|
| 955 | |
|---|
| 956 | _locator->setTransform(localMotionMatrix * _startMotionMatrix); |
|---|
| 957 | |
|---|
| 958 | |
|---|
| 959 | |
|---|
| 960 | return true; |
|---|
| 961 | } |
|---|
| 962 | case osgManipulator::MotionCommand::FINISH: |
|---|
| 963 | { |
|---|
| 964 | return true; |
|---|
| 965 | } |
|---|
| 966 | case osgManipulator::MotionCommand::NONE: |
|---|
| 967 | default: |
|---|
| 968 | return false; |
|---|
| 969 | } |
|---|
| 970 | } |
|---|
| 971 | |
|---|
| 972 | int main( int argc, char **argv ) |
|---|
| 973 | { |
|---|
| 974 | |
|---|
| 975 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 976 | |
|---|
| 977 | |
|---|
| 978 | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use of 3D textures."); |
|---|
| 979 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); |
|---|
| 980 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 981 | arguments.getApplicationUsage()->addCommandLineOption("--images [filenames]","Specify a stack of 2d images to build the 3d volume from."); |
|---|
| 982 | arguments.getApplicationUsage()->addCommandLineOption("--shader","Use OpenGL Shading Language. (default)"); |
|---|
| 983 | arguments.getApplicationUsage()->addCommandLineOption("--no-shader","Disable use of OpenGL Shading Language."); |
|---|
| 984 | arguments.getApplicationUsage()->addCommandLineOption("--gpu-tf","Aply the transfer function on the GPU. (default)"); |
|---|
| 985 | arguments.getApplicationUsage()->addCommandLineOption("--cpu-tf","Apply the transfer function on the CPU."); |
|---|
| 986 | arguments.getApplicationUsage()->addCommandLineOption("--mip","Use Maximum Intensity Projection (MIP) filtering."); |
|---|
| 987 | arguments.getApplicationUsage()->addCommandLineOption("--isosurface","Use Iso surface render."); |
|---|
| 988 | arguments.getApplicationUsage()->addCommandLineOption("--light","Use normals computed on the GPU to render a lit volume."); |
|---|
| 989 | arguments.getApplicationUsage()->addCommandLineOption("-n","Use normals computed on the GPU to render a lit volume."); |
|---|
| 990 | arguments.getApplicationUsage()->addCommandLineOption("--xSize <size>","Relative width of rendered brick."); |
|---|
| 991 | arguments.getApplicationUsage()->addCommandLineOption("--ySize <size>","Relative length of rendered brick."); |
|---|
| 992 | arguments.getApplicationUsage()->addCommandLineOption("--zSize <size>","Relative height of rendered brick."); |
|---|
| 993 | arguments.getApplicationUsage()->addCommandLineOption("--maxTextureSize <size>","Set the texture maximum resolution in the s,t,r (x,y,z) dimensions."); |
|---|
| 994 | arguments.getApplicationUsage()->addCommandLineOption("--s_maxTextureSize <size>","Set the texture maximum resolution in the s (x) dimension."); |
|---|
| 995 | arguments.getApplicationUsage()->addCommandLineOption("--t_maxTextureSize <size>","Set the texture maximum resolution in the t (y) dimension."); |
|---|
| 996 | arguments.getApplicationUsage()->addCommandLineOption("--r_maxTextureSize <size>","Set the texture maximum resolution in the r (z) dimension."); |
|---|
| 997 | arguments.getApplicationUsage()->addCommandLineOption("--compressed","Enable the usage of compressed textures."); |
|---|
| 998 | arguments.getApplicationUsage()->addCommandLineOption("--compressed-arb","Enable the usage of OpenGL ARB compressed textures."); |
|---|
| 999 | arguments.getApplicationUsage()->addCommandLineOption("--compressed-dxt1","Enable the usage of S3TC DXT1 compressed textures."); |
|---|
| 1000 | arguments.getApplicationUsage()->addCommandLineOption("--compressed-dxt3","Enable the usage of S3TC DXT3 compressed textures."); |
|---|
| 1001 | arguments.getApplicationUsage()->addCommandLineOption("--compressed-dxt5","Enable the usage of S3TC DXT5 compressed textures."); |
|---|
| 1002 | arguments.getApplicationUsage()->addCommandLineOption("--modulate-alpha-by-luminance","For each pixel multiply the alpha value by the luminance."); |
|---|
| 1003 | arguments.getApplicationUsage()->addCommandLineOption("--replace-alpha-with-luminance","For each pixel set the alpha value to the luminance."); |
|---|
| 1004 | arguments.getApplicationUsage()->addCommandLineOption("--replace-rgb-with-luminance","For each rgb pixel convert to the luminance."); |
|---|
| 1005 | arguments.getApplicationUsage()->addCommandLineOption("--num-components <num>","Set the number of components to in he target image."); |
|---|
| 1006 | arguments.getApplicationUsage()->addCommandLineOption("--no-rescale","Disable the rescaling of the pixel data to 0.0 to 1.0 range"); |
|---|
| 1007 | arguments.getApplicationUsage()->addCommandLineOption("--rescale","Enable the rescale of the pixel data to 0.0 to 1.0 range (default)."); |
|---|
| 1008 | arguments.getApplicationUsage()->addCommandLineOption("--shift-min-to-zero","Shift the pixel data so min value is 0.0."); |
|---|
| 1009 | arguments.getApplicationUsage()->addCommandLineOption("--sequence-length <num>","Set the length of time that a sequence of images with run for."); |
|---|
| 1010 | arguments.getApplicationUsage()->addCommandLineOption("--sd <num>","Short hand for --sequence-length"); |
|---|
| 1011 | |
|---|
| 1012 | |
|---|
| 1013 | |
|---|
| 1014 | osgViewer::Viewer viewer(arguments); |
|---|
| 1015 | |
|---|
| 1016 | |
|---|
| 1017 | viewer.addEventHandler(new osgViewer::WindowSizeHandler); |
|---|
| 1018 | |
|---|
| 1019 | { |
|---|
| 1020 | osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; |
|---|
| 1021 | |
|---|
| 1022 | keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); |
|---|
| 1023 | |
|---|
| 1024 | osgGA::FlightManipulator* flightManipulator = new osgGA::FlightManipulator(); |
|---|
| 1025 | flightManipulator->setYawControlMode(osgGA::FlightManipulator::NO_AUTOMATIC_YAW); |
|---|
| 1026 | keyswitchManipulator->addMatrixManipulator( '2', "Flight", flightManipulator ); |
|---|
| 1027 | |
|---|
| 1028 | viewer.setCameraManipulator( keyswitchManipulator.get() ); |
|---|
| 1029 | } |
|---|
| 1030 | |
|---|
| 1031 | |
|---|
| 1032 | viewer.addEventHandler(new osgViewer::StatsHandler); |
|---|
| 1033 | |
|---|
| 1034 | viewer.getCamera()->setClearColor(osg::Vec4(0.0f,0.0f,0.0f,0.0f)); |
|---|
| 1035 | |
|---|
| 1036 | |
|---|
| 1037 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 1038 | { |
|---|
| 1039 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 1040 | return 1; |
|---|
| 1041 | } |
|---|
| 1042 | |
|---|
| 1043 | std::string outputFile; |
|---|
| 1044 | while (arguments.read("-o",outputFile)) {} |
|---|
| 1045 | |
|---|
| 1046 | |
|---|
| 1047 | |
|---|
| 1048 | osg::ref_ptr<osg::TransferFunction1D> transferFunction; |
|---|
| 1049 | std::string tranferFunctionFile; |
|---|
| 1050 | while (arguments.read("--tf",tranferFunctionFile)) |
|---|
| 1051 | { |
|---|
| 1052 | transferFunction = readTransferFunctionFile(tranferFunctionFile); |
|---|
| 1053 | } |
|---|
| 1054 | |
|---|
| 1055 | while(arguments.read("--test")) |
|---|
| 1056 | { |
|---|
| 1057 | transferFunction = new osg::TransferFunction1D; |
|---|
| 1058 | transferFunction->setColor(0.0, osg::Vec4(1.0,0.0,0.0,0.0)); |
|---|
| 1059 | transferFunction->setColor(0.5, osg::Vec4(1.0,1.0,0.0,0.5)); |
|---|
| 1060 | transferFunction->setColor(1.0, osg::Vec4(0.0,0.0,1.0,1.0)); |
|---|
| 1061 | } |
|---|
| 1062 | |
|---|
| 1063 | while(arguments.read("--test2")) |
|---|
| 1064 | { |
|---|
| 1065 | transferFunction = new osg::TransferFunction1D; |
|---|
| 1066 | transferFunction->setColor(0.0, osg::Vec4(1.0,0.0,0.0,0.0)); |
|---|
| 1067 | transferFunction->setColor(0.5, osg::Vec4(1.0,1.0,0.0,0.5)); |
|---|
| 1068 | transferFunction->setColor(1.0, osg::Vec4(0.0,0.0,1.0,1.0)); |
|---|
| 1069 | transferFunction->assign(transferFunction->getColorMap()); |
|---|
| 1070 | } |
|---|
| 1071 | |
|---|
| 1072 | { |
|---|
| 1073 | |
|---|
| 1074 | |
|---|
| 1075 | bool invalidOption = false; |
|---|
| 1076 | |
|---|
| 1077 | unsigned int numSlices=500; |
|---|
| 1078 | while (arguments.read("-s",numSlices)) { OSG_NOTICE<<"Warning: -s option no longer supported."<<std::endl; invalidOption = true; } |
|---|
| 1079 | |
|---|
| 1080 | float sliceEnd=1.0f; |
|---|
| 1081 | while (arguments.read("--clip",sliceEnd)) { OSG_NOTICE<<"Warning: --clip option no longer supported."<<std::endl; invalidOption = true; } |
|---|
| 1082 | |
|---|
| 1083 | |
|---|
| 1084 | if (invalidOption) return 1; |
|---|
| 1085 | } |
|---|
| 1086 | |
|---|
| 1087 | float xMultiplier=1.0f; |
|---|
| 1088 | while (arguments.read("--xMultiplier",xMultiplier)) {} |
|---|
| 1089 | |
|---|
| 1090 | float yMultiplier=1.0f; |
|---|
| 1091 | while (arguments.read("--yMultiplier",yMultiplier)) {} |
|---|
| 1092 | |
|---|
| 1093 | float zMultiplier=1.0f; |
|---|
| 1094 | while (arguments.read("--zMultiplier",zMultiplier)) {} |
|---|
| 1095 | |
|---|
| 1096 | |
|---|
| 1097 | float alphaFunc=0.02f; |
|---|
| 1098 | while (arguments.read("--alphaFunc",alphaFunc)) {} |
|---|
| 1099 | |
|---|
| 1100 | |
|---|
| 1101 | |
|---|
| 1102 | ShadingModel shadingModel = Standard; |
|---|
| 1103 | while(arguments.read("--mip")) shadingModel = MaximumIntensityProjection; |
|---|
| 1104 | |
|---|
| 1105 | while (arguments.read("--isosurface") || arguments.read("--iso-surface")) shadingModel = Isosurface; |
|---|
| 1106 | |
|---|
| 1107 | while (arguments.read("--light") || arguments.read("-n")) shadingModel = Light; |
|---|
| 1108 | |
|---|
| 1109 | float xSize=0.0f, ySize=0.0f, zSize=0.0f; |
|---|
| 1110 | while (arguments.read("--xSize",xSize)) {} |
|---|
| 1111 | while (arguments.read("--ySize",ySize)) {} |
|---|
| 1112 | while (arguments.read("--zSize",zSize)) {} |
|---|
| 1113 | |
|---|
| 1114 | osg::ref_ptr<TestSupportOperation> testSupportOperation = new TestSupportOperation; |
|---|
| 1115 | viewer.setRealizeOperation(testSupportOperation.get()); |
|---|
| 1116 | |
|---|
| 1117 | viewer.realize(); |
|---|
| 1118 | |
|---|
| 1119 | int maximumTextureSize = testSupportOperation->maximumTextureSize; |
|---|
| 1120 | int s_maximumTextureSize = maximumTextureSize; |
|---|
| 1121 | int t_maximumTextureSize = maximumTextureSize; |
|---|
| 1122 | int r_maximumTextureSize = maximumTextureSize; |
|---|
| 1123 | while(arguments.read("--maxTextureSize",maximumTextureSize)) |
|---|
| 1124 | { |
|---|
| 1125 | s_maximumTextureSize = maximumTextureSize; |
|---|
| 1126 | t_maximumTextureSize = maximumTextureSize; |
|---|
| 1127 | r_maximumTextureSize = maximumTextureSize; |
|---|
| 1128 | } |
|---|
| 1129 | while(arguments.read("--s_maxTextureSize",s_maximumTextureSize)) {} |
|---|
| 1130 | while(arguments.read("--t_maxTextureSize",t_maximumTextureSize)) {} |
|---|
| 1131 | while(arguments.read("--r_maxTextureSize",r_maximumTextureSize)) {} |
|---|
| 1132 | |
|---|
| 1133 | osg::Texture::InternalFormatMode internalFormatMode = osg::Texture::USE_IMAGE_DATA_FORMAT; |
|---|
| 1134 | while(arguments.read("--compressed") || arguments.read("--compressed-arb")) { internalFormatMode = osg::Texture::USE_ARB_COMPRESSION; } |
|---|
| 1135 | |
|---|
| 1136 | while(arguments.read("--compressed-dxt1")) { internalFormatMode = osg::Texture::USE_S3TC_DXT1_COMPRESSION; } |
|---|
| 1137 | while(arguments.read("--compressed-dxt3")) { internalFormatMode = osg::Texture::USE_S3TC_DXT3_COMPRESSION; } |
|---|
| 1138 | while(arguments.read("--compressed-dxt5")) { internalFormatMode = osg::Texture::USE_S3TC_DXT5_COMPRESSION; } |
|---|
| 1139 | |
|---|
| 1140 | |
|---|
| 1141 | |
|---|
| 1142 | ColourSpaceOperation colourSpaceOperation = NO_COLOUR_SPACE_OPERATION; |
|---|
| 1143 | osg::Vec4 colourModulate(0.25f,0.25f,0.25f,0.25f); |
|---|
| 1144 | while(arguments.read("--modulate-alpha-by-luminance")) { colourSpaceOperation = MODULATE_ALPHA_BY_LUMINANCE; } |
|---|
| 1145 | while(arguments.read("--modulate-alpha-by-colour", colourModulate.x(),colourModulate.y(),colourModulate.z(),colourModulate.w() )) { colourSpaceOperation = MODULATE_ALPHA_BY_COLOUR; } |
|---|
| 1146 | while(arguments.read("--replace-alpha-with-luminance")) { colourSpaceOperation = REPLACE_ALPHA_WITH_LUMINANCE; } |
|---|
| 1147 | while(arguments.read("--replace-rgb-with-luminance")) { colourSpaceOperation = REPLACE_RGB_WITH_LUMINANCE; } |
|---|
| 1148 | |
|---|
| 1149 | |
|---|
| 1150 | enum RescaleOperation |
|---|
| 1151 | { |
|---|
| 1152 | NO_RESCALE, |
|---|
| 1153 | RESCALE_TO_ZERO_TO_ONE_RANGE, |
|---|
| 1154 | SHIFT_MIN_TO_ZERO |
|---|
| 1155 | }; |
|---|
| 1156 | |
|---|
| 1157 | RescaleOperation rescaleOperation = RESCALE_TO_ZERO_TO_ONE_RANGE; |
|---|
| 1158 | while(arguments.read("--no-rescale")) rescaleOperation = NO_RESCALE; |
|---|
| 1159 | while(arguments.read("--rescale")) rescaleOperation = RESCALE_TO_ZERO_TO_ONE_RANGE; |
|---|
| 1160 | while(arguments.read("--shift-min-to-zero")) rescaleOperation = SHIFT_MIN_TO_ZERO; |
|---|
| 1161 | |
|---|
| 1162 | |
|---|
| 1163 | bool resizeToPowerOfTwo = false; |
|---|
| 1164 | |
|---|
| 1165 | unsigned int numComponentsDesired = 0; |
|---|
| 1166 | while(arguments.read("--num-components", numComponentsDesired)) {} |
|---|
| 1167 | |
|---|
| 1168 | bool useManipulator = false; |
|---|
| 1169 | while(arguments.read("--manipulator") || arguments.read("-m")) { useManipulator = true; } |
|---|
| 1170 | |
|---|
| 1171 | |
|---|
| 1172 | bool useShader = true; |
|---|
| 1173 | while(arguments.read("--shader")) { useShader = true; } |
|---|
| 1174 | while(arguments.read("--no-shader")) { useShader = false; } |
|---|
| 1175 | |
|---|
| 1176 | bool gpuTransferFunction = true; |
|---|
| 1177 | while(arguments.read("--gpu-tf")) { gpuTransferFunction = true; } |
|---|
| 1178 | while(arguments.read("--cpu-tf")) { gpuTransferFunction = false; } |
|---|
| 1179 | |
|---|
| 1180 | double sequenceLength = 10.0; |
|---|
| 1181 | while(arguments.read("--sequence-duration", sequenceLength) || |
|---|
| 1182 | arguments.read("--sd", sequenceLength)) {} |
|---|
| 1183 | |
|---|
| 1184 | typedef std::list< osg::ref_ptr<osg::Image> > Images; |
|---|
| 1185 | Images images; |
|---|
| 1186 | |
|---|
| 1187 | |
|---|
| 1188 | std::string vh_filename; |
|---|
| 1189 | while (arguments.read("--vh", vh_filename)) |
|---|
| 1190 | { |
|---|
| 1191 | std::string raw_filename, transfer_filename; |
|---|
| 1192 | int xdim(0), ydim(0), zdim(0); |
|---|
| 1193 | |
|---|
| 1194 | osgDB::ifstream header(vh_filename.c_str()); |
|---|
| 1195 | if (header) |
|---|
| 1196 | { |
|---|
| 1197 | header >> raw_filename >> transfer_filename >> xdim >> ydim >> zdim >> xSize >> ySize >> zSize; |
|---|
| 1198 | } |
|---|
| 1199 | |
|---|
| 1200 | if (xdim*ydim*zdim==0) |
|---|
| 1201 | { |
|---|
| 1202 | std::cout<<"Error in reading volume header "<<vh_filename<<std::endl; |
|---|
| 1203 | return 1; |
|---|
| 1204 | } |
|---|
| 1205 | |
|---|
| 1206 | if (!raw_filename.empty()) |
|---|
| 1207 | { |
|---|
| 1208 | images.push_back(readRaw(xdim, ydim, zdim, 1, 1, "little", raw_filename)); |
|---|
| 1209 | } |
|---|
| 1210 | |
|---|
| 1211 | if (!transfer_filename.empty()) |
|---|
| 1212 | { |
|---|
| 1213 | osgDB::ifstream fin(transfer_filename.c_str()); |
|---|
| 1214 | if (fin) |
|---|
| 1215 | { |
|---|
| 1216 | osg::TransferFunction1D::ColorMap colorMap; |
|---|
| 1217 | float value = 0.0; |
|---|
| 1218 | while(fin && value<=1.0) |
|---|
| 1219 | { |
|---|
| 1220 | float red, green, blue, alpha; |
|---|
| 1221 | fin >> red >> green >> blue >> alpha; |
|---|
| 1222 | if (fin) |
|---|
| 1223 | { |
|---|
| 1224 | colorMap[value] = osg::Vec4(red/255.0f,green/255.0f,blue/255.0f,alpha/255.0f); |
|---|
| 1225 | std::cout<<"value = "<<value<<" ("<<red<<", "<<green<<", "<<blue<<", "<<alpha<<")"; |
|---|
| 1226 | std::cout<<" ("<<colorMap[value]<<")"<<std::endl; |
|---|
| 1227 | } |
|---|
| 1228 | value += 1/255.0; |
|---|
| 1229 | } |
|---|
| 1230 | |
|---|
| 1231 | if (colorMap.empty()) |
|---|
| 1232 | { |
|---|
| 1233 | std::cout<<"Error: No values read from transfer function file: "<<transfer_filename<<std::endl; |
|---|
| 1234 | return 0; |
|---|
| 1235 | } |
|---|
| 1236 | |
|---|
| 1237 | transferFunction = new osg::TransferFunction1D; |
|---|
| 1238 | transferFunction->assign(colorMap); |
|---|
| 1239 | } |
|---|
| 1240 | } |
|---|
| 1241 | |
|---|
| 1242 | } |
|---|
| 1243 | |
|---|
| 1244 | |
|---|
| 1245 | int sizeX, sizeY, sizeZ, numberBytesPerComponent, numberOfComponents; |
|---|
| 1246 | std::string endian, raw_filename; |
|---|
| 1247 | while (arguments.read("--raw", sizeX, sizeY, sizeZ, numberBytesPerComponent, numberOfComponents, endian, raw_filename)) |
|---|
| 1248 | { |
|---|
| 1249 | images.push_back(readRaw(sizeX, sizeY, sizeZ, numberBytesPerComponent, numberOfComponents, endian, raw_filename)); |
|---|
| 1250 | } |
|---|
| 1251 | |
|---|
| 1252 | int images_pos = arguments.find("--images"); |
|---|
| 1253 | if (images_pos>=0) |
|---|
| 1254 | { |
|---|
| 1255 | ImageList imageList; |
|---|
| 1256 | int pos=images_pos+1; |
|---|
| 1257 | for(;pos<arguments.argc() && !arguments.isOption(pos);++pos) |
|---|
| 1258 | { |
|---|
| 1259 | std::string arg(arguments[pos]); |
|---|
| 1260 | if (arg.find('*') != std::string::npos) |
|---|
| 1261 | { |
|---|
| 1262 | osgDB::DirectoryContents contents = osgDB::expandWildcardsInFilename(arg); |
|---|
| 1263 | for (unsigned int i = 0; i < contents.size(); ++i) |
|---|
| 1264 | { |
|---|
| 1265 | osg::Image *image = osgDB::readImageFile( contents[i] ); |
|---|
| 1266 | |
|---|
| 1267 | if(image) |
|---|
| 1268 | { |
|---|
| 1269 | OSG_NOTICE<<"Read osg::Image FileName::"<<image->getFileName()<<", pixelFormat=0x"<<std::hex<<image->getPixelFormat()<<std::dec<<", s="<<image->s()<<", t="<<image->t()<<", r="<<image->r()<<std::endl; |
|---|
| 1270 | imageList.push_back(image); |
|---|
| 1271 | } |
|---|
| 1272 | } |
|---|
| 1273 | } |
|---|
| 1274 | else |
|---|
| 1275 | { |
|---|
| 1276 | |
|---|
| 1277 | osg::Image *image = osgDB::readImageFile( arguments[pos] ); |
|---|
| 1278 | |
|---|
| 1279 | if(image) |
|---|
| 1280 | { |
|---|
| 1281 | OSG_NOTICE<<"Read osg::Image FileName::"<<image->getFileName()<<", pixelFormat=0x"<<std::hex<<image->getPixelFormat()<<std::dec<<", s="<<image->s()<<", t="<<image->t()<<", r="<<image->r()<<std::endl; |
|---|
| 1282 | imageList.push_back(image); |
|---|
| 1283 | } |
|---|
| 1284 | } |
|---|
| 1285 | } |
|---|
| 1286 | |
|---|
| 1287 | arguments.remove(images_pos, pos-images_pos); |
|---|
| 1288 | |
|---|
| 1289 | |
|---|
| 1290 | ProcessRow processRow; |
|---|
| 1291 | osg::Image* image = createTexture3D(imageList, processRow, numComponentsDesired, s_maximumTextureSize, t_maximumTextureSize, r_maximumTextureSize, resizeToPowerOfTwo); |
|---|
| 1292 | if (image) |
|---|
| 1293 | { |
|---|
| 1294 | images.push_back(image); |
|---|
| 1295 | } |
|---|
| 1296 | } |
|---|
| 1297 | |
|---|
| 1298 | |
|---|
| 1299 | |
|---|
| 1300 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 1301 | |
|---|
| 1302 | |
|---|
| 1303 | if (arguments.errors()) |
|---|
| 1304 | { |
|---|
| 1305 | arguments.writeErrorMessages(std::cout); |
|---|
| 1306 | return 1; |
|---|
| 1307 | } |
|---|
| 1308 | |
|---|
| 1309 | |
|---|
| 1310 | |
|---|
| 1311 | for(int pos=1;pos<arguments.argc();++pos) |
|---|
| 1312 | { |
|---|
| 1313 | if (!arguments.isOption(pos)) |
|---|
| 1314 | { |
|---|
| 1315 | std::string filename = arguments[pos]; |
|---|
| 1316 | if (osgDB::getLowerCaseFileExtension(filename)=="dicom") |
|---|
| 1317 | { |
|---|
| 1318 | |
|---|
| 1319 | osg::Image* image = osgDB::readImageFile(filename); |
|---|
| 1320 | if (image) |
|---|
| 1321 | { |
|---|
| 1322 | images.push_back(image); |
|---|
| 1323 | } |
|---|
| 1324 | } |
|---|
| 1325 | else |
|---|
| 1326 | { |
|---|
| 1327 | osgDB::FileType fileType = osgDB::fileType(filename); |
|---|
| 1328 | if (fileType == osgDB::FILE_NOT_FOUND) |
|---|
| 1329 | { |
|---|
| 1330 | filename = osgDB::findDataFile(filename); |
|---|
| 1331 | fileType = osgDB::fileType(filename); |
|---|
| 1332 | } |
|---|
| 1333 | |
|---|
| 1334 | if (fileType == osgDB::DIRECTORY) |
|---|
| 1335 | { |
|---|
| 1336 | osg::Image* image = osgDB::readImageFile(filename+".dicom"); |
|---|
| 1337 | if (image) images.push_back(image); |
|---|
| 1338 | } |
|---|
| 1339 | else if (fileType == osgDB::REGULAR_FILE) |
|---|
| 1340 | { |
|---|
| 1341 | |
|---|
| 1342 | osg::Image* image = osgDB::readImageFile( filename ); |
|---|
| 1343 | if (image) images.push_back(image); |
|---|
| 1344 | } |
|---|
| 1345 | else |
|---|
| 1346 | { |
|---|
| 1347 | osg::notify(osg::NOTICE)<<"Error: could not find file: "<<filename<<std::endl; |
|---|
| 1348 | return 1; |
|---|
| 1349 | } |
|---|
| 1350 | } |
|---|
| 1351 | } |
|---|
| 1352 | } |
|---|
| 1353 | |
|---|
| 1354 | if (images.empty()) |
|---|
| 1355 | { |
|---|
| 1356 | std::cout<<"No model loaded, please specify and volumetric image file on the command line."<<std::endl; |
|---|
| 1357 | return 1; |
|---|
| 1358 | } |
|---|
| 1359 | |
|---|
| 1360 | |
|---|
| 1361 | Images::iterator sizeItr = images.begin(); |
|---|
| 1362 | int image_s = (*sizeItr)->s(); |
|---|
| 1363 | int image_t = (*sizeItr)->t(); |
|---|
| 1364 | int image_r = (*sizeItr)->r(); |
|---|
| 1365 | ++sizeItr; |
|---|
| 1366 | |
|---|
| 1367 | for(;sizeItr != images.end(); ++sizeItr) |
|---|
| 1368 | { |
|---|
| 1369 | if ((*sizeItr)->s() != image_s || |
|---|
| 1370 | (*sizeItr)->t() != image_t || |
|---|
| 1371 | (*sizeItr)->r() != image_r) |
|---|
| 1372 | { |
|---|
| 1373 | std::cout<<"Images in sequence are not of the same dimensions."<<std::endl; |
|---|
| 1374 | return 1; |
|---|
| 1375 | } |
|---|
| 1376 | } |
|---|
| 1377 | |
|---|
| 1378 | |
|---|
| 1379 | osg::ref_ptr<osgVolume::ImageDetails> details = dynamic_cast<osgVolume::ImageDetails*>(images.front()->getUserData()); |
|---|
| 1380 | osg::ref_ptr<osg::RefMatrix> matrix = details ? details->getMatrix() : dynamic_cast<osg::RefMatrix*>(images.front()->getUserData()); |
|---|
| 1381 | |
|---|
| 1382 | if (!matrix) |
|---|
| 1383 | { |
|---|
| 1384 | if (xSize==0.0) xSize = static_cast<float>(image_s); |
|---|
| 1385 | if (ySize==0.0) ySize = static_cast<float>(image_t); |
|---|
| 1386 | if (zSize==0.0) zSize = static_cast<float>(image_r); |
|---|
| 1387 | |
|---|
| 1388 | matrix = new osg::RefMatrix(xSize, 0.0, 0.0, 0.0, |
|---|
| 1389 | 0.0, ySize, 0.0, 0.0, |
|---|
| 1390 | 0.0, 0.0, zSize, 0.0, |
|---|
| 1391 | 0.0, 0.0, 0.0, 1.0); |
|---|
| 1392 | } |
|---|
| 1393 | |
|---|
| 1394 | |
|---|
| 1395 | if (xMultiplier!=1.0 || yMultiplier!=1.0 || zMultiplier!=1.0) |
|---|
| 1396 | { |
|---|
| 1397 | matrix->postMultScale(osg::Vec3d(fabs(xMultiplier), fabs(yMultiplier), fabs(zMultiplier))); |
|---|
| 1398 | } |
|---|
| 1399 | |
|---|
| 1400 | osg::Vec4 minValue(FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX); |
|---|
| 1401 | osg::Vec4 maxValue(-FLT_MAX, -FLT_MAX, -FLT_MAX, -FLT_MAX); |
|---|
| 1402 | bool computeMinMax = false; |
|---|
| 1403 | for(Images::iterator itr = images.begin(); |
|---|
| 1404 | itr != images.end(); |
|---|
| 1405 | ++itr) |
|---|
| 1406 | { |
|---|
| 1407 | osg::Vec4 localMinValue, localMaxValue; |
|---|
| 1408 | if (osg::computeMinMax(itr->get(), localMinValue, localMaxValue)) |
|---|
| 1409 | { |
|---|
| 1410 | if (localMinValue.r()<minValue.r()) minValue.r() = localMinValue.r(); |
|---|
| 1411 | if (localMinValue.g()<minValue.g()) minValue.g() = localMinValue.g(); |
|---|
| 1412 | if (localMinValue.b()<minValue.b()) minValue.b() = localMinValue.b(); |
|---|
| 1413 | if (localMinValue.a()<minValue.a()) minValue.a() = localMinValue.a(); |
|---|
| 1414 | |
|---|
| 1415 | if (localMaxValue.r()>maxValue.r()) maxValue.r() = localMaxValue.r(); |
|---|
| 1416 | if (localMaxValue.g()>maxValue.g()) maxValue.g() = localMaxValue.g(); |
|---|
| 1417 | if (localMaxValue.b()>maxValue.b()) maxValue.b() = localMaxValue.b(); |
|---|
| 1418 | if (localMaxValue.a()>maxValue.a()) maxValue.a() = localMaxValue.a(); |
|---|
| 1419 | |
|---|
| 1420 | osg::notify(osg::NOTICE)<<" ("<<localMinValue<<") ("<<localMaxValue<<") "<<(*itr)->getFileName()<<std::endl; |
|---|
| 1421 | |
|---|
| 1422 | computeMinMax = true; |
|---|
| 1423 | } |
|---|
| 1424 | } |
|---|
| 1425 | |
|---|
| 1426 | if (computeMinMax) |
|---|
| 1427 | { |
|---|
| 1428 | osg::notify(osg::NOTICE)<<"Min value "<<minValue<<std::endl; |
|---|
| 1429 | osg::notify(osg::NOTICE)<<"Max value "<<maxValue<<std::endl; |
|---|
| 1430 | |
|---|
| 1431 | float minComponent = minValue[0]; |
|---|
| 1432 | minComponent = osg::minimum(minComponent,minValue[1]); |
|---|
| 1433 | minComponent = osg::minimum(minComponent,minValue[2]); |
|---|
| 1434 | minComponent = osg::minimum(minComponent,minValue[3]); |
|---|
| 1435 | |
|---|
| 1436 | float maxComponent = maxValue[0]; |
|---|
| 1437 | maxComponent = osg::maximum(maxComponent,maxValue[1]); |
|---|
| 1438 | maxComponent = osg::maximum(maxComponent,maxValue[2]); |
|---|
| 1439 | maxComponent = osg::maximum(maxComponent,maxValue[3]); |
|---|
| 1440 | |
|---|
| 1441 | #if 0 |
|---|
| 1442 | switch(rescaleOperation) |
|---|
| 1443 | { |
|---|
| 1444 | case(NO_RESCALE): |
|---|
| 1445 | break; |
|---|
| 1446 | |
|---|
| 1447 | case(RESCALE_TO_ZERO_TO_ONE_RANGE): |
|---|
| 1448 | { |
|---|
| 1449 | float scale = 0.99f/(maxComponent-minComponent); |
|---|
| 1450 | float offset = -minComponent * scale; |
|---|
| 1451 | |
|---|
| 1452 | for(Images::iterator itr = images.begin(); |
|---|
| 1453 | itr != images.end(); |
|---|
| 1454 | ++itr) |
|---|
| 1455 | { |
|---|
| 1456 | osg::offsetAndScaleImage(itr->get(), |
|---|
| 1457 | osg::Vec4(offset, offset, offset, offset), |
|---|
| 1458 | osg::Vec4(scale, scale, scale, scale)); |
|---|
| 1459 | } |
|---|
| 1460 | break; |
|---|
| 1461 | } |
|---|
| 1462 | case(SHIFT_MIN_TO_ZERO): |
|---|
| 1463 | { |
|---|
| 1464 | float offset = -minComponent; |
|---|
| 1465 | |
|---|
| 1466 | for(Images::iterator itr = images.begin(); |
|---|
| 1467 | itr != images.end(); |
|---|
| 1468 | ++itr) |
|---|
| 1469 | { |
|---|
| 1470 | osg::offsetAndScaleImage(itr->get(), |
|---|
| 1471 | osg::Vec4(offset, offset, offset, offset), |
|---|
| 1472 | osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); |
|---|
| 1473 | } |
|---|
| 1474 | break; |
|---|
| 1475 | } |
|---|
| 1476 | }; |
|---|
| 1477 | #endif |
|---|
| 1478 | } |
|---|
| 1479 | |
|---|
| 1480 | |
|---|
| 1481 | if (colourSpaceOperation!=NO_COLOUR_SPACE_OPERATION) |
|---|
| 1482 | { |
|---|
| 1483 | for(Images::iterator itr = images.begin(); |
|---|
| 1484 | itr != images.end(); |
|---|
| 1485 | ++itr) |
|---|
| 1486 | { |
|---|
| 1487 | (*itr) = doColourSpaceConversion(colourSpaceOperation, itr->get(), colourModulate); |
|---|
| 1488 | } |
|---|
| 1489 | } |
|---|
| 1490 | |
|---|
| 1491 | if (!gpuTransferFunction && transferFunction.valid()) |
|---|
| 1492 | { |
|---|
| 1493 | for(Images::iterator itr = images.begin(); |
|---|
| 1494 | itr != images.end(); |
|---|
| 1495 | ++itr) |
|---|
| 1496 | { |
|---|
| 1497 | *itr = osgVolume::applyTransferFunction(itr->get(), transferFunction.get()); |
|---|
| 1498 | } |
|---|
| 1499 | } |
|---|
| 1500 | |
|---|
| 1501 | osg::ref_ptr<osg::Image> image_3d = 0; |
|---|
| 1502 | |
|---|
| 1503 | if (images.size()==1) |
|---|
| 1504 | { |
|---|
| 1505 | osg::notify(osg::NOTICE)<<"Single image "<<images.size()<<" volumes."<<std::endl; |
|---|
| 1506 | image_3d = images.front(); |
|---|
| 1507 | } |
|---|
| 1508 | else |
|---|
| 1509 | { |
|---|
| 1510 | osg::notify(osg::NOTICE)<<"Creating sequence of "<<images.size()<<" volumes."<<std::endl; |
|---|
| 1511 | |
|---|
| 1512 | osg::ref_ptr<osg::ImageSequence> imageSequence = new osg::ImageSequence; |
|---|
| 1513 | imageSequence->setLength(sequenceLength); |
|---|
| 1514 | image_3d = imageSequence.get(); |
|---|
| 1515 | for(Images::iterator itr = images.begin(); |
|---|
| 1516 | itr != images.end(); |
|---|
| 1517 | ++itr) |
|---|
| 1518 | { |
|---|
| 1519 | imageSequence->addImage(itr->get()); |
|---|
| 1520 | } |
|---|
| 1521 | imageSequence->play(); |
|---|
| 1522 | } |
|---|
| 1523 | |
|---|
| 1524 | osg::ref_ptr<osgVolume::Volume> volume = new osgVolume::Volume; |
|---|
| 1525 | osg::ref_ptr<osgVolume::VolumeTile> tile = new osgVolume::VolumeTile; |
|---|
| 1526 | volume->addChild(tile.get()); |
|---|
| 1527 | |
|---|
| 1528 | osg::ref_ptr<osgVolume::ImageLayer> layer = new osgVolume::ImageLayer(image_3d.get()); |
|---|
| 1529 | |
|---|
| 1530 | if (details) |
|---|
| 1531 | { |
|---|
| 1532 | layer->setTexelOffset(details->getTexelOffset()); |
|---|
| 1533 | layer->setTexelScale(details->getTexelScale()); |
|---|
| 1534 | } |
|---|
| 1535 | |
|---|
| 1536 | switch(rescaleOperation) |
|---|
| 1537 | { |
|---|
| 1538 | case(NO_RESCALE): |
|---|
| 1539 | break; |
|---|
| 1540 | |
|---|
| 1541 | case(RESCALE_TO_ZERO_TO_ONE_RANGE): |
|---|
| 1542 | { |
|---|
| 1543 | layer->rescaleToZeroToOneRange(); |
|---|
| 1544 | break; |
|---|
| 1545 | } |
|---|
| 1546 | case(SHIFT_MIN_TO_ZERO): |
|---|
| 1547 | { |
|---|
| 1548 | layer->translateMinToZero(); |
|---|
| 1549 | break; |
|---|
| 1550 | } |
|---|
| 1551 | }; |
|---|
| 1552 | |
|---|
| 1553 | layer->setLocator(new osgVolume::Locator(*matrix)); |
|---|
| 1554 | tile->setLocator(new osgVolume::Locator(*matrix)); |
|---|
| 1555 | |
|---|
| 1556 | tile->setLayer(layer.get()); |
|---|
| 1557 | |
|---|
| 1558 | tile->setEventCallback(new osgVolume::PropertyAdjustmentCallback()); |
|---|
| 1559 | |
|---|
| 1560 | if (useShader) |
|---|
| 1561 | { |
|---|
| 1562 | |
|---|
| 1563 | osgVolume::SwitchProperty* sp = new osgVolume::SwitchProperty; |
|---|
| 1564 | sp->setActiveProperty(0); |
|---|
| 1565 | |
|---|
| 1566 | osgVolume::AlphaFuncProperty* ap = new osgVolume::AlphaFuncProperty(alphaFunc); |
|---|
| 1567 | osgVolume::SampleDensityProperty* sd = new osgVolume::SampleDensityProperty(0.005); |
|---|
| 1568 | osgVolume::TransparencyProperty* tp = new osgVolume::TransparencyProperty(1.0); |
|---|
| 1569 | osgVolume::TransferFunctionProperty* tfp = transferFunction.valid() ? new osgVolume::TransferFunctionProperty(transferFunction.get()) : 0; |
|---|
| 1570 | |
|---|
| 1571 | { |
|---|
| 1572 | |
|---|
| 1573 | osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; |
|---|
| 1574 | cp->addProperty(ap); |
|---|
| 1575 | cp->addProperty(sd); |
|---|
| 1576 | cp->addProperty(tp); |
|---|
| 1577 | if (tfp) cp->addProperty(tfp); |
|---|
| 1578 | |
|---|
| 1579 | sp->addProperty(cp); |
|---|
| 1580 | } |
|---|
| 1581 | |
|---|
| 1582 | { |
|---|
| 1583 | |
|---|
| 1584 | osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; |
|---|
| 1585 | cp->addProperty(ap); |
|---|
| 1586 | cp->addProperty(sd); |
|---|
| 1587 | cp->addProperty(tp); |
|---|
| 1588 | cp->addProperty(new osgVolume::LightingProperty); |
|---|
| 1589 | if (tfp) cp->addProperty(tfp); |
|---|
| 1590 | |
|---|
| 1591 | sp->addProperty(cp); |
|---|
| 1592 | } |
|---|
| 1593 | |
|---|
| 1594 | { |
|---|
| 1595 | |
|---|
| 1596 | osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; |
|---|
| 1597 | cp->addProperty(sd); |
|---|
| 1598 | cp->addProperty(tp); |
|---|
| 1599 | cp->addProperty(new osgVolume::IsoSurfaceProperty(alphaFunc)); |
|---|
| 1600 | if (tfp) cp->addProperty(tfp); |
|---|
| 1601 | |
|---|
| 1602 | sp->addProperty(cp); |
|---|
| 1603 | } |
|---|
| 1604 | |
|---|
| 1605 | { |
|---|
| 1606 | |
|---|
| 1607 | osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; |
|---|
| 1608 | cp->addProperty(ap); |
|---|
| 1609 | cp->addProperty(sd); |
|---|
| 1610 | cp->addProperty(tp); |
|---|
| 1611 | cp->addProperty(new osgVolume::MaximumIntensityProjectionProperty); |
|---|
| 1612 | if (tfp) cp->addProperty(tfp); |
|---|
| 1613 | |
|---|
| 1614 | sp->addProperty(cp); |
|---|
| 1615 | } |
|---|
| 1616 | |
|---|
| 1617 | switch(shadingModel) |
|---|
| 1618 | { |
|---|
| 1619 | case(Standard): sp->setActiveProperty(0); break; |
|---|
| 1620 | case(Light): sp->setActiveProperty(1); break; |
|---|
| 1621 | case(Isosurface): sp->setActiveProperty(2); break; |
|---|
| 1622 | case(MaximumIntensityProjection): sp->setActiveProperty(3); break; |
|---|
| 1623 | } |
|---|
| 1624 | layer->addProperty(sp); |
|---|
| 1625 | |
|---|
| 1626 | |
|---|
| 1627 | tile->setVolumeTechnique(new osgVolume::RayTracedTechnique); |
|---|
| 1628 | } |
|---|
| 1629 | else |
|---|
| 1630 | { |
|---|
| 1631 | layer->addProperty(new osgVolume::AlphaFuncProperty(alphaFunc)); |
|---|
| 1632 | tile->setVolumeTechnique(new osgVolume::FixedFunctionTechnique); |
|---|
| 1633 | } |
|---|
| 1634 | |
|---|
| 1635 | if (!outputFile.empty()) |
|---|
| 1636 | { |
|---|
| 1637 | std::string ext = osgDB::getFileExtension(outputFile); |
|---|
| 1638 | std::string name_no_ext = osgDB::getNameLessExtension(outputFile); |
|---|
| 1639 | if (ext=="osg") |
|---|
| 1640 | { |
|---|
| 1641 | if (image_3d.valid()) |
|---|
| 1642 | { |
|---|
| 1643 | image_3d->setFileName(name_no_ext + ".dds"); |
|---|
| 1644 | osgDB::writeImageFile(*image_3d, image_3d->getFileName()); |
|---|
| 1645 | } |
|---|
| 1646 | osgDB::writeNodeFile(*volume, outputFile); |
|---|
| 1647 | } |
|---|
| 1648 | else if (ext=="ive") |
|---|
| 1649 | { |
|---|
| 1650 | osgDB::writeNodeFile(*volume, outputFile); |
|---|
| 1651 | } |
|---|
| 1652 | else if (ext=="dds") |
|---|
| 1653 | { |
|---|
| 1654 | osgDB::writeImageFile(*image_3d, outputFile); |
|---|
| 1655 | } |
|---|
| 1656 | else |
|---|
| 1657 | { |
|---|
| 1658 | std::cout<<"Extension not support for file output, not file written."<<std::endl; |
|---|
| 1659 | } |
|---|
| 1660 | |
|---|
| 1661 | return 0; |
|---|
| 1662 | } |
|---|
| 1663 | |
|---|
| 1664 | if (volume.valid()) |
|---|
| 1665 | { |
|---|
| 1666 | |
|---|
| 1667 | osg::ref_ptr<osg::Node> loadedModel = volume.get(); |
|---|
| 1668 | |
|---|
| 1669 | if (useManipulator) |
|---|
| 1670 | { |
|---|
| 1671 | osg::ref_ptr<osg::Group> group = new osg::Group; |
|---|
| 1672 | |
|---|
| 1673 | #if 1 |
|---|
| 1674 | osg::ref_ptr<osgManipulator::Dragger> dragger = new osgManipulator::TabBoxDragger; |
|---|
| 1675 | #else |
|---|
| 1676 | osg::ref_ptr<osgManipulator::Dragger> dragger = new osgManipulator::TrackballDragger(); |
|---|
| 1677 | #endif |
|---|
| 1678 | dragger->setupDefaultGeometry(); |
|---|
| 1679 | dragger->setHandleEvents(true); |
|---|
| 1680 | dragger->setActivationModKeyMask(osgGA::GUIEventAdapter::MODKEY_SHIFT); |
|---|
| 1681 | dragger->addDraggerCallback(new DraggerVolumeTileCallback(tile.get(), tile->getLocator())); |
|---|
| 1682 | dragger->setMatrix(osg::Matrix::translate(0.5,0.5,0.5)*tile->getLocator()->getTransform()); |
|---|
| 1683 | |
|---|
| 1684 | |
|---|
| 1685 | group->addChild(dragger.get()); |
|---|
| 1686 | |
|---|
| 1687 | |
|---|
| 1688 | |
|---|
| 1689 | group->addChild(volume.get()); |
|---|
| 1690 | |
|---|
| 1691 | loadedModel = group; |
|---|
| 1692 | } |
|---|
| 1693 | |
|---|
| 1694 | |
|---|
| 1695 | |
|---|
| 1696 | viewer.setSceneData(loadedModel.get()); |
|---|
| 1697 | |
|---|
| 1698 | |
|---|
| 1699 | viewer.run(); |
|---|
| 1700 | } |
|---|
| 1701 | |
|---|
| 1702 | return 0; |
|---|
| 1703 | } |
|---|