Changeset 8954 for OpenSceneGraph/trunk/examples/osgvolume/osgvolume.cpp
- Timestamp:
- 09/29/08 12:56:42 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgvolume/osgvolume.cpp
r8953 r8954 22 22 #include <osg/Texture3D> 23 23 #include <osg/Texture1D> 24 #include <osg/ImageSequence> 24 25 #include <osg/TexGen> 25 26 #include <osg/Geode> … … 45 46 46 47 #include <osgGA/EventVisitor> 48 #include <osgGA/TrackballManipulator> 49 #include <osgGA/FlightManipulator> 50 #include <osgGA/KeySwitchMatrixManipulator> 47 51 48 52 #include <osgUtil/CullVisitor> … … 1787 1791 viewer.addEventHandler(new osgViewer::WindowSizeHandler); 1788 1792 1793 { 1794 osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; 1795 1796 keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); 1797 keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); 1798 1799 viewer.setCameraManipulator( keyswitchManipulator.get() ); 1800 } 1801 1789 1802 // add the stats handler 1790 1803 viewer.addEventHandler(new osgViewer::StatsHandler); … … 1897 1910 while(arguments.read("--cpu-tf")) { gpuTransferFunction = false; } 1898 1911 1899 osg::ref_ptr<osg::Image> image_3d; 1900 1912 typedef std::list< osg::ref_ptr<osg::Image> > Images; 1913 Images images; 1914 1915 1901 1916 std::string vh_filename; 1902 1917 while (arguments.read("--vh", vh_filename)) … … 1919 1934 if (!raw_filename.empty()) 1920 1935 { 1921 image _3d = readRaw(xdim, ydim, zdim, 1, 1, "little", raw_filename);1936 images.push_back(readRaw(xdim, ydim, zdim, 1, 1, "little", raw_filename)); 1922 1937 } 1923 1938 … … 1960 1975 while (arguments.read("--raw", sizeX, sizeY, sizeZ, numberBytesPerComponent, numberOfComponents, endian, raw_filename)) 1961 1976 { 1962 image _3d = readRaw(sizeX, sizeY, sizeZ, numberBytesPerComponent, numberOfComponents, endian, raw_filename);1977 images.push_back(readRaw(sizeX, sizeY, sizeZ, numberBytesPerComponent, numberOfComponents, endian, raw_filename)); 1963 1978 } 1964 1979 … … 1979 1994 // pack the textures into a single texture. 1980 1995 ProcessRow processRow; 1981 image _3d = createTexture3D(imageList, processRow, numComponentsDesired, s_maximumTextureSize, t_maximumTextureSize, r_maximumTextureSize, resizeToPowerOfTwo);1996 images.push_back(createTexture3D(imageList, processRow, numComponentsDesired, s_maximumTextureSize, t_maximumTextureSize, r_maximumTextureSize, resizeToPowerOfTwo)); 1982 1997 } 1983 1998 … … 1992 2007 return 1; 1993 2008 } 2009 1994 2010 1995 2011 // assume remaining arguments are file names of textures. 1996 for(int pos=1;pos<arguments.argc() && !image_3d;++pos)2012 for(int pos=1;pos<arguments.argc();++pos) 1997 2013 { 1998 2014 if (!arguments.isOption(pos)) … … 2001 2017 if (osgDB::getLowerCaseFileExtension(filename)=="dicom") 2002 2018 { 2003 image _3d = osgDB::readImageFile( filename);2019 images.push_back(osgDB::readImageFile( filename )); 2004 2020 } 2005 2021 else … … 2038 2054 // pack the textures into a single texture. 2039 2055 ProcessRow processRow; 2040 image _3d = createTexture3D(imageList, processRow, numComponentsDesired, s_maximumTextureSize, t_maximumTextureSize, r_maximumTextureSize, resizeToPowerOfTwo);2056 images.push_back(createTexture3D(imageList, processRow, numComponentsDesired, s_maximumTextureSize, t_maximumTextureSize, r_maximumTextureSize, resizeToPowerOfTwo)); 2041 2057 2042 2058 } … … 2044 2060 { 2045 2061 // not an option so assume string is a filename. 2046 image _3d = osgDB::readImageFile( filename);2062 images.push_back(osgDB::readImageFile( filename )); 2047 2063 } 2048 2064 else … … 2055 2071 } 2056 2072 2057 if ( !image_3d)2073 if (images.empty()) 2058 2074 { 2059 2075 std::cout<<"No model loaded, please specify and volumetric image file on the command line."<<std::endl; 2060 2076 return 1; 2061 2077 } 2078 2079 2080 Images::iterator sizeItr = images.begin(); 2081 xSize = (*sizeItr)->s(); 2082 ySize = (*sizeItr)->t(); 2083 zSize = (*sizeItr)->r(); 2084 ++sizeItr; 2085 for(;sizeItr != images.end(); ++sizeItr) 2086 { 2087 if ((*sizeItr)->s() != xSize || 2088 (*sizeItr)->t() != ySize || 2089 (*sizeItr)->r() != zSize) 2090 { 2091 std::cout<<"Images in sequence are not of the same dimensions."<<std::endl; 2092 return 1; 2093 } 2094 } 2095 2062 2096 2063 2097 #if 0 … … 2071 2105 } 2072 2106 #else 2073 xSize = image_3d->s();2074 ySize = image_3d->t();2075 zSize = image_3d->r();2076 2107 #endif 2077 2108 2078 2109 2079 2110 osg::Vec4 minValue, maxValue; 2080 if (osgVolume::computeMinMax(image_3d.get(), minValue, maxValue)); 2111 bool computeMinMax = false; 2112 for(Images::iterator itr = images.begin(); 2113 itr != images.end(); 2114 ++itr) 2115 { 2116 if (osgVolume::computeMinMax(itr->get(), minValue, maxValue)) computeMinMax = true; 2117 } 2118 2119 2120 if (computeMinMax) 2081 2121 { 2082 2122 osg::notify(osg::NOTICE)<<"Min value "<<minValue<<std::endl; … … 2096 2136 float offset = -minComponent * scale; 2097 2137 2098 osgVolume::offsetAndScaleImage(image_3d.get(), 2099 osg::Vec4(offset, offset, offset, offset), 2100 osg::Vec4(scale, scale, scale, scale)); 2101 2102 } 2103 2104 #if 0 2105 osg::Vec4 newMinValue, newMaxValue; 2106 if (osgVolume::computeMinMax(image_3d.get(), newMinValue, newMaxValue)); 2107 { 2108 osg::notify(osg::NOTICE)<<"After min value "<<newMinValue<<std::endl; 2109 osg::notify(osg::NOTICE)<<"After max value "<<newMaxValue<<std::endl; 2110 2111 } 2112 #endif 2138 2139 for(Images::iterator itr = images.begin(); 2140 itr != images.end(); 2141 ++itr) 2142 { 2143 osgVolume::offsetAndScaleImage(itr->get(), 2144 osg::Vec4(offset, offset, offset, offset), 2145 osg::Vec4(scale, scale, scale, scale)); 2146 } 2147 } 2148 2113 2149 2114 2150 if (colourSpaceOperation!=NO_COLOUR_SPACE_OPERATION) 2115 2151 { 2116 doColourSpaceConversion(colourSpaceOperation, image_3d.get(), colourModulate); 2152 for(Images::iterator itr = images.begin(); 2153 itr != images.end(); 2154 ++itr) 2155 { 2156 doColourSpaceConversion(colourSpaceOperation, itr->get(), colourModulate); 2157 } 2117 2158 } 2118 2159 2119 2160 if (!gpuTransferFunction && transferFunction.valid()) 2120 2161 { 2121 image_3d = applyTransferFunction(image_3d.get(), transferFunction.get()); 2122 } 2123 2124 osg::ref_ptr<osg::Image> normalmap_3d = createNormalMap ? createNormalMapTexture(image_3d.get()) : 0; 2125 2126 2127 2162 for(Images::iterator itr = images.begin(); 2163 itr != images.end(); 2164 ++itr) 2165 { 2166 *itr = applyTransferFunction(itr->get(), transferFunction.get()); 2167 } 2168 } 2169 2170 osg::ref_ptr<osg::Image> image_3d = 0; 2171 2172 if (images.size()==1) 2173 { 2174 osg::notify(osg::NOTICE)<<"Single image "<<images.size()<<" volumes."<<std::endl; 2175 image_3d = images.front(); 2176 } 2177 else 2178 { 2179 osg::notify(osg::NOTICE)<<"Creating sequence of "<<images.size()<<" volumes."<<std::endl; 2180 2181 osg::ref_ptr<osg::ImageSequence> imageSequence = new osg::ImageSequence; 2182 image_3d = imageSequence.get(); 2183 for(Images::iterator itr = images.begin(); 2184 itr != images.end(); 2185 ++itr) 2186 { 2187 imageSequence->addImage(itr->get()); 2188 } 2189 imageSequence->play(); 2190 } 2191 2192 osg::ref_ptr<osg::Image> normalmap_3d = 0; 2193 if (createNormalMap) 2194 { 2195 if (images.size()==1) 2196 { 2197 normalmap_3d = createNormalMapTexture(images.front().get()); 2198 } 2199 else 2200 { 2201 osg::ref_ptr<osg::ImageSequence> normalmapSequence = new osg::ImageSequence; 2202 normalmap_3d = normalmapSequence.get(); 2203 for(Images::iterator itr = images.begin(); 2204 itr != images.end(); 2205 ++itr) 2206 { 2207 normalmapSequence->addImage(createNormalMapTexture(itr->get())); 2208 } 2209 normalmapSequence->play(); 2210 } 2211 } 2212 2128 2213 // create a model from the images. 2129 2214 osg::Node* rootNode = 0;
