示例#1
0
bool SceneFileHandlerBase::write(Node  * const  node,
                                 Char8   const *fileName,
                                 bool           compress)
{
    bool           retCode = false;
    SceneFileType *type    = getFileType(fileName);

    if(type != NULL)
    {
        updateWriteProgress(0);
        triggerWriteBegin(fileName);
        
        SINFO << "try to write "
              << fileName
              << " as "
              << type->getName()
              << std::endl;

        std::ofstream out(fileName, std::ios::binary);

        if(out)
        {
            retCode = write(node, out, fileName, compress);
            out.close();
        }
        else
        {
            SWARNING << "Can not open output stream for file '"
                     << fileName
                     << "'!"
                     << std::endl;
        }

#ifndef OSG_DISABLE_DEPRECATED
        if(!retCode)
        {
            retCode = type->writeFile(node, fileName);
        }
#endif

        if(!retCode)
        {
            SWARNING << "Couldn't write " << fileName << std::endl;
        }
        else
        {
            triggerWriteEnd(fileName);
        }
    }
    else
        SWARNING << "can't write "
                 << fileName
                 << "; unknown scene format"
                 << std::endl;

    return retCode;
}
示例#2
0
bool SceneFileHandlerBase::write(Node         * const  node,
                                 std::ostream         &os,
                                 Char8          const *fileNameOrExtension,
                                 bool                  compress           )
{
    bool           retCode = false;
    SceneFileType *type    = getFileType(fileNameOrExtension);

    if(type != NULL)
    {
        updateWriteProgress(0);

        SINFO << "try to write stream as " << type->getName() << std::endl;

        if(_writeFP != NULL)
        {
            retCode = _writeFP(type, node, os, fileNameOrExtension, compress);
        }
        else
        {
            if(compress == true)
            {
#ifdef OSG_WITH_ZLIB
                SINFO << "writing compressed stream." << std::endl;

                zip_ostream zipper(os, true);

                retCode = type->write(node, zipper, fileNameOrExtension);

                zipper.zflush();
#else
                SFATAL << "Compressed streams are not supported! Build "
                       << "with zlib= options."
                       << std::endl;
#endif
            }
            else
            {
                retCode = type->write(node, os, fileNameOrExtension);
            }
        }
    }
    else
    {
        SWARNING << "can't write stream unknown scene format" << std::endl;
    }

    return retCode;
}
示例#3
0
//----------------------------
// Function name: write
//----------------------------
//
//Parameters:
//p: const Scene &image, const char *fileName
//GlobalVars:
//g:
//Returns:
//r:bool
// Caution
//c:
//Assumations:
//a:
//Describtions:
//d:
//SeeAlso:
//s:
//
//------------------------------
bool SceneFileHandler::write(const NodePtr &node, std::ostream &os,
                             const Char8 *fileNameOrExtension, bool compress)
{
    bool retCode = false;
    SceneFileType *type = getFileType(fileNameOrExtension);

    if(type)
    {
        updateWriteProgress(0);
        SINFO << "try to write stream as " << type->getName() << std::endl;

        if(_writeFP != NULL)
        {
            retCode = _writeFP(type, node, os, fileNameOrExtension, compress);
        }
        else
        {
            if(compress)
            {
#ifdef OSG_ZSTREAM_SUPPORTED
                SINFO << "writing compressed stream." << std::endl;
                zip_ostream zipper(os, true);
                retCode = type->write(node, zipper, fileNameOrExtension);
                zipper.zflush();
#else
                SFATAL << "Compressed streams are not supported! Configure with --enable-png --with-png=DIR options." << std::endl;
#endif
            }
            else
            {
                retCode = type->write(node, os, fileNameOrExtension);
            }
        }
    }
    else
        SWARNING << "can't write stream unknown scene format" << std::endl;

    return retCode;
}
示例#4
0
NodeTransitPtr SceneFileHandlerBase::read(const Char8      *fileName,
                                                GraphOpSeq *graphOpSeq,       
                                                Resolver    resolver,
                                                bool        bWarnNotFound )
{
    NodeTransitPtr returnValue(NULL);

    if(fileName == NULL)
    {
        SWARNING << "cannot read NULL file" << std::endl;
        return NodeTransitPtr(NULL);
    }

    std::string fullFilePath = initPathHandler(fileName);

    if(fullFilePath.empty() == true)
    {
        if(_readFP != NULL)
        {
            // that's a fallback could be a url so the callback
            // can handle this correctly.
            SceneFileType *type = getFileType(fileName);
            if(type != NULL)
            {
                // create a dummy stream with the bad flag set.
                std::ifstream in;
                in.setstate(std::ios::badbit);
                returnValue = _readFP(type, in, fileName);
            }
            else
            {
                if(bWarnNotFound == true)
                    SWARNING << "Couldn't open file " << fileName << std::endl;
            }
        }
        else
        {
            if(bWarnNotFound == true)
                SWARNING << "Couldn't open file " << fileName << std::endl;
        }

        commitChanges();

        return returnValue;
    }


    SceneFileType *type  = getFileType(fullFilePath.c_str());
    NodeUnrecPtr   scene = NULL;

    if(type != NULL)
    {
        triggerReadBegin(fullFilePath.c_str());
        updateReadProgress(0);

        SINFO << "try to read " << fullFilePath
              << " as "         << type->getName() << std::endl;

        std::ifstream in(fullFilePath.c_str(), std::ios::binary);

        if(in)
        {
            scene = read(in, fullFilePath.c_str(), graphOpSeq);

            in.close();

            if(scene != NULL)
            {
                triggerReadEnd(fullFilePath.c_str());

                FileContextAttachmentUnrecPtr pFContext = 
                    dynamic_cast<FileContextAttachment *>(
                        scene->findAttachment(
                            FileContextAttachment::getClassGroupId()));

                if(pFContext == NULL)
                {
                    pFContext = FileContextAttachment::create();

                    pFContext->setResolvedName(fullFilePath);

                    scene->addAttachment(pFContext);
                }
            }
        }
        else
        {
            if(bWarnNotFound == true)
            {
                SWARNING << "Couldn't open input stream for file "
                         << fullFilePath
                         << std::endl;
            }
        }

#ifndef OSG_DISABLE_DEPRECATED

        // Ok stream interface didn't work try via filename
        if(scene == NULL)
            scene = type->readFile(fullFilePath.c_str());

        if(scene != NULL)
        {
            if(graphOpSeq != NULL)
                graphOpSeq->run(scene);

            SINFO    << "read ok:"        << std::endl;
        }
        else
        {
            if(bWarnNotFound == true)
                SWARNING << "could not read " << std::endl;
        }
#endif

#if 0
        if(scene != NULL && graphOpSeq != NULL)
        {
            SINFO    << "Running GraphOps..." << std::endl;
            graphOpSeq->run(scene);
        }
#endif
    }
    else
    {
        if(bWarnNotFound == true)
        {
            SWARNING << "could not read "       << fullFilePath
                     << "; unknown file format" << std::endl;
        }
    }

    commitChanges();

    return NodeTransitPtr(scene);
}
示例#5
0
NodeTransitPtr SceneFileHandlerBase::read(
          std::istream &is,
    const Char8        *fileNameOrExtension,
          GraphOpSeq   *graphOpSeq         ,       
          Resolver      resolver           )
{
    SceneFileType *type  = getFileType(fileNameOrExtension);
    NodeUnrecPtr   scene = NULL;

    if(!fileNameOrExtension)
    {
        SWARNING << "cannot read NULL extension" << std::endl;
        return NodeTransitPtr(scene);
    }

    if(type != NULL)
    {
        SINFO << "try to read stream as " << type->getName() << std::endl;

        // check for fileio read callback
        if(_readFP != NULL)
        {
            initReadProgress(is);
            scene = _readFP(type, is, fileNameOrExtension);
            terminateReadProgress();
        }
        else
        {
            if(isGZip(is))
            {
                SINFO << "Detected gzip compressed stream." << std::endl;

#ifdef OSG_WITH_ZLIB

                initReadProgress(is);

                zip_istream unzipper(is);

                scene = type->read(unzipper, 
                                   fileNameOrExtension, 
                                   resolver ? resolver : _oGlobalResolver);

                if(scene != NULL)
                {
                    if(unzipper.check_crc() == true)
                    {
                        SINFO << "Compressed stream has correct checksum."
                              << std::endl;
                    }
                    else
                    {
                        SWARNING << "Compressed stream has wrong checksum."
                                 << std::endl;
                    }
                }
                terminateReadProgress();
#else
                SFATAL << "Compressed streams are not supported! Configure "
                       << "with --enable-png --with-png=DIR options."
                       << std::endl;
#endif
            }
            else
            {
                initReadProgress(is);

                scene = type->read(is, 
                                   fileNameOrExtension, 
                                   resolver  ? resolver : _oGlobalResolver);

                terminateReadProgress();
            }
        }

        if(scene != NULL)
        {
            if(graphOpSeq != NULL)
                graphOpSeq->traverse(scene);

            SINFO    << "read ok:"        << std::endl;
        }
        else
        {
            SWARNING << "could not read " << std::endl;
        }
    }
    else
    {
        SWARNING << "could not read unknown file format" << std::endl;
    }

    commitChanges();

    return NodeTransitPtr(scene);
}
示例#6
0
NodePtr SceneFileHandler::read(const  Char8  *fileName,
                               GraphOpSeq *graphOpSeq)
{
    if(!fileName)
    {
        SWARNING << "cannot read NULL file" << std::endl;
        return NullFC;
    }

    std::string fullFilePath = initPathHandler(fileName);
    if(fullFilePath.empty())
    {
        if(_readFP != NULL)
        {
            // that's a fallback could be a url so the callback
            // can handle this correctly.
            SceneFileType *type = getFileType(fileName);
            if(type != NULL)
            {
                // create a dummy stream with the bad flag set.
                std::ifstream in;
                in.setstate(std::ios::badbit);
                return _readFP(type, in, fileName);
            }
            else
            {
                SWARNING << "Couldn't open file " << fileName << std::endl;
                return NullFC;
            }
        }
        else
        {
            SWARNING << "Couldn't open file " << fileName << std::endl;
            return NullFC;
        }
    }

    SceneFileType *type = getFileType(fullFilePath.c_str());
    NodePtr scene = NullFC;

    if (type)
    {
        triggerReadBegin(fullFilePath.c_str());
        updateReadProgress(0);

        SINFO << "try to read " << fullFilePath
              << " as "         << type->getName() << std::endl;

        std::ifstream in(fullFilePath.c_str(), std::ios::binary);

        if(in)
        {
            scene = read(in, fullFilePath.c_str(), graphOpSeq);
            in.close();

            if(scene != NullFC)
            {
                triggerReadEnd(fullFilePath.c_str());
                return scene;
            }
        }
        else
        {
            SWARNING << "Couldn't open input stream for file " << fullFilePath << std::endl;
        }



#ifndef OSG_DISABLE_DEPRECATED
        // Ok stream interface didn't work try via filename
        if(scene == NullFC)
            scene = type->readFile(fullFilePath.c_str());

        if (scene != NullFC)
        {
            if(graphOpSeq != NULL)
                graphOpSeq->run(scene);

            SINFO    << "read ok:"        << std::endl;
        }
        else
        {
            SWARNING << "could not read " << std::endl;
        }
#endif
    }
    else
    {
        SWARNING << "could not read "       << fullFilePath
                 << "; unknown file format" << std::endl;
    }

    return scene;
}
示例#7
0
NodePtr SceneFileHandler::read(std::istream &is, const Char8* fileNameOrExtension,
                               GraphOpSeq *graphOpSeq)
{
    SceneFileType *type = getFileType(fileNameOrExtension);
    NodePtr        scene = NullFC;

    if(!fileNameOrExtension)
    {
        SWARNING << "cannot read NULL extension" << std::endl;
        return NullFC;
    }

    if (type)
    {
        SINFO << "try to read stream as " << type->getName() << std::endl;

        // check for fileio read callback
        if(_readFP != NULL)
        {
            initReadProgress(is);
            scene = _readFP(type, is, fileNameOrExtension);
            terminateReadProgress();
        }
        else
        {
            if(isGZip(is))
            {
                SINFO << "Detected gzip compressed stream." << std::endl;

#ifdef OSG_ZSTREAM_SUPPORTED
                initReadProgress(is);
                zip_istream unzipper(is);
                scene = type->read(unzipper, fileNameOrExtension);
                if(scene != NullFC)
                {
                    if(unzipper.check_crc())
                        SINFO << "Compressed stream has correct checksum." << std::endl;
                    else
                        SFATAL << "Compressed stream has wrong checksum." << std::endl;
                }
                terminateReadProgress();
#else
                SFATAL << "Compressed streams are not supported! Configure with --enable-png --with-png=DIR options." << std::endl;
#endif
            }
            else
            {
                initReadProgress(is);
                scene = type->read(is, fileNameOrExtension);
                terminateReadProgress();
            }
        }

        if(scene != NullFC)
        {
            if(graphOpSeq != NULL)
                graphOpSeq->run(scene);

            SINFO    << "read ok:"        << std::endl;
        }
        else
        {
            SWARNING << "could not read " << std::endl;
        }
    }
    else
    {
        SWARNING << "could not read unknown file format" << std::endl;
    }

    return scene;
}