void readUInt32ArrayProperty(const std::string &archiveName) { // Open an existing archive for reading. Indicate that we want // Alembic to throw exceptions on errors. std::cout << "Reading " << archiveName << std::endl; IArchive archive( Alembic::AbcCoreHDF5::ReadArchive(), archiveName, ErrorHandler::kThrowPolicy ); IObject archiveTop = archive.getTop(); // Determine the number of (top level) children the archive has const unsigned int numChildren = archiveTop.getNumChildren(); ABCA_ASSERT( numChildren == 1, "Wrong number of children (expected 1)"); std::cout << "The archive has " << numChildren << " children:" << std::endl; // Iterate through them, print out their names IObject child( archiveTop, archiveTop.getChildHeader(0).getName() ); std::cout << " named '" << child.getName() << "'"; // Properties ICompoundProperty props = child.getProperties(); size_t numProperties = props.getNumProperties(); // only top-level props ABCA_ASSERT( numProperties == 1, "Expected 1 property, found " << numProperties); std::cout << " with one property"; std::vector<std::string> propNames(1); propNames[0] = props.getPropertyHeader(0).getName(); std::cout << " named '" << propNames[0] << "'" << std::endl; PropertyType pType = props.getPropertyHeader(0).getPropertyType(); ABCA_ASSERT( pType == kArrayProperty, "Expected an array property, but didn't find one" ); std::cout << " which is an array property"; DataType dType = props.getPropertyHeader(0).getDataType(); ABCA_ASSERT( dType.getPod() == kUint32POD, "Expected an unsigned int (kUint32POD) property, but didn't" " find one" ); // We know this is an array property (I'm eliding the if/else // statements required to recognize and handle this properly) IUInt32ArrayProperty primes( props, propNames[0] ); size_t numSamples = primes.getNumSamples(); std::cout << ".. it has " << numSamples << " samples" << std::endl; ABCA_ASSERT( numSamples == 5, "Expected 5 samples, found " << numSamples ); const TimeSampling ts = primes.getTimeSampling(); std::cout << "..with time/value pairs: " << std::endl;; for (int ss=0; ss<numSamples; ss++) { std::cout << " "; ISampleSelector iss( (index_t) ss); std::cout << ts.getSampleTime( (index_t) ss ) << " / "; UInt32ArraySamplePtr samplePtr; primes.get( samplePtr, iss ); std::cout << "[ "; size_t numPoints = samplePtr->size(); for ( size_t jj=0 ; jj<numPoints ; jj++ ) std::cout << (*samplePtr)[jj] << " "; std::cout << "]" << std::endl; // ASSERT that we are reading the correct values for ( size_t jj=0 ; jj<numPoints ; jj++ ) ABCA_ASSERT( (*samplePtr)[jj] == g_primes[jj], "Incorrect value read from archive." ); } std::cout << std::endl; // Done - the archive closes itself }
void readUInt32ArrayProperty(const std::string &archiveName, bool useOgawa) { // Open an existing archive for reading. Indicate that we want // Alembic to throw exceptions on errors. std::cout << "Reading " << archiveName << std::endl; 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(); // Determine the number of (top level) children the archive has const unsigned int numChildren = archiveTop.getNumChildren(); ABCA_ASSERT( numChildren == 1, "Wrong number of children (expected 1)"); std::cout << "The archive has " << numChildren << " children:" << std::endl; // Iterate through them, print out their names IObject child( archiveTop, archiveTop.getChildHeader(0).getName() ); std::cout << " named '" << child.getName() << "'"; // Properties ICompoundProperty props = child.getProperties(); size_t numProperties = props.getNumProperties(); // only top-level props ABCA_ASSERT( numProperties == 1, "Expected 1 property, found " << numProperties); std::cout << " with one property"; std::vector<std::string> propNames(1); propNames[0] = props.getPropertyHeader(0).getName(); std::cout << " named '" << propNames[0] << "'" << std::endl; PropertyType pType = props.getPropertyHeader(0).getPropertyType(); ABCA_ASSERT( pType == kArrayProperty, "Expected an array property, but didn't find one" ); std::cout << " which is an array property"; DataType dType = props.getPropertyHeader(0).getDataType(); ABCA_ASSERT( dType.getPod() == kUint32POD, "Expected an unsigned int (kUint32POD) property, but didn't" " find one" ); // We know this is an array property (I'm eliding the if/else // statements required to recognize and handle this properly) IUInt32ArrayProperty primes( props, propNames[0] ); size_t numSamples = primes.getNumSamples(); std::cout << ".. it has " << numSamples << " samples" << std::endl; ABCA_ASSERT( numSamples == 5, "Expected 5 samples, found " << numSamples ); const TimeSamplingPtr ts = primes.getTimeSampling(); std::cout << "..with time/value pairs: " << std::endl;; for (unsigned int ss=0; ss<numSamples; ss++) { std::cout << " "; ISampleSelector iss( (index_t) ss); std::cout << ts->getSampleTime( (index_t) ss ) << " / "; UInt32ArraySamplePtr samplePtr; primes.get( samplePtr, iss ); std::cout << "[ "; size_t numPoints = samplePtr->size(); for ( size_t jj=0 ; jj<numPoints ; jj++ ) std::cout << (*samplePtr)[jj] << " "; std::cout << "]" << std::endl; // ASSERT that we are reading the correct values for ( size_t jj=0 ; jj<numPoints ; jj++ ) ABCA_ASSERT( (*samplePtr)[jj] == g_primes[jj], "Incorrect value read from archive." ); std::vector< Alembic::Util::uint32_t > uintPrimes( numPoints ); primes.getAs( &uintPrimes.front(), iss ); for ( size_t jj=0 ; jj<numPoints ; jj++ ) ABCA_ASSERT( uintPrimes[jj] == g_primes[jj], "Incorrect value via getAs from archive." ); std::vector< Alembic::Util::int16_t > shortPrimes( numPoints ); primes.getAs( &shortPrimes.front(), AbcA::kInt16POD, iss ); for ( size_t jj=0 ; jj<numPoints ; jj++ ) ABCA_ASSERT( ( unsigned int ) shortPrimes[jj] == g_primes[jj], "Incorrect value via getAs(POD) from archive." ); } std::cout << std::endl; ABCA_ASSERT( archive.getMaxNumSamplesForTimeSamplingIndex(1) == (index_t) numSamples, "Incorrect number of max samples in readUInt32ArrayProperty"); double start, end; GetArchiveStartAndEndTime( archive, start, end ); TESTING_ASSERT( almostEqual(start, 123.0) ); TESTING_ASSERT( almostEqual(end, 123.0 + 4.0 / 24.0) ); // Done - the archive closes itself }