IECore::MurmurHash ScenePlug::setNamesHash() const { ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed ); removeNonGlobalContextVariables( tmpContext.get() ); Context::Scope scopedContext( tmpContext.get() ); return setNamesPlug()->hash(); }
IECore::ConstInternedStringVectorDataPtr ScenePlug::setNames() const { ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed ); removeNonGlobalContextVariables( tmpContext.get() ); Context::Scope scopedContext( tmpContext.get() ); return setNamesPlug()->getValue(); }
IECore::ConstCompoundObjectPtr ScenePlug::globals() const { ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed ); removeNonGlobalContextVariables( tmpContext.get() ); Context::Scope scopedContext( tmpContext.get() ); return globalsPlug()->getValue(); }
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(); }
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(); }
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; }
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(); }
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; }
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(); }
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; }
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; }
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(); }
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(); }
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 ); }
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++; } } } } } }
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(); } }
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; }
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 ); }
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 ); } }
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; } } }
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(); }
const Context *Context::current() { ContextStack &stack = g_threadContexts.local(); if( !stack.size() ) { return g_defaultContext.get(); } return stack.top(); }
void _MatrixStorage::setContext( ContextPtr context ) { if ( context.get() != mContext.get() ) { LAMA_LOG_DEBUG( logger, *this << ": new location = " << *context << ", old location = " << *mContext ) } mContext = context; }
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(); } }
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(); } }
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 ); }
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() ) ); }
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 ); } }
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(); }
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 ); } }