Show
Ignore:
Timestamp:
08/22/08 18:35:49 (6 years ago)
Author:
robert
Message:

Added support for reading the image transform from UserData? in the form of a Matrix.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgvolume/osgvolume.cpp

    r8777 r8780  
    4747 
    4848#include <osgViewer/Viewer> 
     49 
     50#include <osg/io_utils> 
    4951 
    5052#include <iostream> 
     
    632634    float halfSize = size*0.5f; 
    633635    float y = halfSize; 
    634     float dy =-size*1.4/(float)(numSlices-1)*sliceEnd; 
     636    float dy =-size/(float)(numSlices-1)*sliceEnd; 
    635637 
    636638    //y = -halfSize; 
     
    711713                case(osgGA::GUIEventAdapter::DRAG): 
    712714                { 
    713                     float v = ea.getY()*0.5f+0.5f; 
     715                    float v = (ea.getY()-ea.getYmin())/(ea.getYmax()-ea.getYmin()); 
    714716                    osg::Uniform* uniform = 0; 
    715717                    if (_updateTransparency && (uniform = stateset->getUniform("transparency"))) uniform->set(v); 
     
    746748osg::Node* createShaderModel(osg::ref_ptr<osg::Image>& image_3d, osg::ref_ptr<osg::Image>& /*normalmap_3d*/, 
    747749                       osg::Texture::InternalFormatMode internalFormatMode, 
    748                        float /*xSize*/, float /*ySize*/, float /*zSize*/, 
     750                       float xSize, float ySize, float zSize, 
    749751                       float /*xMultiplier*/, float /*yMultiplier*/, float /*zMultiplier*/, 
    750752                       unsigned int /*numSlices*/=500, float /*sliceEnd*/=1.0f, float alphaFuncValue=0.02f, bool maximumIntensityProjection = false) 
     
    762764    // imbalanced dimensions of the 256x256x4 texture. 
    763765    osg::Texture3D* texture3D = new osg::Texture3D; 
     766    texture3D->setResizeNonPowerOfTwoHint(false); 
    764767    texture3D->setFilter(osg::Texture3D::MIN_FILTER,osg::Texture3D::LINEAR); 
    765768    texture3D->setFilter(osg::Texture3D::MAG_FILTER,osg::Texture3D::LINEAR); 
     
    845848            "            texcoord += deltaTexCoord; \n" 
    846849            "        }\n" 
    847             "    if (gl_FragColor.w>1.0) gl_FragColor.w = 1.0; \n" 
     850            "        if (gl_FragColor.w>1.0) gl_FragColor.w = 1.0; \n" 
     851            "        if (gl_FragColor.w==0.0) discard;\n" 
    848852            "}\n"; 
    849853 
     
    876880 
    877881        osg::Vec3Array* coords = new osg::Vec3Array(8); 
     882#if 0 
    878883        (*coords)[0].set(0,0,0); 
    879         (*coords)[1].set(1,0,0); 
    880         (*coords)[2].set(1,1,0); 
    881         (*coords)[3].set(0,1,0); 
    882         (*coords)[4].set(0,0,1); 
    883         (*coords)[5].set(1,0,1); 
    884         (*coords)[6].set(1,1,1); 
    885         (*coords)[7].set(0,1,1); 
     884        (*coords)[1].set(xSize,0,0); 
     885        (*coords)[2].set(xSize,ySize,0); 
     886        (*coords)[3].set(0,ySize,0); 
     887        (*coords)[4].set(0,0,zSize); 
     888        (*coords)[5].set(xSize,0,zSize); 
     889        (*coords)[6].set(ySize,ySize,zSize); 
     890        (*coords)[7].set(0,ySize,zSize); 
    886891        geom->setVertexArray(coords); 
    887  
     892#else 
     893        (*coords)[0].set(0,0,0); 
     894        (*coords)[1].set(1.0,0,0); 
     895        (*coords)[2].set(1.0, 1.0,0); 
     896        (*coords)[3].set(0,1.0,0); 
     897        (*coords)[4].set(0,0,1.0); 
     898        (*coords)[5].set(1.0,0,1.0); 
     899        (*coords)[6].set(1.0,1.0,1.0); 
     900        (*coords)[7].set(0,1.0,1.0); 
     901        geom->setVertexArray(coords); 
     902#endif 
    888903        osg::Vec3Array* tcoords = new osg::Vec3Array(8); 
    889904        (*tcoords)[0].set(0,0,0); 
     
    956971    bool two_pass = normalmap_3d.valid() && (image_3d->getPixelFormat()==GL_RGB || image_3d->getPixelFormat()==GL_RGBA); 
    957972 
     973    osg::BoundingBox bb(-xSize*0.5f,-ySize*0.5f,-zSize*0.5f,xSize*0.5f,ySize*0.5f,zSize*0.5f); 
     974 
     975    float maxAxis = xSize; 
     976    if (ySize > maxAxis) maxAxis = ySize; 
     977    if (zSize > maxAxis) maxAxis = zSize; 
     978 
    958979    osg::Group* group = new osg::Group; 
    959980     
     
    961982    texgenNode_0->setTextureUnit(0); 
    962983    texgenNode_0->getTexGen()->setMode(osg::TexGen::EYE_LINEAR); 
    963     texgenNode_0->getTexGen()->setPlane(osg::TexGen::S, osg::Plane(xMultiplier,0.0f,0.0f,0.5f)); 
    964     texgenNode_0->getTexGen()->setPlane(osg::TexGen::T, osg::Plane(0.0f,yMultiplier,0.0f,0.5f)); 
    965     texgenNode_0->getTexGen()->setPlane(osg::TexGen::R, osg::Plane(0.0f,0.0f,zMultiplier,0.5f)); 
     984    texgenNode_0->getTexGen()->setPlane(osg::TexGen::S, osg::Plane(xMultiplier/xSize,0.0f,0.0f,0.5f)); 
     985    texgenNode_0->getTexGen()->setPlane(osg::TexGen::T, osg::Plane(0.0f,yMultiplier/ySize,0.0f,0.5f)); 
     986    texgenNode_0->getTexGen()->setPlane(osg::TexGen::R, osg::Plane(0.0f,0.0f,zMultiplier/zSize,0.5f)); 
    966987     
    967988    if (two_pass) 
     
    9831004    } 
    9841005 
    985     osg::BoundingBox bb(-xSize*0.5f,-ySize*0.5f,-zSize*0.5f,xSize*0.5f,ySize*0.5f,zSize*0.5f); 
     1006    float cubeSize = sqrtf(xSize*xSize+ySize*ySize+zSize*zSize); 
    9861007 
    9871008    osg::ClipNode* clipnode = new osg::ClipNode; 
    988     clipnode->addChild(createCube(1.0f,1.0f, numSlices,sliceEnd)); 
     1009    clipnode->addChild(createCube(cubeSize,1.0f, numSlices,sliceEnd)); 
    9891010    clipnode->createClipBox(bb); 
    9901011 
     
    10821103            // set up color texture 
    10831104            osg::Texture3D* texture3D = new osg::Texture3D; 
     1105            texture3D->setResizeNonPowerOfTwoHint(false); 
    10841106            texture3D->setFilter(osg::Texture3D::MIN_FILTER,osg::Texture3D::LINEAR); 
    10851107            texture3D->setFilter(osg::Texture3D::MAG_FILTER,osg::Texture3D::LINEAR); 
     
    11121134            osg::ref_ptr<osg::Image> normalmap_3d = createNormalMapTexture(image_3d.get()); 
    11131135            osg::Texture3D* bump_texture3D = new osg::Texture3D; 
     1136            bump_texture3D->setResizeNonPowerOfTwoHint(false); 
    11141137            bump_texture3D->setFilter(osg::Texture3D::MIN_FILTER,osg::Texture3D::LINEAR); 
    11151138            bump_texture3D->setFilter(osg::Texture3D::MAG_FILTER,osg::Texture3D::LINEAR); 
     
    11541177        // imbalanced dimensions of the 256x256x4 texture. 
    11551178        osg::Texture3D* texture3D = new osg::Texture3D; 
     1179        texture3D->setResizeNonPowerOfTwoHint(false); 
    11561180        texture3D->setFilter(osg::Texture3D::MIN_FILTER,osg::Texture3D::LINEAR); 
    11571181        texture3D->setFilter(osg::Texture3D::MAG_FILTER,osg::Texture3D::LINEAR); 
     
    16071631 
    16081632 
     1633    osg::RefMatrix* matrix = dynamic_cast<osg::RefMatrix*>(image_3d->getUserData()); 
     1634    if (matrix) 
     1635    { 
     1636        osg::notify(osg::NOTICE)<<"Image has Matrix = "<<*matrix<<std::endl; 
     1637        xSize = image_3d->s() * (*matrix)(0,0); 
     1638        ySize = image_3d->t() * (*matrix)(1,1); 
     1639        zSize = image_3d->r() * (*matrix)(2,2); 
     1640    } 
     1641 
    16091642 
    16101643    // create a model from the images.