# -*- coding:utf-8 -*- 

#
# Test playground
#


#
# External dependencies
#
import timeit
from numpy import allclose, invert, copy
from PyMeshToolkit import *


# Global variables
testmesh = None


#
# Test function
#

def Test( mesh ) :
	
	global testmesh
	testmesh = mesh
	
	#~ m = ReadX3d( 'Models/buddha_clean.x3d' )
	#~ UpdateNormals( m )
	#~ UpdateNeighbors( m )
	#~ print( m )
	#~ print( Check( m ) )
	#~ v = GlutViewer( m )
	#~ v.Run()
	
	
	
	r1 = Test1()
	r2 = Test2()
	r3 = Test3()
	print( "Test 1 : {}".format( timeit.timeit("Test1()", setup="from test import Test1", number=1) ) )
	print( "Test 2 : {}".format( timeit.timeit("Test2()", setup="from test import Test2", number=1) ) )
	print( "Test 3 : {}".format( timeit.timeit("Test3()", setup="from test import Test3", number=1) ) )

	
def Test1() :

	return ReadVrml( 'Models/buddha_clean.wrl' )
	
	

def Test2() :

	return ReadObj( 'Models/buddha_clean.obj' )
	

def Test3() :

	return ReadX3d( 'Models/buddha_clean.x3d' )


# -*- coding:utf-8 -*- 

#
# Test playground
#


#
# External dependencies
#
import timeit
import numpy as np
from numpy import allclose, invert, copy
import PyMeshToolkit
from PyMeshToolkit import *


# Global variables
testmesh = None


#
# Test function
#

def Test( mesh ) :
	
	GenerateSaddleSurface()

	#~ global testmesh
	#~ testmesh = mesh
	#~ 
	#~ r1 = Test1()
	#~ r2 = Test2()
	#~ print( "Test 1 : {}".format( timeit.timeit("Test1()", setup="from PyMeshToolkit.Core.Test import Test1", number=1) ) )
	#~ print( "Test 2 : {}".format( timeit.timeit("Test2()", setup="from PyMeshToolkit.Core.Test import Test2", number=1) ) )
	#~ print( allclose( r1, r2 ) )

	
def Test1() :

	return PyMeshToolkit.Core.GetNormalCurvature( testmesh )
	
	

def Test2() :

	return PyMeshToolkit.Core.GetNormalCurvatureReference( testmesh )
	

def GenerateSaddleSurface( xsize = 200, ysize = 200 ) :
	
	# Compute vertex coordinates
	X, Y = np.meshgrid( np.linspace( -2, 2, xsize ), np.linspace( -2, 2, ysize ) )
	Z = ( X ** 2 - Y ** 2 ) * 0.5
	
	# Create the vertex array
	vertices = np.array( (X.flatten(), Y.flatten(), Z.flatten()) ).T
	
	# Find the diagonal that minimizes the Z difference
	right_diagonal = np.absolute( Z[1:,1:] - Z[:-1,:-1] ) < np.absolute( Z[1:,:-1] - Z[:-1,1:] )

	# Create the faces
	faces = []
	for j in range( ysize - 1 ) :
		for i in range( xsize - 1 ) :
			if right_diagonal[j,i] :
				face1 = np.array( [j*xsize+i, j*xsize+i+1, (j+1)*xsize+i+1] )
				face2 = np.array( [j*xsize+i, (j+1)*xsize+i+1, (j+1)*xsize+i] )
			else :
				face1 = np.array( [j*xsize+i, j*xsize+i+1, (j+1)*xsize+i] )
				face2 = np.array( [j*xsize+i+1, (j+1)*xsize+i+1, (j+1)*xsize+i] )
			faces.append( face1 )
			faces.append( face2 )
			
	mesh = PyMeshToolkit.Core.Mesh( 'Saddle', vertices, faces )

	# Return the newly constructed triangular mesh
	PyMeshToolkit.File.Ply.WritePly( mesh, 'saddle.ply' )

Add GenerateSaddleSurface function.