コード例 #1
0
ファイル: ICamera.cpp プロジェクト: AWhetter/alembic
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();
}
コード例 #2
0
//-*****************************************************************************
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 );
        }
    }
}