Added support into the .p3d format for specifying the osgDB::Options::OptionString via the <tag options="value">.

Added support into .vnc plugin for passing in the keywords "swap", "RGB", "RGBA", "BGR", "BGRA" as OptionString values to allow .p3d presentations to control
whether the pixelformat should be swapped or set to a specific format.
This commit is contained in:
Robert Osfield
2011-10-26 14:25:56 +00:00
parent 5d26d16fd3
commit 881078289d
4 changed files with 99 additions and 27 deletions

View File

@@ -222,10 +222,10 @@ public:
struct ModelData
{
ModelData():
effect("") {}
ModelData() {}
std::string effect;
std::string options;
};
struct ImageData
@@ -239,7 +239,8 @@ public:
loopingMode(osg::ImageStream::NO_LOOPING),
page(-1),
backgroundColor(1.0f,1.0f,1.0f,1.0f) {}
std::string options;
float width;
float height;
osg::Vec4 region;
@@ -274,6 +275,7 @@ public:
region[3] = region[4] = region[5] = 1.0f;
}
std::string options;
ShadingModel shadingModel;
osg::ref_ptr<osg::TransferFunction1D> transferFunction;
bool useTabbedDragger;
@@ -393,7 +395,7 @@ public:
void addStereoImagePair(const std::string& filenameLeft, const ImageData& imageDataLeft, const std::string& filenameRight,const ImageData& imageDataRight, const PositionData& positionData);
void addGraph(const std::string& filename,const std::string& options,const PositionData& positionData, const ImageData& imageData);
void addGraph(const std::string& filename,const PositionData& positionData, const ImageData& imageData);
void addVNC(const std::string& filename,const PositionData& positionData, const ImageData& imageData, const std::string& password);
void addBrowser(const std::string& filename,const PositionData& positionData, const ImageData& imageData);
void addPDF(const std::string& filename,const PositionData& positionData, const ImageData& imageData);

View File

@@ -798,6 +798,12 @@ bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::Slid
OSG_NOTIFY(_notifyLevel)<<"read effect \""<<value.effect<<"\""<<std::endl;
}
if (getProperty(cur, "options", value.options))
{
propertiesRead = true;
OSG_NOTIFY(_notifyLevel)<<"read options \""<<value.options<<"\""<<std::endl;
}
return propertiesRead;
}
@@ -813,6 +819,12 @@ bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::Slid
OSG_NOTIFY(_notifyLevel)<<"read page \""<<value.page<<"\""<<std::endl;
}
if (getProperty(cur, "options", value.options))
{
propertiesRead = true;
OSG_NOTIFY(_notifyLevel)<<"read options \""<<value.options<<"\""<<std::endl;
}
osg::Vec4 bgColour;
if (getProperty(cur, "background", value.backgroundColor))
{
@@ -1018,6 +1030,8 @@ void ReaderWriterP3DXML::parseVolume(osgPresentation::SlideShowConstructor& cons
volumeData.transferFunction = readTransferFunctionFile(transferFunctionFile, 1.0/255.0);
}
if (getProperty(cur, "options", volumeData.options)) {}
// check for draggers required
std::string dragger;
if (getProperty(cur, "dragger", dragger))
@@ -1301,7 +1315,7 @@ void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& const
std::string options;
getProperty(cur, "options", options);
constructor.addGraph(cur->getTrimmedContents(), options,
constructor.addGraph(cur->getTrimmedContents(),
positionRead ? positionData : constructor.getImagePositionData(),
imageData);
}

View File

@@ -52,8 +52,10 @@ class LibVncImage : public osgWidget::VncImage
static void passwordCheck(rfbClient* client,const char* encryptedPassWord,int len);
static char* getPassword(rfbClient* client);
std::string _optionString;
std::string _username;
std::string _password;
double _timeOfLastUpdate;
double _timeOfLastRender;
@@ -277,7 +279,7 @@ void LibVncImage::close()
rfbBool LibVncImage::resizeImage(rfbClient* client)
{
osg::Image* image = (osg::Image*)(rfbClientGetClientData(client, 0));
LibVncImage* image = (LibVncImage*)(rfbClientGetClientData(client, 0));
int width = client->width;
int height = client->height;
@@ -286,15 +288,23 @@ rfbBool LibVncImage::resizeImage(rfbClient* client)
OSG_NOTICE<<"resize "<<width<<", "<<height<<", "<<depth<<" image = "<<image<<std::endl;
PrintPixelFormat(&(client->format));
#ifdef __APPLE__
// feedback is that Mac's have an endian swap even though the PixelFormat results see under OSX are identical.
bool swap = true;
#else
bool swap = client->format.redShift!=0;
#endif
if (!image->_optionString.empty())
{
if (image->_optionString.find("swap")!=std::string::npos) swap = true;
}
GLenum gl_pixelFormat = swap ? GL_BGRA : GL_RGBA;
if (!image->_optionString.empty())
{
if (image->_optionString.find("RGB")!=std::string::npos) gl_pixelFormat = GL_RGBA;
if (image->_optionString.find("RGBA")!=std::string::npos) gl_pixelFormat = GL_RGBA;
if (image->_optionString.find("BGR")!=std::string::npos) gl_pixelFormat = GL_BGRA;
if (image->_optionString.find("BGRA")!=std::string::npos) gl_pixelFormat = GL_BGRA;
}
image->allocateImage(width, height, 1, gl_pixelFormat, GL_UNSIGNED_BYTE);
image->setInternalTextureFormat(GL_RGBA);
@@ -393,6 +403,11 @@ class ReaderWriterVNC : public osgDB::ReaderWriter
image->_password = details->password;
}
if (options && !options->getOptionString().empty())
{
image->_optionString = options->getOptionString();
}
if (!image->connect(hostname))
{
return "Could not connect to "+hostname;

View File

@@ -879,7 +879,14 @@ void SlideShowConstructor::addImage(const std::string& filename, const PositionD
{
if (!_currentLayer) addLayer();
osg::Image* image = osgDB::readImageFile(filename, _options.get());
osg::ref_ptr<osgDB::Options> options = _options;
if (!imageData.options.empty())
{
options = _options->cloneOptions();
options->setOptionString(imageData.options);
}
osg::Image* image = osgDB::readImageFile(filename, options.get());
if (image) recordOptionsFilePath(_options.get());
@@ -1016,12 +1023,25 @@ void SlideShowConstructor::addStereoImagePair(const std::string& filenameLeft, c
{
if (!_currentLayer) addLayer();
osg::ref_ptr<osgDB::Options> optionsLeft = _options;
if (!imageDataLeft.options.empty())
{
optionsLeft = _options->cloneOptions();
optionsLeft->setOptionString(imageDataLeft.options);
}
osg::ref_ptr<osg::Image> imageLeft = osgDB::readImageFile(filenameLeft, _options.get());
if (imageLeft.valid()) recordOptionsFilePath(_options.get());
osg::ref_ptr<osgDB::Options> optionsRight = _options;
if (!imageDataRight.options.empty())
{
optionsRight = _options->cloneOptions();
optionsRight->setOptionString(imageDataRight.options);
}
osg::ref_ptr<osg::Image> imageRight = (filenameRight==filenameLeft) ? imageLeft.get() : osgDB::readImageFile(filenameRight, _options.get());
if (imageRight.valid()) recordOptionsFilePath(_options.get());
osg::ref_ptr<osg::Image> imageLeft = osgDB::readImageFile(filenameLeft, optionsLeft.get());
if (imageLeft.valid()) recordOptionsFilePath(optionsLeft.get());
osg::ref_ptr<osg::Image> imageRight = (filenameRight==filenameLeft) ? imageLeft.get() : osgDB::readImageFile(filenameRight, optionsRight.get());
if (imageRight.valid()) recordOptionsFilePath(optionsRight.get());
if (!imageLeft && !imageRight) return;
@@ -1209,7 +1229,7 @@ void SlideShowConstructor::addStereoImagePair(const std::string& filenameLeft, c
_currentLayer->addChild(subgraph);
}
void SlideShowConstructor::addGraph(const std::string& contents,const std::string& options,const PositionData& positionData, const ImageData& imageData)
void SlideShowConstructor::addGraph(const std::string& contents, const PositionData& positionData, const ImageData& imageData)
{
static int s_count=0;
@@ -1247,9 +1267,9 @@ void SlideShowConstructor::addGraph(const std::string& contents,const std::strin
dotFileName = tmpDirectory+osgDB::getStrippedName(filename)+std::string(".dot");
osg::ref_ptr<osgDB::Options> opts = _options.valid() ? _options->cloneOptions() : (new osgDB::Options);
if (!options.empty())
if (!imageData.options.empty())
{
opts->setOptionString(options);
opts->setOptionString(imageData.options);
}
opts->setObjectCacheHint(osgDB::Options::CACHE_NONE);
@@ -1327,7 +1347,14 @@ osg::Image* SlideShowConstructor::addInteractiveImage(const std::string& filenam
{
if (!_currentLayer) addLayer();
osg::Image* image = osgDB::readImageFile(filename, _options.get());
osg::ref_ptr<osgDB::Options> options = _options;
if (!imageData.options.empty())
{
options = _options->cloneOptions();
options->setOptionString(imageData.options);
}
osg::Image* image = osgDB::readImageFile(filename, options.get());
OSG_INFO<<"addInteractiveImage("<<filename<<") "<<image<<std::endl;
@@ -1491,6 +1518,13 @@ void SlideShowConstructor::addModel(const std::string& filename, const PositionD
{
OSG_INFO<<"SlideShowConstructor::addModel("<<filename<<")"<<std::endl;
osg::ref_ptr<osgDB::Options> options = _options;
if (!modelData.options.empty())
{
options = _options->cloneOptions();
options->setOptionString(modelData.options);
}
osg::Node* subgraph = 0;
if (filename=="sphere")
@@ -1509,8 +1543,8 @@ void SlideShowConstructor::addModel(const std::string& filename, const PositionD
}
else
{
subgraph = osgDB::readNodeFile(filename, _options.get());
if (subgraph) recordOptionsFilePath(_options.get());
subgraph = osgDB::readNodeFile(filename, options.get());
if (subgraph) recordOptionsFilePath(options.get());
}
if (subgraph)
@@ -1763,6 +1797,13 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
PositionData positionData(in_positionData);
osg::ref_ptr<osgDB::Options> options = _options;
if (!volumeData.options.empty())
{
options = _options->cloneOptions();
options->setOptionString(volumeData.options);
}
std::string foundFile = filename;
osg::ref_ptr<osg::Image> image;
osg::ref_ptr<osgVolume::Volume> volume;
@@ -1784,7 +1825,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
itr != filenames.end();
++itr)
{
osg::ref_ptr<osg::Image> loadedImage = osgDB::readImageFile(*itr);
osg::ref_ptr<osg::Image> loadedImage = osgDB::readImageFile(*itr, options.get());
if (loadedImage.valid())
{
images.push_back(loadedImage.get());
@@ -1804,7 +1845,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
if (fileType == osgDB::DIRECTORY)
{
image = osgDB::readImageFile(foundFile+".dicom", _options.get());
image = osgDB::readImageFile(foundFile+".dicom", options.get());
}
else if (fileType == osgDB::REGULAR_FILE)
{
@@ -1817,14 +1858,14 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
}
else
{
image = osgDB::readImageFile( foundFile, _options.get() );
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() );
image = osgDB::readImageFile( filename, options.get() );
if (image) recordOptionsFilePath(options.get() );
}
}