| 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 | enum ShadingModel |
|---|
| 74 | { |
|---|
| 75 | Standard, |
|---|
| 76 | Light, |
|---|
| 77 | Isosurface, |
|---|
| 78 | MaximumIntensityProjection |
|---|
| 79 | }; |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | osg::Image* createTexture3D(osg::ImageList& imageList, |
|---|
| 83 | unsigned int numComponentsDesired, |
|---|
| 84 | int s_maximumTextureSize, |
|---|
| 85 | int t_maximumTextureSize, |
|---|
| 86 | int r_maximumTextureSize, |
|---|
| 87 | bool resizeToPowerOfTwo) |
|---|
| 88 | { |
|---|
| 89 | |
|---|
| 90 | if (numComponentsDesired==0) |
|---|
| 91 | { |
|---|
| 92 | return osg::createImage3DWithAlpha(imageList, |
|---|
| 93 | s_maximumTextureSize, |
|---|
| 94 | t_maximumTextureSize, |
|---|
| 95 | r_maximumTextureSize, |
|---|
| 96 | resizeToPowerOfTwo); |
|---|
| 97 | } |
|---|
| 98 | else |
|---|
| 99 | { |
|---|
| 100 | GLenum desiredPixelFormat = 0; |
|---|
| 101 | switch(numComponentsDesired) |
|---|
| 102 | { |
|---|
| 103 | case(1) : desiredPixelFormat = GL_LUMINANCE; break; |
|---|
| 104 | case(2) : desiredPixelFormat = GL_LUMINANCE_ALPHA; break; |
|---|
| 105 | case(3) : desiredPixelFormat = GL_RGB; break; |
|---|
| 106 | case(4) : desiredPixelFormat = GL_RGBA; break; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | return osg::createImage3D(imageList, |
|---|
| 110 | desiredPixelFormat, |
|---|
| 111 | s_maximumTextureSize, |
|---|
| 112 | t_maximumTextureSize, |
|---|
| 113 | r_maximumTextureSize, |
|---|
| 114 | resizeToPowerOfTwo); |
|---|
| 115 | } |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | struct ModulateAlphaByLuminanceOperator |
|---|
| 119 | { |
|---|
| 120 | ModulateAlphaByLuminanceOperator() {} |
|---|
| 121 | |
|---|
| 122 | inline void luminance(float&) const {} |
|---|
| 123 | inline void alpha(float&) const {} |
|---|
| 124 | inline void luminance_alpha(float& l,float& a) const { a*= l; } |
|---|
| 125 | inline void rgb(float&,float&,float&) const {} |
|---|
| 126 | inline void rgba(float& r,float& g,float& b,float& a) const { float l = (r+g+b)*0.3333333; a *= l;} |
|---|
| 127 | }; |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | struct ScaleOperator |
|---|
| 131 | { |
|---|
| 132 | ScaleOperator():_scale(1.0f) {} |
|---|
| 133 | ScaleOperator(float scale):_scale(scale) {} |
|---|
| 134 | ScaleOperator(const ScaleOperator& so):_scale(so._scale) {} |
|---|
| 135 | |
|---|
| 136 | ScaleOperator& operator = (const ScaleOperator& so) { _scale = so._scale; return *this; } |
|---|
| 137 | |
|---|
| 138 | float _scale; |
|---|
| 139 | |
|---|
| 140 | inline void luminance(float& l) const { l*= _scale; } |
|---|
| 141 | inline void alpha(float& a) const { a*= _scale; } |
|---|
| 142 | inline void luminance_alpha(float& l,float& a) const { l*= _scale; a*= _scale; } |
|---|
| 143 | inline void rgb(float& r,float& g,float& b) const { r*= _scale; g*=_scale; b*=_scale; } |
|---|
| 144 | inline void rgba(float& r,float& g,float& b,float& a) const { r*= _scale; g*=_scale; b*=_scale; a*=_scale; } |
|---|
| 145 | }; |
|---|
| 146 | |
|---|
| 147 | struct RecordRowOperator |
|---|
| 148 | { |
|---|
| 149 | RecordRowOperator(unsigned int num):_colours(num),_pos(0) {} |
|---|
| 150 | |
|---|
| 151 | mutable std::vector<osg::Vec4> _colours; |
|---|
| 152 | mutable unsigned int _pos; |
|---|
| 153 | |
|---|
| 154 | inline void luminance(float l) const { rgba(l,l,l,1.0f); } |
|---|
| 155 | inline void alpha(float a) const { rgba(1.0f,1.0f,1.0f,a); } |
|---|
| 156 | inline void luminance_alpha(float l,float a) const { rgba(l,l,l,a); } |
|---|
| 157 | inline void rgb(float r,float g,float b) const { rgba(r,g,b,1.0f); } |
|---|
| 158 | inline void rgba(float r,float g,float b,float a) const { _colours[_pos++].set(r,g,b,a); } |
|---|
| 159 | }; |
|---|
| 160 | |
|---|
| 161 | struct WriteRowOperator |
|---|
| 162 | { |
|---|
| 163 | WriteRowOperator():_pos(0) {} |
|---|
| 164 | WriteRowOperator(unsigned int num):_colours(num),_pos(0) {} |
|---|
| 165 | |
|---|
| 166 | std::vector<osg::Vec4> _colours; |
|---|
| 167 | mutable unsigned int _pos; |
|---|
| 168 | |
|---|
| 169 | inline void luminance(float& l) const { l = _colours[_pos++].r(); } |
|---|
| 170 | inline void alpha(float& a) const { a = _colours[_pos++].a(); } |
|---|
| 171 | inline void luminance_alpha(float& l,float& a) const { l = _colours[_pos].r(); a = _colours[_pos++].a(); } |
|---|
| 172 | inline void rgb(float& r,float& g,float& b) const { r = _colours[_pos].r(); g = _colours[_pos].g(); b = _colours[_pos].b(); } |
|---|
| 173 | 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(); } |
|---|
| 174 | }; |
|---|
| 175 | |
|---|
| 176 | void clampToNearestValidPowerOfTwo(int& sizeX, int& sizeY, int& sizeZ, int s_maximumTextureSize, int t_maximumTextureSize, int r_maximumTextureSize) |
|---|
| 177 | { |
|---|
| 178 | |
|---|
| 179 | int s_nearestPowerOfTwo = 1; |
|---|
| 180 | while(s_nearestPowerOfTwo<sizeX && s_nearestPowerOfTwo<s_maximumTextureSize) s_nearestPowerOfTwo*=2; |
|---|
| 181 | |
|---|
| 182 | int t_nearestPowerOfTwo = 1; |
|---|
| 183 | while(t_nearestPowerOfTwo<sizeY && t_nearestPowerOfTwo<t_maximumTextureSize) t_nearestPowerOfTwo*=2; |
|---|
| 184 | |
|---|
| 185 | int r_nearestPowerOfTwo = 1; |
|---|
| 186 | while(r_nearestPowerOfTwo<sizeZ && r_nearestPowerOfTwo<r_maximumTextureSize) r_nearestPowerOfTwo*=2; |
|---|
| 187 | |
|---|
| 188 | sizeX = s_nearestPowerOfTwo; |
|---|
| 189 | sizeY = t_nearestPowerOfTwo; |
|---|
| 190 | sizeZ = r_nearestPowerOfTwo; |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | osg::Image* readRaw(int sizeX, int sizeY, int sizeZ, int numberBytesPerComponent, int numberOfComponents, const std::string& endian, const std::string& raw_filename) |
|---|
| 194 | { |
|---|
| 195 | osgDB::ifstream fin(raw_filename.c_str(), std::ifstream::binary); |
|---|
| 196 | if (!fin) return 0; |
|---|
| 197 | |
|---|
| 198 | GLenum pixelFormat; |
|---|
| 199 | switch(numberOfComponents) |
|---|
| 200 | { |
|---|
| 201 | case 1 : pixelFormat = GL_LUMINANCE; break; |
|---|
| 202 | case 2 : pixelFormat = GL_LUMINANCE_ALPHA; break; |
|---|
| 203 | case 3 : pixelFormat = GL_RGB; break; |
|---|
| 204 | case 4 : pixelFormat = GL_RGBA; break; |
|---|
| 205 | default : |
|---|
| 206 | osg::notify(osg::NOTICE)<<"Error: numberOfComponents="<<numberOfComponents<<" not supported, only 1,2,3 or 4 are supported."<<std::endl; |
|---|
| 207 | return 0; |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | GLenum dataType; |
|---|
| 212 | switch(numberBytesPerComponent) |
|---|
| 213 | { |
|---|
| 214 | case 1 : dataType = GL_UNSIGNED_BYTE; break; |
|---|
| 215 | case 2 : dataType = GL_UNSIGNED_SHORT; break; |
|---|
| 216 | case 4 : dataType = GL_UNSIGNED_INT; break; |
|---|
| 217 | default : |
|---|
| 218 | osg::notify(osg::NOTICE)<<"Error: numberBytesPerComponent="<<numberBytesPerComponent<<" not supported, only 1,2 or 4 are supported."<<std::endl; |
|---|
| 219 | return 0; |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | int s_maximumTextureSize=256, t_maximumTextureSize=256, r_maximumTextureSize=256; |
|---|
| 223 | |
|---|
| 224 | int sizeS = sizeX; |
|---|
| 225 | int sizeT = sizeY; |
|---|
| 226 | int sizeR = sizeZ; |
|---|
| 227 | clampToNearestValidPowerOfTwo(sizeS, sizeT, sizeR, s_maximumTextureSize, t_maximumTextureSize, r_maximumTextureSize); |
|---|
| 228 | |
|---|
| 229 | osg::ref_ptr<osg::Image> image = new osg::Image; |
|---|
| 230 | image->allocateImage(sizeS, sizeT, sizeR, pixelFormat, dataType); |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | bool endianSwap = (osg::getCpuByteOrder()==osg::BigEndian) ? (endian!="big") : (endian=="big"); |
|---|
| 234 | |
|---|
| 235 | unsigned int r_offset = (sizeZ<sizeR) ? sizeR/2 - sizeZ/2 : 0; |
|---|
| 236 | |
|---|
| 237 | int offset = endianSwap ? numberBytesPerComponent : 0; |
|---|
| 238 | int delta = endianSwap ? -1 : 1; |
|---|
| 239 | for(int r=0;r<sizeZ;++r) |
|---|
| 240 | { |
|---|
| 241 | for(int t=0;t<sizeY;++t) |
|---|
| 242 | { |
|---|
| 243 | char* data = (char*) image->data(0,t,r+r_offset); |
|---|
| 244 | for(int s=0;s<sizeX;++s) |
|---|
| 245 | { |
|---|
| 246 | if (!fin) return 0; |
|---|
| 247 | |
|---|
| 248 | for(int c=0;c<numberOfComponents;++c) |
|---|
| 249 | { |
|---|
| 250 | char* ptr = data+offset; |
|---|
| 251 | for(int b=0;b<numberBytesPerComponent;++b) |
|---|
| 252 | { |
|---|
| 253 | fin.read((char*)ptr, 1); |
|---|
| 254 | ptr += delta; |
|---|
| 255 | } |
|---|
| 256 | data += numberBytesPerComponent; |
|---|
| 257 | } |
|---|
| 258 | } |
|---|
| 259 | } |
|---|
| 260 | } |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | { |
|---|
| 265 | |
|---|
| 266 | osg::Vec4 minValue, maxValue; |
|---|
| 267 | osg::computeMinMax(image.get(), minValue, maxValue); |
|---|
| 268 | osg::modifyImage(image.get(),ScaleOperator(1.0f/maxValue.r())); |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | fin.close(); |
|---|
| 273 | |
|---|
| 274 | if (dataType!=GL_UNSIGNED_BYTE) |
|---|
| 275 | { |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | osg::ref_ptr<osg::Image> new_image = new osg::Image; |
|---|
| 279 | new_image->allocateImage(sizeS, sizeT, sizeR, pixelFormat, GL_UNSIGNED_BYTE); |
|---|
| 280 | |
|---|
| 281 | RecordRowOperator readOp(sizeS); |
|---|
| 282 | WriteRowOperator writeOp; |
|---|
| 283 | |
|---|
| 284 | for(int r=0;r<sizeR;++r) |
|---|
| 285 | { |
|---|
| 286 | for(int t=0;t<sizeT;++t) |
|---|
| 287 | { |
|---|
| 288 | |
|---|
| 289 | readOp._pos = 0; |
|---|
| 290 | writeOp._pos = 0; |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | osg::readRow(sizeS, pixelFormat, dataType, image->data(0,t,r), readOp); |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | writeOp._colours.swap(readOp._colours); |
|---|
| 297 | |
|---|
| 298 | osg::modifyRow(sizeS, pixelFormat, GL_UNSIGNED_BYTE, new_image->data(0,t,r), writeOp); |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | writeOp._colours.swap(readOp._colours); |
|---|
| 302 | } |
|---|
| 303 | } |
|---|
| 304 | |
|---|
| 305 | image = new_image; |
|---|
| 306 | } |
|---|
| 307 | |
|---|
| 308 | return image.release(); |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | } |
|---|
| 312 | |
|---|
| 313 | enum ColourSpaceOperation |
|---|
| 314 | { |
|---|
| 315 | NO_COLOUR_SPACE_OPERATION, |
|---|
| 316 | MODULATE_ALPHA_BY_LUMINANCE, |
|---|
| 317 | MODULATE_ALPHA_BY_COLOUR, |
|---|
| 318 | REPLACE_ALPHA_WITH_LUMINANCE, |
|---|
| 319 | REPLACE_RGB_WITH_LUMINANCE |
|---|
| 320 | }; |
|---|
| 321 | |
|---|
| 322 | struct ModulateAlphaByColourOperator |
|---|
| 323 | { |
|---|
| 324 | ModulateAlphaByColourOperator(const osg::Vec4& colour):_colour(colour) { _lum = _colour.length(); } |
|---|
| 325 | |
|---|
| 326 | osg::Vec4 _colour; |
|---|
| 327 | float _lum; |
|---|
| 328 | |
|---|
| 329 | inline void luminance(float&) const {} |
|---|
| 330 | inline void alpha(float&) const {} |
|---|
| 331 | inline void luminance_alpha(float& l,float& a) const { a*= l*_lum; } |
|---|
| 332 | inline void rgb(float&,float&,float&) const {} |
|---|
| 333 | 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()); } |
|---|
| 334 | }; |
|---|
| 335 | |
|---|
| 336 | struct ReplaceAlphaWithLuminanceOperator |
|---|
| 337 | { |
|---|
| 338 | ReplaceAlphaWithLuminanceOperator() {} |
|---|
| 339 | |
|---|
| 340 | inline void luminance(float&) const {} |
|---|
| 341 | inline void alpha(float&) const {} |
|---|
| 342 | inline void luminance_alpha(float& l,float& a) const { a= l; } |
|---|
| 343 | inline void rgb(float&,float&,float&) const { } |
|---|
| 344 | inline void rgba(float& r,float& g,float& b,float& a) const { float l = (r+g+b)*0.3333333; a = l; } |
|---|
| 345 | }; |
|---|
| 346 | |
|---|
| 347 | osg::Image* doColourSpaceConversion(ColourSpaceOperation op, osg::Image* image, osg::Vec4& colour) |
|---|
| 348 | { |
|---|
| 349 | switch(op) |
|---|
| 350 | { |
|---|
| 351 | case (MODULATE_ALPHA_BY_LUMINANCE): |
|---|
| 352 | { |
|---|
| 353 | std::cout<<"doing conversion MODULATE_ALPHA_BY_LUMINANCE"<<std::endl; |
|---|
| 354 | osg::modifyImage(image,ModulateAlphaByLuminanceOperator()); |
|---|
| 355 | return image; |
|---|
| 356 | } |
|---|
| 357 | case (MODULATE_ALPHA_BY_COLOUR): |
|---|
| 358 | { |
|---|
| 359 | std::cout<<"doing conversion MODULATE_ALPHA_BY_COLOUR"<<std::endl; |
|---|
| 360 | osg::modifyImage(image,ModulateAlphaByColourOperator(colour)); |
|---|
| 361 | return image; |
|---|
| 362 | } |
|---|
| 363 | case (REPLACE_ALPHA_WITH_LUMINANCE): |
|---|
| 364 | { |
|---|
| 365 | std::cout<<"doing conversion REPLACE_ALPHA_WITH_LUMINANCE"<<std::endl; |
|---|
| 366 | osg::modifyImage(image,ReplaceAlphaWithLuminanceOperator()); |
|---|
| 367 | return image; |
|---|
| 368 | } |
|---|
| 369 | case (REPLACE_RGB_WITH_LUMINANCE): |
|---|
| 370 | { |
|---|
| 371 | std::cout<<"doing conversion REPLACE_ALPHA_WITH_LUMINANCE"<<std::endl; |
|---|
| 372 | osg::Image* newImage = new osg::Image; |
|---|
| 373 | newImage->allocateImage(image->s(), image->t(), image->r(), GL_LUMINANCE, image->getDataType()); |
|---|
| 374 | osg::copyImage(image, 0, 0, 0, image->s(), image->t(), image->r(), |
|---|
| 375 | newImage, 0, 0, 0, false); |
|---|
| 376 | return newImage; |
|---|
| 377 | } |
|---|
| 378 | default: |
|---|
| 379 | return image; |
|---|
| 380 | } |
|---|
| 381 | } |
|---|
| 382 | |
|---|
| 383 | |
|---|
| 384 | osg::TransferFunction1D* readTransferFunctionFile(const std::string& filename, float colorScale=1.0f) |
|---|
| 385 | { |
|---|
| 386 | std::string foundFile = osgDB::findDataFile(filename); |
|---|
| 387 | if (foundFile.empty()) |
|---|
| 388 | { |
|---|
| 389 | std::cout<<"Error: could not find transfer function file : "<<filename<<std::endl; |
|---|
| 390 | return 0; |
|---|
| 391 | } |
|---|
| 392 | |
|---|
| 393 | std::cout<<"Reading transfer function "<<filename<<std::endl; |
|---|
| 394 | |
|---|
| 395 | osg::TransferFunction1D::ColorMap colorMap; |
|---|
| 396 | osgDB::ifstream fin(foundFile.c_str()); |
|---|
| 397 | while(fin) |
|---|
| 398 | { |
|---|
| 399 | float value, red, green, blue, alpha; |
|---|
| 400 | fin >> value >> red >> green >> blue >> alpha; |
|---|
| 401 | if (fin) |
|---|
| 402 | { |
|---|
| 403 | std::cout<<"value = "<<value<<" ("<<red<<", "<<green<<", "<<blue<<", "<<alpha<<")"<<std::endl; |
|---|
| 404 | colorMap[value] = osg::Vec4(red*colorScale,green*colorScale,blue*colorScale,alpha*colorScale); |
|---|
| 405 | } |
|---|
| 406 | } |
|---|
| 407 | |
|---|
| 408 | if (colorMap.empty()) |
|---|
| 409 | { |
|---|
| 410 | std::cout<<"Error: No values read from transfer function file: "<<filename<<std::endl; |
|---|
| 411 | return 0; |
|---|
| 412 | } |
|---|
| 413 | |
|---|
| 414 | osg::TransferFunction1D* tf = new osg::TransferFunction1D; |
|---|
| 415 | tf->assign(colorMap); |
|---|
| 416 | |
|---|
| 417 | return tf; |
|---|
| 418 | } |
|---|
| 419 | |
|---|
| 420 | |
|---|
| 421 | class TestSupportOperation: public osg::GraphicsOperation |
|---|
| 422 | { |
|---|
| 423 | public: |
|---|
| 424 | |
|---|
| 425 | TestSupportOperation(): |
|---|
| 426 | osg::GraphicsOperation("TestSupportOperation",false), |
|---|
| 427 | supported(true), |
|---|
| 428 | errorMessage(), |
|---|
| 429 | maximumTextureSize(256) {} |
|---|
| 430 | |
|---|
| 431 | virtual void operator () (osg::GraphicsContext* gc) |
|---|
| 432 | { |
|---|
| 433 | OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mutex); |
|---|
| 434 | |
|---|
| 435 | glGetIntegerv( GL_MAX_3D_TEXTURE_SIZE, &maximumTextureSize ); |
|---|
| 436 | |
|---|
| 437 | osg::notify(osg::NOTICE)<<"Max texture size="<<maximumTextureSize<<std::endl; |
|---|
| 438 | } |
|---|
| 439 | |
|---|
| 440 | OpenThreads::Mutex mutex; |
|---|
| 441 | bool supported; |
|---|
| 442 | std::string errorMessage; |
|---|
| 443 | GLint maximumTextureSize; |
|---|
| 444 | }; |
|---|
| 445 | |
|---|
| 446 | class DraggerVolumeTileCallback : public osgManipulator::DraggerCallback |
|---|
| 447 | { |
|---|
| 448 | public: |
|---|
| 449 | |
|---|
| 450 | DraggerVolumeTileCallback(osgVolume::VolumeTile* volume, osgVolume::Locator* locator): |
|---|
| 451 | _volume(volume), |
|---|
| 452 | _locator(locator) {} |
|---|
| 453 | |
|---|
| 454 | |
|---|
| 455 | virtual bool receive(const osgManipulator::MotionCommand& command); |
|---|
| 456 | |
|---|
| 457 | |
|---|
| 458 | osg::observer_ptr<osgVolume::VolumeTile> _volume; |
|---|
| 459 | osg::ref_ptr<osgVolume::Locator> _locator; |
|---|
| 460 | |
|---|
| 461 | osg::Matrix _startMotionMatrix; |
|---|
| 462 | |
|---|
| 463 | osg::Matrix _localToWorld; |
|---|
| 464 | osg::Matrix _worldToLocal; |
|---|
| 465 | |
|---|
| 466 | }; |
|---|
| 467 | |
|---|
| 468 | bool DraggerVolumeTileCallback::receive(const osgManipulator::MotionCommand& command) |
|---|
| 469 | { |
|---|
| 470 | if (!_locator) return false; |
|---|
| 471 | |
|---|
| 472 | switch (command.getStage()) |
|---|
| 473 | { |
|---|
| 474 | case osgManipulator::MotionCommand::START: |
|---|
| 475 | { |
|---|
| 476 | |
|---|
| 477 | _startMotionMatrix = _locator->getTransform(); |
|---|
| 478 | |
|---|
| 479 | |
|---|
| 480 | osg::NodePath nodePathToRoot; |
|---|
| 481 | osgManipulator::computeNodePathToRoot(*_volume,nodePathToRoot); |
|---|
| 482 | _localToWorld = _startMotionMatrix * osg::computeLocalToWorld(nodePathToRoot); |
|---|
| 483 | _worldToLocal = osg::Matrix::inverse(_localToWorld); |
|---|
| 484 | |
|---|
| 485 | return true; |
|---|
| 486 | } |
|---|
| 487 | case osgManipulator::MotionCommand::MOVE: |
|---|
| 488 | { |
|---|
| 489 | |
|---|
| 490 | osg::Matrix localMotionMatrix = _localToWorld * command.getWorldToLocal() |
|---|
| 491 | * command.getMotionMatrix() |
|---|
| 492 | * command.getLocalToWorld() * _worldToLocal; |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | _locator->setTransform(localMotionMatrix * _startMotionMatrix); |
|---|
| 496 | |
|---|
| 497 | |
|---|
| 498 | |
|---|
| 499 | return true; |
|---|
| 500 | } |
|---|
| 501 | case osgManipulator::MotionCommand::FINISH: |
|---|
| 502 | { |
|---|
| 503 | return true; |
|---|
| 504 | } |
|---|
| 505 | case osgManipulator::MotionCommand::NONE: |
|---|
| 506 | default: |
|---|
| 507 | return false; |
|---|
| 508 | } |
|---|
| 509 | } |
|---|
| 510 | |
|---|
| 511 | int main( int argc, char **argv ) |
|---|
| 512 | { |
|---|
| 513 | |
|---|
| 514 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 515 | |
|---|
| 516 | |
|---|
| 517 | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use of 3D textures."); |
|---|
| 518 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); |
|---|
| 519 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 520 | arguments.getApplicationUsage()->addCommandLineOption("--images [filenames]","Specify a stack of 2d images to build the 3d volume from."); |
|---|
| 521 | arguments.getApplicationUsage()->addCommandLineOption("--shader","Use OpenGL Shading Language. (default)"); |
|---|
| 522 | arguments.getApplicationUsage()->addCommandLineOption("--no-shader","Disable use of OpenGL Shading Language."); |
|---|
| 523 | arguments.getApplicationUsage()->addCommandLineOption("--gpu-tf","Aply the transfer function on the GPU. (default)"); |
|---|
| 524 | arguments.getApplicationUsage()->addCommandLineOption("--cpu-tf","Apply the transfer function on the CPU."); |
|---|
| 525 | arguments.getApplicationUsage()->addCommandLineOption("--mip","Use Maximum Intensity Projection (MIP) filtering."); |
|---|
| 526 | arguments.getApplicationUsage()->addCommandLineOption("--isosurface","Use Iso surface render."); |
|---|
| 527 | arguments.getApplicationUsage()->addCommandLineOption("--light","Use normals computed on the GPU to render a lit volume."); |
|---|
| 528 | arguments.getApplicationUsage()->addCommandLineOption("-n","Use normals computed on the GPU to render a lit volume."); |
|---|
| 529 | arguments.getApplicationUsage()->addCommandLineOption("--xSize <size>","Relative width of rendered brick."); |
|---|
| 530 | arguments.getApplicationUsage()->addCommandLineOption("--ySize <size>","Relative length of rendered brick."); |
|---|
| 531 | arguments.getApplicationUsage()->addCommandLineOption("--zSize <size>","Relative height of rendered brick."); |
|---|
| 532 | arguments.getApplicationUsage()->addCommandLineOption("--maxTextureSize <size>","Set the texture maximum resolution in the s,t,r (x,y,z) dimensions."); |
|---|
| 533 | arguments.getApplicationUsage()->addCommandLineOption("--s_maxTextureSize <size>","Set the texture maximum resolution in the s (x) dimension."); |
|---|
| 534 | arguments.getApplicationUsage()->addCommandLineOption("--t_maxTextureSize <size>","Set the texture maximum resolution in the t (y) dimension."); |
|---|
| 535 | arguments.getApplicationUsage()->addCommandLineOption("--r_maxTextureSize <size>","Set the texture maximum resolution in the r (z) dimension."); |
|---|
| 536 | arguments.getApplicationUsage()->addCommandLineOption("--modulate-alpha-by-luminance","For each pixel multiply the alpha value by the luminance."); |
|---|
| 537 | arguments.getApplicationUsage()->addCommandLineOption("--replace-alpha-with-luminance","For each pixel set the alpha value to the luminance."); |
|---|
| 538 | arguments.getApplicationUsage()->addCommandLineOption("--replace-rgb-with-luminance","For each rgb pixel convert to the luminance."); |
|---|
| 539 | arguments.getApplicationUsage()->addCommandLineOption("--num-components <num>","Set the number of components to in he target image."); |
|---|
| 540 | arguments.getApplicationUsage()->addCommandLineOption("--no-rescale","Disable the rescaling of the pixel data to 0.0 to 1.0 range"); |
|---|
| 541 | arguments.getApplicationUsage()->addCommandLineOption("--rescale","Enable the rescale of the pixel data to 0.0 to 1.0 range (default)."); |
|---|
| 542 | arguments.getApplicationUsage()->addCommandLineOption("--shift-min-to-zero","Shift the pixel data so min value is 0.0."); |
|---|
| 543 | arguments.getApplicationUsage()->addCommandLineOption("--sequence-length <num>","Set the length of time that a sequence of images with run for."); |
|---|
| 544 | arguments.getApplicationUsage()->addCommandLineOption("--sd <num>","Short hand for --sequence-length"); |
|---|
| 545 | arguments.getApplicationUsage()->addCommandLineOption("--sdwm <num>","Set the SampleDensityWhenMovingProperty to specified value"); |
|---|
| 546 | arguments.getApplicationUsage()->addCommandLineOption("--lod","Enable techniques to reduce the level of detail when moving."); |
|---|
| 547 | |
|---|
| 548 | |
|---|
| 549 | |
|---|
| 550 | osgViewer::Viewer viewer(arguments); |
|---|
| 551 | |
|---|
| 552 | |
|---|
| 553 | viewer.addEventHandler(new osgViewer::WindowSizeHandler); |
|---|
| 554 | |
|---|
| 555 | { |
|---|
| 556 | osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; |
|---|
| 557 | |
|---|
| 558 | keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); |
|---|
| 559 | |
|---|
| 560 | osgGA::FlightManipulator* flightManipulator = new osgGA::FlightManipulator(); |
|---|
| 561 | flightManipulator->setYawControlMode(osgGA::FlightManipulator::NO_AUTOMATIC_YAW); |
|---|
| 562 | keyswitchManipulator->addMatrixManipulator( '2', "Flight", flightManipulator ); |
|---|
| 563 | |
|---|
| 564 | viewer.setCameraManipulator( keyswitchManipulator.get() ); |
|---|
| 565 | } |
|---|
| 566 | |
|---|
| 567 | |
|---|
| 568 | viewer.addEventHandler(new osgViewer::StatsHandler); |
|---|
| 569 | |
|---|
| 570 | viewer.getCamera()->setClearColor(osg::Vec4(0.0f,0.0f,0.0f,0.0f)); |
|---|
| 571 | |
|---|
| 572 | |
|---|
| 573 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 574 | { |
|---|
| 575 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 576 | return 1; |
|---|
| 577 | } |
|---|
| 578 | |
|---|
| 579 | std::string outputFile; |
|---|
| 580 | while (arguments.read("-o",outputFile)) {} |
|---|
| 581 | |
|---|
| 582 | |
|---|
| 583 | |
|---|
| 584 | osg::ref_ptr<osg::TransferFunction1D> transferFunction; |
|---|
| 585 | std::string tranferFunctionFile; |
|---|
| 586 | while (arguments.read("--tf",tranferFunctionFile)) |
|---|
| 587 | { |
|---|
| 588 | transferFunction = readTransferFunctionFile(tranferFunctionFile); |
|---|
| 589 | } |
|---|
| 590 | while (arguments.read("--tf-255",tranferFunctionFile)) |
|---|
| 591 | { |
|---|
| 592 | transferFunction = readTransferFunctionFile(tranferFunctionFile,1.0f/255.0f); |
|---|
| 593 | } |
|---|
| 594 | |
|---|
| 595 | while(arguments.read("--test")) |
|---|
| 596 | { |
|---|
| 597 | transferFunction = new osg::TransferFunction1D; |
|---|
| 598 | transferFunction->setColor(0.0, osg::Vec4(1.0,0.0,0.0,0.0)); |
|---|
| 599 | transferFunction->setColor(0.5, osg::Vec4(1.0,1.0,0.0,0.5)); |
|---|
| 600 | transferFunction->setColor(1.0, osg::Vec4(0.0,0.0,1.0,1.0)); |
|---|
| 601 | } |
|---|
| 602 | |
|---|
| 603 | while(arguments.read("--test2")) |
|---|
| 604 | { |
|---|
| 605 | transferFunction = new osg::TransferFunction1D; |
|---|
| 606 | transferFunction->setColor(0.0, osg::Vec4(1.0,0.0,0.0,0.0)); |
|---|
| 607 | transferFunction->setColor(0.5, osg::Vec4(1.0,1.0,0.0,0.5)); |
|---|
| 608 | transferFunction->setColor(1.0, osg::Vec4(0.0,0.0,1.0,1.0)); |
|---|
| 609 | transferFunction->assign(transferFunction->getColorMap()); |
|---|
| 610 | } |
|---|
| 611 | |
|---|
| 612 | { |
|---|
| 613 | |
|---|
| 614 | |
|---|
| 615 | bool invalidOption = false; |
|---|
| 616 | |
|---|
| 617 | unsigned int numSlices=500; |
|---|
| 618 | while (arguments.read("-s",numSlices)) { OSG_NOTICE<<"Warning: -s option no longer supported."<<std::endl; invalidOption = true; } |
|---|
| 619 | |
|---|
| 620 | float sliceEnd=1.0f; |
|---|
| 621 | while (arguments.read("--clip",sliceEnd)) { OSG_NOTICE<<"Warning: --clip option no longer supported."<<std::endl; invalidOption = true; } |
|---|
| 622 | |
|---|
| 623 | |
|---|
| 624 | if (invalidOption) return 1; |
|---|
| 625 | } |
|---|
| 626 | |
|---|
| 627 | float xMultiplier=1.0f; |
|---|
| 628 | while (arguments.read("--xMultiplier",xMultiplier)) {} |
|---|
| 629 | |
|---|
| 630 | float yMultiplier=1.0f; |
|---|
| 631 | while (arguments.read("--yMultiplier",yMultiplier)) {} |
|---|
| 632 | |
|---|
| 633 | float zMultiplier=1.0f; |
|---|
| 634 | while (arguments.read("--zMultiplier",zMultiplier)) {} |
|---|
| 635 | |
|---|
| 636 | |
|---|
| 637 | float alphaFunc=0.02f; |
|---|
| 638 | while (arguments.read("--alphaFunc",alphaFunc)) {} |
|---|
| 639 | |
|---|
| 640 | |
|---|
| 641 | |
|---|
| 642 | ShadingModel shadingModel = Standard; |
|---|
| 643 | while(arguments.read("--mip")) shadingModel = MaximumIntensityProjection; |
|---|
| 644 | |
|---|
| 645 | while (arguments.read("--isosurface") || arguments.read("--iso-surface")) shadingModel = Isosurface; |
|---|
| 646 | |
|---|
| 647 | while (arguments.read("--light") || arguments.read("-n")) shadingModel = Light; |
|---|
| 648 | |
|---|
| 649 | float xSize=0.0f, ySize=0.0f, zSize=0.0f; |
|---|
| 650 | while (arguments.read("--xSize",xSize)) {} |
|---|
| 651 | while (arguments.read("--ySize",ySize)) {} |
|---|
| 652 | while (arguments.read("--zSize",zSize)) {} |
|---|
| 653 | |
|---|
| 654 | osg::ref_ptr<TestSupportOperation> testSupportOperation = new TestSupportOperation; |
|---|
| 655 | viewer.setRealizeOperation(testSupportOperation.get()); |
|---|
| 656 | |
|---|
| 657 | viewer.realize(); |
|---|
| 658 | |
|---|
| 659 | int maximumTextureSize = testSupportOperation->maximumTextureSize; |
|---|
| 660 | int s_maximumTextureSize = maximumTextureSize; |
|---|
| 661 | int t_maximumTextureSize = maximumTextureSize; |
|---|
| 662 | int r_maximumTextureSize = maximumTextureSize; |
|---|
| 663 | while(arguments.read("--maxTextureSize",maximumTextureSize)) |
|---|
| 664 | { |
|---|
| 665 | s_maximumTextureSize = maximumTextureSize; |
|---|
| 666 | t_maximumTextureSize = maximumTextureSize; |
|---|
| 667 | r_maximumTextureSize = maximumTextureSize; |
|---|
| 668 | } |
|---|
| 669 | while(arguments.read("--s_maxTextureSize",s_maximumTextureSize)) {} |
|---|
| 670 | while(arguments.read("--t_maxTextureSize",t_maximumTextureSize)) {} |
|---|
| 671 | while(arguments.read("--r_maxTextureSize",r_maximumTextureSize)) {} |
|---|
| 672 | |
|---|
| 673 | |
|---|
| 674 | ColourSpaceOperation colourSpaceOperation = NO_COLOUR_SPACE_OPERATION; |
|---|
| 675 | osg::Vec4 colourModulate(0.25f,0.25f,0.25f,0.25f); |
|---|
| 676 | while(arguments.read("--modulate-alpha-by-luminance")) { colourSpaceOperation = MODULATE_ALPHA_BY_LUMINANCE; } |
|---|
| 677 | while(arguments.read("--modulate-alpha-by-colour", colourModulate.x(),colourModulate.y(),colourModulate.z(),colourModulate.w() )) { colourSpaceOperation = MODULATE_ALPHA_BY_COLOUR; } |
|---|
| 678 | while(arguments.read("--replace-alpha-with-luminance")) { colourSpaceOperation = REPLACE_ALPHA_WITH_LUMINANCE; } |
|---|
| 679 | while(arguments.read("--replace-rgb-with-luminance")) { colourSpaceOperation = REPLACE_RGB_WITH_LUMINANCE; } |
|---|
| 680 | |
|---|
| 681 | |
|---|
| 682 | enum RescaleOperation |
|---|
| 683 | { |
|---|
| 684 | NO_RESCALE, |
|---|
| 685 | RESCALE_TO_ZERO_TO_ONE_RANGE, |
|---|
| 686 | SHIFT_MIN_TO_ZERO |
|---|
| 687 | }; |
|---|
| 688 | |
|---|
| 689 | RescaleOperation rescaleOperation = RESCALE_TO_ZERO_TO_ONE_RANGE; |
|---|
| 690 | while(arguments.read("--no-rescale")) rescaleOperation = NO_RESCALE; |
|---|
| 691 | while(arguments.read("--rescale")) rescaleOperation = RESCALE_TO_ZERO_TO_ONE_RANGE; |
|---|
| 692 | while(arguments.read("--shift-min-to-zero")) rescaleOperation = SHIFT_MIN_TO_ZERO; |
|---|
| 693 | |
|---|
| 694 | |
|---|
| 695 | bool resizeToPowerOfTwo = false; |
|---|
| 696 | |
|---|
| 697 | unsigned int numComponentsDesired = 0; |
|---|
| 698 | while(arguments.read("--num-components", numComponentsDesired)) {} |
|---|
| 699 | |
|---|
| 700 | bool useManipulator = false; |
|---|
| 701 | while(arguments.read("--manipulator") || arguments.read("-m")) { useManipulator = true; } |
|---|
| 702 | |
|---|
| 703 | |
|---|
| 704 | bool useShader = true; |
|---|
| 705 | while(arguments.read("--shader")) { useShader = true; } |
|---|
| 706 | while(arguments.read("--no-shader")) { useShader = false; } |
|---|
| 707 | |
|---|
| 708 | bool gpuTransferFunction = true; |
|---|
| 709 | while(arguments.read("--gpu-tf")) { gpuTransferFunction = true; } |
|---|
| 710 | while(arguments.read("--cpu-tf")) { gpuTransferFunction = false; } |
|---|
| 711 | |
|---|
| 712 | double sampleDensityWhenMoving = 0.0; |
|---|
| 713 | while(arguments.read("--sdwm", sampleDensityWhenMoving)) {} |
|---|
| 714 | |
|---|
| 715 | while(arguments.read("--lod")) { sampleDensityWhenMoving = 0.02; } |
|---|
| 716 | |
|---|
| 717 | double sequenceLength = 10.0; |
|---|
| 718 | while(arguments.read("--sequence-duration", sequenceLength) || |
|---|
| 719 | arguments.read("--sd", sequenceLength)) {} |
|---|
| 720 | |
|---|
| 721 | typedef std::list< osg::ref_ptr<osg::Image> > Images; |
|---|
| 722 | Images images; |
|---|
| 723 | |
|---|
| 724 | |
|---|
| 725 | std::string vh_filename; |
|---|
| 726 | while (arguments.read("--vh", vh_filename)) |
|---|
| 727 | { |
|---|
| 728 | std::string raw_filename, transfer_filename; |
|---|
| 729 | int xdim(0), ydim(0), zdim(0); |
|---|
| 730 | |
|---|
| 731 | osgDB::ifstream header(vh_filename.c_str()); |
|---|
| 732 | if (header) |
|---|
| 733 | { |
|---|
| 734 | header >> raw_filename >> transfer_filename >> xdim >> ydim >> zdim >> xSize >> ySize >> zSize; |
|---|
| 735 | } |
|---|
| 736 | |
|---|
| 737 | if (xdim*ydim*zdim==0) |
|---|
| 738 | { |
|---|
| 739 | std::cout<<"Error in reading volume header "<<vh_filename<<std::endl; |
|---|
| 740 | return 1; |
|---|
| 741 | } |
|---|
| 742 | |
|---|
| 743 | if (!raw_filename.empty()) |
|---|
| 744 | { |
|---|
| 745 | images.push_back(readRaw(xdim, ydim, zdim, 1, 1, "little", raw_filename)); |
|---|
| 746 | } |
|---|
| 747 | |
|---|
| 748 | if (!transfer_filename.empty()) |
|---|
| 749 | { |
|---|
| 750 | osgDB::ifstream fin(transfer_filename.c_str()); |
|---|
| 751 | if (fin) |
|---|
| 752 | { |
|---|
| 753 | osg::TransferFunction1D::ColorMap colorMap; |
|---|
| 754 | float value = 0.0; |
|---|
| 755 | while(fin && value<=1.0) |
|---|
| 756 | { |
|---|
| 757 | float red, green, blue, alpha; |
|---|
| 758 | fin >> red >> green >> blue >> alpha; |
|---|
| 759 | if (fin) |
|---|
| 760 | { |
|---|
| 761 | colorMap[value] = osg::Vec4(red/255.0f,green/255.0f,blue/255.0f,alpha/255.0f); |
|---|
| 762 | std::cout<<"value = "<<value<<" ("<<red<<", "<<green<<", "<<blue<<", "<<alpha<<")"; |
|---|
| 763 | std::cout<<" ("<<colorMap[value]<<")"<<std::endl; |
|---|
| 764 | } |
|---|
| 765 | value += 1/255.0; |
|---|
| 766 | } |
|---|
| 767 | |
|---|
| 768 | if (colorMap.empty()) |
|---|
| 769 | { |
|---|
| 770 | std::cout<<"Error: No values read from transfer function file: "<<transfer_filename<<std::endl; |
|---|
| 771 | return 0; |
|---|
| 772 | } |
|---|
| 773 | |
|---|
| 774 | transferFunction = new osg::TransferFunction1D; |
|---|
| 775 | transferFunction->assign(colorMap); |
|---|
| 776 | } |
|---|
| 777 | } |
|---|
| 778 | |
|---|
| 779 | } |
|---|
| 780 | |
|---|
| 781 | |
|---|
| 782 | int sizeX, sizeY, sizeZ, numberBytesPerComponent, numberOfComponents; |
|---|
| 783 | std::string endian, raw_filename; |
|---|
| 784 | while (arguments.read("--raw", sizeX, sizeY, sizeZ, numberBytesPerComponent, numberOfComponents, endian, raw_filename)) |
|---|
| 785 | { |
|---|
| 786 | images.push_back(readRaw(sizeX, sizeY, sizeZ, numberBytesPerComponent, numberOfComponents, endian, raw_filename)); |
|---|
| 787 | } |
|---|
| 788 | |
|---|
| 789 | int images_pos = arguments.find("--images"); |
|---|
| 790 | if (images_pos>=0) |
|---|
| 791 | { |
|---|
| 792 | osg::ImageList imageList; |
|---|
| 793 | int pos=images_pos+1; |
|---|
| 794 | for(;pos<arguments.argc() && !arguments.isOption(pos);++pos) |
|---|
| 795 | { |
|---|
| 796 | std::string arg(arguments[pos]); |
|---|
| 797 | if (arg.find('*') != std::string::npos) |
|---|
| 798 | { |
|---|
| 799 | osgDB::DirectoryContents contents = osgDB::expandWildcardsInFilename(arg); |
|---|
| 800 | for (unsigned int i = 0; i < contents.size(); ++i) |
|---|
| 801 | { |
|---|
| 802 | osg::Image *image = osgDB::readImageFile( contents[i] ); |
|---|
| 803 | |
|---|
| 804 | if(image) |
|---|
| 805 | { |
|---|
| 806 | 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; |
|---|
| 807 | imageList.push_back(image); |
|---|
| 808 | } |
|---|
| 809 | } |
|---|
| 810 | } |
|---|
| 811 | else |
|---|
| 812 | { |
|---|
| 813 | |
|---|
| 814 | osg::Image *image = osgDB::readImageFile( arguments[pos] ); |
|---|
| 815 | |
|---|
| 816 | if(image) |
|---|
| 817 | { |
|---|
| 818 | 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; |
|---|
| 819 | imageList.push_back(image); |
|---|
| 820 | } |
|---|
| 821 | } |
|---|
| 822 | } |
|---|
| 823 | |
|---|
| 824 | arguments.remove(images_pos, pos-images_pos); |
|---|
| 825 | |
|---|
| 826 | |
|---|
| 827 | osg::Image* image = createTexture3D(imageList, numComponentsDesired, s_maximumTextureSize, t_maximumTextureSize, r_maximumTextureSize, resizeToPowerOfTwo); |
|---|
| 828 | if (image) |
|---|
| 829 | { |
|---|
| 830 | images.push_back(image); |
|---|
| 831 | } |
|---|
| 832 | } |
|---|
| 833 | |
|---|
| 834 | |
|---|
| 835 | |
|---|
| 836 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 837 | |
|---|
| 838 | |
|---|
| 839 | if (arguments.errors()) |
|---|
| 840 | { |
|---|
| 841 | arguments.writeErrorMessages(std::cout); |
|---|
| 842 | return 1; |
|---|
| 843 | } |
|---|
| 844 | |
|---|
| 845 | |
|---|
| 846 | |
|---|
| 847 | for(int pos=1;pos<arguments.argc();++pos) |
|---|
| 848 | { |
|---|
| 849 | if (!arguments.isOption(pos)) |
|---|
| 850 | { |
|---|
| 851 | std::string filename = arguments[pos]; |
|---|
| 852 | if (osgDB::getLowerCaseFileExtension(filename)=="dicom") |
|---|
| 853 | { |
|---|
| 854 | |
|---|
| 855 | osg::Image* image = osgDB::readImageFile(filename); |
|---|
| 856 | if (image) |
|---|
| 857 | { |
|---|
| 858 | images.push_back(image); |
|---|
| 859 | } |
|---|
| 860 | } |
|---|
| 861 | else |
|---|
| 862 | { |
|---|
| 863 | osgDB::FileType fileType = osgDB::fileType(filename); |
|---|
| 864 | if (fileType == osgDB::FILE_NOT_FOUND) |
|---|
| 865 | { |
|---|
| 866 | filename = osgDB::findDataFile(filename); |
|---|
| 867 | fileType = osgDB::fileType(filename); |
|---|
| 868 | } |
|---|
| 869 | |
|---|
| 870 | if (fileType == osgDB::DIRECTORY) |
|---|
| 871 | { |
|---|
| 872 | osg::Image* image = osgDB::readImageFile(filename+".dicom"); |
|---|
| 873 | if (image) images.push_back(image); |
|---|
| 874 | } |
|---|
| 875 | else if (fileType == osgDB::REGULAR_FILE) |
|---|
| 876 | { |
|---|
| 877 | |
|---|
| 878 | osg::Image* image = osgDB::readImageFile( filename ); |
|---|
| 879 | if (image) images.push_back(image); |
|---|
| 880 | } |
|---|
| 881 | else |
|---|
| 882 | { |
|---|
| 883 | osg::notify(osg::NOTICE)<<"Error: could not find file: "<<filename<<std::endl; |
|---|
| 884 | return 1; |
|---|
| 885 | } |
|---|
| 886 | } |
|---|
| 887 | } |
|---|
| 888 | } |
|---|
| 889 | |
|---|
| 890 | if (images.empty()) |
|---|
| 891 | { |
|---|
| 892 | std::cout<<"No model loaded, please specify and volumetric image file on the command line."<<std::endl; |
|---|
| 893 | return 1; |
|---|
| 894 | } |
|---|
| 895 | |
|---|
| 896 | |
|---|
| 897 | Images::iterator sizeItr = images.begin(); |
|---|
| 898 | int image_s = (*sizeItr)->s(); |
|---|
| 899 | int image_t = (*sizeItr)->t(); |
|---|
| 900 | int image_r = (*sizeItr)->r(); |
|---|
| 901 | ++sizeItr; |
|---|
| 902 | |
|---|
| 903 | for(;sizeItr != images.end(); ++sizeItr) |
|---|
| 904 | { |
|---|
| 905 | if ((*sizeItr)->s() != image_s || |
|---|
| 906 | (*sizeItr)->t() != image_t || |
|---|
| 907 | (*sizeItr)->r() != image_r) |
|---|
| 908 | { |
|---|
| 909 | std::cout<<"Images in sequence are not of the same dimensions."<<std::endl; |
|---|
| 910 | return 1; |
|---|
| 911 | } |
|---|
| 912 | } |
|---|
| 913 | |
|---|
| 914 | |
|---|
| 915 | osg::ref_ptr<osgVolume::ImageDetails> details = dynamic_cast<osgVolume::ImageDetails*>(images.front()->getUserData()); |
|---|
| 916 | osg::ref_ptr<osg::RefMatrix> matrix = details ? details->getMatrix() : dynamic_cast<osg::RefMatrix*>(images.front()->getUserData()); |
|---|
| 917 | |
|---|
| 918 | if (!matrix) |
|---|
| 919 | { |
|---|
| 920 | if (xSize==0.0) xSize = static_cast<float>(image_s); |
|---|
| 921 | if (ySize==0.0) ySize = static_cast<float>(image_t); |
|---|
| 922 | if (zSize==0.0) zSize = static_cast<float>(image_r); |
|---|
| 923 | |
|---|
| 924 | matrix = new osg::RefMatrix(xSize, 0.0, 0.0, 0.0, |
|---|
| 925 | 0.0, ySize, 0.0, 0.0, |
|---|
| 926 | 0.0, 0.0, zSize, 0.0, |
|---|
| 927 | 0.0, 0.0, 0.0, 1.0); |
|---|
| 928 | } |
|---|
| 929 | |
|---|
| 930 | |
|---|
| 931 | if (xMultiplier!=1.0 || yMultiplier!=1.0 || zMultiplier!=1.0) |
|---|
| 932 | { |
|---|
| 933 | matrix->postMultScale(osg::Vec3d(fabs(xMultiplier), fabs(yMultiplier), fabs(zMultiplier))); |
|---|
| 934 | } |
|---|
| 935 | |
|---|
| 936 | osg::Vec4 minValue(FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX); |
|---|
| 937 | osg::Vec4 maxValue(-FLT_MAX, -FLT_MAX, -FLT_MAX, -FLT_MAX); |
|---|
| 938 | bool computeMinMax = false; |
|---|
| 939 | for(Images::iterator itr = images.begin(); |
|---|
| 940 | itr != images.end(); |
|---|
| 941 | ++itr) |
|---|
| 942 | { |
|---|
| 943 | osg::Vec4 localMinValue, localMaxValue; |
|---|
| 944 | if (osg::computeMinMax(itr->get(), localMinValue, localMaxValue)) |
|---|
| 945 | { |
|---|
| 946 | if (localMinValue.r()<minValue.r()) minValue.r() = localMinValue.r(); |
|---|
| 947 | if (localMinValue.g()<minValue.g()) minValue.g() = localMinValue.g(); |
|---|
| 948 | if (localMinValue.b()<minValue.b()) minValue.b() = localMinValue.b(); |
|---|
| 949 | if (localMinValue.a()<minValue.a()) minValue.a() = localMinValue.a(); |
|---|
| 950 | |
|---|
| 951 | if (localMaxValue.r()>maxValue.r()) maxValue.r() = localMaxValue.r(); |
|---|
| 952 | if (localMaxValue.g()>maxValue.g()) maxValue.g() = localMaxValue.g(); |
|---|
| 953 | if (localMaxValue.b()>maxValue.b()) maxValue.b() = localMaxValue.b(); |
|---|
| 954 | if (localMaxValue.a()>maxValue.a()) maxValue.a() = localMaxValue.a(); |
|---|
| 955 | |
|---|
| 956 | osg::notify(osg::NOTICE)<<" ("<<localMinValue<<") ("<<localMaxValue<<") "<<(*itr)->getFileName()<<std::endl; |
|---|
| 957 | |
|---|
| 958 | computeMinMax = true; |
|---|
| 959 | } |
|---|
| 960 | } |
|---|
| 961 | |
|---|
| 962 | if (computeMinMax) |
|---|
| 963 | { |
|---|
| 964 | osg::notify(osg::NOTICE)<<"Min value "<<minValue<<std::endl; |
|---|
| 965 | osg::notify(osg::NOTICE)<<"Max value "<<maxValue<<std::endl; |
|---|
| 966 | |
|---|
| 967 | float minComponent = minValue[0]; |
|---|
| 968 | minComponent = osg::minimum(minComponent,minValue[1]); |
|---|
| 969 | minComponent = osg::minimum(minComponent,minValue[2]); |
|---|
| 970 | minComponent = osg::minimum(minComponent,minValue[3]); |
|---|
| 971 | |
|---|
| 972 | float maxComponent = maxValue[0]; |
|---|
| 973 | maxComponent = osg::maximum(maxComponent,maxValue[1]); |
|---|
| 974 | maxComponent = osg::maximum(maxComponent,maxValue[2]); |
|---|
| 975 | maxComponent = osg::maximum(maxComponent,maxValue[3]); |
|---|
| 976 | |
|---|
| 977 | #if 0 |
|---|
| 978 | switch(rescaleOperation) |
|---|
| 979 | { |
|---|
| 980 | case(NO_RESCALE): |
|---|
| 981 | break; |
|---|
| 982 | |
|---|
| 983 | case(RESCALE_TO_ZERO_TO_ONE_RANGE): |
|---|
| 984 | { |
|---|
| 985 | float scale = 0.99f/(maxComponent-minComponent); |
|---|
| 986 | float offset = -minComponent * scale; |
|---|
| 987 | |
|---|
| 988 | for(Images::iterator itr = images.begin(); |
|---|
| 989 | itr != images.end(); |
|---|
| 990 | ++itr) |
|---|
| 991 | { |
|---|
| 992 | osg::offsetAndScaleImage(itr->get(), |
|---|
| 993 | osg::Vec4(offset, offset, offset, offset), |
|---|
| 994 | osg::Vec4(scale, scale, scale, scale)); |
|---|
| 995 | } |
|---|
| 996 | break; |
|---|
| 997 | } |
|---|
| 998 | case(SHIFT_MIN_TO_ZERO): |
|---|
| 999 | { |
|---|
| 1000 | float offset = -minComponent; |
|---|
| 1001 | |
|---|
| 1002 | for(Images::iterator itr = images.begin(); |
|---|
| 1003 | itr != images.end(); |
|---|
| 1004 | ++itr) |
|---|
| 1005 | { |
|---|
| 1006 | osg::offsetAndScaleImage(itr->get(), |
|---|
| 1007 | osg::Vec4(offset, offset, offset, offset), |
|---|
| 1008 | osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); |
|---|
| 1009 | } |
|---|
| 1010 | break; |
|---|
| 1011 | } |
|---|
| 1012 | }; |
|---|
| 1013 | #endif |
|---|
| 1014 | } |
|---|
| 1015 | |
|---|
| 1016 | |
|---|
| 1017 | if (colourSpaceOperation!=NO_COLOUR_SPACE_OPERATION) |
|---|
| 1018 | { |
|---|
| 1019 | for(Images::iterator itr = images.begin(); |
|---|
| 1020 | itr != images.end(); |
|---|
| 1021 | ++itr) |
|---|
| 1022 | { |
|---|
| 1023 | (*itr) = doColourSpaceConversion(colourSpaceOperation, itr->get(), colourModulate); |
|---|
| 1024 | } |
|---|
| 1025 | } |
|---|
| 1026 | |
|---|
| 1027 | if (!gpuTransferFunction && transferFunction.valid()) |
|---|
| 1028 | { |
|---|
| 1029 | for(Images::iterator itr = images.begin(); |
|---|
| 1030 | itr != images.end(); |
|---|
| 1031 | ++itr) |
|---|
| 1032 | { |
|---|
| 1033 | *itr = osgVolume::applyTransferFunction(itr->get(), transferFunction.get()); |
|---|
| 1034 | } |
|---|
| 1035 | } |
|---|
| 1036 | |
|---|
| 1037 | osg::ref_ptr<osg::Image> image_3d = 0; |
|---|
| 1038 | |
|---|
| 1039 | if (images.size()==1) |
|---|
| 1040 | { |
|---|
| 1041 | osg::notify(osg::NOTICE)<<"Single image "<<images.size()<<" volumes."<<std::endl; |
|---|
| 1042 | image_3d = images.front(); |
|---|
| 1043 | } |
|---|
| 1044 | else |
|---|
| 1045 | { |
|---|
| 1046 | osg::notify(osg::NOTICE)<<"Creating sequence of "<<images.size()<<" volumes."<<std::endl; |
|---|
| 1047 | |
|---|
| 1048 | osg::ref_ptr<osg::ImageSequence> imageSequence = new osg::ImageSequence; |
|---|
| 1049 | imageSequence->setLength(sequenceLength); |
|---|
| 1050 | image_3d = imageSequence.get(); |
|---|
| 1051 | for(Images::iterator itr = images.begin(); |
|---|
| 1052 | itr != images.end(); |
|---|
| 1053 | ++itr) |
|---|
| 1054 | { |
|---|
| 1055 | imageSequence->addImage(itr->get()); |
|---|
| 1056 | } |
|---|
| 1057 | imageSequence->play(); |
|---|
| 1058 | } |
|---|
| 1059 | |
|---|
| 1060 | osg::ref_ptr<osgVolume::Volume> volume = new osgVolume::Volume; |
|---|
| 1061 | osg::ref_ptr<osgVolume::VolumeTile> tile = new osgVolume::VolumeTile; |
|---|
| 1062 | volume->addChild(tile.get()); |
|---|
| 1063 | |
|---|
| 1064 | osg::ref_ptr<osgVolume::ImageLayer> layer = new osgVolume::ImageLayer(image_3d.get()); |
|---|
| 1065 | |
|---|
| 1066 | if (details) |
|---|
| 1067 | { |
|---|
| 1068 | layer->setTexelOffset(details->getTexelOffset()); |
|---|
| 1069 | layer->setTexelScale(details->getTexelScale()); |
|---|
| 1070 | } |
|---|
| 1071 | |
|---|
| 1072 | switch(rescaleOperation) |
|---|
| 1073 | { |
|---|
| 1074 | case(NO_RESCALE): |
|---|
| 1075 | break; |
|---|
| 1076 | |
|---|
| 1077 | case(RESCALE_TO_ZERO_TO_ONE_RANGE): |
|---|
| 1078 | { |
|---|
| 1079 | layer->rescaleToZeroToOneRange(); |
|---|
| 1080 | break; |
|---|
| 1081 | } |
|---|
| 1082 | case(SHIFT_MIN_TO_ZERO): |
|---|
| 1083 | { |
|---|
| 1084 | layer->translateMinToZero(); |
|---|
| 1085 | break; |
|---|
| 1086 | } |
|---|
| 1087 | }; |
|---|
| 1088 | |
|---|
| 1089 | if (xMultiplier<0.0 || yMultiplier<0.0 || zMultiplier<0.0) |
|---|
| 1090 | { |
|---|
| 1091 | layer->setLocator(new osgVolume::Locator( |
|---|
| 1092 | osg::Matrix::translate(xMultiplier<0.0 ? -1.0 : 0.0, yMultiplier<0.0 ? -1.0 : 0.0, zMultiplier<0.0 ? -1.0 : 0.0) * |
|---|
| 1093 | osg::Matrix::scale(xMultiplier<0.0 ? -1.0 : 1.0, yMultiplier<0.0 ? -1.0 : 1.0, zMultiplier<0.0 ? -1.0 : 1.0) * |
|---|
| 1094 | (*matrix) |
|---|
| 1095 | ));; |
|---|
| 1096 | } |
|---|
| 1097 | else |
|---|
| 1098 | { |
|---|
| 1099 | layer->setLocator(new osgVolume::Locator(*matrix)); |
|---|
| 1100 | } |
|---|
| 1101 | tile->setLocator(new osgVolume::Locator(*matrix)); |
|---|
| 1102 | |
|---|
| 1103 | tile->setLayer(layer.get()); |
|---|
| 1104 | |
|---|
| 1105 | tile->setEventCallback(new osgVolume::PropertyAdjustmentCallback()); |
|---|
| 1106 | |
|---|
| 1107 | if (useShader) |
|---|
| 1108 | { |
|---|
| 1109 | |
|---|
| 1110 | osgVolume::SwitchProperty* sp = new osgVolume::SwitchProperty; |
|---|
| 1111 | sp->setActiveProperty(0); |
|---|
| 1112 | |
|---|
| 1113 | osgVolume::AlphaFuncProperty* ap = new osgVolume::AlphaFuncProperty(alphaFunc); |
|---|
| 1114 | osgVolume::SampleDensityProperty* sd = new osgVolume::SampleDensityProperty(0.005); |
|---|
| 1115 | osgVolume::SampleDensityWhenMovingProperty* sdwm = sampleDensityWhenMoving!=0.0 ? new osgVolume::SampleDensityWhenMovingProperty(sampleDensityWhenMoving) : 0; |
|---|
| 1116 | osgVolume::TransparencyProperty* tp = new osgVolume::TransparencyProperty(1.0); |
|---|
| 1117 | osgVolume::TransferFunctionProperty* tfp = transferFunction.valid() ? new osgVolume::TransferFunctionProperty(transferFunction.get()) : 0; |
|---|
| 1118 | |
|---|
| 1119 | { |
|---|
| 1120 | |
|---|
| 1121 | osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; |
|---|
| 1122 | cp->addProperty(ap); |
|---|
| 1123 | cp->addProperty(sd); |
|---|
| 1124 | cp->addProperty(tp); |
|---|
| 1125 | if (sdwm) cp->addProperty(sdwm); |
|---|
| 1126 | if (tfp) cp->addProperty(tfp); |
|---|
| 1127 | |
|---|
| 1128 | sp->addProperty(cp); |
|---|
| 1129 | } |
|---|
| 1130 | |
|---|
| 1131 | { |
|---|
| 1132 | |
|---|
| 1133 | osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; |
|---|
| 1134 | cp->addProperty(ap); |
|---|
| 1135 | cp->addProperty(sd); |
|---|
| 1136 | cp->addProperty(tp); |
|---|
| 1137 | cp->addProperty(new osgVolume::LightingProperty); |
|---|
| 1138 | if (sdwm) cp->addProperty(sdwm); |
|---|
| 1139 | if (tfp) cp->addProperty(tfp); |
|---|
| 1140 | |
|---|
| 1141 | sp->addProperty(cp); |
|---|
| 1142 | } |
|---|
| 1143 | |
|---|
| 1144 | { |
|---|
| 1145 | |
|---|
| 1146 | osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; |
|---|
| 1147 | cp->addProperty(sd); |
|---|
| 1148 | cp->addProperty(tp); |
|---|
| 1149 | cp->addProperty(new osgVolume::IsoSurfaceProperty(alphaFunc)); |
|---|
| 1150 | if (sdwm) cp->addProperty(sdwm); |
|---|
| 1151 | if (tfp) cp->addProperty(tfp); |
|---|
| 1152 | |
|---|
| 1153 | sp->addProperty(cp); |
|---|
| 1154 | } |
|---|
| 1155 | |
|---|
| 1156 | { |
|---|
| 1157 | |
|---|
| 1158 | osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; |
|---|
| 1159 | cp->addProperty(ap); |
|---|
| 1160 | cp->addProperty(sd); |
|---|
| 1161 | cp->addProperty(tp); |
|---|
| 1162 | cp->addProperty(new osgVolume::MaximumIntensityProjectionProperty); |
|---|
| 1163 | if (sdwm) cp->addProperty(sdwm); |
|---|
| 1164 | if (tfp) cp->addProperty(tfp); |
|---|
| 1165 | |
|---|
| 1166 | sp->addProperty(cp); |
|---|
| 1167 | } |
|---|
| 1168 | |
|---|
| 1169 | switch(shadingModel) |
|---|
| 1170 | { |
|---|
| 1171 | case(Standard): sp->setActiveProperty(0); break; |
|---|
| 1172 | case(Light): sp->setActiveProperty(1); break; |
|---|
| 1173 | case(Isosurface): sp->setActiveProperty(2); break; |
|---|
| 1174 | case(MaximumIntensityProjection): sp->setActiveProperty(3); break; |
|---|
| 1175 | } |
|---|
| 1176 | layer->addProperty(sp); |
|---|
| 1177 | |
|---|
| 1178 | |
|---|
| 1179 | tile->setVolumeTechnique(new osgVolume::RayTracedTechnique); |
|---|
| 1180 | } |
|---|
| 1181 | else |
|---|
| 1182 | { |
|---|
| 1183 | layer->addProperty(new osgVolume::AlphaFuncProperty(alphaFunc)); |
|---|
| 1184 | tile->setVolumeTechnique(new osgVolume::FixedFunctionTechnique); |
|---|
| 1185 | } |
|---|
| 1186 | |
|---|
| 1187 | if (!outputFile.empty()) |
|---|
| 1188 | { |
|---|
| 1189 | std::string ext = osgDB::getFileExtension(outputFile); |
|---|
| 1190 | std::string name_no_ext = osgDB::getNameLessExtension(outputFile); |
|---|
| 1191 | if (ext=="osg" || ext=="osgt" || ext=="osgx" ) |
|---|
| 1192 | { |
|---|
| 1193 | if (image_3d.valid()) |
|---|
| 1194 | { |
|---|
| 1195 | image_3d->setFileName(name_no_ext + ".dds"); |
|---|
| 1196 | osgDB::writeImageFile(*image_3d, image_3d->getFileName()); |
|---|
| 1197 | } |
|---|
| 1198 | osgDB::writeNodeFile(*volume, outputFile); |
|---|
| 1199 | } |
|---|
| 1200 | else if (ext=="ive" || ext=="osgb" ) |
|---|
| 1201 | { |
|---|
| 1202 | osgDB::writeNodeFile(*volume, outputFile); |
|---|
| 1203 | } |
|---|
| 1204 | else if (ext=="dds") |
|---|
| 1205 | { |
|---|
| 1206 | osgDB::writeImageFile(*image_3d, outputFile); |
|---|
| 1207 | } |
|---|
| 1208 | else |
|---|
| 1209 | { |
|---|
| 1210 | std::cout<<"Extension not support for file output, not file written."<<std::endl; |
|---|
| 1211 | } |
|---|
| 1212 | |
|---|
| 1213 | return 0; |
|---|
| 1214 | } |
|---|
| 1215 | |
|---|
| 1216 | if (volume.valid()) |
|---|
| 1217 | { |
|---|
| 1218 | |
|---|
| 1219 | osg::ref_ptr<osg::Node> loadedModel = volume.get(); |
|---|
| 1220 | |
|---|
| 1221 | if (useManipulator) |
|---|
| 1222 | { |
|---|
| 1223 | osg::ref_ptr<osg::Group> group = new osg::Group; |
|---|
| 1224 | |
|---|
| 1225 | #if 1 |
|---|
| 1226 | osg::ref_ptr<osgManipulator::Dragger> dragger = new osgManipulator::TabBoxDragger; |
|---|
| 1227 | #else |
|---|
| 1228 | osg::ref_ptr<osgManipulator::Dragger> dragger = new osgManipulator::TrackballDragger(); |
|---|
| 1229 | #endif |
|---|
| 1230 | dragger->setupDefaultGeometry(); |
|---|
| 1231 | dragger->setHandleEvents(true); |
|---|
| 1232 | dragger->setActivationModKeyMask(osgGA::GUIEventAdapter::MODKEY_SHIFT); |
|---|
| 1233 | dragger->addDraggerCallback(new DraggerVolumeTileCallback(tile.get(), tile->getLocator())); |
|---|
| 1234 | dragger->setMatrix(osg::Matrix::translate(0.5,0.5,0.5)*tile->getLocator()->getTransform()); |
|---|
| 1235 | |
|---|
| 1236 | |
|---|
| 1237 | group->addChild(dragger.get()); |
|---|
| 1238 | |
|---|
| 1239 | |
|---|
| 1240 | |
|---|
| 1241 | group->addChild(volume.get()); |
|---|
| 1242 | |
|---|
| 1243 | loadedModel = group; |
|---|
| 1244 | } |
|---|
| 1245 | |
|---|
| 1246 | |
|---|
| 1247 | |
|---|
| 1248 | viewer.setSceneData(loadedModel.get()); |
|---|
| 1249 | |
|---|
| 1250 | |
|---|
| 1251 | viewer.run(); |
|---|
| 1252 | } |
|---|
| 1253 | |
|---|
| 1254 | return 0; |
|---|
| 1255 | } |
|---|