void Example1_GeomBaseIn()
{
    IArchive archive( Alembic::AbcCoreHDF5::ReadArchive(), "curves1.abc" );
    std::cout << "\nReading: " << archive.getName() << std::endl;

    std::cout <<"constructing curves" << std::endl;
    IObject myCurvesAsObj( IObject( archive, kTop) , "reallly_long_curves_name");
    ICurves myCurves( IObject( archive, kTop) , "reallly_long_curves_name");
    IGeomBaseObject geomBaseObject ( myCurvesAsObj, kWrapExisting);
    TESTING_ASSERT( IGeomBase::matches( myCurves.getMetaData() ) );

    std::cout << "getting schema" << std::endl;
    IGeomBase geomBase = geomBaseObject.getSchema();
    std::cout << "done getting schema" << std::endl;

    // get the samples from the curves
    IGeomBase::Sample geomBaseSample;
    geomBase.get( geomBaseSample );

    // test the bounding box
    TESTING_ASSERT( geomBaseSample.getSelfBounds().min == V3d( -1.0, -1.0, -1.0 ) );
    std::cout << "bounds max " << geomBaseSample.getSelfBounds().max << std::endl;
    TESTING_ASSERT( geomBaseSample.getSelfBounds().max == V3d( 1.0, 1.0, 1.0 ) );



}
Exemple #2
0
//-*****************************************************************************
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] );
            }
        }
    }
}
//-*****************************************************************************
void Example1_MeshIn()
{
    IArchive archive( Alembic::AbcCoreHDF5::ReadArchive(), "polyMesh1.abc" );
    std::cout << "Reading: " << archive.getName() << std::endl;

    IGeomBaseObject geomBase( IObject( archive, kTop ), "meshy" );
    TESTING_ASSERT( geomBase.getSchema().getSelfBoundsProperty().valid() );

    IPolyMesh meshyObj( IObject( archive, kTop ), "meshy" );
    IPolyMeshSchema &mesh = meshyObj.getSchema();
    IN3fGeomParam N = mesh.getNormalsParam();
    IV2fGeomParam uv = mesh.getUVsParam();

    TESTING_ASSERT( ! N.isIndexed() );

    TESTING_ASSERT( ! uv.isIndexed() );

    IPolyMeshSchema::Sample mesh_samp;
    mesh.get( mesh_samp );
    IGeomBase::Sample baseSamp;
    geomBase.getSchema().get( baseSamp );

    TESTING_ASSERT( mesh_samp.getSelfBounds().min == V3d( -1.0, -1.0, -1.0 ) );

    TESTING_ASSERT( mesh_samp.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 ) );

    ICompoundProperty arbattrs = mesh.getArbGeomParams();

    // we didn't set any on write, so on read, it should be an invalid container
    TESTING_ASSERT( ! arbattrs );

    // getExpandedValue() takes an optional ISampleSelector;
    // getVals() returns a TypedArraySamplePtr
    N3fArraySamplePtr nsp = N.getExpandedValue().getVals();

    TESTING_ASSERT( N.isConstant() );
    TESTING_ASSERT( uv.isConstant() );

    TESTING_ASSERT( IsGeomParam( N.getMetaData() ) );

    N3f n0 = (*nsp)[0];

    for ( size_t i = 0 ; i < nsp->size() ; ++i )
    {
        std::cout << i << "th normal: " << (*nsp)[i] << std::endl;
    }

    TESTING_ASSERT( n0 == N3f( -1.0f, 0.0f, 0.0f ) );
    std::cout << "0th normal: " << n0 << std::endl;

    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;

    std::cout << "Mesh num vertices: "
              << mesh_samp.getPositions()->size() << std::endl;

    std::cout << "0th vertex from the mesh sample: "
              << (*(mesh_samp.getPositions()))[0] << std::endl;

    std::cout << "0th vertex from the mesh sample with get method: "
              << mesh_samp.getPositions()->get()[0] << std::endl;
}