Changeset 8780 for OpenSceneGraph/trunk/examples/osgvolume/osgvolume.cpp
- Timestamp:
- 08/22/08 18:35:49 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgvolume/osgvolume.cpp
r8777 r8780 47 47 48 48 #include <osgViewer/Viewer> 49 50 #include <osg/io_utils> 49 51 50 52 #include <iostream> … … 632 634 float halfSize = size*0.5f; 633 635 float y = halfSize; 634 float dy =-size *1.4/(float)(numSlices-1)*sliceEnd;636 float dy =-size/(float)(numSlices-1)*sliceEnd; 635 637 636 638 //y = -halfSize; … … 711 713 case(osgGA::GUIEventAdapter::DRAG): 712 714 { 713 float v = ea.getY()*0.5f+0.5f;715 float v = (ea.getY()-ea.getYmin())/(ea.getYmax()-ea.getYmin()); 714 716 osg::Uniform* uniform = 0; 715 717 if (_updateTransparency && (uniform = stateset->getUniform("transparency"))) uniform->set(v); … … 746 748 osg::Node* createShaderModel(osg::ref_ptr<osg::Image>& image_3d, osg::ref_ptr<osg::Image>& /*normalmap_3d*/, 747 749 osg::Texture::InternalFormatMode internalFormatMode, 748 float /*xSize*/, float /*ySize*/, float /*zSize*/,750 float xSize, float ySize, float zSize, 749 751 float /*xMultiplier*/, float /*yMultiplier*/, float /*zMultiplier*/, 750 752 unsigned int /*numSlices*/=500, float /*sliceEnd*/=1.0f, float alphaFuncValue=0.02f, bool maximumIntensityProjection = false) … … 762 764 // imbalanced dimensions of the 256x256x4 texture. 763 765 osg::Texture3D* texture3D = new osg::Texture3D; 766 texture3D->setResizeNonPowerOfTwoHint(false); 764 767 texture3D->setFilter(osg::Texture3D::MIN_FILTER,osg::Texture3D::LINEAR); 765 768 texture3D->setFilter(osg::Texture3D::MAG_FILTER,osg::Texture3D::LINEAR); … … 845 848 " texcoord += deltaTexCoord; \n" 846 849 " }\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" 848 852 "}\n"; 849 853 … … 876 880 877 881 osg::Vec3Array* coords = new osg::Vec3Array(8); 882 #if 0 878 883 (*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); 886 891 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 888 903 osg::Vec3Array* tcoords = new osg::Vec3Array(8); 889 904 (*tcoords)[0].set(0,0,0); … … 956 971 bool two_pass = normalmap_3d.valid() && (image_3d->getPixelFormat()==GL_RGB || image_3d->getPixelFormat()==GL_RGBA); 957 972 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 958 979 osg::Group* group = new osg::Group; 959 980 … … 961 982 texgenNode_0->setTextureUnit(0); 962 983 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)); 966 987 967 988 if (two_pass) … … 983 1004 } 984 1005 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); 986 1007 987 1008 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)); 989 1010 clipnode->createClipBox(bb); 990 1011 … … 1082 1103 // set up color texture 1083 1104 osg::Texture3D* texture3D = new osg::Texture3D; 1105 texture3D->setResizeNonPowerOfTwoHint(false); 1084 1106 texture3D->setFilter(osg::Texture3D::MIN_FILTER,osg::Texture3D::LINEAR); 1085 1107 texture3D->setFilter(osg::Texture3D::MAG_FILTER,osg::Texture3D::LINEAR); … … 1112 1134 osg::ref_ptr<osg::Image> normalmap_3d = createNormalMapTexture(image_3d.get()); 1113 1135 osg::Texture3D* bump_texture3D = new osg::Texture3D; 1136 bump_texture3D->setResizeNonPowerOfTwoHint(false); 1114 1137 bump_texture3D->setFilter(osg::Texture3D::MIN_FILTER,osg::Texture3D::LINEAR); 1115 1138 bump_texture3D->setFilter(osg::Texture3D::MAG_FILTER,osg::Texture3D::LINEAR); … … 1154 1177 // imbalanced dimensions of the 256x256x4 texture. 1155 1178 osg::Texture3D* texture3D = new osg::Texture3D; 1179 texture3D->setResizeNonPowerOfTwoHint(false); 1156 1180 texture3D->setFilter(osg::Texture3D::MIN_FILTER,osg::Texture3D::LINEAR); 1157 1181 texture3D->setFilter(osg::Texture3D::MAG_FILTER,osg::Texture3D::LINEAR); … … 1607 1631 1608 1632 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 1609 1642 1610 1643 // create a model from the images.
