//-***************************************************************************** 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) ); } }