Пример #1
0
void testArrayPropHashes()
{
    std::string archiveName = "arrayHashTest.abc";
    {
        AO::WriteArchive w;
        ABCA::ArchiveWriterPtr a = w(archiveName, ABCA::MetaData());
        ABCA::ObjectWriterPtr archive = a->getTop();
        ABCA::ObjectWriterPtr child;

        // add a time sampling for later use
        std::vector < double > timeSamps(1,-4.0);
        ABCA::TimeSamplingType tst(3.0);
        ABCA::TimeSampling ts(tst, timeSamps);
        a->addTimeSampling(ts);

        // 2 objects without any properties whatsoever
        archive->createChild(ABCA::ObjectHeader("emptyA", ABCA::MetaData()));
        archive->createChild(ABCA::ObjectHeader("emptyB", ABCA::MetaData()));

        // 2 objects with with the same property with no samples
        child = archive->createChild(ABCA::ObjectHeader(
            "1propA", ABCA::MetaData()));
        child->getProperties()->createArrayProperty("empty",  ABCA::MetaData(),
            ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);

        child = archive->createChild(ABCA::ObjectHeader(
            "1propB", ABCA::MetaData()));
        child->getProperties()->createArrayProperty("empty",  ABCA::MetaData(),
            ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);

        // 2 objects with with the same property with a differnt name from above
        child = archive->createChild(ABCA::ObjectHeader(
            "1propAName", ABCA::MetaData()));
        child->getProperties()->createArrayProperty("null",  ABCA::MetaData(),
            ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);

        child = archive->createChild(ABCA::ObjectHeader(
            "1propBName", ABCA::MetaData()));
        child->getProperties()->createArrayProperty("null",  ABCA::MetaData(),
            ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);

        // 2 objects with with the same property with a differnt MetaData
        ABCA::MetaData m;
        m.set("Bleep", "bloop");
        child = archive->createChild(ABCA::ObjectHeader(
            "1propAMeta", ABCA::MetaData()));
        child->getProperties()->createArrayProperty("empty", m,
            ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);

        child = archive->createChild(ABCA::ObjectHeader(
            "1propBMeta", ABCA::MetaData()));
        child->getProperties()->createArrayProperty("empty", m,
            ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);

        // 2 objects with with the same property with a different POD
        child = archive->createChild(ABCA::ObjectHeader(
            "1propAPod", ABCA::MetaData()));
        child->getProperties()->createArrayProperty("empty",  ABCA::MetaData(),
            ABCA::DataType(Alembic::Util::kFloat32POD, 1), 0);

        child = archive->createChild(ABCA::ObjectHeader(
            "1propBPod", ABCA::MetaData()));
        child->getProperties()->createArrayProperty("empty",  ABCA::MetaData(),
            ABCA::DataType(Alembic::Util::kFloat32POD, 1), 0);

        // 2 objects with with the same property with a different extent
        child = archive->createChild(ABCA::ObjectHeader(
            "1propAExtent", ABCA::MetaData()));
        child->getProperties()->createArrayProperty("empty",  ABCA::MetaData(),
            ABCA::DataType(Alembic::Util::kInt32POD, 2), 0);

        child = archive->createChild(ABCA::ObjectHeader(
            "1propBExtent", ABCA::MetaData()));
        child->getProperties()->createArrayProperty("empty",  ABCA::MetaData(),
            ABCA::DataType(Alembic::Util::kInt32POD, 2), 0);

        // 2 objects with with the same property with a differnt time sampling
        child = archive->createChild(ABCA::ObjectHeader(
            "1propATS", ABCA::MetaData()));
        child->getProperties()->createArrayProperty("empty",  ABCA::MetaData(),
            ABCA::DataType(Alembic::Util::kInt32POD, 1), 1);

        child = archive->createChild(ABCA::ObjectHeader(
            "1propBTS", ABCA::MetaData()));
        child->getProperties()->createArrayProperty("empty",  ABCA::MetaData(),
            ABCA::DataType(Alembic::Util::kInt32POD, 1), 1);

        // 2 objects with 1 sample
        ABCA::ArrayPropertyWriterPtr awp;
        std::vector <Alembic::Util::int32_t> vali(4, 0);
        Alembic::Util::Dimensions dims(4);
        ABCA::DataType i32d(Alembic::Util::kInt32POD, 1);

        child = archive->createChild(ABCA::ObjectHeader(
            "1propA1Samp", ABCA::MetaData()));
        awp = child->getProperties()->createArrayProperty("int",
            ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);
        awp->setSample(ABCA::ArraySample(&(vali.front()), i32d, dims));

        child = archive->createChild(ABCA::ObjectHeader(
            "1propB1Samp", ABCA::MetaData()));
        awp = child->getProperties()->createArrayProperty("int",
            ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);
        awp->setSample(ABCA::ArraySample(&(vali.front()), i32d, dims));

        // 2 objects with 2 samples, no repeats
        std::vector <Alembic::Util::int32_t> valiB(4, 1);

        child = archive->createChild(ABCA::ObjectHeader(
            "1propA2Samp", ABCA::MetaData()));
        awp = child->getProperties()->createArrayProperty("int",
            ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);
        awp->setSample(ABCA::ArraySample(&(vali.front()), i32d, dims));
        awp->setSample(ABCA::ArraySample(&(valiB.front()), i32d, dims));

        child = archive->createChild(ABCA::ObjectHeader(
            "1propB2Samp", ABCA::MetaData()));
        awp = child->getProperties()->createArrayProperty("int",
            ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);
        awp->setSample(ABCA::ArraySample(&(vali.front()), i32d, dims));
        awp->setSample(ABCA::ArraySample(&(valiB.front()), i32d, dims));

        // 2 objects with 4 samples, with repeats
        child = archive->createChild(ABCA::ObjectHeader(
            "1propA4Samp", ABCA::MetaData()));
        awp = child->getProperties()->createArrayProperty("int",
            ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);
        awp->setSample(ABCA::ArraySample(&(vali.front()), i32d, dims));
        awp->setSample(ABCA::ArraySample(&(vali.front()), i32d, dims));
        awp->setSample(ABCA::ArraySample(&(valiB.front()), i32d, dims));
        awp->setSample(ABCA::ArraySample(&(valiB.front()), i32d, dims));

        child = archive->createChild(ABCA::ObjectHeader(
            "1propB4Samp", ABCA::MetaData()));
        awp = child->getProperties()->createArrayProperty("int",
            ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);
        awp->setSample(ABCA::ArraySample(&(vali.front()), i32d, dims));
        awp->setSample(ABCA::ArraySample(&(vali.front()), i32d, dims));
        awp->setSample(ABCA::ArraySample(&(valiB.front()), i32d, dims));
        awp->setSample(ABCA::ArraySample(&(valiB.front()), i32d, dims));

        // 2 objects with 1 samplem different dimensions
        Alembic::Util::Dimensions dimsB;
        dimsB.setRank(2);
        dimsB[0] = 2;
        dimsB[1] = 2;

        child = archive->createChild(ABCA::ObjectHeader(
            "1propA1Dims", ABCA::MetaData()));
        awp = child->getProperties()->createArrayProperty("int",
            ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);
        awp->setSample(ABCA::ArraySample(&(vali.front()), i32d, dimsB));

        child = archive->createChild(ABCA::ObjectHeader(
            "1propB1Dims", ABCA::MetaData()));
        awp = child->getProperties()->createArrayProperty("int",
            ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);
        awp->setSample(ABCA::ArraySample(&(vali.front()), i32d, dimsB));

        // 2 objects with with the same 2 properties with no samples
        child = archive->createChild(ABCA::ObjectHeader(
            "2propA", ABCA::MetaData()));
        child->getProperties()->createArrayProperty("empty", ABCA::MetaData(),
            ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);
        child->getProperties()->createArrayProperty("null",  ABCA::MetaData(),
            ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);

        child = archive->createChild(ABCA::ObjectHeader(
            "2propB", ABCA::MetaData()));
        child->getProperties()->createArrayProperty("empty",  ABCA::MetaData(),
            ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);
        child->getProperties()->createArrayProperty("null",  ABCA::MetaData(),
            ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);

        // 2 objects with with the same 2 properties created in opposite order
        child = archive->createChild(ABCA::ObjectHeader(
            "2propASwap", ABCA::MetaData()));
        child->getProperties()->createArrayProperty("null",  ABCA::MetaData(),
            ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);
        child->getProperties()->createArrayProperty("empty",  ABCA::MetaData(),
            ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);

        child = archive->createChild(ABCA::ObjectHeader(
            "2propBSwap", ABCA::MetaData()));
        child->getProperties()->createArrayProperty("null",  ABCA::MetaData(),
            ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);
        child->getProperties()->createArrayProperty("empty",  ABCA::MetaData(),
            ABCA::DataType(Alembic::Util::kInt32POD, 1), 0);
    }

    {
        AO::ReadArchive r;
        ABCA::ArchiveReaderPtr a = r( archiveName );
        ABCA::ObjectReaderPtr archive = a->getTop();

        TESTING_ASSERT(archive->getNumChildren() == 26);

        // every 2 hashes should be the same
        for (size_t i = 0; i < archive->getNumChildren(); i += 2)
        {
            Alembic::Util::Digest dA, dB;
            TESTING_ASSERT(archive->getChild(i)->getPropertiesHash(dA) &&
                archive->getChild(i+1)->getPropertiesHash(dB));
            TESTING_ASSERT(dA == dB);
        }

        // make sure that every 2 child objects have different properties hashes
        for (size_t i = 0; i < archive->getNumChildren() / 2; ++i)
        {
            Alembic::Util::Digest dA;
            archive->getChild(i*2)->getPropertiesHash(dA);
            for (size_t j = i + 1; j < archive->getNumChildren() / 2; ++j)
            {
                Alembic::Util::Digest dB;
                archive->getChild(j*2)->getPropertiesHash(dB);
                TESTING_ASSERT(dA != dB);
            }
        }
    }
}
Пример #2
0
//-*****************************************************************************
void printValue( Abc::ICompoundProperty iParent, Abc::PropertyHeader header,
                 int index, bool justSize, bool printTime, double fps )
{
    Abc::ISampleSelector iss( (index_t) index );
    Abc::DataType dt = header.getDataType();
    AbcU::PlainOldDataType pod = dt.getPod();
    AbcU ::uint8_t extent = dt.getExtent();

    if ( header.isArray() ) {
        Abc::IArrayProperty p( iParent, header.getName() );

        if ( printTime ) {
            std::cout << "Time: " <<
                p.getTimeSampling()->getSampleTime( index ) * fps << std::endl;
        }

        if ( justSize ) {
            AbcU::Dimensions dims;
            p.getDimensions( dims, iss );
            std::cout << "Extent: " << (int) extent << " Num points: " <<
                dims.numPoints() << std::endl;
            return;
        }

        switch ( pod )
        {
            CASE_RETURN_ARRAY_VALUE(Abc::BooleanTPTraits, bool, p, header, iss);
            CASE_RETURN_ARRAY_VALUE(Abc::Uint8TPTraits, uint8_t, p, header, iss);
            CASE_RETURN_ARRAY_VALUE(Abc::Int8TPTraits, int8_t, p, header, iss);
            CASE_RETURN_ARRAY_VALUE(Abc::Uint16TPTraits, uint16_t, p, header, iss);
            CASE_RETURN_ARRAY_VALUE(Abc::Int16TPTraits, int16_t, p, header, iss);
            CASE_RETURN_ARRAY_VALUE(Abc::Uint32TPTraits, uint32_t, p, header, iss);
            CASE_RETURN_ARRAY_VALUE(Abc::Int32TPTraits, int32_t, p, header, iss);
            CASE_RETURN_ARRAY_VALUE(Abc::Uint64TPTraits, uint64_t, p, header, iss);
            CASE_RETURN_ARRAY_VALUE(Abc::Int64TPTraits, int64_t, p, header, iss);
            CASE_RETURN_ARRAY_VALUE(Abc::Float32TPTraits, float, p, header, iss);
            CASE_RETURN_ARRAY_VALUE(Abc::Float64TPTraits, double, p, header, iss);
            CASE_RETURN_ARRAY_VALUE(Abc::StringTPTraits, std::string, p, header, iss);
            default:
                std::cout << "Unknown property type" << std::endl;
                break;
        }
    } else if ( header.isScalar() ) {
        Abc::IScalarProperty p( iParent, header.getName() );

        if ( printTime ) {
            std::cout << "Time: " <<
                p.getTimeSampling()->getSampleTime( index ) * fps << std::endl;
        }

        if ( justSize ) {
            std::cout << "Extent: " << (int) extent << std::endl;
            return;
        }

        switch ( pod )
        {
            CASE_RETURN_SCALAR_VALUE( Abc::BooleanTPTraits, p, iss );
            CASE_RETURN_SCALAR_VALUE( Abc::Uint8TPTraits, p, iss );
            CASE_RETURN_SCALAR_VALUE( Abc::Int8TPTraits, p, iss );
            CASE_RETURN_SCALAR_VALUE( Abc::Uint16TPTraits, p, iss );
            CASE_RETURN_SCALAR_VALUE( Abc::Int16TPTraits, p, iss );
            CASE_RETURN_SCALAR_VALUE( Abc::Uint32TPTraits, p, iss );
            CASE_RETURN_SCALAR_VALUE( Abc::Int32TPTraits, p, iss );
            CASE_RETURN_SCALAR_VALUE( Abc::Uint64TPTraits, p, iss );
            CASE_RETURN_SCALAR_VALUE( Abc::Int64TPTraits, p, iss );
            CASE_RETURN_SCALAR_VALUE( Abc::Float32TPTraits, p, iss );
            CASE_RETURN_SCALAR_VALUE( Abc::Float64TPTraits, p, iss );
            CASE_RETURN_SCALAR_VALUE( Abc::StringTPTraits, p, iss );
            default:
                std::cout << "Unknown property type" << std::endl;
                break;
        }

    }
}
void readWriteColorArrayProperty(const std::string &archiveName, bool useOgawa)
{

    {
        OArchive archive;
        if (useOgawa)
        {
            archive = OArchive( Alembic::AbcCoreOgawa::WriteArchive(),
                archiveName, ErrorHandler::kThrowPolicy );
        }
        else
        {
            archive = OArchive( Alembic::AbcCoreHDF5::WriteArchive(),
                archiveName, ErrorHandler::kThrowPolicy );
        }

        OObject archiveTop = archive.getTop();

        OObject child( archiveTop, "test" );
        OCompoundProperty childProps = child.getProperties();

        OC3fArrayProperty shades( childProps, "shades", 0 );

        std::vector < C3f > grays(8);
        grays[0].x = 0.0; grays[0].y = 0.0; grays[0].z = 0.0;
        grays[1].x = 0.125; grays[1].y = 0.125; grays[1].z = 0.125;

        grays[2].x = 0.25; grays[2].y = 0.25; grays[2].z = 0.25;
        grays[3].x = 0.375; grays[3].y = 0.375; grays[3].z = 0.375;

        grays[4].x = 0.5; grays[4].y = 0.5; grays[4].z = 0.5;
        grays[5].x = 0.625; grays[5].y = 0.625; grays[5].z = 0.625;

        grays[6].x = 0.75; grays[6].y = 0.75; grays[6].z = 0.75;
        grays[7].x = 0.875; grays[7].y = 0.875; grays[7].z = 0.875;

        // let's write 4 different color3f[2]
        Dimensions d;
        d.setRank(2);
        d[0] = 2;
        d[1] = 4;

        C3fArraySample cas(&(grays.front()), d);
        shades.set(cas);
    }
    {
        // now read it
        AbcF::IFactory factory;
        factory.setPolicy(  ErrorHandler::kThrowPolicy );
        AbcF::IFactory::CoreType coreType;
        IArchive archive = factory.getArchive(archiveName, coreType);
        TESTING_ASSERT( (useOgawa && coreType == AbcF::IFactory::kOgawa) ||
                        (!useOgawa && coreType == AbcF::IFactory::kHDF5) );

        IObject archiveTop = archive.getTop();

        IObject child( archiveTop, archiveTop.getChildHeader(0).getName() );
        ICompoundProperty props = child.getProperties();
        IC3fArrayProperty shades( props, "shades" );

        C3fArraySamplePtr samplePtr;
        shades.get( samplePtr );

        ABCA_ASSERT( samplePtr->getDimensions().rank() == 2,
                     "Incorrect rank on the sample." );

        ABCA_ASSERT( samplePtr->getDimensions().numPoints() == 8,
                     "Incorrect number of total points." );

        ABCA_ASSERT( samplePtr->getDimensions()[0] == 2,
                     "Incorrect size on dimension 0." );

        ABCA_ASSERT( samplePtr->getDimensions()[1] == 4,
                     "Incorrect size on dimension 1." );

        Alembic::Util::Dimensions dims;
        shades.getDimensions( dims );

        ABCA_ASSERT( dims.rank() == 2,
                     "Incorrect rank on the sample." );

        ABCA_ASSERT( dims.numPoints() == 8,
                     "Incorrect number of total points." );

        ABCA_ASSERT( dims[0] == 2,
                     "Incorrect size on dimension 0." );

        ABCA_ASSERT( dims[1] == 4,
                     "Incorrect size on dimension 1." );

        for (size_t i = 0; i < 8; ++i)
        {
            ABCA_ASSERT( (*samplePtr)[i].x == i/8.0 &&
                         (*samplePtr)[i].x == (*samplePtr)[i].y &&
                         (*samplePtr)[i].x == (*samplePtr)[i].z,
                         "Color [" << i << "] is incorrect.");
        }

        double start, end;
        GetArchiveStartAndEndTime( archive, start, end );

        TESTING_ASSERT( almostEqual(start, 0.0) );
        TESTING_ASSERT( almostEqual(end, 0.0) );
    }
}