Multiple Port Connections

 
 
 

Custom ICENodes can be defined with an unlimited number of input connections, which is useful for implementing nodes that need to process multiple input values of similar types. The maximum number of connections must be specified for each port group with ICENodeDef::AddPortGroup. By default, a port group is created with only one input connection.

The code snippet below demonstrates how to access the multiple connections of a port group from the Evaluate callback:

/*
	Register an input group with up to 10 connections
*/
CStatus RegisterMaxNode( PluginRegistrar& in_reg )
{
	ICENodeDef nodeDef = Application().GetFactory().CreateICENodeDef(L"MaxNode");

	// Define a port group with a maximum of 10 connections. 
	CStatus st = nodeDef.AddPortGroup(ID_G_100, 1, 10);
	st.AssertSucceeded();

	st = nodeDef.AddInputPort( ID_IN_PointPositions, ID_G_100, siICENodeDataVector3, siICENodeStructureSingle, siICENodeContextComponent0D, L"PointPositions", L"PointPositions" );
	st.AssertSucceeded();

	// Add output port.
	st = nodeDef.AddOutputPort( ID_OUT_Max, siICENodeDataVector3, siICENodeStructureSingle, siICENodeContextSingleton,  L"MaxPos", L"MaxPos" );
	st.AssertSucceeded();

	in_reg.RegisterICENode(nodeDef);

	return CStatus::OK;
}


/*
	Evaluate each instance's value to find the maximum value amongst all instances
*/
XSIPLUGINCALLBACK CStatus Max_Evaluate( ICENodeContext& in_ctxt )
{
	ULONG nPortID = in_ctxt.GetEvaluatedOutputPortID();
	switch (nPortID)
	{
		case ID_OUT_MaxPos:
		{
			Application xsi;

			CDataArrayVector3f outData(in_ctxt);
			CVector3f v3fMax(-FLT_MAX,-FLT_MAX,-FLT_MAX);

			// Get the number of port instances defined for group ID_G_100
			ULONG nInstCount;
			in_ctxt.GetGroupInstanceCount(ID_G_100, nInstCount);

			// Iterate over the number of instances to access the data buffer of each input connection
			for (ULONG nInstID=0; nInstID<nInstCount; nInstID++)
			{
				CDataArrayVector3f posArray(in_ctxt, ID_IN_PointPositions, nInstID);	

				CIndexSet indexSet( in_ctxt );
				for ( CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next() )
				{
					CVector3f& v3f = posArray[it];
					if ( v3fMax.GetX() <= v3f.GetX() && v3fMax.GetY() <= v3f.GetY() && v3fMax.GetZ() <= v3f.GetZ() )
					{
						v3fMax = v3f;
					}
				}
			}

			// Output max value
			outData[0] = v3fMax;
		}
	};

	return CStatus::OK; 
}

Creative Commons License Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License