Added support for reading .osg, .osgb, .osgx, .osgt and .ive models that contain volumes from within the volume tag.
This commit is contained in:
parent
537272b98f
commit
9aa7010ded
@ -1753,7 +1753,37 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
|
||||
// osg::Object::DataVariance defaultMatrixDataVariance = osg::Object::DYNAMIC; // STATIC
|
||||
|
||||
std::string foundFile = filename;
|
||||
osg::ref_ptr<osg::Image> image;
|
||||
osg::ref_ptr<osgVolume::Volume> volume;
|
||||
osg::ref_ptr<osgVolume::VolumeTile> tile;
|
||||
osg::ref_ptr<osgVolume::ImageLayer> layer;
|
||||
|
||||
// check for wild cards
|
||||
if (filename.find('*')!=std::string::npos)
|
||||
{
|
||||
osgDB::DirectoryContents filenames = osgDB::expandWildcardsInFilename(filename);
|
||||
if (filenames.empty()) return;
|
||||
|
||||
// make sure images are in alphabetical order.
|
||||
std::sort(filenames.begin(), filenames.end());
|
||||
|
||||
typedef std::vector< osg::ref_ptr<osg::Image> > Images;
|
||||
Images images;
|
||||
for(osgDB::DirectoryContents::iterator itr = filenames.begin();
|
||||
itr != filenames.end();
|
||||
++itr)
|
||||
{
|
||||
osg::ref_ptr<osg::Image> loadedImage = osgDB::readImageFile(*itr);
|
||||
if (loadedImage.valid())
|
||||
{
|
||||
OSG_NOTICE<<"Image loaded "<<*itr<<std::endl;
|
||||
images.push_back(loadedImage.get());
|
||||
}
|
||||
}
|
||||
OSG_NOTICE<<"Need to build volume from images"<<std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
osgDB::FileType fileType = osgDB::fileType(foundFile);
|
||||
if (fileType == osgDB::FILE_NOT_FOUND)
|
||||
{
|
||||
@ -1761,31 +1791,69 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
|
||||
fileType = osgDB::fileType(foundFile);
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Image> image;
|
||||
if (fileType == osgDB::DIRECTORY)
|
||||
{
|
||||
image = osgDB::readImageFile(foundFile+".dicom", _options.get());
|
||||
}
|
||||
else if (fileType == osgDB::REGULAR_FILE)
|
||||
{
|
||||
std::string ext = osgDB::getFileExtension(foundFile);
|
||||
if (ext=="osg" || ext=="ive" || ext=="osgx" || ext=="osgb" || ext=="osgt")
|
||||
{
|
||||
osg::ref_ptr<osg::Object> obj = osgDB::readObjectFile(foundFile);
|
||||
image = dynamic_cast<osg::Image*>(obj.get());
|
||||
volume = dynamic_cast<osgVolume::Volume*>(obj.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
image = osgDB::readImageFile( foundFile, _options.get() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// not found image, so fallback to plguins/callbacks to find the model.
|
||||
image = osgDB::readImageFile( filename, _options.get() );
|
||||
if (image) recordOptionsFilePath(_options.get() );
|
||||
}
|
||||
}
|
||||
|
||||
if (!image && !volume) return;
|
||||
|
||||
if (volume.valid())
|
||||
{
|
||||
if (!tile)
|
||||
{
|
||||
if (volume->getNumChildren()>0)
|
||||
{
|
||||
tile = dynamic_cast<osgVolume::VolumeTile*>(volume->getChild(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
volume = new osgVolume::Volume;
|
||||
}
|
||||
|
||||
if (tile.valid())
|
||||
{
|
||||
layer = dynamic_cast<osgVolume::ImageLayer*>(tile->getLayer());
|
||||
image = layer.valid() ? layer->getImage() : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!image) return;
|
||||
|
||||
tile = new osgVolume::VolumeTile;
|
||||
volume->addChild(tile.get());
|
||||
}
|
||||
|
||||
if (!layer)
|
||||
{
|
||||
if (!image) return;
|
||||
|
||||
osg::ref_ptr<osgVolume::ImageDetails> details = dynamic_cast<osgVolume::ImageDetails*>(image->getUserData());
|
||||
osg::ref_ptr<osg::RefMatrix> matrix = details ? details->getMatrix() : dynamic_cast<osg::RefMatrix*>(image->getUserData());
|
||||
|
||||
osg::ref_ptr<osgVolume::Volume> volume = new osgVolume::Volume;
|
||||
osg::ref_ptr<osgVolume::VolumeTile> tile = new osgVolume::VolumeTile;
|
||||
volume->addChild(tile.get());
|
||||
|
||||
osg::ref_ptr<osgVolume::ImageLayer> layer = new osgVolume::ImageLayer(image.get());
|
||||
if (details)
|
||||
{
|
||||
@ -1875,7 +1943,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
|
||||
layer->addProperty(sp);
|
||||
tile->setVolumeTechnique(new osgVolume::RayTracedTechnique);
|
||||
tile->setEventCallback(new osgVolume::PropertyAdjustmentCallback());
|
||||
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Node> model = volume.get();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user