Re: [script] Comparing two transforms

Date : Fri, 12 Jan 2007 16:55:52 -0500
To : XSI(at)Softimage.COM
From : "Bernard Lebel" <3dbernard(at)gmail.com>
Subject : Re: [script] Comparing two transforms
It is indeed much faster.

More interestingly, compare4 is now 3 times faster than than compare1
and compare3. See results below.

Previous scores:

#INFO : compare1 : 0.088
#INFO : compare2 : 1.897
#INFO : compare3 : 0.085
#INFO : compare4 : 1.551

New scores:

#INFO : compare1 : 0.09
#INFO : compare2 : 0.355
#INFO : compare3 : 0.092
#INFO : compare4 : 0.029


This is sad though, because in my real production case, the matrix can be created only once, but the transform objects are different at every iteration, so the matrix have to be set every time. It is still the fastest way though, but only by 1,5 times. Oh well, can't be perfect :-)

Amazing though how much the creation of matrix objects impacts.

#INFO : compare1 : 0.09
#INFO : compare2 : 0.435
#INFO : compare3 : 0.086
#INFO : compare4 : 0.057




Thanks for the help Bernard




import time import win32com

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




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

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

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



def compare1( oT1, oT2, oMatrixA, oMatrixB ):

	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, 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, oMatrixA, oMatrixB ):

	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, 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


oMatrixA = xsimath.CreateMatrix4() oT1.GetMatrix4( oMatrixA )

oMatrixB = xsimath.CreateMatrix4()
oT2.GetMatrix4( oMatrixB )



aFunctionNames = [ compare1, compare2, compare3, compare4 ]

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





Bernard





On 1/10/07, guillaume laforge <guillaume.laforge.3d(at)gmail.com> wrote:
I think  'xsimath.CreateMatrix4' slow the things. So if you want to compare
try to create the matrix outside the function like you did with the
transform :-)
---
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.