osgEarth 2.1.1
Public Member Functions

ReaderWriterEarth Class Reference

List of all members.

Public Member Functions

 ReaderWriterEarth ()
virtual const char * className ()
virtual bool acceptsExtension (const std::string &extension) const
virtual ReadResult readObject (const std::string &file_name, const Options *options) const
virtual WriteResult writeNode (const osg::Node &node, const std::string &fileName, const Options *options) const
virtual WriteResult writeNode (const osg::Node &node, std::ostream &out, const Options *options) const
virtual ReadResult readNode (const std::string &fileName, const Options *options) const
virtual ReadResult readNode (std::istream &in, const Options *options) const

Detailed Description

Definition at line 35 of file ReaderWriterOsgEarth.cpp.


Constructor & Destructor Documentation

ReaderWriterEarth::ReaderWriterEarth ( ) [inline]

Definition at line 38 of file ReaderWriterOsgEarth.cpp.

{}

Member Function Documentation

virtual bool ReaderWriterEarth::acceptsExtension ( const std::string &  extension) const [inline, virtual]

Definition at line 45 of file ReaderWriterOsgEarth.cpp.

        {
            return osgDB::equalCaseInsensitive( extension, "earth" );
        }
virtual const char* ReaderWriterEarth::className ( ) [inline, virtual]

Definition at line 40 of file ReaderWriterOsgEarth.cpp.

        {
            return "OSG Earth ReaderWriter";
        }
virtual ReadResult ReaderWriterEarth::readNode ( std::istream &  in,
const Options *  options 
) const [inline, virtual]

Definition at line 131 of file ReaderWriterOsgEarth.cpp.

        {
            // pull the URI context from the options structure (since we're reading
            // from an "anonymous" stream here)
            URIContext uriContext( options );            

            osg::ref_ptr<XmlDocument> doc = XmlDocument::load( in, uriContext );            
            if ( !doc.valid() )
                return ReadResult::ERROR_IN_READING_FILE;

            Config docConf = doc->getConfig();

            // support both "map" and "earth" tag names at the top level
            Config conf;
            if ( docConf.hasChild( "map" ) )
                conf = docConf.child( "map" );
            else if ( docConf.hasChild( "earth" ) )
                conf = docConf.child( "earth" );

            MapNode* mapNode =0L;
            if ( !conf.empty() )
            {
                // see if we were given a reference URI to use:
                std::string refURI = uriContext.referrer();                                

                if ( conf.value("version") == "2" )
                {
                    OE_INFO << LC << "Detected a version 2.x earth file" << std::endl;
                    EarthFileSerializer2 ser;
                    mapNode = ser.deserialize( conf, refURI );
                }
                else
                {
                    OE_INFO << LC << "Detected a version 1.x earth file" << std::endl;
                    EarthFileSerializer1 ser;
                    mapNode = ser.deserialize( conf, refURI );
                }
            }

            return ReadResult(mapNode);
        }

Here is the call graph for this function:

virtual ReadResult ReaderWriterEarth::readNode ( const std::string &  fileName,
const Options *  options 
) const [inline, virtual]

Definition at line 85 of file ReaderWriterOsgEarth.cpp.

        {
            std::string ext = osgDB::getFileExtension( fileName );
            if ( !acceptsExtension( ext ) )
                return ReadResult::FILE_NOT_HANDLED;

            // See if the filename starts with server: and strip it off.  This will trick OSG into
            // passing in the filename to our plugin instead of using the CURL plugin if the filename
            // contains a URL.  So, if you want to read a URL, you can use the following format
            // osgDB::readNodeFile("server:http://myserver/myearth.earth").  This should only be
            // necessary for the first level as the other files will have a tilekey prepended to them.
            if ((fileName.length() > 7) && (fileName.substr(0, 7) == "server:"))
                return readNode(fileName.substr(7), options);            

            if ( fileName == "__globe.earth" )
            {
                return ReadResult( new MapNode() );
            }

            else if ( fileName == "__cube.earth" )
            {
                MapOptions options;
                options.coordSysType() = MapOptions::CSTYPE_GEOCENTRIC_CUBE;
                return ReadResult( new MapNode( new Map(options) ) );
            }

            else
            {
                std::string buf;
                if ( HTTPClient::readString( fileName, buf ) != HTTPClient::RESULT_OK )
                    return ReadResult::ERROR_IN_READING_FILE;

                // Since we're now passing off control to the stream, we have to pass along the
                // reference URI as well..
                osg::ref_ptr<Options> myOptions = options ? 
                    static_cast<Options*>(options->clone(osg::CopyOp::DEEP_COPY_ALL)) : 
                    new Options();

                URIContext( fileName ).store( myOptions.get() );
                //myOptions->setPluginData( "__ReaderWriterOsgEarth::ref_uri", (void*)&fileName );

                std::stringstream in( buf );
                return readNode( in, myOptions.get() );
            }
        }

Here is the call graph for this function:

virtual ReadResult ReaderWriterEarth::readObject ( const std::string &  file_name,
const Options *  options 
) const [inline, virtual]

Definition at line 50 of file ReaderWriterOsgEarth.cpp.

        {
            return readNode( file_name, options );
        }
virtual WriteResult ReaderWriterEarth::writeNode ( const osg::Node &  node,
std::ostream &  out,
const Options *  options 
) const [inline, virtual]

Definition at line 67 of file ReaderWriterOsgEarth.cpp.

        {
            osg::Node* searchNode = const_cast<osg::Node*>( &node );
            MapNode* mapNode = MapNode::findMapNode( searchNode );
            if ( !mapNode )
                return WriteResult::ERROR_IN_WRITING_FILE; // i.e., no MapNode found in the graph.

            // serialize the map node to a generic Config object:
            EarthFileSerializer2 ser;
            Config conf = ser.serialize( mapNode );

            // dump that Config out as XML.
            osg::ref_ptr<XmlDocument> xml = new XmlDocument( conf );
            xml->store( out );

            return WriteResult::FILE_SAVED;
        }

Here is the call graph for this function:

virtual WriteResult ReaderWriterEarth::writeNode ( const osg::Node &  node,
const std::string &  fileName,
const Options *  options 
) const [inline, virtual]

Definition at line 55 of file ReaderWriterOsgEarth.cpp.

        {
            if ( !acceptsExtension( osgDB::getFileExtension(fileName) ) )
                return WriteResult::FILE_NOT_HANDLED;

            std::ofstream out( fileName.c_str());
            if ( out.is_open() )
                return writeNode( node, out, options );

            return WriteResult::ERROR_IN_WRITING_FILE;            
        }

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines