void Expression::compute( ValuePlug *output, const Context *context ) const { if( output == executePlug() ) { if( m_engine ) { std::vector<const ValuePlug *> inputs; for( ValuePlugIterator it( inPlug() ); !it.done(); ++it ) { inputs.push_back( it->get() ); } static_cast<ObjectVectorPlug *>( output )->setValue( m_engine->execute( context, inputs ) ); } else { output->setToDefault(); } return; } // See if we're computing a descendant of outPlug(), // and if we are, get the immediate child of outPlug() // that is its parent. const ValuePlug *outPlugChild = output; while( outPlugChild ) { const ValuePlug *p = outPlugChild->parent<ValuePlug>(); if( p == outPlug() ) { break; } outPlugChild = p; } // If we've found such a plug, we can defer to the engine // to do the work of setting it. if( outPlugChild ) { ConstObjectVectorPtr values = executePlug()->getValue(); size_t index = 0; for( ValuePlugIterator it( outPlug() ); !it.done() && *it != outPlugChild; ++it ) { index++; } if( index < values->members().size() ) { m_engine->apply( output, outPlugChild, values->members()[index].get() ); } else { output->setToDefault(); } return; } ComputeNode::compute( output, context ); }
IECore::ConstFloatVectorDataPtr ColorProcessor::computeChannelData( const std::string &channelName, const Imath::V2i &tileOrigin, const Gaffer::Context *context, const ImagePlug *parent ) const { ConstObjectVectorPtr colorData = boost::static_pointer_cast<const ObjectVector>( colorDataPlug()->getValue() ); if( channelName == "R" ) { return boost::static_pointer_cast<const FloatVectorData>( colorData->members()[0] ); } else if( channelName == "G" ) { return boost::static_pointer_cast<const FloatVectorData>( colorData->members()[1] ); } else if( channelName == "B" ) { return boost::static_pointer_cast<const FloatVectorData>( colorData->members()[2] ); } // We're not allowed to return NULL, but we should never get here because channelEnabled() // should be preventing it. return NULL; }
void InteractiveRender::updateShadersWalk( const ScenePlug::ScenePath &path ) { /// \todo Keep a track of the hashes of the shaders at each path, /// and use it to only update the shaders when they've changed. ConstCompoundObjectPtr attributes = inPlug()->attributes( path ); // terminate recursion for invisible locations ConstBoolDataPtr visibility = attributes->member<BoolData>( SceneInterface::visibilityName ); if( visibility && ( !visibility->readable() ) ) { return; } ConstObjectVectorPtr shader = attributes->member<ObjectVector>( "shader" ); if( shader ) { std::string name; ScenePlug::pathToString( path, name ); CompoundDataMap parameters; parameters["exactscopename"] = new StringData( name ); { EditBlock edit( m_renderer.get(), "attribute", parameters ); for( ObjectVector::MemberContainer::const_iterator it = shader->members().begin(), eIt = shader->members().end(); it != eIt; it++ ) { const StateRenderable *s = runTimeCast<const StateRenderable>( it->get() ); if( s ) { s->render( m_renderer.get() ); } } } } ConstInternedStringVectorDataPtr childNames = inPlug()->childNames( path ); ScenePlug::ScenePath childPath = path; childPath.push_back( InternedString() ); // for the child name for( vector<InternedString>::const_iterator it=childNames->readable().begin(); it!=childNames->readable().end(); it++ ) { childPath[path.size()] = *it; updateShadersWalk( childPath ); } }
IECore::ConstFloatVectorDataPtr ColorProcessor::computeChannelData( const std::string &channelName, const Imath::V2i &tileOrigin, const Gaffer::Context *context, const ImagePlug *parent ) const { const std::string &channels = channelsPlug()->getValue(); const std::string &channel = context->get<std::string>( ImagePlug::channelNameContextName ); const std::string &baseName = ImageAlgo::baseName( channel ); if( ( baseName != "R" && baseName != "G" && baseName != "B" ) || !StringAlgo::matchMultiple( channel, channels ) ) { // Auxiliary channel, or not in channel mask. Pass through. return inPlug()->channelDataPlug()->getValue(); } ConstObjectVectorPtr colorData; { Context::EditableScope layerScope( context ); layerScope.set( g_layerNameKey, ImageAlgo::layerName( channel ) ); colorData = boost::static_pointer_cast<const ObjectVector>( colorDataPlug()->getValue() ); } return boost::static_pointer_cast<const FloatVectorData>( colorData->members()[ImageAlgo::colorIndex( baseName)] ); }