Re: [script] Comparing two transforms

Date : Wed, 10 Jan 2007 11:12:51 -0500
To : XSI(at)Softimage.COM
From : "Bernard Lebel" <3dbernard(at)gmail.com>
Subject : Re: [script] Comparing two transforms
Hi everyone,

Thanks a lot for the advice. I've done some timing comparisons between
the 3 techniques (mine, Guillaume's and Joe's).

Basically I'm calling each comparing functions 1000 times.
For function "compare4", I've made integrated Joe's approach into
Guillaume's one, and it made a significant difference.
Here is the code:



import time
import win32com

xsi = Application
xsimath = win32com.client.Dispatch( 'XSI.Math' )




def timer( oT1, oT2, functionName ): time1 = time.clock()

	for i in range(1000):
		functionName( oT1, oT2 )

	time2 = time.clock()
	xsi.logmessage( '%s : %s' % ( functionName.__name__, round(time2 -
time1, 3) ) )



def compare1( oT1, oT2 ):
	
	if round( oT1.PosX, 4 ) != round( oT2.PosX, 4 ):
		return False
	elif round( oT1.PosY, 4 ) != round( oT2.PosY, 4 ):
		return False
	elif round( oT1.PosZ, 4 ) != round( oT2.PosZ, 4 ):
		return False
	elif round( oT1.RotX, 4 ) != round( oT2.RotX, 4 ):
		return False
	elif round( oT1.RotY, 4 ) != round( oT2.RotY, 4 ):
		return False
	elif round( oT1.RotZ, 4 ) != round( oT2.RotZ, 4 ):
		return False
	elif round( oT1.SclX, 4 ) != round( oT2.SclX, 4 ):
		return False
	elif round( oT1.SclY, 4 ) != round( oT2.SclY, 4 ):
		return False
	elif round( oT1.SclZ, 4 ) != round( oT2.SclZ, 4 ):
		return False
	else:
		return True



def compare2( oT1, oT2 ):
	
	oMatrixA = xsimath.CreateMatrix4()
	oT1.GetMatrix4( oMatrixA )
	
	oMatrixB = xsimath.CreateMatrix4()
	oT2.GetMatrix4( oMatrixB )
	
	for i in range(0, 4):
		for j in range(0, 4):
			
			if round( oMatrixA.Value(i, j) ) != round( oMatrixB.Value(i,j) ):
				return False
	
	return True





def compare3( oT1, oT2 ):
	
	if abs( oT1.PosX - oT2.PosX ) > 0.0001:
		return False
	elif abs( oT1.PosY - oT2.PosY ) > 0.0001:
		return False
	elif abs( oT1.PosZ - oT2.PosZ ) > 0.0001:
		return False
	elif abs( oT1.RotX - oT2.RotX ) > 0.0001:
		return False
	elif abs( oT1.RotY - oT2.RotY ) > 0.0001:
		return False
	elif abs( oT1.RotZ - oT2.RotZ ) > 0.0001:
		return False
	elif abs( oT1.SclX - oT2.SclX ) > 0.0001:
		return False
	elif abs( oT1.SclY - oT2.SclY ) > 0.0001:
		return False
	elif abs( oT1.SclZ - oT2.SclZ ) > 0.0001:
		return False
	else:
		return True





def compare4( oT1, oT2 ):
	
	oMatrixA = xsimath.CreateMatrix4()
	oT1.GetMatrix4( oMatrixA )
	
	oMatrixB = xsimath.CreateMatrix4()
	oT2.GetMatrix4( oMatrixB )
	
	for i in range(0, 4):
		for j in range(0, 4):
			
			if abs( oMatrixA.Value(i, j) - oMatrixB.Value(i,j) ) > 0.0001:
				return False
	
	return True









oSel1 = xsi.selection(0)
oT1 = oSel1.Kinematics.Global.Transform

oSel2 = xsi.selection(1)
oT2 = oSel2.Kinematics.Global.Transform


aFunctionNames = [ compare1, compare2, compare3, compare4 ]

for oFunctionName in aFunctionNames:
	timer( oT1, oT2, oFunctionName )




Now here are the results:

#INFO : compare1 : 0.088 -> My function
#INFO : compare2 : 1.897 -> Guillaume
#INFO : compare3 : 0.085 -> Joe
#INFO : compare4 : 1.551 -> Joe's suggestion integrated into Guillaume's


Joe's the big winner by a few milliseconds :-D




Cheers Bernard --- Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body: unsubscribe xsi


Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.