Changeset 144


Ignore:
Timestamp:
Nov 1, 2010, 6:24:56 PM (13 years ago)
Author:
Torben Dannhauer
Message:

start to move osgVisual from argument based configuratiobn to xml file based configuration

Location:
osgVisual
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • osgVisual/include/core/visual_core.h

    r129 r144  
    139139
    140140        /**
    141          * XML File valid?
     141         * XML configuration filename.
    142142         */
    143         bool configFileValid;
     143        std::string configFilename;
     144
    144145
    145146#ifdef USE_SPACENAVIGATOR
  • osgVisual/include/dataIO/visual_dataIO.h

    r118 r144  
    145145        static visual_dataIO* getInstance();
    146146
    147         void init(osgViewer::Viewer* viewer_,osg::ArgumentParser& arguments_);
     147        void init(osgViewer::Viewer* viewer_,osg::ArgumentParser& arguments_, std::string configFileName);
    148148        void shutdown();
    149149        bool isMaster(){if (clusterMode==osgVisual::dataIO_cluster::MASTER) return true; else return false;};
  • osgVisual/include/sky_Silverlining/visual_skySilverLining.h

    r139 r144  
    6565         * @param viewer_ : Pointer to the applications viewer
    6666         */
    67         visual_skySilverLining(osgViewer::Viewer* viewer_);
     67        visual_skySilverLining(osgViewer::Viewer* viewer_, std::string configFileName);
    6868
    6969        /**
  • osgVisual/include/util/visual_util.h

    r88 r144  
    1818#include <string.h>
    1919#include <iostream>
    20 
     20#include <libxml/parser.h>
     21#include <libxml/tree.h>
    2122
    2223#include <osg/Node>
     
    2728
    2829#include <osgViewer/Viewer>
     30
     31#include <OpenThreads/ReentrantMutex>
     32
     33#include <osgUtil/LineSegmentIntersector>
    2934
    3035#ifdef FUNFUNCTIONS_ENABLED
     
    3641#endif
    3742
    38 #include <OpenThreads/ReentrantMutex>
    39 
    40 #include <osgUtil/LineSegmentIntersector>
     43
    4144
    4245namespace osgVisual
     
    216219         */
    217220        static bool setTransparentWindowBackground(osgViewer::Viewer* viewer_);
     221
     222        // Parses for the XML node of the specified module. The caller has to clean up if ret_value!=NULL, otherwise this function cleans up.
     223        // nötige cleanup-Schritte:       xmlFreeDoc(doc); xmlCleanupParser();
     224        static xmlNode* getModuleXMLConfig(std::string configFilename, std::string moduleName, xmlDoc*& doc);
     225
     226private:
     227        static xmlNode* checkXMLNodeChildrenForModule(xmlNode* node, std::string moduleName);
    218228};
    219229
  • osgVisual/src/core/visual_core.cpp

    r143 r144  
    3434        OSG_NOTIFY( osg::ALWAYS ) << "Initialize visual_core..." << std::endl;
    3535
     36        // Check for config file to provide it to all modules during initialization.
     37        if( arguments.read("-c", configFilename) || arguments.read("--config", configFilename) )
     38        {
     39                if( !osgDB::fileExists(configFilename) )
     40                        configFilename = "";
     41                else
     42                        OSG_ALWAYS << "Using configuration file: " << configFilename << std::endl;
     43        }
     44
     45xmlDoc* tmpDoc;
     46util::getModuleXMLConfig( configFilename, "core", tmpDoc );
     47if(tmpDoc)
     48{
     49        xmlFreeDoc(tmpDoc); xmlCleanupParser();
     50}
     51
     52
    3653        // Configure osg to use KdTrees
    3754        osgDB::Registry::instance()->setBuildKdTreesHint(osgDB::ReaderWriter::Options::BUILD_KDTREES);
     
    6380        // Initialize distortion
    6481        OSG_NOTIFY( osg::ALWAYS ) << "Using distortion." << std::endl;
    65         distortion = new visual_distortion( viewer, arguments );
     82        distortion = new visual_distortion( viewer, arguments, configFilename );
    6683        distortion->initialize( rootNode, viewer->getCamera()->getClearColor() );
    6784        distortedSceneGraph = distortion->getDistortedSceneGraph();
     
    7087#ifdef USE_SKY_SILVERLINING
    7188        // Initialize sky
    72         sky = new visual_skySilverLining( viewer );
    73         sky->init(distortedSceneGraph, rootNode);       // Without distortedSceneGraph=NULL
     89        sky = new visual_skySilverLining( viewer, configFilename );
     90        sky->init(distortedSceneGraph, rootNode);       // Without distortion: distortedSceneGraph=NULL
    7491#endif
    7592
    7693        // Initialize DataIO interface
    77         visual_dataIO::getInstance()->init(viewer, arguments);
    78 
    79         // Add manipulators for user interaction - after dataIO to be able to skip it in slaves.
     94        visual_dataIO::getInstance()->init(viewer, arguments, configFilename);
     95
     96        // Add manipulators for user interaction - after dataIO to be able to skip it in slaves rendering machines.
    8097        addManipulators();
    8198
     
    258275void visual_core::parseConfigFile(osg::ArgumentParser& arguments_)
    259276{
    260         configFileValid = false;
    261 
    262         std::string filename;
    263         if( arguments.read("-c", filename) || arguments.read("--config", filename) )
    264         {
    265                 OSG_ALWAYS << "Using configuration file.." << std::endl;
    266                 if( osgDB::fileExists(filename) )
     277        if( configFilename != "" )
     278        {
     279                xmlDoc *doc = NULL;
     280                xmlNode *root_element = NULL;
     281               
     282                doc = xmlReadFile(configFilename.c_str(), NULL, 0);
     283                if (doc == NULL)
    267284                {
    268                         configFileValid = false;
    269                         xmlDoc *doc = NULL;
    270                         xmlNode *root_element = NULL;
    271                        
    272                         doc = xmlReadFile(filename.c_str(), NULL, 0);
    273                         if (doc == NULL)
    274                         {
    275                                 configFileValid = false;
    276                                 OSG_ALWAYS << "visual_core::parseConfigFile() - ERROR: could not parse osgVisual config file" << filename  << std::endl;
    277                         }
    278                         else
    279                         {
    280                                 //  Get the root element node
    281                                 root_element = xmlDocGetRootElement(doc);
    282 
    283                                 // Parse the XML document.
    284                                 checkXMLNode(root_element);
    285 
    286                                 // free the document
    287                                 xmlFreeDoc(doc);;
    288                         }
    289                         // Free the global variables that may have been allocated by the parser.
    290                         xmlCleanupParser();
    291 
    292                         if(!configFileValid)
    293                                 OSG_ALWAYS << "visual_core::parseConfigFile() - ERROR: XML file seems not to be a valid osgVisual configuration file!" << std::endl;
    294 
    295                 }       // IF configfile exists
    296         }       // IF -c END
     285                        OSG_ALWAYS << "visual_core::parseConfigFile() - ERROR: could not parse osgVisual config file" << configFilename  << std::endl;
     286                }
     287                else
     288                {
     289                        //  Get the root element node
     290                        root_element = xmlDocGetRootElement(doc);
     291
     292                        // Parse the XML document.
     293                        checkXMLNode(root_element);
     294
     295                        // free the document
     296                        xmlFreeDoc(doc);;
     297                }
     298                // Free the global variables that may have been allocated by the parser.
     299                xmlCleanupParser();
     300
     301        }       // IF configfile exists
    297302}
    298303
     
    305310                {
    306311                        OSG_DEBUG << "XML node osgvisualconfiguration found" << std::endl;
    307                         configFileValid = true;
     312
    308313                        // Iterate to the next nodes to configure modules and scenery.
    309314                        checkXMLNode(cur_node->children);               
     
    352357                        enabled = false;
    353358
    354                 OSG_ALWAYS << "Module '" << name << "' found. Enabled = " << enabled << std::endl;
    355 
    356359                attr = attr->next;
    357360        }
     361        OSG_ALWAYS << "Module '" << name << "' found. Enabled = " << enabled << std::endl;
    358362
    359363        // Pass the nodes to the corresponding modules...
     
    412416
    413417        // Sky settings:       
    414         sky->setTime(12,00,23);
     418        sky->setTime(15,30,00);
    415419        sky->setVisibility(50000);
    416         sky->addWindVolume( 0.0, 15000.0, 50.0, 90.0 );
     420        sky->addWindVolume( 0.0, 15000.0, 25.0, 90.0 );
    417421       
    418422        //sky->addCloudLayer( 0, 20000, 20000, 600.0, 1000.0, 0.5, CUMULONIMBUS_CAPPILATUS );
    419423        //sky->addCloudLayer( 1, 5000000, 5000000, 600.0, 7351.0, 0.2, CIRRUS_FIBRATUS );
    420424        //sky->addCloudLayer( 2, 50000, 50000, 600.0, 7351.0, 0.2, CIRROCUMULUS );
    421         //sky->addCloudLayer( 3, 50000, 50000, 1300.0, 700.0, 0.07, CUMULUS_CONGESTUS );
    422         sky->addCloudLayer( 1, 100000, 100000, 3500.0, 2000.0, 0.60, STRATOCUMULUS );
     425        ///sky->addCloudLayer( 2, 100000, 100000, 600.0, 2351.0, 0.75, STRATUS );
     426        sky->addCloudLayer( 3, 50000, 50000, 1300.0, 700.0, 0.07, CUMULUS_CONGESTUS );
     427        //sky->addCloudLayer( 1, 100000, 100000, 3500.0, 2000.0, 0.50, STRATOCUMULUS );
    423428
    424429        //sky->setSlotPrecipitation( 1, 0.0, 0.0, 0.0, 25.0 );
  • osgVisual/src/dataIO/visual_dataIO.cpp

    r121 r144  
    4444};
    4545
    46 void visual_dataIO::init(osgViewer::Viewer* viewer_, osg::ArgumentParser& arguments_)
     46void visual_dataIO::init(osgViewer::Viewer* viewer_, osg::ArgumentParser& arguments_, std::string configFileName)
    4747{
    4848        OSG_NOTIFY( osg::ALWAYS ) << "visual_dataIO init()" << std::endl;
  • osgVisual/src/sky_Silverlining/skySilverLining_skyDrawable.cpp

    r143 r144  
    164164                        atmosphere->SetRightVector(-0.201185, 0.979553, 0.0);
    165165
    166                         /** \todo  :not working!! what is wrong? */
    167                         // override the some options of the configuration file with the required settings to make silverlining upgrades easier
    168                         OSG_ALWAYS << "atmosphere from space before : " << atmosphere->GetConfigOptionBoolean("enable-atmosphere-from-space") << std::endl;
    169                         atmosphere->SetConfigOption("enable-atmosphere-from-space", "yes");
    170                         atmosphere->SetConfigOption("draw-sun-below-horizon", "yes");
    171                         OSG_ALWAYS << "atmosphere from space after: " << atmosphere->GetConfigOptionBoolean("enable-atmosphere-from-space") << std::endl;
    172 
    173166            // Set our location (change this to your own latitude and longitude)
    174167            SilverLining::Location loc;
     
    256249                        cloudLayer_->SetLayerPosition( 0.0, 0.0 );
    257250                        cloudLayer_->GenerateShadowMaps(false);
    258                         cloudLayer_->SetIsInfinite( true );
     251                        //cloudLayer_->SetIsInfinite( true );
    259252
    260253
  • osgVisual/src/sky_Silverlining/visual_skySilverLining.cpp

    r143 r144  
    1919using namespace osgVisual;
    2020
    21 visual_skySilverLining::visual_skySilverLining(osgViewer::Viewer* viewer_)
     21visual_skySilverLining::visual_skySilverLining(osgViewer::Viewer* viewer_, std::string configFileName)
    2222{
    2323        OSG_NOTIFY( osg::ALWAYS ) << "Initialize visual_skySilverlining..." << std::endl;
  • osgVisual/src/util/visual_util.cpp

    r130 r144  
    2525util::~util(void)
    2626{
     27}
     28
     29xmlNode* util::getModuleXMLConfig(std::string configFilename, std::string moduleName, xmlDoc*& doc)
     30{
     31        doc = NULL;
     32        xmlNode *root_element = NULL;
     33
     34        // Check for valid parameters
     35        if(configFilename == "")
     36        {
     37                OSG_ALWAYS << "ERROR - util::getModuleXMLConfig() : Invalid Configuration Filename!" << std::endl;
     38                return NULL;
     39        }
     40        if(moduleName == "")
     41        {
     42                OSG_ALWAYS << "ERROR - util::getModuleXMLConfig() : Invalid Module Filename!" << std::endl;
     43                return NULL;
     44        }
     45
     46        // It is a valid XML document?
     47        doc = xmlReadFile(configFilename.c_str(), NULL, 0);     
     48        if (doc == NULL)
     49        {
     50                OSG_ALWAYS << "ERROR - util::getModuleXMLConfig() : " << configFilename << " is not a valid XML file!" << std::endl;
     51                return NULL;
     52        }
     53
     54        //  Get the root element node
     55        root_element = xmlDocGetRootElement(doc);
     56
     57        // Check if it is an osgVisual configuration file
     58        std::string node_name=reinterpret_cast<const char*>(root_element->name);
     59        if(!(root_element->type == XML_ELEMENT_NODE && node_name == "osgvisualconfiguration"))
     60        {
     61                OSG_ALWAYS << "ERROR - util::getModuleXMLConfig() : " << configFilename << " is not an osgVisual configuration file!" << std::endl;
     62                return NULL;
     63        }
     64
     65        // If file is a valid osgVisual config file, check all the root xml node and all of it's children of osgvisualconfiguration for the specified module
     66        xmlNode* tmpNode = checkXMLNodeChildrenForModule(root_element, moduleName);
     67
     68        if( !tmpNode ) // if no valid node was found: clena up. Otherwise: the caller has to clean up.
     69        {
     70                xmlFreeDoc(doc);        // free the document
     71                xmlCleanupParser();     // Free the global variables that may have been allocated by the parser.
     72                return NULL;
     73        }
     74        else
     75                return tmpNode;
     76
     77}
     78
     79xmlNode* util::checkXMLNodeChildrenForModule(xmlNode* node, std::string moduleName)
     80{
     81        for (xmlNode *cur_node = node; cur_node; cur_node = cur_node->next)     // iterate through all elements
     82        {
     83                // Is the node the one we are searching for?
     84                if (cur_node->type == XML_ELEMENT_NODE)
     85                {
     86                        std::string node_name=reinterpret_cast<const char*>(cur_node->name);
     87                        if (node_name == "module")
     88                        {
     89                                OSG_DEBUG << "XML node module found" << std::endl;
     90                                return cur_node;
     91                        }
     92                        else    // Otherwise: check its children..
     93                        {
     94                                xmlNode* tmp_XmlNode = checkXMLNodeChildrenForModule(cur_node->children, moduleName);
     95                                if(tmp_XmlNode)
     96                                        return tmp_XmlNode;
     97                        }
     98                }       // IF NODE TYPE = ELEMENT END
     99
     100                // Proceed with next node in this loop.
     101        }
    27102}
    28103
Note: See TracChangeset for help on using the changeset viewer.