Exemplo n.º 1
0
IECore::ImagePrimitivePtr ToGLTextureConverter::imageFromCompoundData( IECore::CompoundData::ConstPtr data ) const
{

	if ( ! data )
	{
		throw IECore::Exception( "No CompoundData supplied." );
	}

	IECore::Box2iDataPtr dataWindow = 0;

	IECore::CompoundDataMap::const_iterator itData = data->readable().find( "dataWindow" );
	if ( itData == data->readable().end() )
	{
		throw IECore::Exception( "Invalid CompoundData supplied. ImagePrimitive representations need a dataWindow (Box2i)." );
	}
	dataWindow = IECore::runTimeCast<IECore::Box2iData>( itData->second );

	IECore::Box2iDataPtr screenWindow = 0;
	itData = data->readable().find( "displayWindow" );
	if ( itData == data->readable().end() )
	{
		throw IECore::Exception( "Invalid CompoundData supplied. ImagePrimitive representations need a screenWindow (Box2i)." );
	}
	screenWindow = IECore::runTimeCast<IECore::Box2iData>( itData->second );

	IECore::CompoundDataPtr channels = 0;
	itData = data->readable().find( "channels" );
	if ( itData == data->readable().end() )
	{
		throw IECore::Exception( "Invalid CompoundData supplied. ImagePrimitive representations need a CompoundDataMap of channels." );
	}
	channels = IECore::runTimeCast<IECore::CompoundData>( itData->second );


	if ( !dataWindow || !screenWindow || !channels )
	{
		throw IECore::Exception( "Invalid CompoundData representation supplied. Some data is of the wrong type" );
	}


	IECore::ImagePrimitivePtr newImage = new IECore::ImagePrimitive( dataWindow->readable(), screenWindow->readable() );
	for (
			IECore::CompoundDataMap::const_iterator itChannels = channels->readable().begin();
			itChannels != channels->readable().end();
			itChannels++
	)
	{
		IECore::FloatVectorDataPtr channelData = IECore::runTimeCast<IECore::FloatVectorData>( itChannels->second );
		if ( ! channelData )
		{
			throw IECore::Exception( "Invalid channel data found in ImagePrimitive representation, only 32bit float data is supported. Please check texture.");
		}

		newImage->variables.insert( IECore::PrimitiveVariableMap::value_type( itChannels->first, IECore::PrimitiveVariable( IECore::PrimitiveVariable::Vertex, channelData ) ) );

	}

	return newImage;

}