コード例 #1
0
SceneFileHandler::FCPtrStore SceneFileHandler::readTopNodes(
    const  Char8  *fileName,
    GraphOpSeq *graphOpSeq)
{
    std::vector<FieldContainerPtr> nodeVec;

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

    std::string fullFilePath = initPathHandler(fileName);
    if(fullFilePath.empty())
    {
        SWARNING << "Couldn't open file " << fileName << std::endl;
        return nodeVec;
    }

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

    if(in)
    {
        nodeVec = readTopNodes(in, fullFilePath.c_str(), graphOpSeq);
        in.close();
    }
    else
    {
        SWARNING << "Couldn't open input stream for file " << fullFilePath << std::endl;
    }

    // Ok stream interface didn't work try via filename
    if(nodeVec.empty())
    {
        NodePtr scene = read(fullFilePath.c_str());
        if(scene == NullFC)
            return nodeVec;

        while(scene->getNChildren() > 0)
        {
            NodePtr child = scene->getChild(0);
            NodePtr newChild = Node::create();
            while(child->getNChildren() > 0)
                newChild->addChild(child->getChild(0));
            newChild->setCore(child->getCore());
            if(graphOpSeq != NULL)
                graphOpSeq->run(newChild);
            nodeVec.push_back(newChild);
            scene->subChild(child);
        }
    }

    return nodeVec;
}
コード例 #2
0
 FCFileHandlerBase::FCPtrStore FCFileHandlerBase::read(const BoostPath& FilePath)
 {
	 FCPtrStore Result;
	 //Determine if the file exists
	 if(!boost::filesystem::exists(FilePath))
	 {
		SWARNING << "FCFileHandlerBase::read(): " << FilePath.string() << " does not exists." << std::endl;
		return Result;
	 }

	 std::string filename = initPathHandler(FilePath.string().c_str());

	 //Determine the file extension
	 std::string Extension(boost::filesystem::extension(FilePath));
	 boost::algorithm::trim_if(Extension,boost::is_any_of("."));

     //Get the Parent Directory Path of the file
     _RootFilePath = FilePath;
     _RootFilePath.remove_leaf();

	 //Get the FileType for this extension
	 FCFileTypeP TheFileType(getFileType(Extension, FCFileType::OSG_READ_SUPPORTED));

	 //Is that extension supported for reading
	 if(TheFileType == NULL)
	 {
		SWARNING << "FCFileHandlerBase::read(): Cannot read Field Container file: " << FilePath.string() << ", because no File types support " << Extension <<  " extension." << std::endl;
		return Result;
	 }
	 else
	 {
		 //Open up the input stream of the file
		 std::ifstream InputStream(FilePath.string().c_str(), std::ios::binary);

		 if(!InputStream)
		 {
			SWARNING << "FCFileHandlerBase::read(): Couldn't open input stream for file " << FilePath.string() << std::endl;
			return Result;
		 }
		 else
		 {
             //Read from the input stream
             startReadProgressThread(InputStream);
             Result = TheFileType->read(InputStream, FilePath.string());
             stopReadProgressThread();
             
			 InputStream.close();
		 }
	 }

	 return Result;
 }
コード例 #3
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);
}
コード例 #4
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;
}