Esempio n. 1
0
void ColorProcessor::hashColorData( const Gaffer::Context *context, IECore::MurmurHash &h ) const
{
	ConstStringVectorDataPtr channelNamesData;
	{
		ImagePlug::GlobalScope globalScope( context );
		channelNamesData = inPlug()->channelNamesPlug()->getValue();
	}
	const vector<string> &channelNames = channelNamesData->readable();

	const string &layerName = context->get<string>( g_layerNameKey );

	ImagePlug::ChannelDataScope channelDataScope( context );
	for( const auto &baseName : { "R", "G", "B" } )
	{
		string channelName = ImageAlgo::channelName( layerName, baseName );
		if( ImageAlgo::channelExists( channelNames, channelName ) )
		{
			channelDataScope.setChannelName( channelName );
			inPlug()->channelDataPlug()->hash( h );
		}
		else
		{
			ImagePlug::blackTile()->hash( h );
		}
	}
}
Esempio n. 2
0
IECore::MurmurHash ImagePlug::imageHash() const
{
    const Box2i dataWindow = dataWindowPlug()->getValue();
    ConstStringVectorDataPtr channelNamesData = channelNamesPlug()->getValue();
    const vector<string> &channelNames = channelNamesData->readable();

    MurmurHash result = formatPlug()->hash();
    result.append( dataWindowPlug()->hash() );
    result.append( metadataPlug()->hash() );
    result.append( channelNamesPlug()->hash() );

    V2i minTileOrigin = tileOrigin( dataWindow.min );
    V2i maxTileOrigin = tileOrigin( dataWindow.max );

    ContextPtr context = new Context( *Context::current(), Context::Borrowed );
    Context::Scope scope( context.get() );

    for( vector<string>::const_iterator it = channelNames.begin(), eIt = channelNames.end(); it!=eIt; it++ )
    {
        context->set( ImagePlug::channelNameContextName, *it );
        for( int tileOriginY = minTileOrigin.y; tileOriginY<=maxTileOrigin.y; tileOriginY += tileSize() )
        {
            for( int tileOriginX = minTileOrigin.x; tileOriginX<=maxTileOrigin.x; tileOriginX += tileSize() )
            {
                context->set( ImagePlug::tileOriginContextName, V2i( tileOriginX, tileOriginY ) );
                channelDataPlug()->hash( result );
            }
        }
    }

    return result;
}
Esempio n. 3
0
IECore::MurmurHash ImagePlug::imageHash() const
{
	const Box2i dataWindow = dataWindowPlug()->getValue();
	ConstStringVectorDataPtr channelNamesData = channelNamesPlug()->getValue();
	const vector<string> &channelNames = channelNamesData->readable();

	MurmurHash result = formatPlug()->hash();
	result.append( dataWindowPlug()->hash() );
	result.append( metadataPlug()->hash() );
	result.append( channelNamesPlug()->hash() );

	ImageAlgo::parallelGatherTiles(
		this, channelNames,
		// Tile
		[] ( const ImagePlug *imagePlug, const string &channelName, const V2i &tileOrigin )
		{
			return imagePlug->channelDataPlug()->hash();
		},
		// Gather
		[ &result ] ( const ImagePlug *imagePlug, const string &channelName, const V2i &tileOrigin, const IECore::MurmurHash &tileHash )
		{
			result.append( tileHash );
		},
		dataWindow,
		ImageAlgo::BottomToTop
	);

	return result;
}
Esempio n. 4
0
std::string ImageSampler::channelName( const Gaffer::ValuePlug *output ) const
{
	std::string name;

	const Color4fPlug *c = colorPlug();
	if( output == c->getChild( 0 ) )
	{
		name = "R";
	}
	else if( output == c->getChild( 1 ) )
	{
		name = "G";
	}
	else if( output == c->getChild( 2 ) )
	{
		name = "B";
	}
	else if( output == c->getChild( 3 ) )
	{
		name = "A";
	}

	ConstStringVectorDataPtr channelNames = imagePlug()->channelNamesPlug()->getValue();
	if( find( channelNames->readable().begin(), channelNames->readable().end(), name ) != channelNames->readable().end() )
	{
		return name;
	}

	return "";
}
Esempio n. 5
0
void UVWarp::hashEngine( const std::string &channelName, const Imath::V2i &tileOrigin, const Gaffer::Context *context, IECore::MurmurHash &h ) const
{
	Warp::hashEngine( channelName, tileOrigin, context, h );

	h.append( tileOrigin );
	uvPlug()->dataWindowPlug()->hash( h );

	ConstStringVectorDataPtr channelNames = uvPlug()->channelNamesPlug()->getValue();

	ContextPtr tmpContext = new Context( *context, Context::Borrowed );
	Context::Scope scopedContext( tmpContext.get() );

	if( channelExists( channelNames->readable(), "R" ) )
	{
		tmpContext->set<std::string>( ImagePlug::channelNameContextName, "R" );
		uvPlug()->channelDataPlug()->hash( h );
	}

	if( channelExists( channelNames->readable(), "G" ) )
	{
		tmpContext->set<std::string>( ImagePlug::channelNameContextName, "G" );
		uvPlug()->channelDataPlug()->hash( h );
	}

	if( channelExists( channelNames->readable(), "A" ) )
	{
		tmpContext->set<std::string>( ImagePlug::channelNameContextName, "A" );
		uvPlug()->channelDataPlug()->hash( h );
	}

	inPlug()->formatPlug()->hash( h );
}
Esempio n. 6
0
void Unpremultiply::processChannelData( const Gaffer::Context *context, const ImagePlug *parent, const std::string &channel, FloatVectorDataPtr outData ) const
{
	std::string alphaChannel = alphaChannelPlug()->getValue();

	if ( channel == alphaChannel )
	{
		return;
	}

	ConstStringVectorDataPtr inChannelNamesPtr = inPlug()->channelNamesPlug()->getValue();
	const std::vector<std::string> &inChannelNames = inChannelNamesPtr->readable();
	if ( std::find( inChannelNames.begin(), inChannelNames.end(), alphaChannel ) == inChannelNames.end() )
	{
		std::ostringstream channelError;
		channelError << "Channel '" << alphaChannel << "' does not exist";
		throw( IECore::Exception( channelError.str() ) );
	}

	ContextPtr tmpContext = new Context( *context, Context::Borrowed );
	tmpContext->set( ImagePlug::channelNameContextName, alphaChannel );
	Context::Scope scopedContext( tmpContext.get() );

	const std::vector<float> &a = inPlug()->channelDataPlug()->getValue()->readable();
	std::vector<float> &out = outData->writable();

	std::vector<float>::const_iterator aIt = a.begin();
	for ( std::vector<float>::iterator outIt = out.begin(), outItEnd = out.end(); outIt != outItEnd; ++outIt, ++aIt )
	{
		if ( *aIt != 0.0f )
		{
			*outIt /= *aIt;
		}
	}
}
Esempio n. 7
0
IECore::ImagePrimitivePtr ImagePlug::image() const
{
	Format format = formatPlug()->getValue();
	Box2i dataWindow = dataWindowPlug()->getValue();
	Box2i newDataWindow( Imath::V2i(0) );
	
	if( dataWindow.isEmpty() )
	{
		dataWindow = Box2i( Imath::V2i(0) );
	}
	else
	{
		newDataWindow = format.yDownToFormatSpace( dataWindow );
	}
	
	ImagePrimitivePtr result = new ImagePrimitive( newDataWindow, format.getDisplayWindow() );

	ConstStringVectorDataPtr channelNamesData = channelNamesPlug()->getValue();
	const vector<string> &channelNames = channelNamesData->readable();
	
	vector<float *> imageChannelData;
	for( vector<string>::const_iterator it = channelNames.begin(), eIt = channelNames.end(); it!=eIt; it++ )
	{
		FloatVectorDataPtr cd = new FloatVectorData;
		vector<float> &c = cd->writable();
		c.resize( result->variableSize( PrimitiveVariable::Vertex ), 0.0f );
		result->variables[*it] = PrimitiveVariable( PrimitiveVariable::Vertex, cd );
		imageChannelData.push_back( &(c[0]) );
	}
	
	parallel_for( blocked_range2d<size_t>( 0, dataWindow.size().x+1, tileSize(), 0, dataWindow.size().y+1, tileSize() ),
		      GafferImage::Detail::CopyTiles( imageChannelData, channelNames, channelDataPlug(), dataWindow, Context::current(), tileSize()) );
	
	return result;
}
Esempio n. 8
0
void PathFilter::compute( Gaffer::ValuePlug *output, const Gaffer::Context *context ) const
{
	if( output == pathMatcherPlug() )
	{
		ConstStringVectorDataPtr paths = pathsPlug()->getValue();
		PathMatcherDataPtr pathMatcherData = new PathMatcherData;
		pathMatcherData->writable().init( paths->readable().begin(), paths->readable().end() );
		static_cast<PathMatcherDataPlug *>( output )->setValue( pathMatcherData );
		return;
	}

	Filter::compute( output, context );
}
Esempio n. 9
0
IECore::ConstInternedStringVectorDataPtr AlembicSource::computeChildNames( const ScenePath &path, const Gaffer::Context *context, const ScenePlug *parent ) const
{
	if( AlembicInputPtr i = inputForPath( path ) )
	{
		ConstStringVectorDataPtr c = i->childNames();
		InternedStringVectorDataPtr result = new InternedStringVectorData;
		result->writable().insert( result->writable().end(), c->readable().begin(), c->readable().end() );
		return result;
	}
	else
	{
		return parent->childNamesPlug()->defaultValue();
	}
}
Esempio n. 10
0
const Warp::Engine *VectorWarp::computeEngine( const Imath::V2i &tileOrigin, const Gaffer::Context *context ) const
{
	const Box2i tileBound( tileOrigin, tileOrigin + V2i( ImagePlug::tileSize() ) );

	
	Box2i validTileBound;
	ConstStringVectorDataPtr channelNames;
	Box2i displayWindow;

	{
		ImagePlug::GlobalScope c( context );
		validTileBound = BufferAlgo::intersection( tileBound, vectorPlug()->dataWindowPlug()->getValue() );
		channelNames = vectorPlug()->channelNamesPlug()->getValue();
		displayWindow = inPlug()->formatPlug()->getValue().getDisplayWindow();
	}

	ImagePlug::ChannelDataScope channelDataScope( context );

	ConstFloatVectorDataPtr xData = ImagePlug::blackTile();
	if( ImageAlgo::channelExists( channelNames->readable(), "R" ) )
	{
		channelDataScope.setChannelName( "R" );
		xData = vectorPlug()->channelDataPlug()->getValue();
	}

	ConstFloatVectorDataPtr yData = ImagePlug::blackTile();
	if( ImageAlgo::channelExists( channelNames->readable(), "G" ) )
	{
		channelDataScope.setChannelName( "G" );
		yData = vectorPlug()->channelDataPlug()->getValue();
	}

	ConstFloatVectorDataPtr aData = ImagePlug::whiteTile();
	if( ImageAlgo::channelExists( channelNames->readable(), "A" ) )
	{
		channelDataScope.setChannelName( "A" );
		aData = vectorPlug()->channelDataPlug()->getValue();
	}

	return new Engine(
		displayWindow,
		tileBound,
		validTileBound,
		xData,
		yData,
		aData,
		(VectorMode)vectorModePlug()->getValue(),
		(VectorUnits)vectorUnitsPlug()->getValue()
	);
}
Esempio n. 11
0
IECore::ImagePrimitivePtr ImagePlug::image() const
{
	Format format = formatPlug()->getValue();
	Box2i dataWindow = dataWindowPlug()->getValue();
	Box2i newDataWindow( Imath::V2i(0) );

	if( dataWindow.isEmpty() )
	{
		dataWindow = Box2i( Imath::V2i(0) );
	}
	else
	{
		newDataWindow = format.yDownToFormatSpace( dataWindow );
	}

	// use the default format if we don't have an explicit one.
	/// \todo: remove this once FormatPlug is handling it for
	/// us during ExecutableNode::execute (see issue #887).
	if( format.getDisplayWindow().isEmpty() )
	{
		format = Context::current()->get<Format>( Format::defaultFormatContextName, Format() );
	}
	
	ImagePrimitivePtr result = new ImagePrimitive( newDataWindow, format.getDisplayWindow() );
	
	ConstCompoundObjectPtr metadata = metadataPlug()->getValue();
	compoundObjectToCompoundData( metadata.get(), result->blindData() );
	
	ConstStringVectorDataPtr channelNamesData = channelNamesPlug()->getValue();
	const vector<string> &channelNames = channelNamesData->readable();

	vector<float *> imageChannelData;
	for( vector<string>::const_iterator it = channelNames.begin(), eIt = channelNames.end(); it!=eIt; it++ )
	{
		FloatVectorDataPtr cd = new FloatVectorData;
		vector<float> &c = cd->writable();
		c.resize( result->variableSize( PrimitiveVariable::Vertex ), 0.0f );
		result->variables[*it] = PrimitiveVariable( PrimitiveVariable::Vertex, cd );
		imageChannelData.push_back( &(c[0]) );
	}

	parallel_for( blocked_range3d<size_t>( 0, imageChannelData.size(), 1, 0, dataWindow.size().x+1, tileSize(), 0, dataWindow.size().y+1, tileSize() ),
		      GafferImage::Detail::CopyTiles( imageChannelData, channelNames, channelDataPlug(), dataWindow, Context::current(), tileSize()) );

	return result;
}
Esempio n. 12
0
void ColorProcessor::compute( Gaffer::ValuePlug *output, const Gaffer::Context *context ) const
{
	if( output == colorDataPlug() )
	{
		ConstStringVectorDataPtr channelNamesData;
		{
			ImagePlug::GlobalScope globalScope( context );
			channelNamesData = inPlug()->channelNamesPlug()->getValue();
		}
		const vector<string> &channelNames = channelNamesData->readable();

		const string &layerName = context->get<string>( g_layerNameKey );

		FloatVectorDataPtr rgb[3];
		{
			ImagePlug::ChannelDataScope channelDataScope( context );
			int i = 0;
			for( const auto &baseName : { "R", "G", "B" } )
			{
				string channelName = ImageAlgo::channelName( layerName, baseName );
				if( ImageAlgo::channelExists( channelNames, channelName ) )
				{
					channelDataScope.setChannelName( channelName );
					rgb[i] = inPlug()->channelDataPlug()->getValue()->copy();
				}
				else
				{
					rgb[i] = ImagePlug::blackTile()->copy();
				}
				i++;
			}
		}

		processColorData( context, rgb[0].get(), rgb[1].get(), rgb[2].get() );

		ObjectVectorPtr result = new ObjectVector();
		result->members().push_back( rgb[0] );
		result->members().push_back( rgb[1] );
		result->members().push_back( rgb[2] );

		static_cast<ObjectPlug *>( output )->setValue( result );
		return;
	}

	ImageProcessor::compute( output, context );
}
Esempio n. 13
0
void ChannelMaskPlug::maskChannels( std::vector<std::string> &inChannels ) const
{
	ConstStringVectorDataPtr channelNamesData = getValue();
	const std::vector<std::string> &maskChannels = channelNamesData->readable();

	// Intersect the inChannels and the maskChannels in place.
	std::vector<std::string>::iterator cIt( inChannels.begin() );
	while ( cIt != inChannels.end() )
	{
		if ( std::find( maskChannels.begin(), maskChannels.end(), (*cIt) ) == maskChannels.end() )
		{
			cIt = inChannels.erase( cIt );
		}
		else
		{
			++cIt;
		}
	}
}
Esempio n. 14
0
void OSLImage::hashShading( const Gaffer::Context *context, IECore::MurmurHash &h ) const
{
	const V2i tileOrigin = context->get<V2i>( ImagePlug::tileOriginContextName );
	h.append( tileOrigin );
	inPlug()->formatPlug()->hash( h );

	ConstStringVectorDataPtr channelNamesData = inPlug()->channelNamesPlug()->getValue();
	const vector<string> &channelNames = channelNamesData->readable();
	for( vector<string>::const_iterator it = channelNames.begin(), eIt = channelNames.end(); it != eIt; ++it )
	{
		h.append( inPlug()->channelDataHash( *it, tileOrigin ) );
	}

	const OSLShader *shader = runTimeCast<const OSLShader>( shaderPlug()->source<Plug>()->node() );
	if( shader )
	{
		shader->stateHash( h );
	}
}
Esempio n. 15
0
void CopyChannels::compute( Gaffer::ValuePlug *output, const Gaffer::Context *context ) const
{
	if( output == mappingPlug() )
	{
		const string channelMatchPatterns = channelsPlug()->getValue();

		CompoundObjectPtr result = new CompoundObject();
		StringVectorDataPtr channelNamesData = new StringVectorData;
		result->members()["__channelNames"] = channelNamesData;
		vector<string> &channelNames = channelNamesData->writable();
		size_t i = 0;
		for( ImagePlugIterator it( inPlugs() ); !it.done(); ++i, ++it )
		{
			/// \todo We need this check because an unconnected input
			/// has a default channelNames value of [ "R", "G", "B" ],
			/// when it should have an empty default instead. Fix
			/// the ImagePlug constructor and remove the check.
			if( !(*it)->getInput<Plug>() )
			{
				continue;
			}
			ConstStringVectorDataPtr inputChannelNamesData = (*it)->channelNamesPlug()->getValue();
			const vector<string> &inputChannelNames = inputChannelNamesData->readable();
			for( vector<string>::const_iterator cIt = inputChannelNames.begin(), ceIt = inputChannelNames.end(); cIt != ceIt; ++cIt )
			{
				if( i > 0 && !StringAlgo::matchMultiple( *cIt, channelMatchPatterns ) )
				{
					continue;
				}
				if( find( channelNames.begin(), channelNames.end(), *cIt ) == channelNames.end() )
				{
					channelNames.push_back( *cIt );
				}
				result->members()[*cIt] = new IntData( i );
			}
		}
		static_cast<CompoundObjectPlug *>( output )->setValue( result );
		return;
	}

	ImageProcessor::compute( output, context );
}
const std::string &SpherePrimitiveEvaluator::Result::stringPrimVar( const PrimitiveVariable &pv ) const
{
	ConstStringDataPtr data = runTimeCast< const StringData >( pv.data );

	if (data)
	{
		return data->readable();
	}
	else
	{
		ConstStringVectorDataPtr data = runTimeCast< const StringVectorData >( pv.data );

		if (data)
		{
			return data->readable()[0];
		}
	}

	throw InvalidArgumentException( "Could not retrieve primvar data for SpherePrimitiveEvaluator" );
}
Esempio n. 17
0
const Warp::Engine *UVWarp::computeEngine( const std::string &channelName, const Imath::V2i &tileOrigin, const Gaffer::Context *context ) const
{
	const Box2i tileBound( tileOrigin, tileOrigin + V2i( ImagePlug::tileSize() ) );
	const Box2i validTileBound = intersection( tileBound, uvPlug()->dataWindowPlug()->getValue() );

	ConstStringVectorDataPtr channelNames = uvPlug()->channelNamesPlug()->getValue();

	ContextPtr tmpContext = new Context( *context, Context::Borrowed );
	Context::Scope scopedContext( tmpContext.get() );

	ConstFloatVectorDataPtr uData = ImagePlug::blackTile();
	if( channelExists( channelNames->readable(), "R" ) )
	{
		tmpContext->set<std::string>( ImagePlug::channelNameContextName, "R" );
		uData = uvPlug()->channelDataPlug()->getValue();
	}

	ConstFloatVectorDataPtr vData = ImagePlug::blackTile();
	if( channelExists( channelNames->readable(), "G" ) )
	{
		tmpContext->set<std::string>( ImagePlug::channelNameContextName, "G" );
		vData = uvPlug()->channelDataPlug()->getValue();
	}

	ConstFloatVectorDataPtr aData = ImagePlug::whiteTile();
	if( channelExists( channelNames->readable(), "A" ) )
	{
		tmpContext->set<std::string>( ImagePlug::channelNameContextName, "A" );
		aData = uvPlug()->channelDataPlug()->getValue();
	}

	return new Engine(
		inPlug()->formatPlug()->getValue().getDisplayWindow(),
		tileBound,
		validTileBound,
		uData,
		vData,
		aData
	);
}
Esempio n. 18
0
void Set::compute( Gaffer::ValuePlug *output, const Gaffer::Context *context ) const
{
	if( output == pathMatcherPlug() )
	{
		ConstStringVectorDataPtr pathsData = pathsPlug()->getValue();
		const vector<string> &paths = pathsData->readable();

		PathMatcherDataPtr pathMatcherData = new PathMatcherData;
		PathMatcher &pathMatcher = pathMatcherData->writable();

		vector<InternedString> tokenizedPath;
		for( vector<string>::const_iterator it = paths.begin(), eIt = paths.end(); it != eIt; ++it )
		{
			if( it->empty() )
			{
				continue;
			}
			tokenizedPath.clear();
			Gaffer::tokenize( *it, '/', tokenizedPath );
			for( vector<InternedString>::const_iterator nIt = tokenizedPath.begin(), neIt = tokenizedPath.end(); nIt != neIt; ++nIt )
			{
				if( Gaffer::hasWildcards( nIt->c_str() ) || *nIt == g_ellipsis )
				{
					throw IECore::Exception( "Path \"" + *it + "\" contains wildcards." );
				}
			}
			pathMatcher.addPath( tokenizedPath );
		}

		if( filterPlug()->getInput<Gaffer::Plug>() )
		{
			matchingPaths( filterPlug(), inPlug(), pathMatcher );
		}

		static_cast<Gaffer::ObjectPlug *>( output )->setValue( pathMatcherData );
		return;
	}

	FilteredSceneProcessor::compute( output, context );
}
Esempio n. 19
0
IECoreImage::ImagePrimitivePtr ImagePlug::image() const
{
	Format format = formatPlug()->getValue();
	Box2i dataWindow = dataWindowPlug()->getValue();
	Box2i newDataWindow( Imath::V2i( 0 ) );

	if( !BufferAlgo::empty( dataWindow ) )
	{
		newDataWindow = format.toEXRSpace( dataWindow );
	}
	else
	{
		dataWindow = newDataWindow;
	}

	Box2i newDisplayWindow = format.toEXRSpace( format.getDisplayWindow() );

	IECoreImage::ImagePrimitivePtr result = new IECoreImage::ImagePrimitive( newDataWindow, newDisplayWindow );

	ConstCompoundDataPtr metadata = metadataPlug()->getValue();
	result->blindData()->Object::copyFrom( metadata.get() );

	ConstStringVectorDataPtr channelNamesData = channelNamesPlug()->getValue();
	const vector<string> &channelNames = channelNamesData->readable();

	vector<float *> imageChannelData;
	for( vector<string>::const_iterator it = channelNames.begin(), eIt = channelNames.end(); it!=eIt; it++ )
	{
		FloatVectorDataPtr cd = new FloatVectorData;
		vector<float> &c = cd->writable();
		c.resize( result->channelSize(), 0.0f );
		result->channels[*it] = cd;
		imageChannelData.push_back( &(c[0]) );
	}

	CopyTile copyTile( imageChannelData, channelNames, dataWindow );
	ImageAlgo::parallelProcessTiles( this, channelNames, copyTile, dataWindow );

	return result;
}
Esempio n. 20
0
void VectorWarp::hashEngine( const Imath::V2i &tileOrigin, const Gaffer::Context *context, IECore::MurmurHash &h ) const
{
	Warp::hashEngine( tileOrigin, context, h );

	h.append( tileOrigin );

	ConstStringVectorDataPtr channelNames;

	{
		ImagePlug::GlobalScope c( context );
		channelNames = vectorPlug()->channelNamesPlug()->getValue();
		vectorPlug()->dataWindowPlug()->hash( h );
		inPlug()->formatPlug()->hash( h );
	}


	ImagePlug::ChannelDataScope channelDataScope( context );

	if( ImageAlgo::channelExists( channelNames->readable(), "R" ) )
	{
		channelDataScope.setChannelName( "R" );
		vectorPlug()->channelDataPlug()->hash( h );
	}

	if( ImageAlgo::channelExists( channelNames->readable(), "G" ) )
	{
		channelDataScope.setChannelName( "G" );
		vectorPlug()->channelDataPlug()->hash( h );
	}

	if( ImageAlgo::channelExists( channelNames->readable(), "A" ) )
	{
		channelDataScope.setChannelName( "A" );
		vectorPlug()->channelDataPlug()->hash( h );
	}

	vectorModePlug()->hash( h );
	vectorUnitsPlug()->hash( h );
}
Esempio n. 21
0
IECore::ConstStringVectorDataPtr OSLImage::computeChannelNames( const Gaffer::Context *context, const GafferImage::ImagePlug *parent ) const
{
	ConstStringVectorDataPtr channelNamesData = inPlug()->channelNamesPlug()->getValue();

	set<string> result( channelNamesData->readable().begin(), channelNamesData->readable().end() );

	const Box2i dataWindow = inPlug()->dataWindowPlug()->getValue();
	if( !dataWindow.isEmpty() )
	{
		ContextPtr c = new Context( *context, Context::Borrowed );
		c->set( ImagePlug::tileOriginContextName, ImagePlug::tileOrigin( dataWindow.min ) );
		Context::Scope s( c.get() );

		ConstCompoundDataPtr shading = runTimeCast<const CompoundData>( shadingPlug()->getValue() );
		for( CompoundDataMap::const_iterator it = shading->readable().begin(), eIt = shading->readable().end(); it != eIt; ++it )
		{
			result.insert( it->first );
		}
	}

	return new StringVectorData( vector<string>( result.begin(), result.end() ) );
}
Esempio n. 22
0
void Premultiply::processChannelData( const Gaffer::Context *context, const ImagePlug *parent, const std::string &channel, FloatVectorDataPtr outData ) const
{
	std::string alphaChannel = alphaChannelPlug()->getValue();

	if ( channel == alphaChannel )
	{
		return;
	}

	ConstStringVectorDataPtr inChannelNamesPtr;
	{
		ImagePlug::GlobalScope c( context );
		inChannelNamesPtr = inPlug()->channelNamesPlug()->getValue();
	}

	const std::vector<std::string> &inChannelNames = inChannelNamesPtr->readable();
	if ( std::find( inChannelNames.begin(), inChannelNames.end(), alphaChannel ) == inChannelNames.end() )
	{
		std::ostringstream channelError;
		channelError << "Channel '" << alphaChannel << "' does not exist";
		throw( IECore::Exception( channelError.str() ) );
	}

	ImagePlug::ChannelDataScope channelDataScope( context );
	channelDataScope.setChannelName( alphaChannel );

	ConstFloatVectorDataPtr aData = inPlug()->channelDataPlug()->getValue();
	const std::vector<float> &a = aData->readable();
	std::vector<float> &out = outData->writable();

	std::vector<float>::const_iterator aIt = a.begin();
	for ( std::vector<float>::iterator outIt = out.begin(), outItEnd = out.end(); outIt != outItEnd; ++outIt, ++aIt )
	{
		*outIt *= *aIt;
	}
}
Esempio n. 23
0
void PathFilter::plugDirtied( const Gaffer::Plug *plug )
{
	if( plug == pathsPlug() )
	{
		//\todo: share this logic with Switch::variesWithContext()
		Plug* sourcePlug = pathsPlug()->source();
		if( sourcePlug->direction() == Plug::Out && IECore::runTimeCast<const ComputeNode>( sourcePlug->node() ) )
		{
			// pathsPlug() is receiving data from a plug whose value is context varying, meaning
			// we need to use the intermediate pathMatcherPlug() in computeMatch() instead:

			m_pathMatcher = nullptr;
		}
		else
		{
			// pathsPlug() value is not context varying, meaning we can save on graph evaluations
			// by just precomputing it here and directly using it in computeMatch():

			ConstStringVectorDataPtr paths = pathsPlug()->getValue();
			m_pathMatcher = new PathMatcherData;
			m_pathMatcher->writable().init( paths->readable().begin(), paths->readable().end() );
		}
	}
}
Esempio n. 24
0
SmoothSkinningData::SmoothSkinningData( ConstStringVectorDataPtr influenceNames,
										ConstM44fVectorDataPtr influencePose,
										ConstIntVectorDataPtr pointIndexOffsets,
										ConstIntVectorDataPtr pointInfluenceCounts,
										ConstIntVectorDataPtr pointInfluenceIndices,
										ConstFloatVectorDataPtr pointInfluenceWeights)
{
	assert( influenceNames );
	assert( influencePose );
	assert( pointIndexOffsets );
	assert( pointInfluenceCounts );
	assert( pointInfluenceIndices );
	assert( pointInfluenceWeights );

	m_influenceNames = influenceNames->copy();
	m_influencePose = influencePose->copy();
	m_pointIndexOffsets = pointIndexOffsets->copy();
	m_pointInfluenceCounts = pointInfluenceCounts->copy();
	m_pointInfluenceIndices = pointInfluenceIndices->copy();
	m_pointInfluenceWeights = pointInfluenceWeights->copy();
}
Esempio n. 25
0
IECore::ConstCompoundDataPtr OSLImage::computeShading( const Gaffer::Context *context ) const
{
	OSLRenderer::ConstShadingEnginePtr shadingEngine;
	if( const OSLShader *shader = runTimeCast<const OSLShader>( shaderPlug()->source<Plug>()->node() ) )
	{
		shadingEngine = shader->shadingEngine();
	}

	if( !shadingEngine )
	{
		return static_cast<const CompoundData *>( shadingPlug()->defaultValue() );
	}

	const V2i tileOrigin = context->get<V2i>( ImagePlug::tileOriginContextName );
	const Format format = inPlug()->formatPlug()->getValue();

	CompoundDataPtr shadingPoints = new CompoundData();

	V3fVectorDataPtr pData = new V3fVectorData;
	FloatVectorDataPtr uData = new FloatVectorData;
	FloatVectorDataPtr vData = new FloatVectorData;

	vector<V3f> &pWritable = pData->writable();
	vector<float> &uWritable = uData->writable();
	vector<float> &vWritable = vData->writable();

	const size_t tileSize = ImagePlug::tileSize();
	pWritable.reserve( tileSize * tileSize );
	uWritable.reserve( tileSize * tileSize );
	vWritable.reserve( tileSize * tileSize );

	/// \todo Non-zero display window origins - do we have those?
	const float uStep = 1.0f / format.width();
	const float uMin = 0.5f * uStep;

	const float vStep = 1.0f / format.height();
	const float vMin = 0.5f * vStep;

	const size_t xMax = tileOrigin.x + tileSize;
	const size_t yMax = tileOrigin.y + tileSize;
	for( size_t y = tileOrigin.y; y < yMax; ++y )
	{
		const float v = vMin + y * vStep;
		for( size_t x = tileOrigin.x; x < xMax; ++x )
		{
			uWritable.push_back( uMin + x * uStep );
			vWritable.push_back( v );
			pWritable.push_back( V3f( x, y, 0.0f ) );
		}
	}

	shadingPoints->writable()["P"] = pData;
	shadingPoints->writable()["u"] = uData;
	shadingPoints->writable()["v"] = vData;

	ConstStringVectorDataPtr channelNamesData = inPlug()->channelNamesPlug()->getValue();
	const vector<string> &channelNames = channelNamesData->readable();
	for( vector<string>::const_iterator it = channelNames.begin(), eIt = channelNames.end(); it != eIt; ++it )
	{
		shadingPoints->writable()[*it] = boost::const_pointer_cast<FloatVectorData>( inPlug()->channelData( *it, tileOrigin ) );
	}

	CompoundDataPtr result = shadingEngine->shade( shadingPoints.get() );

	// remove results that aren't suitable to become channels
	for( CompoundDataMap::iterator it = result->writable().begin(); it != result->writable().end();  )
	{
		CompoundDataMap::iterator nextIt = it; nextIt++;
		if( !runTimeCast<FloatVectorData>( it->second ) )
		{
			result->writable().erase( it );
		}
		it = nextIt;
	}

	return result;
}
Esempio n. 26
0
bool Merge::hasAlpha( ConstStringVectorDataPtr channelNamesData ) const
{
	const std::vector<std::string> &channelNames = channelNamesData->readable();
	std::vector<std::string>::const_iterator channelIt = std::find( channelNames.begin(), channelNames.end(), "A" );
	return channelIt != channelNames.end();
}