Пример #1
0
//-*****************************************************************************
void lightTest()
{
    std::string fileName = "light1.abc";

    {
        OArchive archive( Alembic::AbcCoreHDF5::WriteArchive(), fileName );
        OLight emptyLightObj( OObject( archive, kTop ), "emptyLight" );
        OLight lightObj( OObject( archive, kTop ), "myLight" );

        CameraSample samp;
        lightObj.getSchema().setCameraSample( samp );
        samp = CameraSample( -0.35, 0.75, 0.1, 0.5 );
        samp.setChildBounds( Abc::Box3d(
            Abc::V3d( 0.0, 0.1, 0.2), Abc::V3d( 0.3, 0.4, 0.5 ) ) );
        lightObj.getSchema().setCameraSample( samp );

        Abc::OCompoundProperty arb = lightObj.getSchema().getArbGeomParams();
        OFloatGeomParam param(arb, "test", false,
            Alembic::AbcGeom::kConstantScope, 1);
        Abc::OCompoundProperty user = lightObj.getSchema().getUserProperties();
        OFloatProperty(user, "test");
    }

    {
        CameraSample samp;
        double top, bottom, left, right;

        IArchive archive( Alembic::AbcCoreHDF5::ReadArchive(), fileName );
        ILight emptyLightObj( IObject( archive, kTop ), "emptyLight" );
        ILight lightObj( IObject( archive, kTop ), "myLight" );

        TESTING_ASSERT( ! emptyLightObj.getSchema().getArbGeomParams() );
        TESTING_ASSERT( ! emptyLightObj.getSchema().getUserProperties() );
        TESTING_ASSERT( ! emptyLightObj.getSchema().getCameraSchema().valid() );
        TESTING_ASSERT(
            lightObj.getSchema().getArbGeomParams().getNumProperties() == 1 );
        TESTING_ASSERT(
            lightObj.getSchema().getUserProperties().getNumProperties() == 1 );

        lightObj.getSchema().getCameraSchema().get( samp, 0 );
        samp.getScreenWindow( top, bottom, left, right );
        TESTING_ASSERT( almostEqual( top, 0.666666666666667 ) );
        TESTING_ASSERT( almostEqual( bottom, -0.666666666666667 ) );
        TESTING_ASSERT( almostEqual( left, -1.0 ) );
        TESTING_ASSERT( almostEqual( right, 1.0 ) );

        lightObj.getSchema().getCameraSchema().get( samp, 1 );
        samp.getScreenWindow( top, bottom, left, right );
        TESTING_ASSERT( almostEqual( top, -0.35 ) );
        TESTING_ASSERT( almostEqual( bottom, 0.75 ) );
        TESTING_ASSERT( almostEqual( left, 0.1 ) );
        TESTING_ASSERT( almostEqual( right, 0.5 ) );

        TESTING_ASSERT(
            ! lightObj.getSchema().getCameraSchema().getChildBoundsProperty() );
    }
}
IECore::ObjectPtr FromAlembicCameraConverter::doAlembicConversion( const Alembic::Abc::IObject &iObject, const Alembic::Abc::ISampleSelector &sampleSelector, const IECore::CompoundObject *operands ) const
{
	ICamera iCamera( iObject, kWrapExisting );
	ICameraSchema &iCameraSchema = iCamera.getSchema();
	CameraSample sample;
	iCameraSchema.get( sample, sampleSelector );
	
	CameraPtr result = new Camera;
	result->parameters()["projection"] = new StringData( "perspective" );
	
	double top, bottom, left, right;
	sample.getScreenWindow( top, bottom, left, right );
	result->parameters()["screenWindow"] = new Box2fData( Box2f( V2f( left, bottom ), V2f( right, top ) ) );
	result->parameters()["projection:fov"] = new FloatData( sample.getFieldOfView() );
	
	return result;
}
//-*****************************************************************************
void OLightSchema::setCameraSample( const CameraSample &iSamp )
{
    ALEMBIC_ABC_SAFE_CALL_BEGIN( "OLightSchema::setCameraSample" );

    if ( ! m_cameraSchema.valid() )
    {
        m_cameraSchema = OCameraSchema( this->getPtr(), ".camera", m_tsPtr );
    }

    // clear the child bounds if they happen to be set on the camera sample
    // since that data is meaninless because we have child bounds on the
    // light schema
    CameraSample samp = iSamp;
    Abc::Box3d childBounds;
    samp.setChildBounds(childBounds);

    m_cameraSchema.set( samp );

    ALEMBIC_ABC_SAFE_CALL_END();
}
Пример #4
0
void ICameraSchema::get( CameraSample & oSample,
    const Abc::ISampleSelector &iSS ) const
{
    ALEMBIC_ABC_SAFE_CALL_BEGIN( "ICameraSchema::get()" );

    double sampleData[16];
    m_coreProperties.get( sampleData, iSS );

    oSample.reset();

    oSample.setFocalLength( sampleData[0] );
    oSample.setHorizontalAperture( sampleData[1] );
    oSample.setHorizontalFilmOffset( sampleData[2] );
    oSample.setVerticalAperture( sampleData[3] );
    oSample.setVerticalFilmOffset( sampleData[4] );
    oSample.setLensSqueezeRatio( sampleData[5] );

    oSample.setOverScanLeft(sampleData[6]);
    oSample.setOverScanRight(sampleData[7]);
    oSample.setOverScanTop(sampleData[8]);
    oSample.setOverScanBottom(sampleData[9]);

    oSample.setFStop(sampleData[10]);
    oSample.setFocusDistance(sampleData[11]);
    oSample.setShutterOpen(sampleData[12]);
    oSample.setShutterClose(sampleData[13]);

    oSample.setNearClippingPlane(sampleData[14]);
    oSample.setFarClippingPlane(sampleData[15]);

    if ( m_smallFilmBackChannels &&
         m_smallFilmBackChannels.getNumSamples() > 0 )
    {
        AbcA::index_t sampIdx = iSS.getIndex(
            m_coreProperties.getTimeSampling(),
            m_smallFilmBackChannels.getNumSamples() );

        std::vector < double > channels (
            m_smallFilmBackChannels.getDataType().getExtent() );
        m_smallFilmBackChannels.get( &channels.front(), sampIdx );

        std::size_t numOps = m_ops.size();
        std::size_t curChan = 0;
        for ( std::size_t i = 0; i < numOps; ++i )
        {
            oSample.addOp( m_ops[i] );
            FilmBackXformOp & curOp = oSample[i];
            std::size_t opChannels = curOp.getNumChannels();
            for ( std::size_t j = 0; j < opChannels; ++j, ++curChan )
            {
                curOp.setChannelValue( j, channels[curChan] );
            }
        }
    }
    else if ( m_largeFilmBackChannels &&
              m_largeFilmBackChannels.getNumSamples() > 0 )
    {
        AbcA::index_t sampIdx = iSS.getIndex(
            m_coreProperties.getTimeSampling(),
            m_largeFilmBackChannels.getNumSamples() );

        Abc::DoubleArraySamplePtr chanSamp;
        m_largeFilmBackChannels.get( chanSamp, sampIdx );

        std::size_t numOps = m_ops.size();
        std::size_t curChan = 0;
        for ( std::size_t i = 0; i < numOps; ++i )
        {
            oSample.addOp( m_ops[i] );
            FilmBackXformOp & curOp = oSample[i];
            std::size_t opChannels = curOp.getNumChannels();
            for ( std::size_t j = 0; j < opChannels; ++j, ++curChan )
            {
                curOp.setChannelValue( j, (*chanSamp)[curChan] );
            }
        }
    }

    ALEMBIC_ABC_SAFE_CALL_END();
}
//-*****************************************************************************
void cameraTest()
{
    std::string fileName = "camera1.abc";
    {
        OArchive archive( Alembic::AbcCoreHDF5::WriteArchive(), fileName );
        CameraSample samp;
        OCamera simpleCamObj( OObject( archive, kTop ), "simpleCam" );
        simpleCamObj.getSchema().set( samp );

        OCamera camObj( OObject( archive, kTop ), "cam" );
        OCameraSchema camSchema = camObj.getSchema();
        samp.addOp( FilmBackXformOp( kScaleFilmBackOperation, "scale" ) );
        samp.addOp( FilmBackXformOp( kTranslateFilmBackOperation, "offset" ) );
        camSchema.set( samp );

        samp[0].setScale( V2d( 2.0, 3.0 ) );
        samp[1].setChannelValue( 0, 4.0 );
        samp[1].setChannelValue( 1, 5.0 );
        samp.setLensSqueezeRatio( 2.0 );
        samp.setHorizontalAperture( 4.8 );
        samp.setVerticalFilmOffset( 3.0 );
        camSchema.set( samp );
    }

    {
        M33d identity;
        identity.makeIdentity();

        CameraSample samp;

        IArchive archive( Alembic::AbcCoreHDF5::ReadArchive(), fileName );
        ICamera simpleCam( IObject( archive, kTop ), "simpleCam" );
        ICamera cam( IObject( archive, kTop ), "cam" );

        // all default data
        simpleCam.getSchema().get( samp );
        TESTING_ASSERT( simpleCam.getSchema().getNumSamples() == 1 );
        TESTING_ASSERT( almostEqual( samp.getFocalLength(), 35.0 ) );
        TESTING_ASSERT( almostEqual( samp.getHorizontalAperture(), 3.6 ) );
        TESTING_ASSERT( almostEqual( samp.getVerticalAperture(), 2.4 ) );
        TESTING_ASSERT( almostEqual( samp.getHorizontalFilmOffset(), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp.getVerticalFilmOffset(), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp.getLensSqueezeRatio(), 1.0 ) );
        TESTING_ASSERT( almostEqual( samp.getOverScanLeft(), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp.getOverScanRight(), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp.getOverScanTop(), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp.getOverScanBottom(), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp.getFStop(), 5.6 ) );
        TESTING_ASSERT( almostEqual( samp.getFocusDistance(), 5.0 ) );
        TESTING_ASSERT( almostEqual( samp.getShutterOpen(), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp.getShutterClose(), 1.0 ) );
        TESTING_ASSERT( almostEqual( samp.getNearClippingPlane(), 0.1 ) );
        TESTING_ASSERT( almostEqual( samp.getFarClippingPlane(), 100000.0 ) );
        TESTING_ASSERT( samp.getNumOps() == 0 );
        TESTING_ASSERT( samp.getNumOpChannels() == 0 );
        TESTING_ASSERT( samp.getFilmBackMatrix() == identity );

        TESTING_ASSERT( cam.getSchema().getNumSamples() == 2 );

        cam.getSchema().get( samp );
        TESTING_ASSERT( almostEqual( samp.getFocalLength(), 35.0 ) );
        TESTING_ASSERT( almostEqual( samp.getHorizontalAperture(), 3.6 ) );
        TESTING_ASSERT( almostEqual( samp.getVerticalAperture(), 2.4 ) );
        TESTING_ASSERT( almostEqual( samp.getHorizontalFilmOffset(), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp.getVerticalFilmOffset(), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp.getLensSqueezeRatio(), 1.0 ) );
        TESTING_ASSERT( almostEqual( samp.getOverScanLeft(), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp.getOverScanRight(), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp.getOverScanTop(), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp.getOverScanBottom(), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp.getFStop(), 5.6 ) );
        TESTING_ASSERT( almostEqual( samp.getFocusDistance(), 5.0 ) );
        TESTING_ASSERT( almostEqual( samp.getShutterOpen(), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp.getShutterClose(), 1.0 ) );
        TESTING_ASSERT( almostEqual( samp.getNearClippingPlane(), 0.1 ) );
        TESTING_ASSERT( almostEqual( samp.getFarClippingPlane(), 100000.0 ) );
        TESTING_ASSERT( samp.getNumOps() == 2 );
        TESTING_ASSERT( samp.getNumOpChannels() == 4 );
        TESTING_ASSERT( samp[0].getHint() == "scale" );
        TESTING_ASSERT( samp[0].getType() == kScaleFilmBackOperation );
        TESTING_ASSERT( samp[0].getNumChannels() == 2 );
        TESTING_ASSERT( almostEqual( samp[0].getChannelValue(0), 1.0 ) );
        TESTING_ASSERT( almostEqual( samp[0].getChannelValue(1), 1.0 ) );
        TESTING_ASSERT( samp[1].getHint() == "offset" );
        TESTING_ASSERT( samp[1].getType() == kTranslateFilmBackOperation );
        TESTING_ASSERT( samp[1].getNumChannels() == 2 );
        TESTING_ASSERT( almostEqual( samp[1].getChannelValue(0), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp[1].getChannelValue(1), 0.0 ) );
        TESTING_ASSERT( samp.getFilmBackMatrix() == identity );

        cam.getSchema().get( samp, 1 );
        TESTING_ASSERT( almostEqual( samp.getFocalLength(), 35.0 ) );
        TESTING_ASSERT( almostEqual( samp.getHorizontalAperture(), 4.8 ) );
        TESTING_ASSERT( almostEqual( samp.getVerticalAperture(), 2.4 ) );
        TESTING_ASSERT( almostEqual( samp.getHorizontalFilmOffset(), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp.getVerticalFilmOffset(), 3.0 ) );
        TESTING_ASSERT( almostEqual( samp.getLensSqueezeRatio(), 2.0 ) );
        TESTING_ASSERT( almostEqual( samp.getOverScanLeft(), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp.getOverScanRight(), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp.getOverScanTop(), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp.getOverScanBottom(), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp.getFStop(), 5.6 ) );
        TESTING_ASSERT( almostEqual( samp.getFocusDistance(), 5.0 ) );
        TESTING_ASSERT( almostEqual( samp.getShutterOpen(), 0.0 ) );
        TESTING_ASSERT( almostEqual( samp.getShutterClose(), 1.0 ) );
        TESTING_ASSERT( almostEqual( samp.getNearClippingPlane(), 0.1 ) );
        TESTING_ASSERT( almostEqual( samp.getFarClippingPlane(), 100000.0 ) );
        TESTING_ASSERT( samp.getNumOps() == 2 );
        TESTING_ASSERT( samp.getNumOpChannels() == 4 );
        TESTING_ASSERT( samp[0].getHint() == "scale" );
        TESTING_ASSERT( samp[0].getType() == kScaleFilmBackOperation );
        TESTING_ASSERT( samp[0].getNumChannels() == 2 );
        TESTING_ASSERT( almostEqual( samp[0].getChannelValue(0), 2.0 ) );
        TESTING_ASSERT( almostEqual( samp[0].getChannelValue(1), 3.0 ) );
        TESTING_ASSERT( samp[0].getScale().equalWithAbsError( V2d( 2.0, 3.0 ),
            VAL_EPSILON ) );
        TESTING_ASSERT( samp[1].getHint() == "offset" );
        TESTING_ASSERT( samp[1].getType() == kTranslateFilmBackOperation );
        TESTING_ASSERT( samp[1].getNumChannels() == 2 );
        TESTING_ASSERT( almostEqual( samp[1].getChannelValue(0), 4.0 ) );
        TESTING_ASSERT( almostEqual( samp[1].getChannelValue(1), 5.0 ) );
        TESTING_ASSERT( samp[1].getTranslate().equalWithAbsError(
            V2d( 4.0, 5.0 ), VAL_EPSILON ) );

        M33d m;
        m.makeIdentity();
        m.scale( V2d( 2.0, 3.0 ) );
        m.translate( V2d( 4.0, 5.0 ) );
        TESTING_ASSERT( samp.getFilmBackMatrix().equalWithAbsError( m,
            VAL_EPSILON ) );
    }
}
//-*****************************************************************************
void corePropertiesTest()
{
    std::string fileName = "camera2.abc";
    {
        OArchive archive( Alembic::AbcCoreHDF5::WriteArchive(), fileName );
        CameraSample samp;

        OCamera camObj( OObject( archive, kTop ), "cam" );
        OCameraSchema camSchema = camObj.getSchema();

        // set some nonsense values just to test reading/writing
        for ( std::size_t i = 0; i < 10; ++i )
        {
            samp.setFocalLength( i * 1000.0 + 1.0 );
            samp.setHorizontalAperture( i * 1000.0 + 2.0 );
            samp.setVerticalAperture( i * 1000.0 + 3.0 );
            samp.setHorizontalFilmOffset( i * 1000.0 + 4.0 );
            samp.setVerticalFilmOffset( i * 1000.0 + 5.0 );
            samp.setLensSqueezeRatio( i * 1000.0 + 6.0 );
            samp.setOverScanLeft( i * 1000.0 + 7.0 );
            samp.setOverScanRight( i * 1000.0 + 8.0 );
            samp.setOverScanTop( i * 1000.0 + 9.0 );
            samp.setOverScanBottom( i * 1000.0 + 10.0 );
            samp.setFStop( i * 1000.0 + 11.0 );
            samp.setFocusDistance( i * 1000.0 + 12.0 );
            samp.setShutterOpen( i * 1000.0 + 13.0 );
            samp.setShutterClose( i * 1000.0 + 14.0 );
            samp.setNearClippingPlane( i * 1000.0 + 15.0 );
            samp.setFarClippingPlane( i * 1000.0 + 16.0 );
            camSchema.set( samp );
        }
    }

    {
        M33d identity;
        identity.makeIdentity();

        CameraSample samp;

        IArchive archive( Alembic::AbcCoreHDF5::ReadArchive(), fileName );
        ICamera cam( IObject( archive, kTop ), "cam" );

        TESTING_ASSERT( cam.getSchema().getNumSamples() == 10 );

        for ( std::size_t i; i < 10; ++i )
        {
            cam.getSchema().get( samp );
            TESTING_ASSERT( almostEqual( samp.getFocalLength(),
                1000.0 * i + 1.0 ) );
            TESTING_ASSERT( almostEqual( samp.getHorizontalAperture(),
                1000.0 * i + 2.0 ) );
            TESTING_ASSERT( almostEqual( samp.getVerticalAperture(),
                1000.0 * i + 3.0 ) );
            TESTING_ASSERT( almostEqual( samp.getHorizontalFilmOffset(),
                1000.0 * i + 4.0 ) );
            TESTING_ASSERT( almostEqual( samp.getVerticalFilmOffset(),
                1000.0 * i + 5.0 ) );
            TESTING_ASSERT( almostEqual( samp.getLensSqueezeRatio(),
                1000.0 * i + 6.0 ) );
            TESTING_ASSERT( almostEqual( samp.getOverScanLeft(),
                1000.0 * i + 7.0 ) );
            TESTING_ASSERT( almostEqual( samp.getOverScanRight(),
                1000.0 * i + 8.0 ) );
            TESTING_ASSERT( almostEqual( samp.getOverScanTop(),
                1000.0 * i + 9.0 ) );
            TESTING_ASSERT( almostEqual( samp.getOverScanBottom(),
                1000.0 * i + 10.0 ) );
            TESTING_ASSERT( almostEqual( samp.getFStop(),
                1000.0 * i + 11.0 ) );
            TESTING_ASSERT( almostEqual( samp.getFocusDistance(),
                1000.0 * i + 12.0 ) );
            TESTING_ASSERT( almostEqual( samp.getShutterOpen(),
                1000.0 * i + 13.0 ) );
            TESTING_ASSERT( almostEqual( samp.getShutterClose(),
                1000.0 * i + 14.0 ) );
            TESTING_ASSERT( almostEqual( samp.getNearClippingPlane(),
                1000.0 * i + 15.0 ) );
            TESTING_ASSERT( almostEqual( samp.getFarClippingPlane(),
                1000.0 * i + 16.0 ) );
            TESTING_ASSERT( samp.getNumOps() == 0 );
            TESTING_ASSERT( samp.getNumOpChannels() == 0 );
        }
    }
}
Пример #7
0
//-*****************************************************************************
void OCameraSchema::set( const CameraSample &iSamp )
{
    ALEMBIC_ABC_SAFE_CALL_BEGIN( "OCameraSchema::set()" );

    double sampleData[16];
    for ( size_t i = 0; i < 16; ++i )
        sampleData[i] = iSamp.getCoreValue( i );

    if ( m_coreProperties.getNumSamples() == 0 )
    {
        m_initialSample = iSamp;

        std::size_t numChannels = iSamp.getNumOpChannels();
        std::size_t numOps = iSamp.getNumOps();

        std::vector < std::string > filmBackOps( numOps );
        std::vector <double> opChannels ( numChannels );

        std::size_t curChannel = 0;
        for ( std::size_t i = 0; i < numOps; ++i )
        {
            const FilmBackXformOp & op = iSamp[i];
            filmBackOps[i] = op.getTypeAndHint();
            for ( std::size_t j = 0; j < op.getNumChannels();
                ++j, ++curChannel )
            {
                opChannels[curChannel] = op.getChannelValue( j );
            }
        }

        // we are in scalar territory, write the ops as scalar
        if ( numOps > 0 && numOps < 256 )
        {
            AbcA::DataType dType( Util::kStringPOD, numOps );
            Abc::OScalarProperty filmBackOpsProp( this->getPtr(),
                ".filmBackOps", dType );
            filmBackOpsProp.set( &filmBackOps.front() );
        }
        // too big for scalar, write ops as an array
        else if ( numChannels >= 256 )
        {
            OStringArrayProperty filmBackOpsProp( this->getPtr(),
                ".filmBackOps" );
            StringArraySample ssamp( &filmBackOps.front(), filmBackOps.size() );
            filmBackOpsProp.set( ssamp );
        }

        // do the same thing for the channels
        if ( numChannels > 0 && numChannels < 256 )
        {
            AbcA::DataType dType( Util::kFloat64POD, numChannels );
            m_smallFilmBackChannelsProperty = Abc::OScalarProperty( this->getPtr(),
                ".filmBackChannels", dType );
            m_smallFilmBackChannelsProperty.set( &opChannels.front() );

        }
        else if ( numChannels >= 256 )
        {
            m_bigFilmBackChannelsProperty = Abc::ODoubleArrayProperty( this->getPtr(),
                ".filmBackChannels" );
            DoubleArraySample dsamp( &opChannels.front(), opChannels.size() );
            m_bigFilmBackChannelsProperty.set( dsamp );
        }
    }
    else
    {
        std::size_t numOps = iSamp.getNumOps();
        ABCA_ASSERT( numOps == m_initialSample.getNumOps(),
            "Number of Film Back Xform Ops differ expected: " <<
            m_initialSample.getNumOps() << " got: " << numOps );

        std::vector <double> opChannels ( m_initialSample.getNumOpChannels() );
        std::size_t chan = 0;
        for ( std::size_t i = 0; i < numOps; ++i )
        {
            const FilmBackXformOp & op = iSamp[i];
            const FilmBackXformOp & oldOp = m_initialSample[i];

            ABCA_ASSERT( oldOp.getType() == op.getType(),
                "Film Back Xform Operation type differs from initial sample"
                " at index: " << i );

            std::size_t numChannels = op.getNumChannels();
            for ( std::size_t j = 0; j < numChannels; ++j, ++chan )
            {
                opChannels[chan] = op.getChannelValue( j );
            }
        }

        if ( m_smallFilmBackChannelsProperty )
        {
            m_smallFilmBackChannelsProperty.set( &opChannels.front() );
        }
        else if ( m_bigFilmBackChannelsProperty )
        {
            DoubleArraySample dsamp( &opChannels.front(), opChannels.size() );
            m_bigFilmBackChannelsProperty.set( dsamp );
        }
        // else no film back channels
    }

    m_coreProperties.set( sampleData );

    ALEMBIC_ABC_SAFE_CALL_END();
}