MCPcopy Create free account
hub / github.com/ImageEngine/cortex / testSphere

Method testSphere

test/IECoreScene/MeshPrimitive.py:339–409  ·  view source on GitHub ↗
( self )

Source from the content-addressed store, hash-verified

337 self.assertEqual( r.point(), imath.V3f( 0, 1, 0 ) )
338
339 def testSphere( self ) :
340
341 m = IECoreScene.MeshPrimitive.createSphere( radius = 1, divisions = imath.V2i( 30, 40 ) )
342 self.assertTrue( IECore.BoxAlgo.contains( imath.Box3f( imath.V3f( -1 ), imath.V3f( 1 ) ), m.bound() ) )
343 self.assertTrue( m.arePrimitiveVariablesValid() )
344 me = IECoreScene.PrimitiveEvaluator.create( IECoreScene.MeshAlgo.triangulate( m ) )
345 mer = me.createResult()
346 s = IECoreScene.SpherePrimitive( 1 )
347 se = IECoreScene.PrimitiveEvaluator.create( s )
348 ser = se.createResult()
349 for s in range( 0, 100 ) :
350 for t in range( 0, 100 ) :
351 uv = imath.V2f( s / 100.0, t / 100.0 )
352 if not me.pointAtUV( uv, mer ) :
353 # Not all UV coordinates are covered,
354 # due to the row of triangles at the
355 # poles.
356 continue
357 self.assertTrue( se.pointAtUV( uv, ser ) )
358 self.assertTrue( mer.point().equalWithAbsError( ser.point(), 1e-2 ) )
359
360 # test divisions
361 m = IECoreScene.MeshPrimitive.createSphere( radius = 1, divisions = imath.V2i( 300, 300 ) )
362 self.assertTrue( IECore.BoxAlgo.contains( imath.Box3f( imath.V3f( -1 ), imath.V3f( 1 ) ), m.bound() ) )
363 self.assertTrue( m.arePrimitiveVariablesValid() )
364 me = IECoreScene.PrimitiveEvaluator.create( IECoreScene.MeshAlgo.triangulate( m ) )
365 mer = me.createResult()
366 for s in range( 0, 100 ) :
367 for t in range( 0, 100 ) :
368 uv = imath.V2f( s / 100.0, t / 100.0 )
369 if not me.pointAtUV( uv, mer ) :
370 # Not all UV coordinates are covered,
371 # due to the row of triangles at the
372 # poles.
373 continue
374 self.assertTrue( se.pointAtUV( uv, ser ) )
375 # more divisions means points are closer to ground truth
376 self.assertTrue( mer.point().equalWithAbsError( ser.point(), 1e-4 ) )
377
378 # test radius
379 m = IECoreScene.MeshPrimitive.createSphere( radius = 2, divisions = imath.V2i( 30, 40 ) )
380 self.assertFalse( IECore.BoxAlgo.contains( imath.Box3f( imath.V3f( -1 ), imath.V3f( 1 ) ), m.bound() ) )
381 self.assertTrue( IECore.BoxAlgo.contains( imath.Box3f( imath.V3f( -2 ), imath.V3f( 2 ) ), m.bound() ) )
382 self.assertTrue( m.arePrimitiveVariablesValid() )
383 me = IECoreScene.PrimitiveEvaluator.create( IECoreScene.MeshAlgo.triangulate( m ) )
384 mer = me.createResult()
385 s = IECoreScene.SpherePrimitive( 2 )
386 se = IECoreScene.PrimitiveEvaluator.create( s )
387 ser = se.createResult()
388 for s in range( 0, 100 ) :
389 for t in range( 0, 100 ) :
390 uv = imath.V2f( s / 100.0, t / 100.0 )
391 if not me.pointAtUV( uv, mer ) :
392 # Not all UV coordinates are covered,
393 # due to the row of triangles at the
394 # poles.
395 continue
396 self.assertTrue( se.pointAtUV( uv, ser ) )

Callers

nothing calls this directly

Calls 11

createSphereMethod · 0.80
triangulateMethod · 0.80
numFacesMethod · 0.80
containsMethod · 0.45
boundMethod · 0.45
createMethod · 0.45
createResultMethod · 0.45
SpherePrimitiveMethod · 0.45
pointAtUVMethod · 0.45
pointMethod · 0.45

Tested by

no test coverage detected