Hi,

When I set up a multi-phase ice-node according to the specifications set on
the webpage linked below in_ctxt.GetEvaluationPhaseIndex( ); returns -1 and
I naturally none of the phase switch parts get executed.
http://download.autodesk.com/global/docs/softimage2013/en_us/sdkguide/index.html?url=files/cus_icenodes_MultiPhaseCustomICENode.htm,topicNumber=d30e19848

Below is a simplified version of my SubmitEvaluationPhaseInfo and Evaluate
callbacks.

If you run it, this is the output:
# INFO : Reached beginning of Evaluate callback.
# INFO : -1
# INFO : Reached multi-threaded part of Evaluate callback
And that repeated for every thread.
So the part before the phase switch and after is being evaluated, but the
part inside of it isn't because  ULONG nPhase =
in_ctxt.GetEvaluationPhaseIndex( ); apparently returns -1.
I've gone over everything 10 times and in my eyes everything is set up
correctly, but clearly I'm making a mistake somewhere.
I would really appreciate it if somebody experienced would take a look.

I've also attached the entire c++ file.

Thank you so much guys.

SICALLBACK GetTextureColorByUV_SubmitEvaluationPhaseInfo( ICENodeContext&
in_ctxt )
{
ULONG nPhase = in_ctxt.GetEvaluationPhaseIndex( );

// Note: A case statement is needed for each phase we want to define. Each
phase should submit one or multiple ports to
// process. Be sure to call in_ctxt.SetLastEvaluationPhase() to specify the
last phase to process.
switch( nPhase )
{
case 0:
{
// Example for pulling a port for evaluation.
in_ctxt.AddEvaluationPhaseInputPort( ID_IN_ImagePath );
}
case 1:
{
// Example for pulling a port for evaluation.
in_ctxt.AddEvaluationPhaseInputPort( ID_IN_U );
in_ctxt.AddEvaluationPhaseInputPort( ID_IN_V );
 // Tells XSI that phase 1 is the last phase to process
in_ctxt.SetLastEvaluationPhase();
}
break;

default:
// Abort evaluation if the current phase is not handled
return CStatus::Abort;
}
return CStatus::OK;
}

SICALLBACK GetTextureColorByUV_Evaluate( ICENodeContext& in_ctxt )
{
// Code sample to demonstrate how to implement a multi-phase evaluation
callback.
 // Process all phases first. The Evaluate callback is called in
single-threading
// for each phase declared in the
GetTextureColorByUV_SubmitEvaluationPhaseInfo callback.
ULONG nPhase = in_ctxt.GetEvaluationPhaseIndex( );
* Application().LogMessage("Reached multi-threaded part of Evaluate
callback");
*
* Application().LogMessage(CString(nPhase));*
switch( nPhase )
{
// Note: A case statement is needed here for each phase declared in
GetTextureColorByUV_SubmitEvaluationPhaseInfo
case 0:
{
CDataArrayString ImagePathData( in_ctxt, ID_IN_ImagePath );
* Application().LogMessage("Reached End of phase");*
 // Store results in user data ...
return CStatus::OK;
}
case 1:
{
return CStatus::OK;
}
break;
};

// Note: The last phase is always processed in multi-threading.
ULONG out_portID = in_ctxt.GetEvaluatedOutputPortID( );

switch( out_portID )
{
case ID_OUT_Color :
{
// Get the output port array ...
CDataArray2DColor4f outData( in_ctxt );

// Get the input data buffers for each port
CDataArray2DFloat UData( in_ctxt, ID_IN_U );
CDataArray2DFloat VData( in_ctxt, ID_IN_V );

* Application().LogMessage("Reached multi-threaded part of Evaluate
callback");*

  // We need a CIndexSet to iterate over the data
CIndexSet indexSet( in_ctxt );
for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
{
 // Add code to set output port...
CDataArray2DFloat::Accessor USubArray = UData[it];
CDataArray2DFloat::Accessor VSubArray = VData[it];
CDataArray2DColor4f::Accessor outDataSubArray =
outData.Resize(it, USubArray.GetCount());

for (ULONG i=0; i<USubArray.GetCount( ); i++)
{
outDataSubArray[i].PutR(1);
outDataSubArray[i].PutG(1);
outDataSubArray[i].PutB(1);
outDataSubArray[i].PutA(1);
}
}
}
break;
};

return CStatus::OK;
}
// GetTextureColorByUV Plugin
// Initial code generated by Softimage SDK Wizard
// Executed Tue Jul 2 23:47:46 UTC+0200 2013 by Leo
// 
// 
// Tip: You need to compile the generated code before you can load the plug-in.
// After you compile the plug-in, you can load it by clicking Update All in the Plugin Manager.
#include <xsi_application.h>
#include <xsi_context.h>
#include <xsi_pluginregistrar.h>
#include <xsi_status.h>

#include <xsi_icenodecontext.h>
#include <xsi_icenodedef.h>
#include <xsi_command.h>
#include <xsi_factory.h>
#include <xsi_longarray.h>
#include <xsi_doublearray.h>
#include <xsi_math.h>
#include <xsi_vector2f.h>
#include <xsi_vector3f.h>
#include <xsi_vector4f.h>
#include <xsi_matrix3f.h>
#include <xsi_matrix4f.h>
#include <xsi_rotationf.h>
#include <xsi_quaternionf.h>
#include <xsi_color4f.h>
#include <xsi_shape.h>
#include <xsi_icegeometry.h>
#include <xsi_iceportstate.h>
#include <xsi_indexset.h>
#include <xsi_dataarray.h>
#include <xsi_dataarray2D.h>
#include "lodepng.h"
#include <iostream>
#include <vector>

// Defines port, group and map identifiers used for registering the ICENode
enum IDs
{
	ID_IN_U = 1,
	ID_IN_V = 2,
	ID_IN_ImagePath = 3,
	ID_G_100 = 100,
	ID_OUT_Color = 200,
	ID_TYPE_CNS = 400,
	ID_STRUCT_CNS,
	ID_CTXT_CNS,
	ID_UNDEF = ULONG_MAX
};

XSI::CStatus RegisterGetTextureColorByUV( XSI::PluginRegistrar& in_reg );

using namespace XSI; 

SICALLBACK XSILoadPlugin( PluginRegistrar& in_reg )
{
	in_reg.PutAuthor(L"LeonardKoch");
	in_reg.PutName(L"GetTextureColorByUV Plugin");
	in_reg.PutVersion(1,0);

	RegisterGetTextureColorByUV( in_reg );

	//RegistrationInsertionPoint - do not remove this line

	return CStatus::OK;
}

SICALLBACK XSIUnloadPlugin( const PluginRegistrar& in_reg )
{
	CString strPluginName;
	strPluginName = in_reg.GetName();
	Application().LogMessage(strPluginName + L" has been unloaded.",siVerboseMsg);
	return CStatus::OK;
}

CStatus RegisterGetTextureColorByUV( PluginRegistrar& in_reg )
{
	ICENodeDef nodeDef;
	nodeDef = Application().GetFactory().CreateICENodeDef(L"GetTextureColorByUV",L"GetTextureColorByUV");

	CStatus st;
	st = nodeDef.PutColor(154,0,102);
	st.AssertSucceeded( ) ;

	st = nodeDef.PutThreadingModel(XSI::siICENodeMultiEvaluationPhase);
	st.AssertSucceeded( ) ;


	// Add input ports and groups.
	st = nodeDef.AddPortGroup(ID_G_100);
	st.AssertSucceeded( ) ;

	st = nodeDef.AddInputPort(ID_IN_U,ID_G_100,siICENodeDataFloat,siICENodeStructureArray,siICENodeContextComponent0D,L"U",L"U",0,CValue(),CValue(),ID_UNDEF,ID_UNDEF,ID_CTXT_CNS);
	st.AssertSucceeded( ) ;

	st = nodeDef.AddInputPort(ID_IN_V,ID_G_100,siICENodeDataFloat,siICENodeStructureArray,siICENodeContextComponent0D,L"V",L"V",0,CValue(),CValue(),ID_UNDEF,ID_UNDEF,ID_CTXT_CNS);
	st.AssertSucceeded( ) ;

	st = nodeDef.AddInputPort(ID_IN_ImagePath,ID_G_100,siICENodeDataString,siICENodeStructureSingle,siICENodeContextSingleton,L"ImagePath",L"ImagePath",L"default string",CValue(),CValue(),ID_UNDEF,ID_UNDEF,ID_CTXT_CNS);
	st.AssertSucceeded( ) ;

	// Add output ports.
	st = nodeDef.AddOutputPort(ID_OUT_Color,siICENodeDataColor4,siICENodeStructureArray,siICENodeContextComponent0D,L"Color",L"Color",ID_UNDEF,ID_UNDEF,ID_CTXT_CNS);
	st.AssertSucceeded( ) ;

	PluginItem nodeItem = in_reg.RegisterICENode(nodeDef);
	nodeItem.PutCategories(L"LKFUnderTheHood");

	return CStatus::OK;
}

SICALLBACK GetTextureColorByUV_SubmitEvaluationPhaseInfo( ICENodeContext& in_ctxt )
{
	ULONG nPhase = in_ctxt.GetEvaluationPhaseIndex( );

	// Note: A case statement is needed for each phase we want to define. Each phase should submit one or multiple ports to
	// process. Be sure to call in_ctxt.SetLastEvaluationPhase() to specify the last phase to process.
	switch( nPhase )
	{
		case 0:
		{
			// Example for pulling a port for evaluation. 
			in_ctxt.AddEvaluationPhaseInputPort( ID_IN_ImagePath );
		}
		case 1:
		{
			// Example for pulling a port for evaluation. 
			in_ctxt.AddEvaluationPhaseInputPort( ID_IN_U );
			in_ctxt.AddEvaluationPhaseInputPort( ID_IN_V );
			
			// Tells XSI that phase 1 is the last phase to process
			in_ctxt.SetLastEvaluationPhase();
		}
		break;

		default:
			// Abort evaluation if the current phase is not handled
			return CStatus::Abort;		
	}
	return CStatus::OK;
}

SICALLBACK GetTextureColorByUV_Evaluate( ICENodeContext& in_ctxt )
{
	// Code sample to demonstrate how to implement a multi-phase evaluation callback.
	
	// Process all phases first. The Evaluate callback is called in single-threading 
	// for each phase declared in the GetTextureColorByUV_SubmitEvaluationPhaseInfo callback.
	ULONG nPhase = in_ctxt.GetEvaluationPhaseIndex( );

	Application().LogMessage("Reached beginning of Evaluate callback.");

	switch( nPhase )
	{
		// Note: A case statement is needed here for each phase declared in GetTextureColorByUV_SubmitEvaluationPhaseInfo
		case 0:
		{
			CDataArrayString ImagePathData( in_ctxt, ID_IN_ImagePath );
			/*
			std::vector<unsigned char> image; //the raw pixels
			unsigned width, height;

			//decode
			unsigned error = lodepng::decode(image, width, height, ImagePathData[0].GetAsciiString());
			//ULONG imageWidth = ULONG(width);
			//ULONG imageHeight = ULONG(height);

			//if there's an error, display it
			if(error) Application().LogMessage(CString("Decode Failed."));
			//the pixels are now in the vector "image", 4 bytes per pixel, ordered RGBARGBA..., use it as texture, draw it, ..
			CValueArray imageData;
			for (int k = 0; k < image.size(); k++)
			{
				imageData.Add(CValue(ULONG(image[k])));
			}
			*/
			Application().LogMessage("Reached End of phase");
			
			// Store results in user data ...
			//in_ctxt.PutUserData( imageData );
			return CStatus::OK;
		}
		case 1:
		{
			return CStatus::OK;
		}
		break;
	};

	// Note: The last phase is always processed in multi-threading.
	ULONG out_portID = in_ctxt.GetEvaluatedOutputPortID( );

	switch( out_portID )
	{
		case ID_OUT_Color :
		{
			// Get the output port array ...
			CDataArray2DColor4f outData( in_ctxt );
			
			// Get the pre-evaluated data from the user data 
			//CValueArray imageUserData = in_ctxt.GetUserData( );
			ULONG imageWidth = 4096;
			ULONG imageHeight = 4096;

			// Get the input data buffers for each port
			CDataArray2DFloat UData( in_ctxt, ID_IN_U );
			CDataArray2DFloat VData( in_ctxt, ID_IN_V );
			Application().LogMessage("Reached multi-threaded part of Evaluate callback");
 			// We need a CIndexSet to iterate over the data
			CIndexSet indexSet( in_ctxt );
			for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
			{
				
				// Add code to set output port...
				CDataArray2DFloat::Accessor USubArray = UData[it];
				CDataArray2DFloat::Accessor VSubArray = VData[it];
				CDataArray2DColor4f::Accessor outDataSubArray = outData.Resize(it, USubArray.GetCount());

				for (ULONG i=0; i<USubArray.GetCount( ); i++)
				{
					/*
					ULONG uPos;
					ULONG vPos;
					if (USubArray[i] > 0 && USubArray[i] < 1)
					{
						uPos = floor(imageWidth*USubArray[i]);
					}
					else
					{
						if (USubArray[i] <= 0)
						{
							uPos = 0;
						}
						else
						{
							uPos = imageWidth-1;
						}
					}

					if (VSubArray[i] > 0 && VSubArray[i] < 1)
					{
						vPos = floor(imageHeight*VSubArray[i]);
					}
					else
					{
						if (VSubArray[i] <= 0)
						{
							vPos = 0;
						}
						else
						{
							vPos = imageWidth-1;
						}
					}
					ULONG arrayPos = (vPos*imageWidth*4)+uPos*4;
					*/
					outDataSubArray[i].PutR(1);
					outDataSubArray[i].PutG(1);
					outDataSubArray[i].PutB(1);
					outDataSubArray[i].PutA(1);
					//outDataSubArray[i].PutR(float(imageUserData[arrayPos])/255);
					//outDataSubArray[i].PutG(float(imageUserData[arrayPos+1])/255);
					//outDataSubArray[i].PutB(float(imageUserData[arrayPos+2])/255);
					//outDataSubArray[i].PutA(1);

					
				}
			}
		}
		break;
	};

	return CStatus::OK;	
}

Reply via email to