IECore::ImagePrimitivePtr ToGLTextureConverter::imageFromCompoundData( IECore::CompoundData::ConstPtr data ) const
{

	if ( ! data )
	{
		throw IECore::Exception( "No CompoundData supplied." );
	}

	IECore::Box2iDataPtr dataWindow = 0;

	IECore::CompoundDataMap::const_iterator itData = data->readable().find( "dataWindow" );
	if ( itData == data->readable().end() )
	{
		throw IECore::Exception( "Invalid CompoundData supplied. ImagePrimitive representations need a dataWindow (Box2i)." );
	}
	dataWindow = IECore::runTimeCast<IECore::Box2iData>( itData->second );

	IECore::Box2iDataPtr screenWindow = 0;
	itData = data->readable().find( "displayWindow" );
	if ( itData == data->readable().end() )
	{
		throw IECore::Exception( "Invalid CompoundData supplied. ImagePrimitive representations need a screenWindow (Box2i)." );
	}
	screenWindow = IECore::runTimeCast<IECore::Box2iData>( itData->second );

	IECore::CompoundDataPtr channels = 0;
	itData = data->readable().find( "channels" );
	if ( itData == data->readable().end() )
	{
		throw IECore::Exception( "Invalid CompoundData supplied. ImagePrimitive representations need a CompoundDataMap of channels." );
	}
	channels = IECore::runTimeCast<IECore::CompoundData>( itData->second );


	if ( !dataWindow || !screenWindow || !channels )
	{
		throw IECore::Exception( "Invalid CompoundData representation supplied. Some data is of the wrong type" );
	}


	IECore::ImagePrimitivePtr newImage = new IECore::ImagePrimitive( dataWindow->readable(), screenWindow->readable() );
	for (
			IECore::CompoundDataMap::const_iterator itChannels = channels->readable().begin();
			itChannels != channels->readable().end();
			itChannels++
	)
	{
		IECore::FloatVectorDataPtr channelData = IECore::runTimeCast<IECore::FloatVectorData>( itChannels->second );
		if ( ! channelData )
		{
			throw IECore::Exception( "Invalid channel data found in ImagePrimitive representation, only 32bit float data is supported. Please check texture.");
		}

		newImage->variables.insert( IECore::PrimitiveVariableMap::value_type( itChannels->first, IECore::PrimitiveVariable( IECore::PrimitiveVariable::Vertex, channelData ) ) );

	}

	return newImage;

}
Example #2
0
IECore::ConstCompoundObjectPtr SubTree::computeGlobals( const Gaffer::Context *context, const ScenePlug *parent ) const
{
	IECore::CompoundObjectPtr result = inPlug()->globalsPlug()->getValue()->copy();

	const IECore::CompoundData *inputForwardDeclarations = result->member<IECore::CompoundData>( "gaffer:forwardDeclarations" );
	if( inputForwardDeclarations )
	{
		std::string root = rootPlug()->getValue();
		if( !root.size() || root[root.size()-1] != '/' )
		{
			root += "/";
		}

		IECore::CompoundDataPtr forwardDeclarations = new IECore::CompoundData;
		for( IECore::CompoundDataMap::const_iterator it = inputForwardDeclarations->readable().begin(), eIt = inputForwardDeclarations->readable().end(); it != eIt; it++ )
		{
			const IECore::InternedString &inputPath = it->first;
			if( inputPath.string().compare( 0, root.size(), root ) == 0 )
			{
				std::string outputPath( inputPath, root.size()-1 );
				forwardDeclarations->writable()[outputPath] = it->second;
			}
		}
		result->members()["gaffer:forwardDeclarations"] = forwardDeclarations;
	}

	return result;
}
Example #3
0
IECore::ConstCompoundDataPtr ImageMetadata::computeProcessedMetadata( const Gaffer::Context *context, const IECore::CompoundData *inputMetadata ) const
{
	const CompoundDataPlug *p = metadataPlug();
	if ( !p->children().size() )
	{
		return inputMetadata;
	}

	IECore::CompoundDataPtr result = new IECore::CompoundData;
	// Since we're not going to modify any existing members (only add new ones),
	// and our result becomes const on returning it, we can directly reference
	// the input members in our result without copying. Be careful not to modify
	// them though!
	result->writable() = inputMetadata->readable();

	std::string name;
	for ( CompoundDataPlug::MemberPlugIterator it( p ); !it.done(); ++it )
	{
		IECore::DataPtr d = p->memberDataAndName( it->get(), name );
		if ( d )
		{
			result->writable()[name] = d;
		}
	}

	return result;
}
Example #4
0
IECore::ConstCompoundDataPtr CopyImageMetadata::computeProcessedMetadata( const Gaffer::Context *context, const IECore::CompoundData *inputMetadata ) const
{
	ConstCompoundDataPtr copyFrom = copyFromPlug()->metadataPlug()->getValue();
	if( copyFrom->readable().empty() )
	{
		return inputMetadata;
	}

	const std::string names = namesPlug()->getValue();
	const bool invert = invertNamesPlug()->getValue();
	if ( !invert && !names.size() )
	{
		return inputMetadata;
	}

	IECore::CompoundDataPtr result = inputMetadata->copy();
	for( IECore::CompoundData::ValueType::const_iterator it = copyFrom->readable().begin(), eIt = copyFrom->readable().end(); it != eIt; ++it )
	{
		if( StringAlgo::matchMultiple( it->first.c_str(), names.c_str() ) != invert )
		{
			result->writable()[it->first] = it->second;
		}
	}

	return result;
}
IECore::CompoundDataPtr IECoreRI::SXRendererImplementation::shadePlane( const V2i &resolution ) const
{
	IECore::CompoundDataPtr points = new IECore::CompoundData();
	
	V3fVectorDataPtr pData = new IECore::V3fVectorData();
	V3fVectorDataPtr nData = new IECore::V3fVectorData();
	FloatVectorDataPtr sData = new IECore::FloatVectorData();
	FloatVectorDataPtr tData = new IECore::FloatVectorData();

	std::vector<V3f> &p = pData->writable();
	std::vector<V3f> &n = nData->writable();
	std::vector<float> &s = sData->writable();
	std::vector<float> &t = tData->writable();
	
	unsigned numPoints = resolution[0] * resolution[1];
	
	p.resize( numPoints );
	n.resize( numPoints );
	s.resize( numPoints );
	t.resize( numPoints );
	
	unsigned xResMinus1 = resolution[0] - 1;
	unsigned yResMinus1 = resolution[1] - 1;
	
	unsigned i = 0;
	for( int y = 0; y < resolution[1]; y++ )
	{
		for( int x = 0; x < resolution[0]; x++ )
		{
			p[i] = V3f( float(x) / xResMinus1 , float(y) / yResMinus1, 0.0 );	
			s[i] = p[i][0];
			t[i] = p[i][1];
			n[i] = V3f( 0.0f, 0.0f, 1.0f );
			i++;
		}
	}	
	
	points->writable()[ "P" ] = pData;
	points->writable()[ "N" ] = nData;
	points->writable()[ "s" ] = sData;
	points->writable()[ "t" ] = tData;
	
	return shade( points, resolution );
}
Example #6
0
IECore::ConstCompoundObjectPtr Group::computeGlobals( const Gaffer::Context *context, const ScenePlug *parent ) const
{
	IECore::CompoundObjectPtr result = inPlug()->globalsPlug()->getValue()->copy();
	
	std::string groupName = namePlug()->getValue();

	ConstCompoundObjectPtr mapping = staticPointerCast<const CompoundObject>( inputMappingPlug()->getValue() );
	const ObjectVector *forwardMappings = mapping->member<ObjectVector>( "__GroupForwardMappings", true /* throw if missing */ );

	IECore::CompoundDataPtr forwardDeclarations = new IECore::CompoundData;
	for( size_t i = 0, e = m_inPlugs.inputs().size(); i < e; i++ )
	{
		const CompoundData *forwardMapping = static_cast<const IECore::CompoundData *>( forwardMappings->members()[i].get() );
		ConstCompoundObjectPtr inputGlobals = m_inPlugs.inputs()[i]->globalsPlug()->getValue();
		const CompoundData *inputForwardDeclarations = inputGlobals->member<CompoundData>( "gaffer:forwardDeclarations" );
		if( inputForwardDeclarations )
		{
			for( CompoundDataMap::const_iterator it = inputForwardDeclarations->readable().begin(), eIt = inputForwardDeclarations->readable().end(); it != eIt; it++ )
			{
				/// \todo This would all be much nicer if the forward declarations data structure
				/// used ScenePlug::ScenePaths or something similar - then we could ditch all the
				/// string munging.
				const InternedString &inputPath = it->first;
				size_t secondSlashPos = inputPath.string().find( '/', 1 );
				const std::string inputName( inputPath.string(), 1, secondSlashPos - 1 );
				const InternedString &outputName = forwardMapping->member<InternedStringData>( inputName, true /* throw if missing */ )->readable();
				std::string outputPath = std::string( "/" ) + groupName + "/" + outputName.string();
				if( secondSlashPos != string::npos )
				{
					outputPath += inputPath.string().substr( secondSlashPos );
				}
				forwardDeclarations->writable()[outputPath] = it->second;
			}
		}
	}
	result->members()["gaffer:forwardDeclarations"] = forwardDeclarations;
	
	return result;
}
Example #7
0
IECore::CompoundDataPtr LinkedScene::linkAttributeData( const SceneInterface *scene, double time )
{
	IECore::CompoundDataPtr d = linkAttributeData(scene);
	d->writable()[g_time] = new DoubleData(time);
	return d;
}
Example #8
0
IECore::CompoundDataPtr GXEvaluator::evaluate( const IECore::IntVectorData *faceIndices, const IECore::FloatVectorData *u, const IECore::FloatVectorData *v, const std::vector<std::string> &primVarNames ) const
{
	// do some basic validation of our input

	size_t numPoints = faceIndices->readable().size();
	if( u->readable().size() != numPoints || v->readable().size() != numPoints )
	{
		throw InvalidArgumentException( "faceIndices, u and v must all have the same length" );
	}
	
	validatePrimVarNames( primVarNames );
	
	// create surface points
	ScopedContext context( m_context );

	const std::vector<int> faceIndicesReadable = faceIndices->readable();
	const std::vector<float> uReadable = u->readable();
	const std::vector<float> vReadable = v->readable();
	
	std::vector<GxSurfacePoint> surfacePoints( numPoints );
	for( unsigned i=0; i<numPoints; i++ )
	{
		int status = GxCreateSurfacePoint( m_geo, faceIndicesReadable[i], uReadable[i], vReadable[i], 0.0f, &(surfacePoints[i]) );
		if( status==RIE_RANGE )
		{
			for( unsigned j=0; j<i; j++ )
			{
				GxFreeSurfacePoint( surfacePoints[j] );				
			}
			throw InvalidArgumentException( boost::str( boost::format( "faceIndex %d out of range" ) % faceIndicesReadable[i] ) );
		}
	}

	// query all the primvars

	IECore::CompoundDataPtr result = new IECore::CompoundData;
	for( vector<string>::const_iterator it=primVarNames.begin(); it!=primVarNames.end(); it++ )
	{
		switch( m_primitiveVariableTypes.find( *it )->second )
		{
			case FloatVectorDataTypeId :
				result->writable()[*it] = evaluatePrimitiveVariable<FloatVectorData>( surfacePoints, *it );
				break;
			case V3fVectorDataTypeId :
				result->writable()[*it] = evaluatePrimitiveVariable<V3fVectorData>( surfacePoints, *it );
				break;
			case Color3fVectorDataTypeId :
				result->writable()[*it] = evaluatePrimitiveVariable<Color3fVectorData>( surfacePoints, *it );
				break;
			default :
				assert( 0 ); // shouldnt be here as we checked types earlier
		}
	}

	// clean up

	for( unsigned i=0; i<numPoints; i++ )
	{
		GxFreeSurfacePoint( surfacePoints[i] );
	}
	
	return result;
}
ClientDisplayDriver::ClientDisplayDriver( const Imath::Box2i &displayWindow, const Imath::Box2i &dataWindow, const std::vector<std::string> &channelNames, IECore::ConstCompoundDataPtr parameters ) :
		DisplayDriver( displayWindow, dataWindow, channelNames, parameters ),
		m_data( new PrivateData() )
{
	// expects three custom StringData parameters : displayHost, displayPort and displayType
	const StringData *displayHostData = parameters->member<StringData>( "displayHost", true /* throw if missing */ );
	const StringData *displayPortData = parameters->member<StringData>( "displayPort", true /* throw if missing */ );
	
	m_data->m_host = displayHostData->readable();
	m_data->m_port = displayPortData->readable();
	
	tcp::resolver resolver(m_data->m_service);
	tcp::resolver::query query(m_data->m_host, m_data->m_port);

	boost::system::error_code error;
	tcp::resolver::iterator iterator = resolver.resolve( query, error );	
	if( !error )
	{
		error = boost::asio::error::host_not_found;
		while( error && iterator != tcp::resolver::iterator() )
		{
			m_data->m_socket.close();
			m_data->m_socket.connect( *iterator++, error );
		}
	}
	if( error )
	{
		throw Exception( std::string( "Could not connect to remote display driver server : " ) + error.message() );
	}

	MemoryIndexedIOPtr io;
	ConstCharVectorDataPtr buf;
	Box2iDataPtr displayWindowData = new Box2iData( displayWindow );
	Box2iDataPtr dataWindowData = new Box2iData( dataWindow );
	StringVectorDataPtr channelNamesData = new StringVectorData( channelNames );

	IECore::CompoundDataPtr tmpParameters = parameters->copy();
	tmpParameters->writable()[ "clientPID" ] = new IntData( getpid() );

	// build the data block
	io = new MemoryIndexedIO( ConstCharVectorDataPtr(), IndexedIO::rootPath, IndexedIO::Exclusive | IndexedIO::Write );
	displayWindowData->Object::save( io, "displayWindow" );
	dataWindowData->Object::save( io, "dataWindow" );
	channelNamesData->Object::save( io, "channelNames" );
	tmpParameters->Object::save( io, "parameters" );
	buf = io->buffer();

	size_t dataSize = buf->readable().size();

	sendHeader( DisplayDriverServerHeader::imageOpen, dataSize );

	m_data->m_socket.send( boost::asio::buffer( &(buf->readable()[0]), dataSize ) );

	if ( receiveHeader( DisplayDriverServerHeader::imageOpen ) != sizeof(m_data->m_scanLineOrderOnly) )
	{
		throw Exception( "Invalid returned scanLineOrder from display driver server!" );
	}
	m_data->m_socket.receive( boost::asio::buffer( &m_data->m_scanLineOrderOnly, sizeof(m_data->m_scanLineOrderOnly) ) );
	
	if ( receiveHeader( DisplayDriverServerHeader::imageOpen ) != sizeof(m_data->m_acceptsRepeatedData) )
	{
		throw Exception( "Invalid returned acceptsRepeatedData from display driver server!" );
	}
	m_data->m_socket.receive( boost::asio::buffer( &m_data->m_acceptsRepeatedData, sizeof(m_data->m_acceptsRepeatedData) ) );
}