当前位置: 首页>>代码示例>>C++>>正文


C++ FilterPtr::tap方法代码示例

本文整理汇总了C++中FilterPtr::tap方法的典型用法代码示例。如果您正苦于以下问题:C++ FilterPtr::tap方法的具体用法?C++ FilterPtr::tap怎么用?C++ FilterPtr::tap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FilterPtr的用法示例。


在下文中一共展示了FilterPtr::tap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: computeChannelData

IECore::ConstFloatVectorDataPtr Reformat::computeChannelData( const std::string &channelName, const Imath::V2i &tileOrigin, const Gaffer::Context *context, const ImagePlug *parent ) const
{
	// Allocate the new tile
	FloatVectorDataPtr outDataPtr = new FloatVectorData;
	std::vector<float> &out = outDataPtr->writable();
	out.resize( ImagePlug::tileSize() * ImagePlug::tileSize() );

	// Create some useful variables...
	Imath::V2f scaleFactor( scale() );
	Imath::V2d inFormatOffset( inPlug()->formatPlug()->getValue().getDisplayWindow().min );
	Imath::V2d outFormatOffset( formatPlug()->getValue().getDisplayWindow().min );

	Imath::Box2i outTile( tileOrigin, Imath::V2i( tileOrigin.x + ImagePlug::tileSize() - 1, tileOrigin.y + ImagePlug::tileSize() - 1 ) );

	Imath::Box2f inTile(
		Imath::V2f(
			double( outTile.min.x - outFormatOffset.x ) / scaleFactor.x + inFormatOffset.x,
			double( outTile.min.y - outFormatOffset.y ) / scaleFactor.y + inFormatOffset.y
		),
		Imath::V2f(
			double( outTile.max.x - outFormatOffset.x + 1. ) / scaleFactor.x + inFormatOffset.x - 1.,
			double( outTile.max.y - outFormatOffset.y + 1. ) / scaleFactor.y + inFormatOffset.y - 1.
		)
	);

	// Create our filter.
	FilterPtr f = Filter::create( filterPlug()->getValue(), 1.f / scaleFactor.y );

	// If we are filtering with a box filter then just don't bother filtering
	// at all and just integer sample instead...
	if ( static_cast<GafferImage::TypeId>( f->typeId() ) == GafferImage::BoxFilterTypeId )
	{
		Imath::Box2i sampleBox(
			Imath::V2i( IECore::fastFloatFloor( inTile.min.x ), IECore::fastFloatCeil( inTile.min.y ) ),
			Imath::V2i( IECore::fastFloatFloor( inTile.max.x ), IECore::fastFloatCeil( inTile.max.y ) )
		);

		Sampler sampler( inPlug(), channelName, sampleBox, f, Sampler::Clamp );
		for ( int y = outTile.min.y, ty = 0; y <= outTile.max.y; ++y, ++ty )
		{
			for ( int x = outTile.min.x, tx = 0; x <= outTile.max.x; ++x, ++tx )
			{
				float value = sampler.sample( float( ( x + .5f - outFormatOffset.x ) / scaleFactor.x + inFormatOffset.x ), float( ( y + .5f - outFormatOffset.y ) / scaleFactor.y + inFormatOffset.y ) );
				out[ tx + ImagePlug::tileSize() * ty ] = value;
			}
		}
		return outDataPtr;
	}

	// Get the dimensions of our filter and create a box that we can use to define the bounds of our input.
	int fHeight = f->width();

	int sampleMinY = f->tap( inTile.min.y );
	int sampleMaxY = f->tap( inTile.max.y );

	f->setScale( 1.f / scaleFactor.x );
	int sampleMinX = f->tap( inTile.min.x );
	int sampleMaxX = f->tap( inTile.max.x );

	int fWidth = f->width();

	Imath::Box2i sampleBox(
		Imath::V2i( sampleMinX, sampleMinY ),
		Imath::V2i( sampleMaxX + fWidth, sampleMaxY + fHeight )
	);

	int sampleBoxWidth = sampleBox.size().x + 1;
	int sampleBoxHeight = sampleBox.size().y + 1;

	// Create a temporary buffer that we can write the result of the first pass to.
	// We extend the buffer vertically as we will need additional information in the
	// vertical squash (the second pass) to properly convolve the filter.
	float buffer[ ImagePlug::tileSize() * sampleBoxHeight ];

	// Create several buffers for each pixel in the output row (or column depending on the pass)
	// into which we can place the indices for the pixels that are contribute to it's result and
	// their weight.

	// A buffer that holds a list of pixel contributions and their weights for every pixel in the output buffer.
	// As it gets reused for both passes we make it large enough to hold both so that we don't have to resize it later.
	std::vector<Contribution> contribution( ImagePlug::tileSize() * ( sampleBoxHeight > sampleBoxWidth ? sampleBoxHeight : sampleBoxWidth ) );

	// The total number of pixels that contribute towards each pixel in th resulting image.
	std::vector<int> coverageTotal( ImagePlug::tileSize() );

	// The total weighted sum of contribution that each pixel in the output gets.
	// This value is used to normalize the result.
	std::vector<float> weightedSum( ImagePlug::tileSize() );

	// Horizontal Pass
	// Here we build a row buffer of contributing pixels and their weights for every pixel in the row.
	int contributionIdx = 0;
	for ( int i = 0; i < ImagePlug::tileSize(); ++i, contributionIdx += fWidth )
	{
		float center = ( outTile.min.x + i + 0.5 - outFormatOffset.x ) / scaleFactor.x + inFormatOffset.x;
		int tap = f->tap( center );

		int n = 0;
		weightedSum[i] = 0.;
		for ( int j = tap; j < tap+fWidth; ++j )
//.........这里部分代码省略.........
开发者ID:cedriclaunay,项目名称:gaffer,代码行数:101,代码来源:Reformat.cpp


注:本文中的FilterPtr::tap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。