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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 );
Note: See TracChangeset for help on using the changeset viewer.