Completed first pass at providing commandline option usage via the new
osg::ArgumentPareser and osg::ApplicationUsage classes. The osgproducer demo has been implemented using these new mechansims.
This commit is contained in:
@@ -16,18 +16,24 @@
|
||||
|
||||
#include <osg/Export>
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
namespace osg {
|
||||
|
||||
// forward declare
|
||||
class ApplicationUsage;
|
||||
|
||||
class SG_EXPORT ArgumentParser
|
||||
{
|
||||
public:
|
||||
ArgumentParser(int* argc,char **argv):
|
||||
_argc(argc),
|
||||
_argv(argv) {}
|
||||
|
||||
ArgumentParser(int* argc,char **argv);
|
||||
|
||||
void setApplicationUsage(ApplicationUsage* usage) { _usage = usage; }
|
||||
ApplicationUsage* getApplicationUsage() { return _usage; }
|
||||
const ApplicationUsage* getApplicationUsage() const { return _usage; }
|
||||
|
||||
/** return the argument count.*/
|
||||
int& argc() { return *_argc; }
|
||||
|
||||
@@ -40,8 +46,6 @@ class SG_EXPORT ArgumentParser
|
||||
/** return const char* argument at specificed position.*/
|
||||
const char* operator [] (int pos) const { return _argv[pos]; }
|
||||
|
||||
|
||||
|
||||
/** return the program name, as specified by argv[0] */
|
||||
std::string getProgramName() const;
|
||||
|
||||
@@ -131,9 +135,10 @@ class SG_EXPORT ArgumentParser
|
||||
|
||||
protected:
|
||||
|
||||
int* _argc;
|
||||
char** _argv;
|
||||
ErrorMessageMap _errorMessageMap;
|
||||
int* _argc;
|
||||
char** _argv;
|
||||
ErrorMessageMap _errorMessageMap;
|
||||
ApplicationUsage* _usage;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -15,13 +15,16 @@
|
||||
#define OSG_DisplaySettings 1
|
||||
|
||||
#include <osg/Referenced>
|
||||
#include <osg/ArgumentParser>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace osg {
|
||||
|
||||
// forward declare
|
||||
class ArgumentParser;
|
||||
class ApplicationUsage;
|
||||
|
||||
/** DisplaySettings class for encapsulating what visuals are required and
|
||||
* have been set up, and the status of stereo viewing.*/
|
||||
class SG_EXPORT DisplaySettings : public osg::Referenced
|
||||
|
||||
@@ -5,17 +5,12 @@
|
||||
#include <osg/ArgumentParser>
|
||||
#include <osg/ApplicationUsage>
|
||||
|
||||
|
||||
#include <osgUtil/Optimizer>
|
||||
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/FileUtils>
|
||||
|
||||
#include <osgGA/AnimationPathManipulator>
|
||||
|
||||
#include <osgProducer/Viewer>
|
||||
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
|
||||
@@ -23,34 +18,29 @@ int main( int argc, char **argv )
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
// set up the usage document, in case we need to print out how to use this program.
|
||||
osg::ApplicationUsage::instance()->setCommandLineUsage(arguments.getProgramName()+" [options] filename ...");
|
||||
osg::ApplicationUsage::instance()->addCommandLineOption("-h or --help","Display this information");
|
||||
osg::ApplicationUsage::instance()->addCommandLineOption("-p <filename>","Specify camera path file to animate the camera through the loaded scene");
|
||||
|
||||
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getProgramName()+" [options] filename ...");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
|
||||
|
||||
// construct the viewer.
|
||||
osgProducer::Viewer viewer(arguments);
|
||||
|
||||
// set up the value with sensible default event handlers.
|
||||
viewer.setUpViewer();
|
||||
viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
|
||||
|
||||
// if a pathfile has been specified on command line use it to animate the camera via an AnimationPathManipulator.
|
||||
std::string pathfile;
|
||||
while (arguments.read("-p",pathfile))
|
||||
{
|
||||
osg::ref_ptr<osgGA::AnimationPathManipulator> apm = new osgGA::AnimationPathManipulator(pathfile);
|
||||
if( apm.valid() && apm->valid() )
|
||||
{
|
||||
unsigned int num = viewer.addCameraManipulator(apm.get());
|
||||
viewer.selectCameraManipulator(num);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if user request help pritn it out to cout.
|
||||
// if user request help write it out to cout.
|
||||
if (arguments.read("-h") || arguments.read("--help"))
|
||||
{
|
||||
osg::ApplicationUsage::instance()->write(std::cout);
|
||||
arguments.getApplicationUsage()->write(cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// any option left unread are converted into errors to write out later.
|
||||
arguments.reportRemainingOptionsAsUnrecognized();
|
||||
|
||||
// report any errors if they have occured when parsing the program aguments.
|
||||
if (arguments.errors())
|
||||
{
|
||||
arguments.writeErrorMessages(cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -58,21 +48,10 @@ int main( int argc, char **argv )
|
||||
// read the scene from the list of file specified commandline args.
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
||||
|
||||
// any option left unread a converted into errors to write out later.
|
||||
arguments.reportRemainingOptionsAsUnrecognized();
|
||||
|
||||
// report any errors if they have occured when parsing the program aguments.
|
||||
if (arguments.errors())
|
||||
{
|
||||
arguments.writeErrorMessages(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// if no model has been successfully loaded report failure.
|
||||
if (!loadedModel)
|
||||
{
|
||||
std::cout << arguments.getProgramName() <<": No input files" << std::endl;
|
||||
std::cout << arguments.getProgramName() <<": No data loaded" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -100,6 +79,7 @@ int main( int argc, char **argv )
|
||||
viewer.frame();
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -295,29 +295,40 @@ void DisplaySettings::readCommandLine(std::vector<std::string>& commandLine)
|
||||
}
|
||||
}
|
||||
|
||||
void DisplaySettings::readCommandLine(ArgumentParser& parser)
|
||||
void DisplaySettings::readCommandLine(ArgumentParser& arguments)
|
||||
{
|
||||
int pos;
|
||||
while ((pos=parser.find("-stereo"))!=0)
|
||||
|
||||
// report the usage options.
|
||||
if (arguments.getApplicationUsage())
|
||||
{
|
||||
if (parser.match(pos+1,"ANAGLYPHIC")) { parser.remove(pos,2); _stereo = true;_stereoMode = ANAGLYPHIC; }
|
||||
else if (parser.match(pos+1,"QUAD_BUFFER")) { parser.remove(pos,2); _stereo = true;_stereoMode = QUAD_BUFFER; }
|
||||
else if (parser.match(pos+1,"HORIZONTAL_SPLIT")) { parser.remove(pos,2); _stereo = true;_stereoMode = HORIZONTAL_SPLIT; }
|
||||
else if (parser.match(pos+1,"VERTICAL_SPLIT")) { parser.remove(pos,2); _stereo = true;_stereoMode = VERTICAL_SPLIT; }
|
||||
else if (parser.match(pos+1,"LEFT_EYE")) { parser.remove(pos,2); _stereo = true;_stereoMode = LEFT_EYE; }
|
||||
else if (parser.match(pos+1,"RIGHT_EYE")) { parser.remove(pos,2); _stereo = true;_stereoMode = RIGHT_EYE; }
|
||||
else if (parser.match(pos+1,"ON")) { parser.remove(pos,2); _stereo = true; }
|
||||
else if (parser.match(pos+1,"OFF")) { parser.remove(pos,2); _stereo = false; }
|
||||
else { parser.remove(pos); _stereo = true; }
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--stereo","Use default stereo mode which is ANAGLYPHIC if not overriden by environmental variable");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--stereo <mode>","ANAGLYPHIC | QUAD_BUFFER | HORIZONTAL_SPLIT | VERTICAL_SPLIT | LEFT_EYE | RIGHT_EYE | ON | OFF ");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--rgba","Request a RGBA color buffer visual");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--stencil","Request a stencil buffer visual");
|
||||
}
|
||||
|
||||
while (parser.read("-rgba"))
|
||||
|
||||
int pos;
|
||||
while ((pos=arguments.find("--stereo"))!=0)
|
||||
{
|
||||
if (arguments.match(pos+1,"ANAGLYPHIC")) { arguments.remove(pos,2); _stereo = true;_stereoMode = ANAGLYPHIC; }
|
||||
else if (arguments.match(pos+1,"QUAD_BUFFER")) { arguments.remove(pos,2); _stereo = true;_stereoMode = QUAD_BUFFER; }
|
||||
else if (arguments.match(pos+1,"HORIZONTAL_SPLIT")) { arguments.remove(pos,2); _stereo = true;_stereoMode = HORIZONTAL_SPLIT; }
|
||||
else if (arguments.match(pos+1,"VERTICAL_SPLIT")) { arguments.remove(pos,2); _stereo = true;_stereoMode = VERTICAL_SPLIT; }
|
||||
else if (arguments.match(pos+1,"LEFT_EYE")) { arguments.remove(pos,2); _stereo = true;_stereoMode = LEFT_EYE; }
|
||||
else if (arguments.match(pos+1,"RIGHT_EYE")) { arguments.remove(pos,2); _stereo = true;_stereoMode = RIGHT_EYE; }
|
||||
else if (arguments.match(pos+1,"ON")) { arguments.remove(pos,2); _stereo = true; }
|
||||
else if (arguments.match(pos+1,"OFF")) { arguments.remove(pos,2); _stereo = false; }
|
||||
else { arguments.remove(pos); _stereo = true; }
|
||||
}
|
||||
|
||||
while (arguments.read("--rgba"))
|
||||
{
|
||||
_RGB = true;
|
||||
_minimumNumberAlphaBits = 1;
|
||||
}
|
||||
|
||||
while (parser.read("-stencil"))
|
||||
while (arguments.read("--stencil"))
|
||||
{
|
||||
_minimumNumberStencilBits = 1;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,6 @@ Node* osgDB::readNodeFiles(std::vector<std::string>& commandLine)
|
||||
|
||||
Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments)
|
||||
{
|
||||
osgDB::readCommandLine(arguments);
|
||||
|
||||
typedef std::vector<osg::Node*> NodeList;
|
||||
NodeList nodeList;
|
||||
|
||||
@@ -277,22 +277,29 @@ void Registry::readCommandLine(std::vector<std::string>& commandLine)
|
||||
}
|
||||
}
|
||||
|
||||
void Registry::readCommandLine(osg::ArgumentParser& parser)
|
||||
void Registry::readCommandLine(osg::ArgumentParser& arguments)
|
||||
{
|
||||
// report the usage options.
|
||||
if (arguments.getApplicationUsage())
|
||||
{
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-l <library>","Load the plugin");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-e <extension>","Load the plugin associated with handling files with specified extension");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-O <option_string>","Provide an option string to reader/writers used to load databases");
|
||||
}
|
||||
|
||||
std::string value;
|
||||
while(parser.read("-l",value))
|
||||
while(arguments.read("-l",value))
|
||||
{
|
||||
loadLibrary(value);
|
||||
}
|
||||
|
||||
while(parser.read("-e",value))
|
||||
while(arguments.read("-e",value))
|
||||
{
|
||||
std::string libName = createLibraryNameForExt(value);
|
||||
loadLibrary(libName);
|
||||
}
|
||||
|
||||
while(parser.read("-O",value))
|
||||
while(arguments.read("-O",value))
|
||||
{
|
||||
setOptions(new osgDB::ReaderWriter::Options(value));
|
||||
}
|
||||
|
||||
@@ -319,7 +319,7 @@ int *numComponents_ret)
|
||||
else format = depth;
|
||||
|
||||
/* SoDebugError::postInfo("simage_tga_load", "TARGA file: %d %d %d %d %d\n", */
|
||||
/* type, width, height, depth, format); */
|
||||
/* type, width, height, depth, format); */
|
||||
|
||||
rleIsCompressed = 0;
|
||||
rleRemaining = 0;
|
||||
@@ -329,6 +329,13 @@ int *numComponents_ret)
|
||||
bpr = format * width;
|
||||
linebuf = (unsigned char *)malloc(width*depth);
|
||||
|
||||
//check the intended image orientation
|
||||
bool bLeftToRight = (flags&0x10)==0;
|
||||
bool bTopToBottom = (flags&0x20)!=0;
|
||||
int lineoffset = bTopToBottom ? -bpr : bpr;
|
||||
if (bTopToBottom) //move start point to last line in buffer
|
||||
dest += (bpr*(height-1));
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case 1: /* colormap, uncompressed */
|
||||
@@ -352,9 +359,9 @@ int *numComponents_ret)
|
||||
}
|
||||
for (x = 0; x < width; x++)
|
||||
{
|
||||
convert_data(linebuf, dest, x, depth, format);
|
||||
convert_data(linebuf, dest, bLeftToRight ? x : (width-1) - x, depth, format);
|
||||
}
|
||||
dest += bpr;
|
||||
dest += lineoffset;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -395,9 +402,9 @@ int *numComponents_ret)
|
||||
assert(src <= buf + size);
|
||||
for (x = 0; x < width; x++)
|
||||
{
|
||||
convert_data(linebuf, dest, x, depth, format);
|
||||
convert_data(linebuf, dest, bLeftToRight ? x : (width-1) - x, depth, format);
|
||||
}
|
||||
dest += bpr;
|
||||
dest += lineoffset;
|
||||
}
|
||||
if (buf) free(buf);
|
||||
}
|
||||
@@ -437,14 +444,14 @@ int headerlen)
|
||||
if (buf[1] == 1 && buf[2] == 1 && buf[17] < 64)
|
||||
{
|
||||
/* SoDebugError::postInfo("simage_tga_identify", */
|
||||
/* "TARGA colormap file: %s\n", filename); */
|
||||
/* "TARGA colormap file: %s\n", filename); */
|
||||
return 0;
|
||||
}
|
||||
if ((buf[1] == 0 || buf[1] == 1) && buf[2] == 2 && buf[17] < 64) return 1;
|
||||
if (buf[1] == 1 && buf[2] == 9 && buf[17] < 64)
|
||||
{
|
||||
/* SoDebugError::postInfo("simage_tga_identity", */
|
||||
/* "TARGA RLE and colormap file: %s\n", filename); */
|
||||
/* "TARGA RLE and colormap file: %s\n", filename); */
|
||||
|
||||
/* will soon be supported */
|
||||
return 0;
|
||||
@@ -457,7 +464,7 @@ int headerlen)
|
||||
else /* unsupported */
|
||||
{
|
||||
/* SoDebugError::postInfo("simage_tga_identify", */
|
||||
/* "Unsupported TARGA type.\n"); */
|
||||
/* "Unsupported TARGA type.\n"); */
|
||||
}
|
||||
/* not a TGA, or not supported type */
|
||||
return 0;
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
#include <osgProducer/Viewer>
|
||||
#include <osgProducer/FrameStatsHandler>
|
||||
#include <osgProducer/StatsEventHandler>
|
||||
|
||||
#include <osg/LightSource>
|
||||
#include <osg/ApplicationUsage>
|
||||
|
||||
#include <osgUtil/UpdateVisitor>
|
||||
|
||||
@@ -14,6 +11,10 @@
|
||||
#include <osgGA/DriveManipulator>
|
||||
#include <osgGA/StateSetManipulator>
|
||||
|
||||
#include <osgProducer/Viewer>
|
||||
#include <osgProducer/FrameStatsHandler>
|
||||
#include <osgProducer/StatsEventHandler>
|
||||
|
||||
using namespace osgProducer;
|
||||
|
||||
|
||||
@@ -46,7 +47,14 @@ Viewer::Viewer(osg::ArgumentParser& arguments):
|
||||
_frameNumber(0),
|
||||
_kbmcb(0)
|
||||
{
|
||||
// report the usage options.
|
||||
if (arguments.getApplicationUsage())
|
||||
{
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-p <filename>","Specify camera path file to animate the camera through the loaded scene");
|
||||
}
|
||||
|
||||
osg::DisplaySettings::instance()->readCommandLine(arguments);
|
||||
osgDB::readCommandLine(arguments);
|
||||
|
||||
std::string pathfile;
|
||||
while (arguments.read("-p",pathfile))
|
||||
|
||||
Reference in New Issue
Block a user