Esempio n. 1
0
void SceneFileHandlerBase::print (void )
{
    FileTypeMap::iterator sI;

    for(sI = _suffixTypeMap.begin(); sI != _suffixTypeMap.end(); sI++)
    {
        std::string    rw;
        SceneFileType *type = sI->second->front();

        if((type->getFlags() & SceneFileType::OSG_READ_SUPPORTED) &&
           (type->getFlags() & SceneFileType::OSG_WRITE_SUPPORTED))
        {
            rw = "reader and writer";
        }
        else
        {
            if(type->getFlags() & SceneFileType::OSG_READ_SUPPORTED)
                rw = "reader";

            if(type->getFlags() & SceneFileType::OSG_WRITE_SUPPORTED)
                rw = "writer";
        }

        std::cerr << "suffix: " << sI->first.c_str()
                  << ", type: " << sI->second->front()->getName()
                  << " "        << rw
                  << std::endl;
    }
}
Esempio n. 2
0
bool SceneFileHandler::subSceneFileType(SceneFileType &fileType)
{
    bool retCode = false;

    std::list<IDString>::iterator sI;
    FileTypeMap   ::iterator smI;

    IDString suffix;

    for(  sI  = fileType.suffixList().begin();
            sI != fileType.suffixList().end();
            ++sI)
    {
        suffix.set(sI->str());
        suffix.toLower();

        smI = the()._suffixTypeMap.find(suffix);
        if (smI != the()._suffixTypeMap.end())
        {
            the()._suffixTypeMap.erase(smI);
            retCode = true;
        }
    }
    return retCode;
}
Esempio n. 3
0
bool SceneFileHandlerBase::subSceneFileType(SceneFileType &fileType)
{
    bool retCode = false;

    std::list<std::string>::iterator sI;
         FileTypeMap      ::iterator smI;

    std::string suffix;

    for(  sI  = fileType.suffixList().begin();
          sI != fileType.suffixList().end();
        ++sI)
    {
        suffix.assign(sI->c_str());
        //suffix.toLower();
        std::transform(suffix.begin(), suffix.end(), suffix.begin(), ::tolower);
        smI = _suffixTypeMap.find(suffix);

        if (smI != _suffixTypeMap.end())
        {
            _suffixTypeMap.erase(smI);
            retCode = true;
        }
    }
    return retCode;
}
Esempio n. 4
0
void SceneFileHandlerBase::popOptions(const std::string &suffix)
{
    SceneFileType *type   = getFileType(suffix.c_str());

    if(type != NULL)
    {
        type->popOptions();
    }
}
Esempio n. 5
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;
}
Esempio n. 6
0
void SceneFileHandlerBase::pushOptions(const std::string &suffix,
                                             bool         copyTop)
{
    SceneFileType *type   = getFileType(suffix.c_str());

    if(type != NULL)
    {
        type->pushOptions(copyTop);
    }
}
Esempio n. 7
0
const Char8 *SceneFileHandler::getOptions(const Char8 *suffix)
{
    if(suffix == NULL)
        return NULL;

    SceneFileType *type = getFileType(suffix);

    if(type == NULL)
        return NULL;

    return type->getOptions();
}
Esempio n. 8
0
bool SceneFileHandler::setOptions(const Char8 *suffix, const Char8 *options)
{
    if(suffix == NULL)
        return false;

    SceneFileType *type = getFileType(suffix);
    if(type == NULL)
        return false;

    type->setOptions(options);

    return true;
}
Esempio n. 9
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;
}
Esempio n. 10
0
/*! Removes the option \a name from the ImageFileType that handles files
    with the given \a suffix. If the option is not present \c false is
    returned, \c true otherwise.

    \param[in] suffix File extension to choose the scene file type
                      this option applies to.
    \param[in] name Name of the option.
    \return Whether the option was successfully removed.
 */
bool
    SceneFileHandlerBase::unsetOption(
        const std::string &suffix,
        const std::string &name   )
{
    bool           retVal = false;
    SceneFileType *type   = getFileType(suffix.c_str());
    
    if(type != NULL)
    {
        retVal = type->unsetOption(name);
    }
    
    return retVal;
}
Esempio n. 11
0
Int32 SceneFileHandler::getSuffixList(std::list<const Char8 *> & suffixList,
                                      UInt32 flags)
{
    Int32                 count = 0;
    FileTypeMap::iterator sI;

    suffixList.clear();

    for ( sI = _suffixTypeMap.begin(); sI != _suffixTypeMap.end(); ++sI)
    {
        SceneFileType *type = sI->second->front();
        if((type->getFlags() & flags) == flags)
        {
            suffixList.push_back(sI->first.str());
            count++;
        }
    }

    return count;
}
Esempio n. 12
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;
}
Esempio n. 13
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);
}
Esempio n. 14
0
bool SceneFileHandlerBase::addSceneFileType(SceneFileType &fileType)
{
    bool retCode = false;

    std::list<std::string>::iterator sI;
         FileTypeMap      ::iterator smI;

    std::string suffix;

    for(  sI  = fileType.suffixList().begin();
          sI != fileType.suffixList().end();
        ++sI)
    {
        suffix.assign (sI->c_str());
//        suffix.toLower();
        std::transform(suffix.begin(), suffix.end(), suffix.begin(), ::tolower);

        smI = _suffixTypeMap.find(suffix);

        if (smI != _suffixTypeMap.end())
        {
            if(fileType.doOverride() == true)
            {
                FindOverride           overrideFinder;
                FileTypeList::iterator lIt;

                overrideFinder.uiRefPriority = fileType.getOverridePriority();

                lIt = std::find_if(_suffixTypeMap[suffix]->begin(),
                                   _suffixTypeMap[suffix]->end  (),
                                   overrideFinder);

                _suffixTypeMap[suffix]->insert(lIt, &fileType);

                SWARNING << "Added an file type with suffix "
                         << suffix
                         << " overriding "
                         << std::endl;
            }
            else
            {
                _suffixTypeMap[suffix]->push_back(&fileType);

                SWARNING << "Added an file type with suffix "
                         << suffix
                         << " non overriding at the end of the list"
                         << std::endl;
            }
        }
        else
        {
            FileTypeList *pTmpList = new FileTypeList;

            pTmpList->push_back(&fileType);

            _suffixTypeMap[suffix] = pTmpList;

            retCode = true;
        }
    }

    return retCode;
}
Esempio n. 15
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;
}
Esempio n. 16
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);
}
Esempio n. 17
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;
}