Example #1
0
void ImageNode::computeImagePlugs( ValuePlug *output, const Context *context ) const
{
	ImagePlug *imagePlug = output->ancestor<ImagePlug>();
	if( output == imagePlug->formatPlug() )
	{
		static_cast<FormatPlug *>( output )->setValue(
			computeFormat( context, imagePlug )
		);
	}
	else if( output == imagePlug->dataWindowPlug() )
	{
		static_cast<AtomicBox2iPlug *>( output )->setValue(
			computeDataWindow( context, imagePlug )
		);
	}
	else if( output == imagePlug->channelNamesPlug() )
	{
		static_cast<StringVectorDataPlug *>( output )->setValue(
			computeChannelNames( context, imagePlug )
		);
	}
	else if( output == imagePlug->channelDataPlug() )
	{
		std::string channelName = context->get<string>( ImagePlug::channelNameContextName );
		V2i tileOrigin = context->get<V2i>( ImagePlug::tileOriginContextName );
		if( tileOrigin.x % ImagePlug::tileSize() || tileOrigin.y % ImagePlug::tileSize() )
		{
			throw Exception( "The image:tileOrigin must be a multiple of ImagePlug::tileSize()" );
		}
		static_cast<FloatVectorDataPlug *>( output )->setValue(
			computeChannelData( channelName, tileOrigin, context, imagePlug )
		);
	}
}
Example #2
0
void ImageNode::compute( ValuePlug *output, const Context *context ) const
{
	ImagePlug *imagePlug = output->parent<ImagePlug>();
	if( !imagePlug )
	{
		ComputeNode::compute( output, context );
		return;
	}

	// we're computing part of an ImagePlug

	if( !enabled() )
	{
		// disabled nodes just output a default black image.
		output->setToDefault();
		return;
	}

	// node is enabled - defer to our derived classes to perform the appropriate computation

	if( output == imagePlug->formatPlug() )
	{
		static_cast<FormatPlug *>( output )->setValue(
			computeFormat( context, imagePlug )
		);
	}
	else if( output == imagePlug->dataWindowPlug() )
	{
		static_cast<AtomicBox2iPlug *>( output )->setValue(
			computeDataWindow( context, imagePlug )
		);
	}
	else if( output == imagePlug->channelNamesPlug() )
	{
		static_cast<StringVectorDataPlug *>( output )->setValue(
			computeChannelNames( context, imagePlug )
		);
	}
	else if( output == imagePlug->channelDataPlug() )
	{
		std::string channelName = context->get<string>( ImagePlug::channelNameContextName );
		if( channelEnabled( channelName ) )
		{
			V2i tileOrigin = context->get<V2i>( ImagePlug::tileOriginContextName );
			if( tileOrigin.x % ImagePlug::tileSize() || tileOrigin.y % ImagePlug::tileSize() )
			{
				throw Exception( "The image:tileOrigin must be a multiple of ImagePlug::tileSize()" );
			}
			static_cast<FloatVectorDataPlug *>( output )->setValue(
				computeChannelData( channelName, tileOrigin, context, imagePlug )
			);
		}
		else
		{
			output->setToDefault();
		}
	}
}
Example #3
0
void ImageNode::compute( ValuePlug *output, const Context *context ) const
{
	ImagePlug *imagePlug = output->ancestor<ImagePlug>();
	if( imagePlug )
	{
		if( enabled() )
		{
			if( output == imagePlug->channelDataPlug() )
			{
				const std::string &channel = context->get<std::string>( ImagePlug::channelNameContextName );
				if ( channelEnabled( channel ) )
				{
					computeImagePlugs( output, context );
				}
				else
				{
					static_cast<FloatVectorDataPlug *>( output )->setValue(
						imagePlug->channelDataPlug()->defaultValue()
					);
				}
			}
			else
			{
				computeImagePlugs( output, context );
			}
		}
		else
		{
			if( output == imagePlug->formatPlug() )
			{
				static_cast<FormatPlug *>( output )->setValue(
					imagePlug->formatPlug()->defaultValue()
				);
			}
			else if( output == imagePlug->dataWindowPlug() )
			{
				static_cast<AtomicBox2iPlug *>( output )->setValue(
					imagePlug->dataWindowPlug()->defaultValue()
				);
			}
			else if( output == imagePlug->channelNamesPlug() )
			{
				static_cast<StringVectorDataPlug *>( output )->setValue(
					imagePlug->channelNamesPlug()->defaultValue()
				);
			}
			else if( output == imagePlug->channelDataPlug() )
			{
				static_cast<FloatVectorDataPlug *>( output )->setValue(
					imagePlug->channelDataPlug()->defaultValue()
				);
			}
		}
	}
}
Example #4
0
static IECore::ImagePrimitivePtr image( const ImagePlug &plug )
{
	IECorePython::ScopedGILRelease gilRelease;
	return plug.image();
}
Example #5
0
static IECore::FloatVectorDataPtr channelData( const ImagePlug &plug,  const std::string &channelName, const Imath::V2i &tile  )
{
	IECore::ConstFloatVectorDataPtr d = plug.channelData( channelName, tile );
	return d ? d->copy() : 0;
}