diff --git a/examples/osgvolume/osgvolume.cpp b/examples/osgvolume/osgvolume.cpp index 2275a2ff9..d503575fc 100644 --- a/examples/osgvolume/osgvolume.cpp +++ b/examples/osgvolume/osgvolume.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,9 @@ #include #include +#include +#include +#include #include @@ -1786,6 +1790,15 @@ int main( int argc, char **argv ) // add the window size toggle handler viewer.addEventHandler(new osgViewer::WindowSizeHandler); + { + osg::ref_ptr keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; + + keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); + keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); + + viewer.setCameraManipulator( keyswitchManipulator.get() ); + } + // add the stats handler viewer.addEventHandler(new osgViewer::StatsHandler); @@ -1896,8 +1909,10 @@ int main( int argc, char **argv ) while(arguments.read("--gpu-tf")) { gpuTransferFunction = true; } while(arguments.read("--cpu-tf")) { gpuTransferFunction = false; } - osg::ref_ptr image_3d; - + typedef std::list< osg::ref_ptr > Images; + Images images; + + std::string vh_filename; while (arguments.read("--vh", vh_filename)) { @@ -1918,7 +1933,7 @@ int main( int argc, char **argv ) if (!raw_filename.empty()) { - image_3d = readRaw(xdim, ydim, zdim, 1, 1, "little", raw_filename); + images.push_back(readRaw(xdim, ydim, zdim, 1, 1, "little", raw_filename)); } if (!transfer_filename.empty()) @@ -1959,7 +1974,7 @@ int main( int argc, char **argv ) std::string endian, raw_filename; while (arguments.read("--raw", sizeX, sizeY, sizeZ, numberBytesPerComponent, numberOfComponents, endian, raw_filename)) { - image_3d = readRaw(sizeX, sizeY, sizeZ, numberBytesPerComponent, numberOfComponents, endian, raw_filename); + images.push_back(readRaw(sizeX, sizeY, sizeZ, numberBytesPerComponent, numberOfComponents, endian, raw_filename)); } while (arguments.read("--images")) @@ -1978,7 +1993,7 @@ int main( int argc, char **argv ) // pack the textures into a single texture. ProcessRow processRow; - image_3d = createTexture3D(imageList, processRow, numComponentsDesired, s_maximumTextureSize, t_maximumTextureSize, r_maximumTextureSize, resizeToPowerOfTwo); + images.push_back(createTexture3D(imageList, processRow, numComponentsDesired, s_maximumTextureSize, t_maximumTextureSize, r_maximumTextureSize, resizeToPowerOfTwo)); } @@ -1991,16 +2006,17 @@ int main( int argc, char **argv ) arguments.writeErrorMessages(std::cout); return 1; } + // assume remaining arguments are file names of textures. - for(int pos=1;poss(); + ySize = (*sizeItr)->t(); + zSize = (*sizeItr)->r(); + ++sizeItr; + for(;sizeItr != images.end(); ++sizeItr) + { + if ((*sizeItr)->s() != xSize || + (*sizeItr)->t() != ySize || + (*sizeItr)->r() != zSize) + { + std::cout<<"Images in sequence are not of the same dimensions."<(image_3d->getUserData()); if (matrix) @@ -2070,14 +2104,20 @@ int main( int argc, char **argv ) zSize = image_3d->r() * (*matrix)(2,2); } #else - xSize = image_3d->s(); - ySize = image_3d->t(); - zSize = image_3d->r(); #endif osg::Vec4 minValue, maxValue; - if (osgVolume::computeMinMax(image_3d.get(), minValue, maxValue)); + bool computeMinMax = false; + for(Images::iterator itr = images.begin(); + itr != images.end(); + ++itr) + { + if (osgVolume::computeMinMax(itr->get(), minValue, maxValue)) computeMinMax = true; + } + + + if (computeMinMax) { osg::notify(osg::NOTICE)<<"Min value "<get(), + osg::Vec4(offset, offset, offset, offset), + osg::Vec4(scale, scale, scale, scale)); + } } -#if 0 - osg::Vec4 newMinValue, newMaxValue; - if (osgVolume::computeMinMax(image_3d.get(), newMinValue, newMaxValue)); - { - osg::notify(osg::NOTICE)<<"After min value "<get(), colourModulate); + } } if (!gpuTransferFunction && transferFunction.valid()) { - image_3d = applyTransferFunction(image_3d.get(), transferFunction.get()); + for(Images::iterator itr = images.begin(); + itr != images.end(); + ++itr) + { + *itr = applyTransferFunction(itr->get(), transferFunction.get()); + } } - osg::ref_ptr normalmap_3d = createNormalMap ? createNormalMapTexture(image_3d.get()) : 0; - + osg::ref_ptr image_3d = 0; + if (images.size()==1) + { + osg::notify(osg::NOTICE)<<"Single image "< imageSequence = new osg::ImageSequence; + image_3d = imageSequence.get(); + for(Images::iterator itr = images.begin(); + itr != images.end(); + ++itr) + { + imageSequence->addImage(itr->get()); + } + imageSequence->play(); + } + + osg::ref_ptr normalmap_3d = 0; + if (createNormalMap) + { + if (images.size()==1) + { + normalmap_3d = createNormalMapTexture(images.front().get()); + } + else + { + osg::ref_ptr normalmapSequence = new osg::ImageSequence; + normalmap_3d = normalmapSequence.get(); + for(Images::iterator itr = images.begin(); + itr != images.end(); + ++itr) + { + normalmapSequence->addImage(createNormalMapTexture(itr->get())); + } + normalmapSequence->play(); + } + } + // create a model from the images. osg::Node* rootNode = 0;