Alembic::Abc::IObject getObjectFromArchive(XSI::CString path, XSI::CString identifier)
{
  Alembic::Abc::IArchive * archive = getArchiveFromID(path);
  if(archive == NULL)
    return Alembic::Abc::IObject();

  // split the path
  std::string stdIdentifier(identifier.GetAsciiString());
  std::vector<std::string> parts;
  boost::split(parts, stdIdentifier, boost::is_any_of("/"));

  // recurse to find it
  Alembic::Abc::IObject obj = archive->getTop();
  for(size_t i=1;i<parts.size();i++)
  {
    Alembic::Abc::IObject child(obj,parts[i]);
    obj = child;
  }

  return obj;
}
예제 #2
0
파일: AbcLs.cpp 프로젝트: alembic/alembic
//-*****************************************************************************
int main( int argc, char *argv[] )
{
    //float opt_fps = 24.0;
    bool opt_all = false; // show all option
    bool opt_long = false; // long listing option
    bool opt_meta = false; // metadata option
    bool opt_recursive = false; // recursive option
    bool opt_size = false; // array sample size option
    bool opt_time = false; // time info option
    bool opt_values = false; // show all 0th values
    int index = -1; // sample number, at tail of path
    std::string desc( "abcls [OPTION] FILE[/NAME] \n"
    "  -a          include property listings\n"
    "  -f          show time sampling as 24 fps\n"
    "  -h, --help  show this help message\n"
    "  -l          long listing format\n"
    "  -m          show archive metadata\n"
    "  -r          list entries recursively\n"
    "  -s          show the size of a data property sample\n"
    "  -t          show time sampling information\n"
    "  -v          show 0th value for all properties\n"
    );

    /* sigaction if available */
#if defined(_POSIX_VERSION) && (_POSIX_VERSION >= 199506L)
    // seg fault handler
    struct sigaction act;
    sigemptyset(&act.sa_mask);
    act.sa_handler = segfault_sigaction;
    act.sa_flags = SA_SIGINFO;
    sigaction(SIGSEGV, &act, NULL);
    /* signal if available */
#elif defined(_POSIX_VERSION) || defined(_MSC_VER)
    signal(SIGSEGV, segfault_sigaction);
#else
#error No signal interface available
#endif //_POSIX_VERSION

    // check for min args
    if ( argc < 2 ) {
        std::cout << desc << std::endl;
        return 0;
    };

    // parse args
    std::vector<std::string> arguments(argv, argv + argc);
    std::vector<std::string> options;
    std::vector<std::string> files;

    // separate file args from option args
    for ( std::size_t i = 1; i < arguments.size(); i++ ) {
        if ( arguments[ i ].substr( 0, 1 ) == "-" )
            options.push_back( arguments[ i ] );
        else
            files.push_back( arguments[ i ] );
    }

    // help
    if ( argc < 2 ||
         optionExists( options, "h" ) ||
         optionExists( options, "help" )
       ) {
        std::cout << desc << std::endl;
        return 0;
    };

    // set some flags
    double fps = 1.0;
    opt_all = optionExists( options, "a" );
    opt_long = optionExists( options, "l" );
    opt_meta = optionExists( options, "m" );
    opt_recursive = optionExists( options, "r" );
    opt_size = optionExists( options, "s" );
    opt_time = optionExists( options, "t" );
    opt_values = optionExists( options, "v" );
    if ( optionExists( options, "f" ) ) {
        fps = 24.0;
        opt_time = true;
    }

    // open each file
    for ( std::size_t i = 0; i < files.size(); i++ ) {
        if ( files.size() > 1 )
            std::cout << BOLD << files[i] << ':' << RESETCOLOR << std::endl;

        std::stringstream ss( files[i] );
        std::stringstream fp;
        std::string segment;
        std::vector<std::string> seglist;

        /*
         * separate file and object paths, e.g.
         *
         *   ../dir1/foo.abc/bar/baz/index
         *   \_____________/\______/\____/
         *        file         obj   sample
         */
        int j = 0;
        while ( std::getline( ss, segment, '/' ) ) {
            if ( !isFile ( fp.str() ) ) {
                if ( j != 0 )
                    fp << "/";
                fp << segment;
            } else {
                seglist.push_back( segment );
            }
            ++j;
        }

        bool lastIsIndex = false;
        if (!seglist.empty() && is_digit( seglist.back() ) ) {
            index = atoi( seglist.back().c_str() );
            lastIsIndex = true;
        }

        // open the iarchive
        Abc::IArchive archive;
        AbcF::IFactory factory;
        factory.setPolicy(Abc::ErrorHandler::kQuietNoopPolicy);
        AbcF::IFactory::CoreType coreType;
        archive = factory.getArchive(std::string( fp.str() ), coreType);

        // display file metadata
        if ( opt_meta && seglist.size() == 0 ) {
            std::cout  << "Using "
                       << Alembic::AbcCoreAbstract::GetLibraryVersion()
                       << std::endl;;

            std::string appName;
            std::string libraryVersionString;
            Alembic::Util::uint32_t libraryVersion;
            std::string whenWritten;
            std::string userDescription;
            std::string coreName;
            GetArchiveInfo (archive,
                            appName,
                            libraryVersionString,
                            libraryVersion,
                            whenWritten,
                            userDescription);

            if ( coreType == AbcF::IFactory::kOgawa ) {
                coreName = "Ogawa";
            } else if ( coreType == AbcF::IFactory::kHDF5 ) {
                coreName = "HDF5";
            } else {
                coreName = "Unknown";
            };

            if ( appName != "" ) {
                std::cout << "  file written by: " << appName << std::endl;
                std::cout << "  using Alembic : " << libraryVersionString << std::endl;
                std::cout << "  written on : " << whenWritten << std::endl;
                std::cout << "  user description : " << userDescription << std::endl;
            } else {
                std::cout << "  (file doesn't have any ArchiveInfo)"
                          << std::endl;
            }
            std::cout << "  core type : " << coreName << std::endl;
        };

        if ( opt_time && seglist.size() == 0 ) {
            uint32_t numTimes = archive.getNumTimeSamplings();
            std::cout << std::endl << "Time Samplings: " << std::endl;
            for ( uint32_t k = 0; k < numTimes; ++k ) {
                AbcA::TimeSamplingPtr ts = archive.getTimeSampling( k );
                index_t maxSample =
                    archive.getMaxNumSamplesForTimeSamplingIndex( k );
                std::cout << k << " ";
                printTimeSampling( ts, maxSample, fps );
            }
            std::cout << std::endl;

        }

        // walk object hierarchy and find valid objects
        AbcG::IObject test = archive.getTop();
        AbcG::IObject iObj = test;
        while ( test.valid() && seglist.size() > 0 ) {
            test = test.getChild( seglist.front() );
            if ( test.valid() ) {
                iObj = test;
                seglist.erase( seglist.begin() );
            }
        }

        // walk property hierarchy for most recent object
        Abc::ICompoundProperty props = iObj.getProperties();
        const Abc::PropertyHeader* header;
        bool found = false;
        bool shouldPrintValue = false;
        for ( std::size_t i = 0; i < seglist.size(); ++i ) {
            header = props.getPropertyHeader( seglist[i] );
            if ( header && header->isCompound() ) {
                Abc::ICompoundProperty ptest( props, header->getName() );
                if ( ptest.valid() ) {
                    props = ptest;
                    found = true;
                }
            } else if ( header && header->isSimple() ) {
                found = true;

                // if the last value happens to be an index, and we are a
                // property  then dont bother checking the last item in seglist
                if (lastIsIndex && i == seglist.size() - 2)
                {
                    shouldPrintValue = true;
                    break;
                }
            } else {
                std::cout << seglist[i]
                          << ": Invalid object or property"
                          << std::endl;
                return 1;
            }
        }

        // do stuff
        if ( shouldPrintValue ) {
            printValue( props, *header, index, opt_size, opt_time, fps );
        } else {
            if ( found && header->isCompound() )
                visit( props, opt_all, opt_long, opt_meta, opt_recursive, true, opt_values );
            else if ( found && header->isSimple() )
                printChild( props, *header, opt_all, opt_long, opt_values );
            else
                visit( iObj, opt_all, opt_long, opt_meta, opt_recursive, true, opt_values );
            std::cout << RESETCOLOR;
            if ( !opt_long )
                std::cout << std::endl;
        }
    }
    return 0;
}
int main(int argc, char *argv[])
{
    ConversionOptions options;
    bool doConversion = false;

    if (parseArgs( argc, argv, options, doConversion ) == false)
        return 1;

    if (doConversion)
    {
        for( std::vector<std::string>::const_iterator inFile = options.inFiles.begin(); inFile != options.inFiles.end(); inFile++ )
        {
            if (*inFile == options.outFile)
            {
                printf("Error: inFile and outFile must not be the same!\n");
                return 1;
            }
        }

        if (options.toType != IFactoryNS::kHDF5 && options.toType != IFactoryNS::kOgawa)
        {
            printf("Currently only -toHDF and -toOgawa are supported.\n");
            return 1;
        }

        Alembic::AbcCoreFactory::IFactory factory;
        Alembic::AbcCoreFactory::IFactory::CoreType coreType;

        Alembic::Abc::IArchive archive;
        if(options.inFiles.size() == 1)
        {
            archive = factory.getArchive(*options.inFiles.begin(), coreType);
            if (!archive.valid())
            {
                printf("Error: Invalid Alembic file specified: %s\n",
                       options.inFiles.begin()->c_str());
                return 1;
            }
            else if ( !options.force && (
                (coreType == IFactoryNS::kHDF5 &&
                 options.toType == IFactoryNS::kHDF5) ||
                (coreType == IFactoryNS::kOgawa &&
                 options.toType == IFactoryNS::kOgawa)) )
            {
                printf("Warning: Alembic file specified: %s\n", options.inFiles.begin()->c_str());
                printf("is already of the type you want to convert to.\n");
                printf("Please specify -force if you want to do this anyway.\n");
                return 1;
            }
        }
        else
        {
            archive = factory.getArchive(options.inFiles, coreType);
        }

        Alembic::Abc::IObject inTop = archive.getTop();
        Alembic::Abc::OArchive outArchive;
        if (options.toType == IFactoryNS::kHDF5)
        {
            outArchive = Alembic::Abc::OArchive(
                Alembic::AbcCoreHDF5::WriteArchive(),
                options.outFile, inTop.getMetaData(),
                Alembic::Abc::ErrorHandler::kThrowPolicy);
        }
        else if (options.toType == IFactoryNS::kOgawa)
        {
            outArchive = Alembic::Abc::OArchive(
                Alembic::AbcCoreOgawa::WriteArchive(),
                options.outFile, inTop.getMetaData(),
                Alembic::Abc::ErrorHandler::kThrowPolicy);
        }

        // start at 1, we don't need to worry about intrinsic default case
        for (Alembic::Util::uint32_t i = 1; i < archive.getNumTimeSamplings();
             ++i)
        {
            outArchive.addTimeSampling(*archive.getTimeSampling(i));
        }

        Alembic::Abc::OObject outTop = outArchive.getTop();
        copyObject(inTop, outTop);
    }

    return 0;
}
예제 #4
0
int main(int argc, char *argv[])
{

    std::string toType;
    std::string inFile;
    std::string outFile;
    std::string forceStr;

    if (argc == 4)
    {
        toType = argv[1];
        inFile = argv[2];
        outFile = argv[3];
    }
    else if (argc == 5)
    {
        forceStr = argv[1];
        toType = argv[2];
        inFile = argv[3];
        outFile = argv[4];
    }

    if ((argc == 4 || argc == 5) && (forceStr.empty() || forceStr == "-force"))
    {
        if (inFile == outFile)
        {
            printf("Error: inFile and outFile must not be the same!\n");
            return 1;
        }

        if (toType != "-toHDF" && toType != "-toOgawa")
        {
            printf("Error: Unknown conversion type specified %s\n",
                   toType.c_str());
            printf("Currently only -toHDF and -toOgawa are supported.\n");
            return 1;
        }

        Alembic::AbcCoreFactory::IFactory factory;
        Alembic::AbcCoreFactory::IFactory::CoreType coreType;
        Alembic::Abc::IArchive archive = factory.getArchive(inFile, coreType);
        if (!archive.valid())
        {
            printf("Error: Invalid Alembic file specified: %s\n",
                   inFile.c_str());
            return 1;
        }
        else if ( forceStr != "-force" && (
            (coreType == Alembic::AbcCoreFactory::IFactory::kHDF5 &&
             toType == "-toHDF") ||
            (coreType == Alembic::AbcCoreFactory::IFactory::kOgawa &&
             toType == "-toOgawa")) )
        {
            printf("Warning: Alembic file specified: %s\n",inFile.c_str());
            printf("is already of the type you want to convert to.\n");
            printf("Please specify -force if you want to do this anyway.\n");
            return 1;
        }

        Alembic::Abc::IObject inTop = archive.getTop();
        Alembic::Abc::OArchive outArchive;
        if (toType == "-toHDF")
        {
            outArchive = Alembic::Abc::OArchive(
                Alembic::AbcCoreHDF5::WriteArchive(),
                outFile, inTop.getMetaData(),
                Alembic::Abc::ErrorHandler::kThrowPolicy);
        }
        else if (toType == "-toOgawa")
        {
            outArchive = Alembic::Abc::OArchive(
                Alembic::AbcCoreOgawa::WriteArchive(),
                outFile, inTop.getMetaData(),
                Alembic::Abc::ErrorHandler::kThrowPolicy);
        }

        // start at 1, we don't need to worry about intrinsic default case
        for (Alembic::Util::uint32_t i = 1; i < archive.getNumTimeSamplings();
             ++i)
        {
            outArchive.addTimeSampling(*archive.getTimeSampling(i));
        }

        Alembic::Abc::OObject outTop = outArchive.getTop();
        copyObject(inTop, outTop);
        return 0;
    }

    printf ("Usage: abcconvert [-force] OPTION inFile outFile\n");
    printf ("Used to convert an Alembic file from one type to another.\n\n");
    printf ("If -force is not provided and inFile happens to be the same\n");
    printf ("type as OPTION no conversion will be done and a message will\n");
    printf ("be printed out.\n");
    printf ("OPTION has to be one of these:\n\n");
    printf ("  -toHDF   Convert to HDF.\n");
    printf ("  -toOgawa Convert to Ogawa.\n");

    return 1;
}
예제 #5
0
//-*****************************************************************************
int main( int argc, char *argv[] )
{
    bool opt_all = false;
    bool opt_meta = false;
    std::string desc( "abctree [OPTION] FILE[/NAME]\n"
    "  -a          include properties listings\n"
    "  -h, --help  prints this help message\n"
    "  -m          print metadata\n"
    );

    // check for min args
    if ( argc < 2 ) {
        std::cout << desc << std::endl;
        return 0;
    };

    // parse args
    std::vector<std::string> arguments(argv, argv + argc);
    std::vector<std::string> options;
    std::vector<std::string> files;

    // separate file args from option args 
    for ( std::size_t i = 1; i < arguments.size(); i++ ) {
        if ( arguments[ i ].substr( 0, 1 ) == "-" )
            options.push_back( arguments[ i ] );
        else
            files.push_back( arguments[ i ] );
    }

    // help
    if ( argc < 2 ||
         optionExists( options, "h" ) ||
         optionExists( options, "help" )
       ) {
        std::cout << desc << std::endl;
        return 0;
    };

    // set some flags
    opt_all = optionExists( options, "a");
    opt_meta = optionExists( options, "m");

    // open each file
    size_t count = 0;
    for ( std::size_t i = 0; i < files.size(); i++ ) {
        if ( files.size() > 1 )
            std::cout << BOLD << files[i] << ':' << RESETCOLOR << std::endl;

        std::stringstream ss( files[i] );
        std::stringstream fp;
        std::string segment;
        std::vector<std::string> seglist;

        /* 
         * separate file and object paths, e.g.
         *
         *   ../dir1/foo.abc/bar/baz
         *   \_____________/\______/
         *        file         obj
         */
        int j = 0;
        while ( std::getline( ss, segment, '/' ) ) {
            if ( !isFile ( fp.str() ) ) {
                if ( j != 0 )
                    fp << "/";
                fp << segment;
            } else {
                seglist.push_back( segment );
            }
            ++j;
        }

        // open the iarchive
        Abc::IArchive archive;
        AbcF::IFactory factory;
        factory.setPolicy(Abc::ErrorHandler::kQuietNoopPolicy);
        AbcF::IFactory::CoreType coreType;
        archive = factory.getArchive(std::string( fp.str() ), coreType);

        // display file metadata 
        if ( opt_meta ) {
            std::cout  << "Using "
                       << Alembic::AbcCoreAbstract::GetLibraryVersion ()
                       << std::endl;;

            std::string appName;
            std::string libraryVersionString;
            Alembic::Util::uint32_t libraryVersion;
            std::string whenWritten;
            std::string userDescription;
            std::string coreName;
            GetArchiveInfo (archive,
                            appName,
                            libraryVersionString,
                            libraryVersion,
                            whenWritten,
                            userDescription);

            if ( coreType == AbcF::IFactory::kOgawa ) {
                coreName = "Ogawa";
            } else if ( coreType == AbcF::IFactory::kHDF5 ) {
                coreName = "HDF5";
            } else {
                coreName = "Unknown";
            };

            if ( appName != "" ) {
                std::cout << "  file written by: " << appName << std::endl;
                std::cout << "  using Alembic : " << libraryVersionString << std::endl;
                std::cout << "  written on : " << whenWritten << std::endl;
                std::cout << "  user description : " << userDescription << std::endl;
            } else {
                std::cout << "  (file doesn't have any ArchiveInfo)"
                          << std::endl;
            }
            std::cout << "  core type : " << coreName << std::endl;
        };

        // walk object hierarchy and find valid objects
        AbcG::IObject test = archive.getTop();
        AbcG::IObject iObj = test;
        while ( test.valid() && seglist.size() > 0 ) {
            test = test.getChild( seglist.front() );
            if ( test.valid() ) {
                iObj = test;
                seglist.erase( seglist.begin() );
            }
        }

        // walk property hierarchy for most recent valid object
        Abc::ICompoundProperty props = iObj.getProperties();
        const Abc::PropertyHeader* header;
        bool found = false;
        for ( std::size_t i = 0; i < seglist.size(); ++i ) {
            header = props.getPropertyHeader( seglist[i] );
            if ( header && header->isCompound() ) {
                Abc::ICompoundProperty ptest( props, header->getName() );
                if ( ptest.valid() ) {
                    props = ptest;
                    found = true;
                }
            } else if ( header && header->isSimple() ) {
                found = true;
            } else {
                std::cout << seglist[i] 
                          << ": Invalid object or property" 
                          << std::endl;
                return 1;
            }
        }

        // walk the archive tree
        if ( found ) 
            if ( header->isCompound() )
                tree( props );
            else
                tree( Abc::IScalarProperty( props, header->getName() ) );
        else
            tree( iObj, opt_all );

        ++count;
    }

    return 0;
}