void readEmptyCompoundProperties(const std::string &archiveName) { // Open an existing archive for reading. Indicate that we want // Alembic to throw exceptions on errors. AbcF::IFactory factory; factory.setPolicy( ErrorHandler::kThrowPolicy ); AbcF::IFactory::CoreType coreType; IArchive archive = factory.getArchive(archiveName, coreType); IObject archiveTop = archive.getTop(); // Determine the number of (top level) children the archive has const int numChildren = archiveTop.getNumChildren(); ABCA_ASSERT( numChildren == 2, "Wrong number of children (expected 2)"); std::cout << "The archive has " << numChildren << " children:" << std::endl; // Iterate through them, print out their names for (int ii=0; ii<numChildren; ii++) { IObject child( archiveTop, archiveTop.getChildHeader(ii).getName() ); std::cout << " " << child.getName(); std::cout << " has " << child.getNumChildren() << " children" << std::endl; // Properties ICompoundProperty props = child.getProperties(); int numProperties = props.getNumProperties(); std::cout << " ..and " << numProperties << " properties" << std::endl; std::vector<std::string> propNames; for (int pp=0; pp<numProperties; pp++) propNames.push_back( props.getPropertyHeader(pp).getName() ); for (int jj=0; jj<numProperties; jj++) { std::cout << " ..named " << propNames[jj] << std::endl; std::cout << " ..with type: "; PropertyType pType = props.getPropertyHeader(jj).getPropertyType(); if (pType == kCompoundProperty) { std::cout << "compound" << std::endl; } else if (pType == kScalarProperty) { std::cout << "scalar" << std::endl; } else if (pType == kArrayProperty) { std::cout << "array" << std::endl; } } } // Done - the archive closes itself }
//-***************************************************************************** void visitProperties( ICompoundProperty iParent, std::string &ioIndent ) { std::string oldIndent = ioIndent; for ( size_t i = 0 ; i < iParent.getNumProperties() ; i++ ) { PropertyHeader header = iParent.getPropertyHeader( i ); if ( header.isCompound() ) { visitCompoundProperty( ICompoundProperty( iParent, header.getName() ), ioIndent ); } else if ( header.isScalar() ) { visitSimpleProperty( IScalarProperty( iParent, header.getName() ), ioIndent ); } else { assert( header.isArray() ); visitSimpleProperty( IArrayProperty( iParent, header.getName() ), ioIndent ); } } ioIndent = oldIndent; }
// Read side -------------------------------------- IVisibilityProperty GetVisibilityProperty ( IObject & iObject ) { ICompoundProperty prop = iObject.getProperties(); if ( prop.getPropertyHeader (kVisibilityPropertyName) ) { IVisibilityProperty visibilityProperty ( prop, kVisibilityPropertyName ); return visibilityProperty; } return IVisibilityProperty(); }
//-***************************************************************************** void visitCompoundProperty( ICompoundProperty iProp, std::string &ioIndent ) { std::string oldIndent = ioIndent; ioIndent += " "; std::string interp = "schema="; interp += iProp.getMetaData().get( "schema" ); std::cout << ioIndent << "CompoundProperty " << "name=" << iProp.getName() << g_sep << interp << std::endl; visitProperties( iProp, ioIndent ); ioIndent = oldIndent; }
void readSimpleProperties(const std::string &archiveName) { // Open an existing archive for reading. Indicate that we want // Alembic to throw exceptions on errors. AbcF::IFactory factory; factory.setPolicy( ErrorHandler::kThrowPolicy ); AbcF::IFactory::CoreType coreType; IArchive archive = factory.getArchive(archiveName, coreType); IObject archiveTop = archive.getTop(); // Determine the number of (top level) children the archive has const int numChildren = archiveTop.getNumChildren(); TESTING_ASSERT( numChildren == 4 ); std::cout << "The archive has " << numChildren << " children:" << std::endl; // Iterate through them, print out their names for (int ii=0; ii<numChildren; ii++) { IObject child( archiveTop, archiveTop.getChildHeader( ii ).getName() ); std::cout << " " << child.getName(); std::cout << " has " << child.getNumChildren() << " children" << std::endl; // Properties ICompoundProperty props = child.getProperties(); int numProperties = props.getNumProperties(); std::cout << " ..and " << numProperties << " simple properties" << std::endl; std::vector<std::string> propNames; for (int pp=0; pp<numProperties; pp++) propNames.push_back( props.getPropertyHeader(pp).getName() ); for (int jj=0; jj<numProperties; jj++) { std::cout << " ..named " << propNames[jj] << std::endl; std::cout << " ..with type: "; PropertyType pType = props.getPropertyHeader(jj).getPropertyType(); if (pType == kCompoundProperty) { std::cout << "compound" << std::endl; } else if (pType == kScalarProperty) { std::cout << "scalar" << std::endl; } else if (pType == kArrayProperty) { std::cout << "array" << std::endl; } DataType dType = props.getPropertyHeader(jj).getDataType(); std::cout << " ..with POD-type: "; switch (dType.getPod()) { case kBooleanPOD: std::cout << "boolean" << std::endl; break; // Char/UChar case kUint8POD: std::cout << "unsigned char" << std::endl; break; case kInt8POD: std::cout << "char" << std::endl; break; // Short/UShort case kUint16POD: std::cout << "short unsigned int" << std::endl; break; case kInt16POD: std::cout << "short int" << std::endl; break; // Int/UInt case kUint32POD: std::cout << "unsigned int" << std::endl; break; case kInt32POD: std::cout << "int" << std::endl; break; // Long/ULong case kUint64POD: std::cout << "unsigned long int" << std::endl; break; case kInt64POD: std::cout << "long int" << std::endl; break; // Half/Float/Double case kFloat16POD: std::cout << "half" << std::endl; break; case kFloat32POD: std::cout << "float" << std::endl; break; case kFloat64POD: std::cout << "double" << std::endl; break; case kStringPOD: std::cout << "string" << std::endl; break; case kUnknownPOD: default: std::cout << " Unknown! (this is bad)" << std::endl; }; TimeSamplingPtr ts = GetCompoundPropertyReaderPtr(props)-> getScalarProperty( propNames[jj] )->getTimeSampling(); int numSamples = ts->getNumStoredTimes(); std::cout << " ..and " << ts->getTimeSamplingType() << std::endl << " ..and " << numSamples << " samples at times: "; if (numSamples > 0) { std::cout << " ( "; for (int ss=0; ss<numSamples; ss++) std::cout << ts->getSampleTime(ss) << " "; std::cout << ")"; } std::cout << std::endl; std::cout << " ..and values: "; if (numSamples > 0) { for (int ss=0; ss<numSamples; ss++) { ISampleSelector iss( (index_t) ss); switch (dType.getPod()) { // Boolean case kBooleanPOD: { IBoolProperty prop( props, propNames[jj] ); printSampleValue( prop, iss ); break; } // Char/UChar case kUint8POD: { IUcharProperty prop( props, propNames[jj] ); printSampleValue( prop, iss ); break; } case kInt8POD: { ICharProperty prop( props, propNames[jj] ); printSampleValue( prop, iss ); break; } // Short/UShort case kUint16POD: { IUInt16Property prop( props, propNames[jj] ); printSampleValue( prop, iss ); break; } case kInt16POD: { IInt16Property prop( props, propNames[jj] ); printSampleValue( prop, iss ); break; } // Int/UInt case kUint32POD: { IUInt32Property prop( props, propNames[jj] ); printSampleValue( prop, iss ); break; } case kInt32POD: { IInt32Property prop( props, propNames[jj] ); printSampleValue( prop, iss ); break; } // Long/ULong case kUint64POD: { IUInt64Property prop( props, propNames[jj] ); printSampleValue( prop, iss ); break; } case kInt64POD: { IInt64Property prop( props, propNames[jj] ); printSampleValue( prop, iss ); break; } // Half/Float/Double case kFloat16POD: // iostream doesn't understand float_16's //printSampleValue( IHalfProperty( props, propNames[jj] ), // iss ); break; case kFloat32POD: { IFloatProperty prop( props, propNames[jj] ); printSampleValue( prop, iss ); break; } case kFloat64POD: { IDoubleProperty prop( props, propNames[jj] ); printSampleValue( prop, iss ); break; } case kUnknownPOD: default: std::cout << " Unknown! (this is bad)" << std::endl; }; } } std::cout << std::endl; std::cout << std::endl; // done parsing property } } // Done - the archive closes itself }
AtNode * ProcessPointsBase( IPoints & prim, ProcArgs & args, SampleTimeSet & sampleTimes, std::vector<AtPoint> & vidxs, std::vector<float> & radius, MatrixSampleMap * xformSamples ) { if ( !prim.valid() ) { return NULL; } Alembic::AbcGeom::IPointsSchema &ps = prim.getSchema(); TimeSamplingPtr ts = ps.getTimeSampling(); sampleTimes.insert( ts->getFloorIndex(args.frame / args.fps, ps.getNumSamples()).second ); std::string name = args.nameprefix + prim.getFullName(); AtNode * instanceNode = NULL; std::string cacheId; SampleTimeSet singleSampleTimes; singleSampleTimes.insert( ts->getFloorIndex(args.frame / args.fps, ps.getNumSamples()).second ); ICompoundProperty arbGeomParams = ps.getArbGeomParams(); ISampleSelector frameSelector( *singleSampleTimes.begin() ); std::vector<std::string> tags; //get tags if ( arbGeomParams != NULL && arbGeomParams.valid() ) { if (arbGeomParams.getPropertyHeader("mtoa_constant_tags") != NULL) { const PropertyHeader * tagsHeader = arbGeomParams.getPropertyHeader("mtoa_constant_tags"); if (IStringGeomParam::matches( *tagsHeader )) { IStringGeomParam param( arbGeomParams, "mtoa_constant_tags" ); if ( param.valid() ) { IStringGeomParam::prop_type::sample_ptr_type valueSample = param.getExpandedValue( frameSelector ).getVals(); if ( param.getScope() == kConstantScope || param.getScope() == kUnknownScope) { Json::Value jtags; Json::Reader reader; if(reader.parse(valueSample->get()[0], jtags)) for( Json::ValueIterator itr = jtags.begin() ; itr != jtags.end() ; itr++ ) { tags.push_back(jtags[itr.key().asUInt()].asString()); } } } } } } if ( args.makeInstance ) { std::ostringstream buffer; AbcA::ArraySampleKey sampleKey; for ( SampleTimeSet::iterator I = sampleTimes.begin(); I != sampleTimes.end(); ++I ) { ISampleSelector sampleSelector( *I ); ps.getPositionsProperty().getKey(sampleKey, sampleSelector); buffer << GetRelativeSampleTime( args, (*I) ) << ":"; sampleKey.digest.print(buffer); buffer << ":"; } cacheId = buffer.str(); instanceNode = AiNode( "ginstance" ); AiNodeSetStr( instanceNode, "name", name.c_str() ); args.createdNodes.push_back(instanceNode); if ( args.proceduralNode ) { AiNodeSetByte( instanceNode, "visibility", AiNodeGetByte( args.proceduralNode, "visibility" ) ); } else { AiNodeSetByte( instanceNode, "visibility", AI_RAY_ALL ); } ApplyTransformation( instanceNode, xformSamples, args ); NodeCache::iterator I = g_meshCache.find(cacheId); // parameters overrides if(args.linkOverride) ApplyOverrides(name, instanceNode, tags, args); // shader assignation if (nodeHasParameter( instanceNode, "shader" ) ) { if(args.linkShader) { ApplyShaders(name, instanceNode, tags, args); } else { AtArray* shaders = AiNodeGetArray(args.proceduralNode, "shader"); if (shaders->nelements != 0) AiNodeSetArray(instanceNode, "shader", AiArrayCopy(shaders)); } } if ( I != g_meshCache.end() ) { AiNodeSetPtr(instanceNode, "node", (*I).second ); return NULL; } } bool isFirstSample = true; float radiusPoint = 0.1f; if (AiNodeLookUpUserParameter(args.proceduralNode, "radiusPoint") !=NULL ) radiusPoint = AiNodeGetFlt(args.proceduralNode, "radiusPoint"); bool useVelocities = false; if ((sampleTimes.size() == 1) && (args.shutterOpen != args.shutterClose)) { // no sample, and motion blur needed, let's try to get velocities. if(ps.getVelocitiesProperty().valid()) useVelocities = true; } for ( SampleTimeSet::iterator I = sampleTimes.begin(); I != sampleTimes.end(); ++I, isFirstSample = false) { ISampleSelector sampleSelector( *I ); Alembic::AbcGeom::IPointsSchema::Sample sample = ps.getValue( sampleSelector ); Alembic::Abc::P3fArraySamplePtr v3ptr = sample.getPositions(); size_t pSize = sample.getPositions()->size(); if(useVelocities && isFirstSample) { float scaleVelocity = 1.0f; if (AiNodeLookUpUserParameter(args.proceduralNode, "scaleVelocity") !=NULL ) scaleVelocity = AiNodeGetFlt(args.proceduralNode, "scaleVelocity"); vidxs.resize(pSize*2); Alembic::Abc::V3fArraySamplePtr velptr = sample.getVelocities(); float timeoffset = ((args.frame / args.fps) - ts->getFloorIndex((*I), ps.getNumSamples()).second) * args.fps; for ( size_t pId = 0; pId < pSize; ++pId ) { Alembic::Abc::V3f posAtOpen = ((*v3ptr)[pId] + (*velptr)[pId] * scaleVelocity *-timeoffset); AtPoint pos1; pos1.x = posAtOpen.x; pos1.y = posAtOpen.y; pos1.z = posAtOpen.z; vidxs[pId]= pos1; Alembic::Abc::V3f posAtEnd = ((*v3ptr)[pId] + (*velptr)[pId]* scaleVelocity *(1.0f-timeoffset)); AtPoint pos2; pos2.x = posAtEnd.x; pos2.y = posAtEnd.y; pos2.z = posAtEnd.z; vidxs[pId+pSize]= pos2; radius.push_back(radiusPoint); } } else // not motion blur or correctly sampled particles { for ( size_t pId = 0; pId < pSize; ++pId ) { AtPoint pos; pos.x = (*v3ptr)[pId].x; pos.y = (*v3ptr)[pId].y; pos.z = (*v3ptr)[pId].z; vidxs.push_back(pos); radius.push_back(radiusPoint); } } } AtNode* pointsNode = AiNode( "points" ); if (!pointsNode) { AiMsgError("Failed to make points node for %s", prim.getFullName().c_str()); return NULL; } args.createdNodes.push_back(pointsNode); if ( instanceNode != NULL) { AiNodeSetStr( pointsNode, "name", (name + ":src").c_str() ); } else { AiNodeSetStr( pointsNode, "name", name.c_str() ); } if(!useVelocities) { AiNodeSetArray(pointsNode, "points", AiArrayConvert( vidxs.size() / sampleTimes.size(), sampleTimes.size(), AI_TYPE_POINT, (void*)(&(vidxs[0])) )); AiNodeSetArray(pointsNode, "radius", AiArrayConvert( vidxs.size() / sampleTimes.size(), sampleTimes.size(), AI_TYPE_FLOAT, (void*)(&(radius[0])) )); if ( sampleTimes.size() > 1 ) { std::vector<float> relativeSampleTimes; relativeSampleTimes.reserve( sampleTimes.size() ); for (SampleTimeSet::const_iterator I = sampleTimes.begin(); I != sampleTimes.end(); ++I ) { chrono_t sampleTime = GetRelativeSampleTime( args, (*I) ); relativeSampleTimes.push_back(sampleTime); } AiNodeSetArray( pointsNode, "deform_time_samples", AiArrayConvert(relativeSampleTimes.size(), 1, AI_TYPE_FLOAT, &relativeSampleTimes[0])); } } else { AiNodeSetArray(pointsNode, "points", AiArrayConvert( vidxs.size() / 2, 2, AI_TYPE_POINT, (void*)(&(vidxs[0])) )); AiNodeSetArray(pointsNode, "radius", AiArrayConvert( vidxs.size() /2 / sampleTimes.size(), sampleTimes.size(), AI_TYPE_FLOAT, (void*)(&(radius[0])) )); AiNodeSetArray( pointsNode, "deform_time_samples", AiArray(2, 1, AI_TYPE_FLOAT, 0.f, 1.f)); } AddArbitraryGeomParams( arbGeomParams, frameSelector, pointsNode ); if ( instanceNode == NULL ) { if ( xformSamples ) { ApplyTransformation( pointsNode, xformSamples, args ); } return pointsNode; } else { AiNodeSetByte( pointsNode, "visibility", 0 ); AiNodeSetInt( pointsNode, "mode", 1 ); AiNodeSetPtr(instanceNode, "node", pointsNode ); g_meshCache[cacheId] = pointsNode; return pointsNode; } }
//-***************************************************************************** void Example1_MeshIn() { IArchive archive( Alembic::AbcCoreHDF5::ReadArchive(), "subD1.abc" ); std::cout << "Reading: " << archive.getName() << std::endl; IGeomBaseObject geomBase( IObject( archive, kTop ), "subd" ); TESTING_ASSERT( geomBase.getSchema().getSelfBoundsProperty().valid() ); ISubD meshyObj( IObject( archive, kTop ), "subd", ErrorHandler::kNoisyNoopPolicy ); ISubDSchema &mesh = meshyObj.getSchema(); TESTING_ASSERT( mesh.getErrorHandlerPolicy() == ErrorHandler::kNoisyNoopPolicy ); TESTING_ASSERT( mesh.getUVsParam().getValueProperty().getErrorHandlerPolicy() == ErrorHandler::kNoisyNoopPolicy ); TESTING_ASSERT( mesh.getInterpolateBoundaryProperty().getErrorHandlerPolicy() == ErrorHandler::kNoisyNoopPolicy ); TESTING_ASSERT( 3 == mesh.getNumSamples() ); // UVs IV2fGeomParam uv = mesh.getUVsParam(); TESTING_ASSERT( ! uv.isIndexed() ); // we can fake like the UVs are indexed IV2fGeomParam::Sample uvsamp = uv.getIndexedValue(); TESTING_ASSERT( (*(uvsamp.getIndices()))[1] == 1 ); V2f uv2 = (*(uvsamp.getVals()))[2]; TESTING_ASSERT( uv2 == V2f( 1.0f, 1.0f ) ); std::cout << "2th UV: " << uv2 << std::endl; // get the 1th sample by value ISubDSchema::Sample samp1 = mesh.getValue( 1 ); IGeomBase::Sample baseSamp = geomBase.getSchema().getValue( 1 ); std::cout << "bounds: " << samp1.getSelfBounds().min << ", " << samp1.getSelfBounds().max << std::endl; TESTING_ASSERT( samp1.getSelfBounds().min == V3d( -1.0, -1.0, -1.0 ) ); TESTING_ASSERT( samp1.getSelfBounds().max == V3d( 1.0, 1.0, 1.0 ) ); TESTING_ASSERT( baseSamp.getSelfBounds().min == V3d( -1.0, -1.0, -1.0 ) ); TESTING_ASSERT( baseSamp.getSelfBounds().max == V3d( 1.0, 1.0, 1.0 ) ); for ( size_t i = 0 ; i < samp1.getCreaseSharpnesses()->size() ; ++i ) { std::cout << "crease sharpness[" << i << "]: " << (*(samp1.getCreaseSharpnesses()))[i] << std::endl; TESTING_ASSERT( 0.5 == (*(samp1.getCreaseSharpnesses()))[i] ); } for ( size_t i = 0 ; i < samp1.getCornerSharpnesses()->size() ; ++i ) { std::cout << "corner sharpness[" << i << "]: " << (*(samp1.getCornerSharpnesses()))[i] << std::endl; TESTING_ASSERT( 10.0 == (*(samp1.getCornerSharpnesses()))[i] ); } for ( size_t i = 0 ; i < samp1.getVelocities()->size() ; ++i ) { V3f veloc( g_veloc[i*3], g_veloc[i*3+1], g_veloc[i*3+2] ); std::cout << "velocities[" << i << "]: " << (*(samp1.getVelocities()))[i] << std::endl; TESTING_ASSERT( veloc == (*(samp1.getVelocities()))[i] ); } // test the second sample has '1' as the interpolate boundary value TESTING_ASSERT( 1 == samp1.getInterpolateBoundary() ); std::cout << "Interpolate boundary at 1th sample: " << samp1.getInterpolateBoundary() << std::endl; // get the twoth sample by reference ISubDSchema::Sample samp2; mesh.get( samp2, 2 ); TESTING_ASSERT( samp2.getSelfBounds().min == V3d( -1.0, -1.0, -1.0 ) ); TESTING_ASSERT( samp2.getSelfBounds().max == V3d( 1.0, 1.0, 1.0 ) ); TESTING_ASSERT( 0 == samp2.getInterpolateBoundary() ); std::cout << "Interpolate boundary at 2th sample: " << samp2.getInterpolateBoundary() << std::endl; std::cout << "Mesh num vertices: " << samp2.getPositions()->size() << std::endl; std::cout << "0th vertex from the mesh sample: " << (*(samp2.getPositions()))[0] << std::endl; std::cout << "0th vertex from the mesh sample with get method: " << samp2.getPositions()->get()[0] << std::endl; ICompoundProperty arbattrs = mesh.getArbGeomParams(); // This better exist since we wrote custom attr called color to it TESTING_ASSERT( arbattrs ); for (int i = 0; i < 2; ++ i) { PropertyHeader p = arbattrs.getPropertyHeader(i); TESTING_ASSERT( IC3fGeomParam::matches( p ) ); TESTING_ASSERT( OC3fGeomParam::matches( p ) ); TESTING_ASSERT( ! IC3cGeomParam::matches( p ) ); TESTING_ASSERT( ! OC3cGeomParam::matches( p ) ); TESTING_ASSERT( ! IInt32GeomParam::matches( p ) ); TESTING_ASSERT( ! IFloatGeomParam::matches( p ) ); TESTING_ASSERT( ! IDoubleGeomParam::matches( p ) ); TESTING_ASSERT( ! IV3iGeomParam::matches( p ) ); TESTING_ASSERT( ! IV3fGeomParam::matches( p ) ); if ( p.getName() == "color" ) { IC3fGeomParam color(arbattrs, "color"); TESTING_ASSERT( color.getValueProperty().isScalarLike() ); IC3fGeomParam::Sample cSamp0, cSamp1; color.getExpanded(cSamp0, 0); color.getExpanded(cSamp1, 1); TESTING_ASSERT( (*(cSamp0.getVals()))[0] == C3f( 1.0, 0.0, 0.0 ) ); TESTING_ASSERT( (*(cSamp1.getVals()))[0] == C3f( 1.0, 0.0, 1.0 ) ); } else if ( p.getName() == "colori" ) { IC3fGeomParam color(arbattrs, "colori"); TESTING_ASSERT( !color.getValueProperty().isScalarLike() ); IC3fGeomParam::Sample cSamp; color.getIndexed( cSamp ); TESTING_ASSERT( cSamp.getScope() == kFacevaryingScope ); TESTING_ASSERT( cSamp.getVals()->size() == 3 ); TESTING_ASSERT( (*cSamp.getVals())[0] == C3f( 0.0, 1.0, 1.0 ) ); TESTING_ASSERT( (*cSamp.getVals())[1] == C3f( 1.0, 0.0, 1.0 ) ); TESTING_ASSERT( (*cSamp.getVals())[2] == C3f( 1.0, 1.0, 0.0 ) ); Alembic::Util::uint32_t indices[24] = { 2, 2, 1, 1, 0, 0, 1, 2, 1, 1, 1, 0, 0, 0, 2, 2, 0, 0, 0, 2, 2, 2, 1, 1}; for (int j = 0; j < 24; ++j) { TESTING_ASSERT( (*cSamp.getIndices())[j] == indices[j] ); } } } }
//-***************************************************************************** // a recursive function that reads all inputs and write to the given oObject // node if there's no gap in the frame range for animated nodes // void visitObjects(std::vector< IObject > & iObjects, OObject & oParentObj) { OObject outObj; const AbcA::ObjectHeader & header = iObjects[0].getHeader(); // there are a number of things that needs to be checked for each node // to make sure they can be properly stitched together // // for xform node: // locator or normal xform node // if an xform node, numOps and type of ops match // static or no, and if not, timesampling type matches // if sampled, timesampling type should match // if sampled, no frame gaps // if (IXform::matches(header)) { OXformSchema oSchema; init< IXform, IXformSchema, OXform, OXformSchema >(iObjects, oParentObj, oSchema); outObj = oSchema.getObject(); ICompoundPropertyVec iCompoundProps; iCompoundProps.reserve(iObjects.size()); ICompoundProperty cp = iObjects[0].getProperties(); iCompoundProps.push_back(cp); bool isLocator = cp.getPropertyHeader("locator")?true:false; for (size_t i = 1; i < iObjects.size(); i++) { ICompoundProperty cp = iObjects[i].getProperties(); iCompoundProps.push_back(cp); } // stitch the operations if this is an xform node for (size_t i = 0; i < iObjects.size(); i++) { IXformSchema iSchema = IXform(iObjects[i], Alembic::Abc::kWrapExisting).getSchema(); index_t numSamples = iSchema.getNumSamples(); index_t reqIdx = getIndexSample(oSchema.getNumSamples(), oSchema.getTimeSampling(), numSamples, iSchema.getTimeSampling()); for (; reqIdx < numSamples; reqIdx++) { XformSample samp = iSchema.getValue(reqIdx); oSchema.set(samp); } } // stitch "locator" if it's a locator OCompoundProperty oCompoundProp = outObj.getProperties(); if (isLocator) { const PropertyHeader * propHeaderPtr = iCompoundProps[0].getPropertyHeader("locator"); stitchScalarProp(*propHeaderPtr, iCompoundProps, oCompoundProp); } } else if (ISubD::matches(header)) { OSubDSchema oSchema; init< ISubD, ISubDSchema, OSubD, OSubDSchema >(iObjects, oParentObj, oSchema); outObj = oSchema.getObject(); // stitch the SubDSchema // for (size_t i = 0; i < iObjects.size(); i++) { ISubDSchema iSchema = ISubD(iObjects[i], Alembic::Abc::kWrapExisting).getSchema(); index_t numSamples = iSchema.getNumSamples(); IV2fGeomParam uvs = iSchema.getUVsParam(); if (i == 0 && uvs) { oSchema.setUVSourceName(GetSourceName(uvs.getMetaData())); } index_t reqIdx = getIndexSample(oSchema.getNumSamples(), oSchema.getTimeSampling(), numSamples, iSchema.getTimeSampling()); for (; reqIdx < numSamples; reqIdx++) { ISubDSchema::Sample iSamp = iSchema.getValue(reqIdx); OSubDSchema::Sample oSamp; Abc::P3fArraySamplePtr posPtr = iSamp.getPositions(); if (posPtr) oSamp.setPositions(*posPtr); Abc::V3fArraySamplePtr velocPtr = iSamp.getVelocities(); if (velocPtr) oSamp.setVelocities(*velocPtr); Abc::Int32ArraySamplePtr faceIndicesPtr = iSamp.getFaceIndices(); if (faceIndicesPtr) oSamp.setFaceIndices(*faceIndicesPtr); Abc::Int32ArraySamplePtr faceCntPtr = iSamp.getFaceCounts(); if (faceCntPtr) oSamp.setFaceCounts(*faceCntPtr); oSamp.setFaceVaryingInterpolateBoundary(iSamp.getFaceVaryingInterpolateBoundary()); oSamp.setFaceVaryingPropagateCorners(iSamp.getFaceVaryingPropagateCorners()); oSamp.setInterpolateBoundary(iSamp.getInterpolateBoundary()); Abc::Int32ArraySamplePtr creaseIndicesPtr = iSamp.getCreaseIndices(); if (creaseIndicesPtr) oSamp.setCreaseIndices(*creaseIndicesPtr); Abc::Int32ArraySamplePtr creaseLenPtr = iSamp.getCreaseLengths(); if (creaseLenPtr) oSamp.setCreaseLengths(*creaseLenPtr); Abc::FloatArraySamplePtr creaseSpPtr = iSamp.getCreaseSharpnesses(); if (creaseSpPtr) oSamp.setCreaseSharpnesses(*creaseSpPtr); Abc::Int32ArraySamplePtr cornerIndicesPtr = iSamp.getCornerIndices(); if (cornerIndicesPtr) oSamp.setCornerIndices(*cornerIndicesPtr); Abc::FloatArraySamplePtr cornerSpPtr = iSamp.getCornerSharpnesses(); if (cornerSpPtr) oSamp.setCreaseSharpnesses(*cornerSpPtr); Abc::Int32ArraySamplePtr holePtr = iSamp.getHoles(); if (holePtr) oSamp.setHoles(*holePtr); oSamp.setSubdivisionScheme(iSamp.getSubdivisionScheme()); // set uvs IV2fGeomParam::Sample iUVSample; OV2fGeomParam::Sample oUVSample; if (uvs) { getOGeomParamSamp <IV2fGeomParam, IV2fGeomParam::Sample, OV2fGeomParam::Sample>(uvs, iUVSample, oUVSample, reqIdx); oSamp.setUVs(oUVSample); } oSchema.set(oSamp); } } } else if (IPolyMesh::matches(header)) { OPolyMeshSchema oSchema; init< IPolyMesh, IPolyMeshSchema, OPolyMesh, OPolyMeshSchema >(iObjects, oParentObj, oSchema); outObj = oSchema.getObject(); // stitch the PolySchema // for (size_t i = 0; i < iObjects.size(); i++) { IPolyMeshSchema iSchema = IPolyMesh(iObjects[i], Alembic::Abc::kWrapExisting).getSchema(); index_t numSamples = iSchema.getNumSamples(); IN3fGeomParam normals = iSchema.getNormalsParam(); IV2fGeomParam uvs = iSchema.getUVsParam(); if (i == 0 && uvs) { oSchema.setUVSourceName(GetSourceName(uvs.getMetaData())); } index_t reqIdx = getIndexSample(oSchema.getNumSamples(), oSchema.getTimeSampling(), numSamples, iSchema.getTimeSampling()); for (; reqIdx < numSamples; reqIdx++) { IPolyMeshSchema::Sample iSamp = iSchema.getValue(reqIdx); OPolyMeshSchema::Sample oSamp; Abc::P3fArraySamplePtr posPtr = iSamp.getPositions(); if (posPtr) oSamp.setPositions(*posPtr); Abc::V3fArraySamplePtr velocPtr = iSamp.getVelocities(); if (velocPtr) oSamp.setVelocities(*velocPtr); Abc::Int32ArraySamplePtr faceIndicesPtr = iSamp.getFaceIndices(); if (faceIndicesPtr) oSamp.setFaceIndices(*faceIndicesPtr); Abc::Int32ArraySamplePtr faceCntPtr = iSamp.getFaceCounts(); if (faceCntPtr) oSamp.setFaceCounts(*faceCntPtr); // set uvs IV2fGeomParam::Sample iUVSample; OV2fGeomParam::Sample oUVSample; if (uvs) { getOGeomParamSamp <IV2fGeomParam, IV2fGeomParam::Sample, OV2fGeomParam::Sample>(uvs, iUVSample, oUVSample, reqIdx); oSamp.setUVs(oUVSample); } // set normals IN3fGeomParam::Sample iNormalsSample; ON3fGeomParam::Sample oNormalsSample; if (normals) { getOGeomParamSamp <IN3fGeomParam, IN3fGeomParam::Sample, ON3fGeomParam::Sample>(normals, iNormalsSample, oNormalsSample, reqIdx); oSamp.setNormals(oNormalsSample); } oSchema.set(oSamp); } } } else if (ICamera::matches(header)) { OCameraSchema oSchema; init< ICamera, ICameraSchema, OCamera, OCameraSchema >(iObjects, oParentObj, oSchema); outObj = oSchema.getObject(); // stitch the CameraSchemas // for (size_t i = 0; i < iObjects.size(); i++) { ICameraSchema iSchema = ICamera(iObjects[i], Alembic::Abc::kWrapExisting).getSchema(); index_t numSamples = iSchema.getNumSamples(); index_t reqIdx = getIndexSample(oSchema.getNumSamples(), oSchema.getTimeSampling(), numSamples, iSchema.getTimeSampling()); for (; reqIdx < numSamples; reqIdx++) { oSchema.set(iSchema.getValue(reqIdx)); } } } else if (ICurves::matches(header)) { OCurvesSchema oSchema; init< ICurves, ICurvesSchema, OCurves, OCurvesSchema >(iObjects, oParentObj, oSchema); outObj = oSchema.getObject(); // stitch the CurvesSchemas // for (size_t i = 0; i < iObjects.size(); i++) { ICurvesSchema iSchema = ICurves(iObjects[i], Alembic::Abc::kWrapExisting).getSchema(); IV2fGeomParam iUVs = iSchema.getUVsParam(); IN3fGeomParam iNormals = iSchema.getNormalsParam(); IFloatGeomParam iWidths = iSchema.getWidthsParam(); IFloatArrayProperty iKnots = iSchema.getKnotsProperty(); IUcharArrayProperty iOrders = iSchema.getOrdersProperty(); index_t numSamples = iSchema.getNumSamples(); index_t reqIdx = getIndexSample(oSchema.getNumSamples(), oSchema.getTimeSampling(), numSamples, iSchema.getTimeSampling()); for (; reqIdx < numSamples; reqIdx++) { ICurvesSchema::Sample iSamp = iSchema.getValue(reqIdx); OCurvesSchema::Sample oSamp; Abc::P3fArraySamplePtr posPtr = iSamp.getPositions(); if (posPtr) oSamp.setPositions(*posPtr); Abc::V3fArraySamplePtr velocPtr = iSamp.getVelocities(); if (velocPtr) oSamp.setVelocities(*velocPtr); oSamp.setType(iSamp.getType()); Abc::Int32ArraySamplePtr curvsNumPtr = iSamp.getCurvesNumVertices(); if (curvsNumPtr) oSamp.setCurvesNumVertices(*curvsNumPtr); oSamp.setWrap(iSamp.getWrap()); oSamp.setBasis(iSamp.getBasis()); Abc::FloatArraySamplePtr knotsPtr = iSamp.getKnots(); if (knotsPtr) { oSamp.setKnots(*knotsPtr); } Abc::UcharArraySamplePtr ordersPtr = iSamp.getOrders(); if (ordersPtr) { oSamp.setOrders(*ordersPtr); } IFloatGeomParam::Sample iWidthSample; OFloatGeomParam::Sample oWidthSample; if (iWidths) { getOGeomParamSamp <IFloatGeomParam, IFloatGeomParam::Sample, OFloatGeomParam::Sample>(iWidths, iWidthSample, oWidthSample, reqIdx); oSamp.setWidths(oWidthSample); } IV2fGeomParam::Sample iUVSample; OV2fGeomParam::Sample oUVSample; if (iUVs) { getOGeomParamSamp <IV2fGeomParam, IV2fGeomParam::Sample, OV2fGeomParam::Sample>(iUVs, iUVSample, oUVSample, reqIdx); oSamp.setUVs(oUVSample); } IN3fGeomParam::Sample iNormalsSample; ON3fGeomParam::Sample oNormalsSample; if (iNormals) { getOGeomParamSamp <IN3fGeomParam, IN3fGeomParam::Sample, ON3fGeomParam::Sample>(iNormals, iNormalsSample, oNormalsSample, reqIdx); oSamp.setNormals(oNormalsSample); } oSchema.set(oSamp); } } } else if (IPoints::matches(header)) { OPointsSchema oSchema; init< IPoints, IPointsSchema, OPoints, OPointsSchema >(iObjects, oParentObj, oSchema); outObj = oSchema.getObject(); // stitch the PointsSchemas // for (size_t i = 0; i < iObjects.size(); i++) { IPointsSchema iSchema = IPoints(iObjects[i], Alembic::Abc::kWrapExisting).getSchema(); IFloatGeomParam iWidths = iSchema.getWidthsParam(); index_t numSamples = iSchema.getNumSamples(); index_t reqIdx = getIndexSample(oSchema.getNumSamples(), oSchema.getTimeSampling(), numSamples, iSchema.getTimeSampling()); for (; reqIdx < numSamples; reqIdx++) { IPointsSchema::Sample iSamp = iSchema.getValue(reqIdx); OPointsSchema::Sample oSamp; Abc::P3fArraySamplePtr posPtr = iSamp.getPositions(); if (posPtr) oSamp.setPositions(*posPtr); Abc::UInt64ArraySamplePtr idPtr = iSamp.getIds(); if (idPtr) oSamp.setIds(*idPtr); Abc::V3fArraySamplePtr velocPtr = iSamp.getVelocities(); if (velocPtr) oSamp.setVelocities(*velocPtr); IFloatGeomParam::Sample iWidthSample; OFloatGeomParam::Sample oWidthSample; if (iWidths) { getOGeomParamSamp <IFloatGeomParam, IFloatGeomParam::Sample, OFloatGeomParam::Sample>(iWidths, iWidthSample, oWidthSample, reqIdx); oSamp.setWidths(oWidthSample); } oSchema.set(oSamp); } } } else if (INuPatch::matches(header)) { ONuPatchSchema oSchema; init< INuPatch, INuPatchSchema, ONuPatch, ONuPatchSchema >(iObjects, oParentObj, oSchema); outObj = oSchema.getObject(); // stitch the NuPatchSchemas // for (size_t i = 0; i < iObjects.size(); i++) { INuPatchSchema iSchema = INuPatch(iObjects[i], Alembic::Abc::kWrapExisting).getSchema(); index_t numSamples = iSchema.getNumSamples(); IN3fGeomParam normals = iSchema.getNormalsParam(); IV2fGeomParam uvs = iSchema.getUVsParam(); index_t reqIdx = getIndexSample(oSchema.getNumSamples(), oSchema.getTimeSampling(), numSamples, iSchema.getTimeSampling()); for (; reqIdx < numSamples; reqIdx++) { INuPatchSchema::Sample iSamp = iSchema.getValue(reqIdx); ONuPatchSchema::Sample oSamp; Abc::P3fArraySamplePtr posPtr = iSamp.getPositions(); if (posPtr) oSamp.setPositions(*posPtr); Abc::V3fArraySamplePtr velocPtr = iSamp.getVelocities(); if (velocPtr) oSamp.setVelocities(*velocPtr); oSamp.setNu(iSamp.getNumU()); oSamp.setNv(iSamp.getNumV()); oSamp.setUOrder(iSamp.getUOrder()); oSamp.setVOrder(iSamp.getVOrder()); Abc::FloatArraySamplePtr uKnotsPtr = iSamp.getUKnot(); if (uKnotsPtr) oSamp.setUKnot(*uKnotsPtr); Abc::FloatArraySamplePtr vKnotsPtr = iSamp.getVKnot(); if (vKnotsPtr) oSamp.setVKnot(*vKnotsPtr); IV2fGeomParam::Sample iUVSample; OV2fGeomParam::Sample oUVSample; if (uvs) { getOGeomParamSamp <IV2fGeomParam, IV2fGeomParam::Sample, OV2fGeomParam::Sample>(uvs, iUVSample, oUVSample, reqIdx); oSamp.setUVs(oUVSample); } IN3fGeomParam::Sample iNormalsSample; ON3fGeomParam::Sample oNormalsSample; if (normals) { getOGeomParamSamp <IN3fGeomParam, IN3fGeomParam::Sample, ON3fGeomParam::Sample>(normals, iNormalsSample, oNormalsSample, reqIdx); oSamp.setNormals(oNormalsSample); } if (iSchema.hasTrimCurve()) { oSamp.setTrimCurve(iSamp.getTrimNumLoops(), *(iSamp.getTrimNumCurves()), *(iSamp.getTrimNumVertices()), *(iSamp.getTrimOrders()), *(iSamp.getTrimKnots()), *(iSamp.getTrimMins()), *(iSamp.getTrimMaxes()), *(iSamp.getTrimU()), *(iSamp.getTrimV()), *(iSamp.getTrimW())); } oSchema.set(oSamp); } } } else { outObj = OObject(oParentObj, header.getName(), header.getMetaData()); // collect the top level compound property ICompoundPropertyVec iCompoundProps(iObjects.size()); for (size_t i = 0; i < iObjects.size(); i++) { iCompoundProps[i] = iObjects[i].getProperties(); } OCompoundProperty oCompoundProperty = outObj.getProperties(); stitchCompoundProp(iCompoundProps, oCompoundProperty); } // After done writing THIS OObject node, if input nodes have children, // go deeper. // Otherwise we are done here size_t numChildren = iObjects[0].getNumChildren(); // check to make sure all of our iObjects have the same number of children for (size_t j = 1; j < iObjects.size(); j++) { if (numChildren != iObjects[j].getNumChildren()) { std::cerr << "ERROR: " << iObjects[j].getFullName() << " in " << iObjects[j].getArchive().getName() << " has a different number of children than " << iObjects[0].getFullName() << " in " << iObjects[0].getArchive().getName() << std::endl; exit(1); } } for (size_t i = 0 ; i < numChildren; i++ ) { std::vector< IObject > iChildObjects; for (size_t f = 0; f < iObjects.size(); f++) { iChildObjects.push_back(iObjects[f].getChild(i)); } visitObjects(iChildObjects, outObj); } }
void AddArbitraryGeomParams( ICompoundProperty &parent, ISampleSelector &sampleSelector, AtNode * primNode, const std::set<std::string> * excludeNames ) { if ( primNode == NULL || !parent.valid() ) { return; } for ( size_t i = 0; i < parent.getNumProperties(); ++i ) { const PropertyHeader &propHeader = parent.getPropertyHeader( i ); const std::string &propName = propHeader.getName(); if (propName.empty() || ( excludeNames && excludeNames->find( propName ) != excludeNames->end() ) ) { continue; } if ( IFloatGeomParam::matches( propHeader ) ) { AddArbitraryGeomParam<IFloatGeomParam>( parent, propHeader, sampleSelector, primNode, AI_TYPE_FLOAT); } else if ( IInt32GeomParam::matches( propHeader ) ) { AddArbitraryGeomParam<IInt32GeomParam>( parent, propHeader, sampleSelector, primNode, AI_TYPE_INT); } else if ( IStringGeomParam::matches( propHeader ) ) { AddArbitraryStringGeomParam( parent, propHeader, sampleSelector, primNode); } else if ( IV2fGeomParam::matches( propHeader ) ) { AddArbitraryGeomParam<IV2fGeomParam>( parent, propHeader, sampleSelector, primNode, AI_TYPE_VECTOR2); } else if ( IV3fGeomParam::matches( propHeader ) ) { AddArbitraryGeomParam<IV3fGeomParam>( parent, propHeader, sampleSelector, primNode, AI_TYPE_VECTOR); } else if ( IP3fGeomParam::matches( propHeader ) ) { AddArbitraryGeomParam<IP3fGeomParam>( parent, propHeader, sampleSelector, primNode, AI_TYPE_VECTOR); } else if ( IN3fGeomParam::matches( propHeader ) ) { AddArbitraryGeomParam<IN3fGeomParam>( parent, propHeader, sampleSelector, primNode, AI_TYPE_VECTOR); } else if ( IC3fGeomParam::matches( propHeader ) ) { AddArbitraryGeomParam<IC3fGeomParam>( parent, propHeader, sampleSelector, primNode, AI_TYPE_RGB); } else if ( IC4fGeomParam::matches( propHeader ) ) { AddArbitraryGeomParam<IC4fGeomParam>( parent, propHeader, sampleSelector, primNode, AI_TYPE_RGBA); } if ( IM44fGeomParam::matches( propHeader ) ) { AddArbitraryGeomParam<IM44fGeomParam>( parent, propHeader, sampleSelector, primNode, AI_TYPE_MATRIX); } } }
void readProperty(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 3)"); 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 << " " << 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 << " has a simple 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 == kScalarProperty, "Expected a scalar property, but didn't find one" ); DataType dType = props.getPropertyHeader(0).getDataType(); ABCA_ASSERT( dType.getPod() == kFloat64POD, "Expected a double (kFloat64POD) property, but didn't" " find one" ); // We know this is a scalar property (I'm eliding the if/else // statements required to recognize this) IDoubleProperty mass( props, propNames[0] ); size_t numSamples = mass.getNumSamples(); std::cout << ".. it has " << numSamples << " samples" << std::endl; ABCA_ASSERT( numSamples == 5, "Expected 5 samples, found " << numSamples ); std::cout << "..with values: "; for (int ss=0; ss<numSamples; ss++) { ISampleSelector iss( (index_t) ss); printSampleValue( mass, iss ); double massDiff = mass.getValue( iss ) - (33.0 + 0.1*ss); ABCA_ASSERT( fabs(massDiff) < 1e-12, "Incorrect sample value read" ); } std::cout << std::endl; // Done - the archive closes itself }
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 }
//-***************************************************************************** ICompoundProperty::ICompoundProperty( const ICompoundProperty & iParent, const std::string &iName, const Argument &iArg0 ) { init( iParent.getPtr(), iName, GetErrorHandlerPolicy( iParent ), iArg0 ); }
void readProperty(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); ABCA_ASSERT( (useOgawa && coreType == AbcF::IFactory::kOgawa) || (!useOgawa && coreType == AbcF::IFactory::kHDF5), "File did not open as the expected type." ); 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 << " " << 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 == kScalarProperty, "Expected a scalar property, but didn't find one" ); std::cout << " which is a scalar property"; DataType dType = props.getPropertyHeader(0).getDataType(); ABCA_ASSERT( dType.getPod() == kFloat64POD, "Expected a double (kFloat64POD) property, but didn't" " find one" ); // We know this is a scalar property (I'm eliding the if/else // statements required to recognize this) IDoubleProperty mass( props, propNames[0] ); size_t numSamples = mass.getNumSamples(); std::cout << ".. it has " << numSamples << " samples" << std::endl; //ABCA_ASSERT( numSamples == 5, "Expected 5 samples, found " << numSamples ); TimeSamplingPtr ts = mass.getTimeSampling(); std::cout << "..with time/value pairs: "; for (unsigned int ss=0; ss<numSamples; ss++) { ISampleSelector iss( (index_t) ss); std::cout << ts->getSampleTime( (index_t) ss ) << "/"; printSampleValue( mass, iss ); std::cout << " "; double timeDiff = ts->getSampleTime( (index_t) ss ) - (g_startTime + (ss*(g_dt/3.0))); ABCA_ASSERT( fabs(timeDiff) < 1e-12, "Incorrect sample time read" ); double massDiff = mass.getValue( iss ) - (1.0 + 0.1*ss); ABCA_ASSERT( fabs(massDiff) < 1e-12, "Incorrect sample value read" ); } ABCA_ASSERT( archive.getMaxNumSamplesForTimeSamplingIndex(1) == (index_t) numSamples, "Incorrect number of max samples for Time Sampling ID 1."); std::cout << std::endl; // Done - the archive closes itself }
void readV3fArrayProperty(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() == kFloat32POD, "Expected an v3f 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) IV3fArrayProperty positions( props, propNames[0] ); size_t numSamples = positions.getNumSamples(); std::cout << ".. it has " << numSamples << " samples" << std::endl; ABCA_ASSERT( numSamples == 5, "Expected 5 samples, found " << numSamples ); TimeSamplingPtr ts = positions.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 ) << " / "; V3fArraySamplePtr samplePtr; positions.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; if (ss == 2) // no entries in sample #2 { ABCA_ASSERT( numPoints == 0, "Expected an empty sample, but found " << numPoints << " entries." ); } else { for ( size_t jj=0 ; jj<numPoints ; jj++ ) ABCA_ASSERT( (*samplePtr)[jj] == g_vectors[jj], "Incorrect value read from archive." ); } } ABCA_ASSERT( archive.getMaxNumSamplesForTimeSamplingIndex(1) == (index_t) numSamples, "Incorrect number of max samples in readV3fArrayProperty." ); std::cout << std::endl; // Done - the archive closes itself double start, end; GetArchiveStartAndEndTime( archive, start, end ); TESTING_ASSERT( almostEqual(start, 123.0) ); TESTING_ASSERT( almostEqual(end, 123.0 + 4.0 / 24.0) ); }
//-***************************************************************************** void AddArbitraryProperties( ICompoundProperty &parent, ISampleSelector &sampleSelector, ParamListBuilder &ParamListBuilder, const std::set<std::string> * excludeNames ) { for ( size_t i = 0; i < parent.getNumProperties(); ++i ) { const PropertyHeader &propHeader = parent.getPropertyHeader( i ); const std::string &propName = propHeader.getName(); if (propName.empty() || propName[0] == '.' || ( excludeNames && excludeNames->find( propName ) != excludeNames->end() ) || propHeader.getMetaData().get( "geoScope" ).empty() || propHeader.isCompound() // skip compounds for now || propHeader.isScalar() // also skip scalars ) { continue; } if ( IN3fArrayProperty::matches( propHeader ) ) { AddArbitraryPropertyToParamListBuilder<IN3fArrayProperty>( parent, propHeader, sampleSelector, "normal", ParamListBuilder ); } else if ( IV2fArrayProperty::matches( propHeader ) ) { AddArbitraryPropertyToParamListBuilder<IV2fArrayProperty>( parent, propHeader, sampleSelector, "float[2]", ParamListBuilder ); } else if ( IV3fArrayProperty::matches( propHeader ) ) { AddArbitraryPropertyToParamListBuilder<IV3fArrayProperty>( parent, propHeader, sampleSelector, "point", ParamListBuilder ); } else if ( IM44fArrayProperty::matches( propHeader ) ) { AddArbitraryPropertyToParamListBuilder<IM44fArrayProperty>( parent, propHeader, sampleSelector, "matrix", ParamListBuilder ); } else if ( IFloatArrayProperty::matches( propHeader ) ) { AddArbitraryPropertyToParamListBuilder<IFloatArrayProperty>( parent, propHeader, sampleSelector, "float", ParamListBuilder ); } else if ( IInt32ArrayProperty::matches( propHeader ) ) { AddArbitraryPropertyToParamListBuilder<IInt32ArrayProperty>( parent, propHeader, sampleSelector, "int", ParamListBuilder ); } else if ( IStringArrayProperty::matches( propHeader ) ) { AddArbitraryStringPropertyToParamListBuilder( parent, propHeader, sampleSelector, ParamListBuilder ); } } }
void readNestedCommpoundWithVis(const std::string &archiveName) { // Open an existing archive for reading. Indicate that we want // Alembic to throw exceptions on errors. IArchive archive( Alembic::AbcCoreOgawa::ReadArchive(), archiveName, ErrorHandler::kThrowPolicy ); IObject archiveTop = archive.getTop(); TESTING_ASSERT_THROW( GetIArchiveBounds( archive ), Alembic::Util::Exception ); IBox3dProperty boxProp = GetIArchiveBounds( archive, ErrorHandler::kQuietNoopPolicy ); TESTING_ASSERT( !boxProp.valid() ); ICharProperty topVisibility = GetVisibilityProperty (archiveTop); std::cout << "Does this object have VisibilityProperty? " << (bool) (true == topVisibility) << std::endl; ABCA_ASSERT( topVisibility == false, "top object should not have a visibility property"); // Determine the number of (top level) children the archive has const size_t numChildren = archiveTop.getNumChildren(); ABCA_ASSERT( numChildren == 2, "Wrong number of children (expected 2)"); std::cout << "The archive has " << numChildren << " children:" << std::endl; IObject child1; IObject otherChild; // Iterate through them, print out their names for ( size_t ii=0; ii <numChildren; ii++) { IObject child( archiveTop, archiveTop.getChildHeader(ii).getName() ); std::cout << " " << child.getName(); std::cout << " has " << child.getNumChildren() << " children" << std::endl; // Properties ICompoundProperty props = child.getProperties(); size_t numProperties = props.getNumProperties(); std::cout << " ..and " << numProperties << " properties" << std::endl; std::vector<std::string> propNames; for ( size_t pp=0 ; pp < numProperties ; ++pp ) { propNames.push_back( props.getPropertyHeader(pp).getName() ); } for ( size_t jj=0; jj<numProperties; ++jj) { std::cout << " ..named " << propNames[jj] << std::endl; std::cout << " ..with type: "; PropertyType pType = props.getPropertyHeader(jj).getPropertyType(); if (pType == kCompoundProperty) { std::cout << "compound" << std::endl; ICompoundProperty prop( props, propNames[jj] ); std::cout << " Accessing this nested prop for its obj -" << prop.getObject ().getName () << std::endl; } else if (pType == kScalarProperty) { std::cout << "scalar" << std::endl; } else if (pType == kArrayProperty) { std::cout << "array" << std::endl; } } ICharProperty childVisibility; childVisibility = GetVisibilityProperty (child); if (ii == 1) { child1 = child; // This is child_1. It should have visibility property // and it should be set to hidden ABCA_ASSERT( childVisibility == true, "child_1 should have a visibility property"); ABCA_ASSERT( childVisibility.getValue () == kVisibilityHidden, "child_1 visibility should be hidden"); ABCA_ASSERT( childVisibility.getValue () == GetVisibility (child), "child_1 visibility should match call value from GetVisibility ()"); std::cout << " child_1 visibility correctly set to hidden" << std::endl; } else { otherChild = child; ABCA_ASSERT( childVisibility == false, "child object should not have a visibility property"); } } // Test that IsAncestorInvisible () works // // child of child1 (which is hidden) means that this child should be // hidden too IObject child1SubObject( child1, "nested_object"); ABCA_ASSERT( IsAncestorInvisible (archiveTop) == false, "top root should be visible"); ABCA_ASSERT( IsAncestorInvisible (child1SubObject) == true, "object under child1 should eval to being not visible"); ABCA_ASSERT( IsAncestorInvisible (child1) == true, "child1 should eval to being not visible"); ABCA_ASSERT( IsAncestorInvisible (otherChild) == false, "other object should eval to being visible"); // Done - the archive closes itself }