diff --git a/include/osg/ArgumentParser b/include/osg/ArgumentParser index 74c20bd08..d233ef96d 100644 --- a/include/osg/ArgumentParser +++ b/include/osg/ArgumentParser @@ -16,18 +16,24 @@ #include -#include #include +#include +#include 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; }; diff --git a/include/osg/DisplaySettings b/include/osg/DisplaySettings index 713ebfd10..3177dc551 100644 --- a/include/osg/DisplaySettings +++ b/include/osg/DisplaySettings @@ -15,13 +15,16 @@ #define OSG_DisplaySettings 1 #include -#include #include #include 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 diff --git a/src/Demos/osgproducer/osgproducer_viewer.cpp b/src/Demos/osgproducer/osgproducer_viewer.cpp index b58049132..44847b79f 100644 --- a/src/Demos/osgproducer/osgproducer_viewer.cpp +++ b/src/Demos/osgproducer/osgproducer_viewer.cpp @@ -5,17 +5,12 @@ #include #include - #include #include -#include - -#include #include - 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 ","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 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 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; } diff --git a/src/osg/DisplaySettings.cpp b/src/osg/DisplaySettings.cpp index c17d63185..23ac152c3 100644 --- a/src/osg/DisplaySettings.cpp +++ b/src/osg/DisplaySettings.cpp @@ -295,29 +295,40 @@ void DisplaySettings::readCommandLine(std::vector& 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 ","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; } diff --git a/src/osgDB/ReadFile.cpp b/src/osgDB/ReadFile.cpp index ec239fc04..a97924691 100644 --- a/src/osgDB/ReadFile.cpp +++ b/src/osgDB/ReadFile.cpp @@ -99,7 +99,6 @@ Node* osgDB::readNodeFiles(std::vector& commandLine) Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments) { - osgDB::readCommandLine(arguments); typedef std::vector NodeList; NodeList nodeList; diff --git a/src/osgDB/Registry.cpp b/src/osgDB/Registry.cpp index aafc009ce..c3f231e7e 100644 --- a/src/osgDB/Registry.cpp +++ b/src/osgDB/Registry.cpp @@ -277,22 +277,29 @@ void Registry::readCommandLine(std::vector& commandLine) } } -void Registry::readCommandLine(osg::ArgumentParser& parser) +void Registry::readCommandLine(osg::ArgumentParser& arguments) { + // report the usage options. + if (arguments.getApplicationUsage()) + { + arguments.getApplicationUsage()->addCommandLineOption("-l ","Load the plugin"); + arguments.getApplicationUsage()->addCommandLineOption("-e ","Load the plugin associated with handling files with specified extension"); + arguments.getApplicationUsage()->addCommandLineOption("-O ","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)); } diff --git a/src/osgPlugins/tga/ReaderWriterTGA.cpp b/src/osgPlugins/tga/ReaderWriterTGA.cpp index dfeb59a06..3d9964d69 100644 --- a/src/osgPlugins/tga/ReaderWriterTGA.cpp +++ b/src/osgPlugins/tga/ReaderWriterTGA.cpp @@ -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; diff --git a/src/osgProducer/Viewer.cpp b/src/osgProducer/Viewer.cpp index 0d7714b3b..914658686 100644 --- a/src/osgProducer/Viewer.cpp +++ b/src/osgProducer/Viewer.cpp @@ -1,8 +1,5 @@ -#include -#include -#include - #include +#include #include @@ -14,6 +11,10 @@ #include #include +#include +#include +#include + 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 ","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))