1#!/pxrpythonsubst 2# 3# Copyright 2016 Pixar 4# 5# Licensed under the Apache License, Version 2.0 (the "Apache License") 6# with the following modification; you may not use this file except in 7# compliance with the Apache License and the following modification to it: 8# Section 6. Trademarks. is deleted and replaced with: 9# 10# 6. Trademarks. This License does not grant permission to use the trade 11# names, trademarks, service marks, or product names of the Licensor 12# and its affiliates, except as required to comply with Section 4(c) of 13# the License and to reproduce the content of the NOTICE file. 14# 15# You may obtain a copy of the Apache License at 16# 17# http://www.apache.org/licenses/LICENSE-2.0 18# 19# Unless required by applicable law or agreed to in writing, software 20# distributed under the Apache License with the above modification is 21# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 22# KIND, either express or implied. See the Apache License for the specific 23# language governing permissions and limitations under the Apache License. 24# 25from __future__ import division 26 27import sys, math 28import unittest 29from pxr import Gf 30 31def err( msg ): 32 return msg 33 34class TestGfBBox3d(unittest.TestCase): 35 36 def test_Constructors(self): 37 self.assertIsInstance(Gf.Transform(), Gf.Transform), err("constructor") 38 self.assertIsInstance(Gf.Transform(Gf.Vec3d(), 39 Gf.Rotation(), 40 Gf.Vec3d(), 41 Gf.Vec3d(), 42 Gf.Rotation()), Gf.Transform), err("constructor") 43 44 # test GfMatrix4d constructor 45 rotation = Gf.Rotation(Gf.Vec3d(0.5,0.6,0.7), 123) 46 m = Gf.Matrix4d(1.0) 47 m.SetRotate(rotation) 48 t = Gf.Transform(m) 49 tm = t.GetMatrix() 50 tol = 0.001 51 self.assertTrue(Gf.IsClose(tm[0],m[0],tol) and \ 52 Gf.IsClose(tm[1],m[1],tol) and \ 53 Gf.IsClose(tm[2],m[2],tol) and \ 54 Gf.IsClose(tm[3],m[3],tol), \ 55 err("GfTransform(GfMatrix4d) constructor")) 56 57 def test_Properties(self): 58 t = Gf.Transform() 59 t.Set(Gf.Vec3d(2,3,4), Gf.Rotation(Gf.Vec3d(1,0,0), 90), \ 60 Gf.Vec3d(1,2,3), Gf.Vec3d(), Gf.Rotation(Gf.Vec3d(1,1,1), 30)) 61 self.assertTrue(t.translation == Gf.Vec3d(2,3,4) and \ 62 t.rotation == Gf.Rotation(Gf.Vec3d(1,0,0), 90) and \ 63 t.scale == Gf.Vec3d(1,2,3) and \ 64 t.pivotPosition == Gf.Vec3d() and \ 65 t.pivotOrientation == Gf.Rotation(Gf.Vec3d(1,1,1), 30), err("Set")) 66 self.assertEqual(eval(repr(t)), t) 67 68 t = Gf.Transform() 69 self.assertEqual(eval(repr(t)), t) 70 t.SetMatrix(Gf.Matrix4d().SetRotate(Gf.Rotation(Gf.Vec3d(1,1,1), 30))) 71 self.assertTrue(Gf.IsClose(t.rotation.axis, Gf.Vec3d(1,1,1).GetNormalized(), 0.0001) and \ 72 Gf.IsClose(t.rotation.angle, 30, 0.0001), err("SetMatrix")) 73 self.assertEqual(eval(repr(t)), t) 74 75 self.assertEqual(t.SetMatrix(Gf.Matrix4d(1)).GetMatrix(), Gf.Matrix4d(1), err("Get/SetMatrix")) 76 77 t = Gf.Transform() 78 t.Set(Gf.Vec3d(4,5,6), Gf.Rotation(Gf.Vec3d(1,0,0), 90), Gf.Vec3d(1,2,3), \ 79 Gf.Vec3d(2,3,4), Gf.Rotation(Gf.Vec3d(1,1,1), 30)) 80 self.assertEqual(eval(repr(t)), t) 81 m = t.GetMatrix() 82 83 t = Gf.Transform() 84 t.SetIdentity() 85 self.assertEqual(eval(repr(t)), t) 86 self.assertEqual(t.GetMatrix(), Gf.Matrix4d(1), err("Get/SetIdentity")) 87 88 t.scale = Gf.Vec3d(1,2,3) 89 self.assertEqual(eval(repr(t)), t) 90 self.assertEqual(t.scale, Gf.Vec3d(1,2,3), err("scale")) 91 92 t.pivotOrientation = Gf.Rotation(Gf.Vec3d.XAxis(), 30) 93 self.assertEqual(eval(repr(t)), t) 94 self.assertEqual(t.pivotOrientation, Gf.Rotation(Gf.Vec3d.XAxis(), 30), err("scaleOrientation")) 95 96 t.pivotPosition = Gf.Vec3d(3,2,1) 97 self.assertEqual(eval(repr(t)), t) 98 self.assertEqual(t.pivotPosition, Gf.Vec3d(3,2,1), err("center")) 99 100 t.translation = Gf.Vec3d(3,4,5) 101 self.assertEqual(eval(repr(t)), t) 102 self.assertEqual(t.translation, Gf.Vec3d(3,4,5), err("translation")) 103 104 t.rotation = Gf.Rotation(Gf.Vec3d.YAxis(), 60) 105 self.assertEqual(eval(repr(t)), t) 106 self.assertEqual(t.rotation, Gf.Rotation(Gf.Vec3d.YAxis(), 60), err("rotation")) 107 108 self.assertTrue(len(str(Gf.Transform())), err("str")) 109 110 def test_Methods(self): 111 t1 = Gf.Transform() 112 t2 = Gf.Transform() 113 t1.SetMatrix(Gf.Matrix4d().SetRotate(Gf.Rotation(Gf.Vec3d(1,1,1), 60))) 114 t2.SetMatrix(Gf.Matrix4d().SetRotate(Gf.Rotation(Gf.Vec3d(1,1,1), 60))) 115 self.assertEqual(eval(repr(t1)), t1) 116 self.assertEqual(t1, t2, err("equality")) 117 118 t2.SetMatrix(Gf.Matrix4d().SetRotate(Gf.Rotation(Gf.Vec3d.ZAxis(), 60))) 119 self.assertNotEqual(t1, t2, err("inequality")) 120 121 t1 = Gf.Transform() 122 t2 = Gf.Transform() 123 t1.SetMatrix(Gf.Matrix4d().SetRotate(Gf.Rotation(Gf.Vec3d(1,1,1), 60))) 124 t2.rotation = Gf.Rotation(Gf.Vec3d.YAxis(), 60) 125 t1 *= t2 126 self.assertEqual(eval(repr(t1)), t1) 127 self.assertTrue(Gf.IsClose(t1.rotation.axis, Gf.Vec3d(0.495572, 0.858356, 0.132788), 0.0001) and 128 Gf.IsClose(t1.rotation.angle, 105.447, 0.0001), err("*=")) 129 130 t1 = Gf.Transform() 131 t2 = Gf.Transform() 132 t1.SetMatrix(Gf.Matrix4d().SetRotate(Gf.Rotation(Gf.Vec3d(1,1,1), 60))) 133 t2.rotation = Gf.Rotation(Gf.Vec3d.YAxis(), 60) 134 t3 = t1 * t2 135 self.assertEqual(eval(repr(t3)), t3) 136 self.assertTrue(Gf.IsClose(t3.rotation.axis, Gf.Vec3d(0.495572, 0.858356, 0.132788), 0.0001) and \ 137 Gf.IsClose(t3.rotation.angle, 105.447, 0.0001), err("*=")) 138 139 t1 = Gf.Transform() 140 m = Gf.Matrix4d().SetScale(Gf.Vec3d(0,1,1)) 141 t1.SetMatrix(m) 142 self.assertTrue(Gf.IsClose(t1.scale, Gf.Vec3d(0.0, 1, 1), 1e-4), err("SetMatrix")) 143 144if __name__ == '__main__': 145 unittest.main() 146