Example #1
0
IECore::MurmurHash ScenePlug::setNamesHash() const
{
	ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed );
	removeNonGlobalContextVariables( tmpContext.get() );
	Context::Scope scopedContext( tmpContext.get() );
	return setNamesPlug()->hash();
}
Example #2
0
IECore::ConstInternedStringVectorDataPtr ScenePlug::setNames() const
{
	ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed );
	removeNonGlobalContextVariables( tmpContext.get() );
	Context::Scope scopedContext( tmpContext.get() );
	return setNamesPlug()->getValue();
}
Example #3
0
IECore::ConstCompoundObjectPtr ScenePlug::globals() const
{
	ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed );
	removeNonGlobalContextVariables( tmpContext.get() );
	Context::Scope scopedContext( tmpContext.get() );
	return globalsPlug()->getValue();
}
Example #4
0
IECore::MurmurHash ScenePlug::setHash( const IECore::InternedString &setName ) const
{
	ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed );
	tmpContext->set( setNameContextName, setName );
	removeNonGlobalContextVariables( tmpContext.get() );
	Context::Scope scopedContext( tmpContext.get() );
	return setPlug()->hash();
}
Example #5
0
ConstPathMatcherDataPtr ScenePlug::set( const IECore::InternedString &setName ) const
{
	ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed );
	tmpContext->set( setNameContextName, setName );
	removeNonGlobalContextVariables( tmpContext.get() );
	Context::Scope scopedContext( tmpContext.get() );
	return setPlug()->getValue();
}
Example #6
0
IECore::TransformPtr GafferScene::transform( const ScenePlug *scene, const ScenePlug::ScenePath &path, const Imath::V2f &shutter, bool motionBlur )
{
	int numSamples = 1;
	if( motionBlur )
	{
		ConstCompoundObjectPtr attributes = scene->fullAttributes( path );
		const IntData *transformBlurSegmentsData = attributes->member<IntData>( "gaffer:transformBlurSegments" );
		numSamples = transformBlurSegmentsData ? transformBlurSegmentsData->readable() + 1 : 2;

		const BoolData *transformBlurData = attributes->member<BoolData>( "gaffer:transformBlur" );
		if( transformBlurData && !transformBlurData->readable() )
		{
			numSamples = 1;
		}
	}

	MatrixMotionTransformPtr result = new MatrixMotionTransform();
	ContextPtr transformContext = new Context( *Context::current(), Context::Borrowed );
	Context::Scope scopedContext( transformContext.get() );
	for( int i = 0; i < numSamples; i++ )
	{
		float frame = lerp( shutter[0], shutter[1], (float)i / std::max( 1, numSamples - 1 ) );
		transformContext->setFrame( frame );
		result->snapshots()[frame] = scene->fullTransform( path );
	}

	return result;
}
Example #7
0
IECore::ConstObjectPtr ScenePlug::object( const ScenePath &scenePath ) const
{
	ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed );
	tmpContext->set( scenePathContextName, scenePath );
	Context::Scope scopedContext( tmpContext.get() );
	return objectPlug()->getValue();
}
Example #8
0
IECore::CompoundObjectPtr ScenePlug::fullAttributes( const ScenePath &scenePath ) const
{
	ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed );
	Context::Scope scopedContext( tmpContext.get() );

	IECore::CompoundObjectPtr result = new IECore::CompoundObject;
	IECore::CompoundObject::ObjectMap &resultMembers = result->members();
	ScenePath path( scenePath );
	while( path.size() )
	{
		tmpContext->set( scenePathContextName, path );
		IECore::ConstCompoundObjectPtr a = attributesPlug()->getValue();
		const IECore::CompoundObject::ObjectMap &aMembers = a->members();
		for( IECore::CompoundObject::ObjectMap::const_iterator it = aMembers.begin(), eIt = aMembers.end(); it != eIt; it++ )
		{
			if( resultMembers.find( it->first ) == resultMembers.end() )
			{
				resultMembers.insert( *it );
			}
		}		
		path.pop_back();
	}
	
	return result;
}
Example #9
0
Imath::M44f ScenePlug::transform( const ScenePath &scenePath ) const
{
	ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed );
	tmpContext->set( scenePathContextName, scenePath );
	Context::Scope scopedContext( tmpContext.get() );
	return transformPlug()->getValue();
}
Example #10
0
Imath::Box3f SceneNode::unionOfTransformedChildBounds( const ScenePath &path, const ScenePlug *out, const IECore::InternedStringVectorData *childNamesData ) const
{
	ConstInternedStringVectorDataPtr computedChildNames;
	if( !childNamesData )
	{
		computedChildNames = out->childNames( path );
		childNamesData = computedChildNames.get();
	}
	const vector<InternedString> &childNames = childNamesData->readable();

	Box3f result;
	if( childNames.size() )
	{
		ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed );
		Context::Scope scopedContext( tmpContext.get() );

		ScenePath childPath( path );
		childPath.push_back( InternedString() ); // room for the child name
		for( vector<InternedString>::const_iterator it = childNames.begin(); it != childNames.end(); it++ )
		{
			childPath[path.size()] = *it;
			tmpContext->set( ScenePlug::scenePathContextName, childPath );
			Box3f childBound = out->boundPlug()->getValue();
			childBound = transform( childBound, out->transformPlug()->getValue() );
			result.extendBy( childBound );
		}
	}
	return result;
}
Example #11
0
IECore::MurmurHash SceneNode::hashOfTransformedChildBounds( const ScenePath &path, const ScenePlug *out, const IECore::InternedStringVectorData *childNamesData ) const
{
	ConstInternedStringVectorDataPtr computedChildNames;
	if( !childNamesData )
	{
		computedChildNames = out->childNames( path );
		childNamesData = computedChildNames.get();
	}
	const vector<InternedString> &childNames = childNamesData->readable();

	IECore::MurmurHash result;
	if( childNames.size() )
	{
		ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed );
		Context::Scope scopedContext( tmpContext.get() );

		ScenePath childPath( path );
		childPath.push_back( InternedString() ); // room for the child name
		for( vector<InternedString>::const_iterator it = childNames.begin(); it != childNames.end(); it++ )
		{
			childPath[path.size()] = *it;
			tmpContext->set( ScenePlug::scenePathContextName, childPath );
			out->boundPlug()->hash( result );
			out->transformPlug()->hash( result );
		}
	}
	else
	{
		result.append( typeId() );
		result.append( "emptyBound" );
	}
	return result;
}
Example #12
0
IECore::MurmurHash ScenePlug::childNamesHash( const ScenePath &scenePath ) const
{
	ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed );
	tmpContext->set( scenePathContextName, scenePath );
	Context::Scope scopedContext( tmpContext.get() );
	return childNamesPlug()->hash();
}
Example #13
0
IECore::ConstInternedStringVectorDataPtr ScenePlug::childNames( const ScenePath &scenePath ) const
{
	ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed );
	tmpContext->set( scenePathContextName, scenePath );
	Context::Scope scopedContext( tmpContext.get() );
	return childNamesPlug()->getValue();
}
Example #14
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 );
}
Example #15
0
    void operator()( const blocked_range2d<size_t>& r ) const
    {
        ContextPtr context = new Context( *m_parentContext );
        const Box2i operationWindow( V2i( r.rows().begin()+m_dataWindow.min.x, r.cols().begin()+m_dataWindow.min.y ), V2i( r.rows().end()+m_dataWindow.min.x-1, r.cols().end()+m_dataWindow.min.y-1 ) );
        V2i minTileOrigin = ImagePlug::tileOrigin( operationWindow.min );
        V2i maxTileOrigin = ImagePlug::tileOrigin( operationWindow.max );
        size_t imageStride = m_dataWindow.size().x + 1;

        for( int tileOriginY = minTileOrigin.y; tileOriginY <= maxTileOrigin.y; tileOriginY += m_tileSize )
        {
            for( int tileOriginX = minTileOrigin.x; tileOriginX <= maxTileOrigin.x; tileOriginX += m_tileSize )
            {
                for( vector<string>::const_iterator it = m_channelNames.begin(), eIt = m_channelNames.end(); it != eIt; it++ )
                {
                    context->set( ImagePlug::channelNameContextName, *it );
                    context->set( ImagePlug::tileOriginContextName, V2i( tileOriginX, tileOriginY ) );
                    Context::Scope scope( context.get() );
                    Box2i tileBound( V2i( tileOriginX, tileOriginY ), V2i( tileOriginX + m_tileSize - 1, tileOriginY + m_tileSize - 1 ) );
                    Box2i b = boxIntersection( tileBound, operationWindow );

                    ConstFloatVectorDataPtr tileData = m_channelDataPlug->getValue();

                    for( int y = b.min.y; y<=b.max.y; y++ )
                    {
                        const float *tilePtr = &(tileData->readable()[0]) + (y - tileOriginY) * m_tileSize + (b.min.x - tileOriginX);
                        float *channelPtr = m_imageChannelData[it-m_channelNames.begin()] + ( m_dataWindow.size().y - ( y - m_dataWindow.min.y ) ) * imageStride + (b.min.x - m_dataWindow.min.x);
                        for( int x = b.min.x; x <= b.max.x; x++ )
                        {
                            *channelPtr++ = *tilePtr++;
                        }
                    }
                }
            }
        }
    }
Example #16
0
IECore::ConstInternedStringVectorDataPtr Isolate::computeChildNames( const ScenePath &path, const Gaffer::Context *context, const ScenePlug *parent ) const
{
	ContextPtr tmpContext = filterContext( context );
	Context::Scope scopedContext( tmpContext.get() );

	if( mayPruneChildren( path, filterPlug()->getValue() ) )
	{
		// we may need to delete one or more of our children
		ConstInternedStringVectorDataPtr inputChildNamesData = inPlug()->childNamesPlug()->getValue();
		const vector<InternedString> &inputChildNames = inputChildNamesData->readable();

		InternedStringVectorDataPtr outputChildNamesData = new InternedStringVectorData;
		vector<InternedString> &outputChildNames = outputChildNamesData->writable();

		ScenePath childPath = path;
		childPath.push_back( InternedString() ); // for the child name
		for( vector<InternedString>::const_iterator it = inputChildNames.begin(), eIt = inputChildNames.end(); it != eIt; it++ )
		{
			childPath[path.size()] = *it;
			tmpContext->set( ScenePlug::scenePathContextName, childPath );
			if( filterPlug()->getValue() != Filter::NoMatch )
			{
				outputChildNames.push_back( *it );
			}
		}

		return outputChildNamesData;
	}
	else
	{
		// pass through
		return inPlug()->childNamesPlug()->getValue();
	}
}
Example #17
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;
}
Example #18
0
void ColorProcessor::compute( Gaffer::ValuePlug *output, const Gaffer::Context *context ) const
{
	if( output == colorDataPlug() )
	{
		FloatVectorDataPtr r, g, b;
		{
			ContextPtr tmpContext = new Context( *context, Context::Borrowed );
			Context::Scope scopedContext( tmpContext.get() );
			tmpContext->set( ImagePlug::channelNameContextName, string( "R" ) );
			r = inPlug()->channelDataPlug()->getValue()->copy();
			tmpContext->set( ImagePlug::channelNameContextName, string( "G" ) );
			g = inPlug()->channelDataPlug()->getValue()->copy();
			tmpContext->set( ImagePlug::channelNameContextName, string( "B" ) );
			b = inPlug()->channelDataPlug()->getValue()->copy();
		}	
		
		processColorData( context, r.get(), g.get(), b.get() );
		
		ObjectVectorPtr result = new ObjectVector();
		result->members().push_back( r );
		result->members().push_back( g );
		result->members().push_back( b );
		
		static_cast<ObjectPlug *>( output )->setValue( result );
		return;
	}
	
	ImageProcessor::compute( output, context );
}
Example #19
0
void Group::hashBound( const ScenePath &path, const Gaffer::Context *context, const ScenePlug *parent, IECore::MurmurHash &h ) const
{
	if( path.size() == 0 ) // "/"
	{
		SceneProcessor::hashBound( path, context, parent, h );
		for( ScenePlugIterator it( inPlugs() ); it != it.end(); ++it )
		{
			(*it)->boundPlug()->hash( h );
		}
		transformPlug()->hash( h );
	}
	else if( path.size() == 1 ) // "/group"
	{
		SceneProcessor::hashBound( path, context, parent, h );
		ContextPtr tmpContext = new Context( *context, Context::Borrowed );
		tmpContext->set( ScenePlug::scenePathContextName, ScenePath() );
		Context::Scope scopedContext( tmpContext.get() );
		for( ScenePlugIterator it( inPlugs() ); it != it.end(); ++it )
		{
			(*it)->boundPlug()->hash( h );
		}
	}
	else // "/group/..."
	{
		// pass through
		const ScenePlug *sourcePlug = 0;
		ScenePath source = sourcePath( path, namePlug()->getValue(), &sourcePlug );
		h = sourcePlug->boundHash( source );
	}
}
Example #20
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;
		}
	}
}
Example #21
0
IECore::MurmurHash ImagePlug::channelDataHash( const std::string &channelName, const Imath::V2i &tile ) const
{
    ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed );
    tmpContext->set( ImagePlug::channelNameContextName, channelName );
    tmpContext->set( ImagePlug::tileOriginContextName, tile );
    Context::Scope scopedContext( tmpContext.get() );
    return channelDataPlug()->hash();
}
Example #22
0
const Context *Context::current()
{
	ContextStack &stack = g_threadContexts.local();
	if( !stack.size() )
	{
		return g_defaultContext.get();
	}
	return stack.top();
}
Example #23
0
void _MatrixStorage::setContext( ContextPtr context )
{
    if ( context.get() != mContext.get() )
    {
        LAMA_LOG_DEBUG( logger, *this << ": new location = " << *context << ", old location = " << *mContext )
    }

    mContext = context;
}
Example #24
0
void ImageReader::hashMaskedOutput( const Gaffer::ValuePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h, bool alwaysClampToFrame ) const
{
    ContextPtr maskedContext = NULL;
    if( !computeFrameMask( context, maskedContext ) || alwaysClampToFrame )
    {
        Context::Scope scope( maskedContext.get() );
        h = intermediateImagePlug()->getChild<ValuePlug>( output->getName() )->hash();
    }
}
Example #25
0
void ExecutableNode::executeSequence( const std::vector<float> &frames ) const
{
	ContextPtr context = new Context( *Context::current(), Context::Borrowed );
	Context::Scope scopedContext( context.get() );

	for ( std::vector<float>::const_iterator it = frames.begin(); it != frames.end(); ++it )
	{
		context->setFrame( *it );
		execute();
	}
}
Example #26
0
void ColorProcessor::hashColorData( const Gaffer::Context *context, IECore::MurmurHash &h ) const
{
	ContextPtr tmpContext = new Context( *context, Context::Borrowed );
	Context::Scope scopedContext( tmpContext.get() );
	tmpContext->set( ImagePlug::channelNameContextName, string( "R" ) );
	inPlug()->channelDataPlug()->hash( h );
	tmpContext->set( ImagePlug::channelNameContextName, string( "G" ) );
	inPlug()->channelDataPlug()->hash( h );
	tmpContext->set( ImagePlug::channelNameContextName, string( "B" ) );
	inPlug()->channelDataPlug()->hash( h );
}
Example #27
0
void ImageReader::computeMaskedOutput( Gaffer::ValuePlug *output, const Gaffer::Context *context, bool alwaysClampToFrame ) const
{
    ContextPtr maskedContext = NULL;
    bool blackOutside = computeFrameMask( context, maskedContext );
    if( blackOutside && !alwaysClampToFrame )
    {
        output->setToDefault();
        return;
    }

    Context::Scope scope( maskedContext.get() );
    output->setFrom( intermediateImagePlug()->getChild<ValuePlug>( output->getName() ) );
}
Example #28
0
void SceneWriter::executeSequence( const std::vector<float> &frames ) const
{
	const ScenePlug *scene = inPlug()->getInput<ScenePlug>();
	if( !scene )
	{
		throw IECore::Exception( "No input scene" );
	}

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

	std::string fileName = context->substitute( fileNamePlug()->getValue() );
	createDirectories( fileName );
	SceneInterfacePtr output = SceneInterface::create( fileName, IndexedIO::Write );

	for ( std::vector<float>::const_iterator it = frames.begin(); it != frames.end(); ++it )
	{
		context->setFrame( *it );
		double time = *it / g_frameRate;
		writeLocation( scene, ScenePlug::ScenePath(), context.get(), output.get(), time );
	}
}
Example #29
0
IECore::ConstFloatVectorDataPtr ImagePlug::channelData( const std::string &channelName, const Imath::V2i &tile ) const
{
    if( direction()==In && !getInput<Plug>() )
    {
        return channelDataPlug()->defaultValue();
    }

    ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed );
    tmpContext->set( ImagePlug::channelNameContextName, channelName );
    tmpContext->set( ImagePlug::tileOriginContextName, tile );
    Context::Scope scopedContext( tmpContext.get() );

    return channelDataPlug()->getValue();
}
Example #30
0
void OSLImage::hashChannelNames( const GafferImage::ImagePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const
{
	ImageProcessor::hashChannelNames( output, context, h );
	inPlug()->channelNamesPlug()->hash( h );

	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() );
		shadingPlug()->hash( h );
	}
}