Changeset 362
- Timestamp:
- 11/05/02 18:18:45 (6 years ago)
- Files:
-
- trunk/RBRapier/RBRapier/Formats/Lightwave/MeshedObject.py (modified) (3 diffs)
- trunk/RBRapier/RBRapier/Formats/Wavefront/MeshedObject.py (modified) (2 diffs)
- trunk/RBRapier/RBRapier/Renderer/SequenceMgr.py (modified) (1 diff)
- trunk/RBRapier/RBRapier/Tools/Geometry/Analysis/TriangleMesh.py (modified) (1 diff)
- trunk/RBRapier/RBRapier/Tools/Geometry/Analysis/TriangleStripifier.py (modified) (7 diffs)
- trunk/RBRapier/RBRapier/Tools/Geometry/ConvexPolygonTesselation.py (added)
- trunk/RBRapier/RBRapier/Tools/Projections.py (modified) (3 diffs)
- trunk/RBRapier/RBRapier/Tools/Quaternion.py (modified) (17 diffs)
- trunk/RBRapier/RBRapier/Tools/Transformations.py (modified) (23 diffs)
- trunk/RBRapier/RBRapier/Tools/Vector.py (modified) (22 diffs)
- trunk/RBRapier/demo/Lightwave/scene.py (modified) (3 diffs)
- trunk/RBRapier/demo/Wavefront/scene.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/RBRapier/RBRapier/Formats/Lightwave/MeshedObject.py
r360 r362 34 34 from RBRapier.Tools.Geometry.Analysis import TriangleMesh 35 35 from RBRapier.Tools.Geometry.Analysis import LocalityRemapper 36 from RBRapier.Tools.Geometry.ConvexPolygonTesselation import TesselateConvexPolygon 36 37 37 38 from RBRapier.Renderer.Geometry import VertexArrays … … 158 159 else: 159 160 mesh = MeshFactory() 160 bTODOPrinted = 0161 161 for FaceTraversal in Group.Faces: 162 FaceTraversal = FaceTraversal.IndexList 163 if not bTODOPrinted and len(FaceTraversal) > 4: 164 print "TODO: teselate faces of more than 4 vertices" 165 print 166 bTODOPrinted = 1 167 v0,v1 = FaceTraversal[:2] 168 for v2 in FaceTraversal[2:]: 169 face = mesh.AddFace(v0,v1,v2) 162 FaceTraversal = TesselateConvexPolygon(FaceTraversal.IndexList) 163 for each in FaceTraversal: 164 face = mesh.AddFace(*each) 170 165 if face: 171 166 normal = face.CalculateNormal(self.Vertices.data) 172 self.Normals.data[v0] += normal 173 self.Normals.data[v1] += normal 174 self.Normals.data[v2] += normal 175 else: 176 assert v0==v1 or v1==v2 or v2==v0 177 v1 = v2 167 for v in each: 168 self.Normals.data[v] += normal 178 169 179 170 if __debug__: … … 196 187 197 188 for data in self.Normals.data: 198 data[:] /= Numeric.s um(data*data)189 data[:] /= Numeric.sqrt(Numeric.sum(data*data)) 199 190 200 191 def SimpleTraversals(self): trunk/RBRapier/RBRapier/Formats/Wavefront/MeshedObject.py
r349 r362 34 34 from RBRapier.Tools.Geometry.Analysis import TriangleMesh 35 35 from RBRapier.Tools.Geometry.Analysis import LocalityRemapper 36 from RBRapier.Tools.Geometry.ConvexPolygonTesselation import TesselateConvexPolygon 36 37 37 38 from RBRapier.Renderer.Geometry import VertexArrays … … 163 164 else: 164 165 mesh = MeshFactory() 165 bTODOPrinted = 0166 166 for FaceTraversal in Group.Faces: 167 if not bTODOPrinted and len(FaceTraversal) > 4: 168 print "TODO: teselate faces of more than 4 vertices" 169 print 170 bTODOPrinted = 1 171 v0,v1 = FaceTraversal[:2] 172 for v2 in FaceTraversal[2:]: 173 mesh.AddFace(v0[0],v1[0],v2[0]) 174 v1 = v2 167 FaceTraversal = TesselateConvexPolygon([idx[0] for idx in FaceTraversal]) 168 for each in FaceTraversal: 169 face = mesh.AddFace(*each) 175 170 if __debug__: 176 171 print '%-20s[%6d]: ' % (Group.Names[0], len(mesh.Faces)*3), trunk/RBRapier/RBRapier/Renderer/SequenceMgr.py
r351 r362 61 61 elif isinstance(getattr(Element, 'Execute', None), types.MethodType): 62 62 ElementFn = Element.Execute 63 elif isinstance(getattr(Element, 'Select', None), types.MethodType): 64 ElementFn = Element.Select 63 65 self.Elements.insert(idx, (priority, ElementFn, Element)) 64 66 trunk/RBRapier/RBRapier/Tools/Geometry/Analysis/TriangleMesh.py
r360 r362 180 180 <FaceEdgeMesh |edges|=13 |faces|=6> 181 181 >>> face = mesh.Faces[0]; face 182 < Mesh&EdgedFace v=(0, 1, 2)>182 <FaceEdgeMesh&EdgedFace v=(0, 1, 2)> 183 183 >>> face.OtherVertex(0,1) 184 184 2 185 185 >>> face.GetEdge(2,1) 186 < Mesh&Edge ev=(1, 2)>186 <FaceEdgeMesh&Edge ev=(1, 2)> 187 187 """ 188 188 trunk/RBRapier/RBRapier/Tools/Geometry/Analysis/TriangleStripifier.py
r355 r362 295 295 Origional can be found at http://developer.nvidia.com/view.asp?IO=nvtristrip_library. 296 296 297 >>> mesh = Mesh. Mesh()297 >>> mesh = Mesh.FaceEdgeMesh(); mesh.CleanFaces = 1 298 298 >>> rows = [range(0,4), range(4,8), range(8,12), range(12,16)] 299 299 >>> r0 = rows[0] … … 301 301 ... _MakeSimpleMesh(mesh, _ConjoinMeshData(r0, r1)); r0=r1 302 302 >>> mesh 303 < Mesh |edges|=33 |faces|=18>303 <FaceEdgeMesh |edges|=33 |faces|=18> 304 304 >>> stripifier = TriangleStripifier() 305 305 >>> r = stripifier.Stripify(mesh) 306 >>> stripifier.TriangleList, stripifier.Triangle Fans, stripifier.TriangleStrips307 ([], [ ], [[2, 1, 2, 5, 6, 9, 10, 13, 14], [1, 0, 1, 4, 5, 8, 9, 12, 13], [3, 2, 3, 6, 7, 10, 11, 14, 15]])306 >>> stripifier.TriangleList, stripifier.TriangleStrips 307 ([], [[2, 1, 2, 5, 6, 9, 10, 13, 14], [1, 0, 1, 4, 5, 8, 9, 12, 13], [3, 2, 3, 6, 7, 10, 11, 14, 15]]) 308 308 >>> stripifier.Selector.MinStripLength = 100 309 309 >>> r = stripifier.Stripify(mesh) 310 >>> stripifier.TriangleList, stripifier.Triangle Fans, stripifier.TriangleStrips311 ([1, 5, 2, 5, 2, 6, 5, 9, 6, 9, 6, 10, 9, 13, 10, 13, 10, 14, 0, 4, 1, 4, 1, 5, 4, 8, 5, 8, 5, 9, 8, 12, 9, 12, 9, 13, 2, 6, 3, 6, 3, 7, 6, 10, 7, 10, 7, 11, 10, 14, 11, 14, 11, 15], [] , [])310 >>> stripifier.TriangleList, stripifier.TriangleStrips 311 ([1, 5, 2, 5, 2, 6, 5, 9, 6, 9, 6, 10, 9, 13, 10, 13, 10, 14, 0, 4, 1, 4, 1, 5, 4, 8, 5, 8, 5, 9, 8, 12, 9, 12, 9, 13, 2, 6, 3, 6, 3, 7, 6, 10, 7, 10, 7, 11, 10, 14, 11, 14, 11, 15], []) 312 312 >>> del stripifier.Selector.MinStripLength 313 313 """ … … 341 341 342 342 __call__ = Stripify 343 344 def StripifyIter(self, mesh, OnProgress=None): 345 # TODO: Could find triangle fans here 346 Strips = self._FindAllStrips(mesh, OnProgress) 347 348 for strip in Strips: 349 if len(strip.Faces) < self.Selector.MinStripLength: 350 yield 'list', strip.TraingleListIndices() 351 else: 352 yield 'strip', strip.TriangleStripIndices() 343 353 344 354 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 423 433 stripId = _Counter() 424 434 FacesComplete = 0. 425 self.Strips =result = []435 #result = [] 426 436 427 437 try: … … 468 478 469 479 # And commit it to the resultset 470 result.extend(BestExperiment)471 480 for each in BestExperiment: 472 481 FacesComplete += each.Commit() 482 yield each 483 #result.extend(BestExperiment) 473 484 474 485 # and update anyone watching … … 477 488 pass 478 489 479 for face in mesh.Faces: 480 try: del face.StripId 481 except AttributeError: pass 482 483 return result 490 if getattr(mesh, 'CleanFaces', 0): 491 for face in mesh.Faces: 492 try: del face.StripId 493 except AttributeError: pass 494 495 #return result 484 496 485 497 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 520 532 521 533 startmesh = time.clock() 522 mesh = Mesh. Mesh()534 mesh = Mesh.FaceEdgeMesh() 523 535 r0 = rows[0] 524 536 for r1 in rows[1:]: trunk/RBRapier/RBRapier/Tools/Projections.py
r356 r362 133 133 <Orthographic: l=-2.0, r=3.0, b=5.0, t=8.0, n=-9.0, f=-2.0 > 134 134 >>> proj.asArray4x4() 135 array([[ 0.4 , 0. , 0. , 0.2 ], 136 [ 0. , 0.66666667, 0. , 4.33333333], 137 [ 0. , 0. , -0.28571429, -1.57142857], 138 [ 0. , 0. , 0. , 1. ]]) 139 135 array([[ 0.40000001, 0. , 0. , 0.2 ], 136 [ 0. , 0.66666669, 0. , 4.33333349], 137 [ 0. , 0. , -0.2857143 , -1.57142854], 138 [ 0. , 0. , 0. , 1. ]],'f') 140 139 """ 141 140 … … 230 229 <Frustm: l=-2.0, r=3.0, b=5.0, t=8.0, n=-9.0, f=-2.0 > 231 230 >>> proj.asArray4x4() 232 array([[-3.6 , 0. , 0.2 , 0. ], 233 [ 0. , -6. , 4.33333333, 0. ], 234 [ 0. , 0. , 1.57142857, -2.57142857], 235 [ 0. , 0. , -1. , 0. ]]) 236 231 array([[-3.5999999 , 0. , 0.2 , 0. ], 232 [ 0. , -6. , 4.33333349, 0. ], 233 [ 0. , 0. , 1.57142854, -2.57142854], 234 [ 0. , 0. , -1. , 0. ]],'f') 237 235 """ 238 236 … … 270 268 <Persepctive: ViewAngle=30.0, Aspect=1.234, n=0.5, f=23.2 > 271 269 >>> proj.asArray4x4() 272 array([[ 4.605350 7, 0. , 0. , 0. ],273 [ 0. , 3.732050 81, 0. , 0. ],274 [ 0. , 0. , -1.0440528 6, -0.51101322],275 [ 0. , 0. , -1. , 0. ]] )270 array([[ 4.60535049, 0. , 0. , 0. ], 271 [ 0. , 3.7320509 , 0. , 0. ], 272 [ 0. , 0. , -1.04405284, -0.51101321], 273 [ 0. , 0. , -1. , 0. ]],'f') 276 274 >>> proj.AspectRatio 277 275 1.2339999999999995 trunk/RBRapier/RBRapier/Tools/Quaternion.py
r356 r362 43 43 44 44 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 45 #~ Constants / Variables / Etc. 46 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 47 48 _NumericType = Numeric.Float 49 50 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 45 51 #~ Definitions 46 52 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 109 115 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 110 116 111 NumericType = Numeric.Float32117 NumericType = _NumericType 112 118 113 119 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 258 264 value = Numeric.innerproduct(self._array, self._array) 259 265 if squared: return value 260 else: return math.sqrt(value)266 else: return Numeric.sqrt(value) 261 267 262 268 def Normalize(self): … … 315 321 0.52359877559829859 316 322 """ 317 return 2. * math.acos(Numeric.innerproduct(self._array, other._array))323 return 2. * Numeric.arccos(Numeric.innerproduct(self._array, other._array)) 318 324 319 325 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 325 331 """ 326 332 try: 327 return 2. * _rad2deg * math.acos(self._array[0])333 return 2. * _rad2deg * Numeric.arccos(self._array[0]) 328 334 except ValueError: return 0. 329 335 def setAngle(self, value): … … 345 351 """ 346 352 try: 347 return 2. * math.acos(self._array[0])353 return 2. * Numeric.arccos(self._array[0]) 348 354 except ValueError: return 0. 349 355 def setRadians(self, value): … … 351 357 >>> aa = Quaternion.fromAngleAxis(30., (0., 0., 1.)); aa 352 358 <Quaternion: 0.965925826289 + 0.0i + 0.0j + 0.258819045103k> 353 >>> aa.Radians = math.pi/4.; aa359 >>> aa.Radians = Numeric.pi/4.; aa 354 360 <Quaternion: 0.923879532511 + 0.0i + 0.0j + 0.382683432365k> 355 361 >>> aa.Radians … … 379 385 def Log(self): 380 386 """ 381 >>> ra = Quaternion.fromRadianAxis( math.pi/3., (1.,0.,0.)); ra387 >>> ra = Quaternion.fromRadianAxis(Numeric.pi/3., (1.,0.,0.)); ra 382 388 <Quaternion: 0.866025403784 + 0.5i + 0.0j + 0.0k> 383 389 >>> ra.Log() … … 386 392 <Quaternion: 0.866025403784 + 0.5i + 0.0j + 0.0k> 387 393 """ 388 Radians = math.acos(self._array[0])389 sinR = math.sin(Radians)394 Radians = Numeric.arccos(self._array[0]) 395 sinR = Numeric.sin(Radians) 390 396 if sinR > 0: 391 397 result = (Radians/sinR) * self … … 397 403 def Exp(self, power=1.): 398 404 """ 399 >>> ra = Quaternion.fromRadianAxis( math.pi/3., (1.,0.,0.)); ra405 >>> ra = Quaternion.fromRadianAxis(Numeric.pi/3., (1.,0.,0.)); ra 400 406 <Quaternion: 0.866025403784 + 0.5i + 0.0j + 0.0k> 401 407 >>> ra.Exp() … … 404 410 <Quaternion: 0.0 + 0.5i + 0.0j + 0.0k> 405 411 """ 406 Radians = math.sqrt(Numeric.dot(self._array[1:], self._array[1:]))407 sinR, cosR = math.sin(power * Radians), math.cos(power * Radians)412 Radians = Numeric.sqrt(Numeric.dot(self._array[1:], self._array[1:])) 413 sinR, cosR = Numeric.sin(power * Radians), Numeric.cos(power * Radians) 408 414 if Radians > 0: 409 415 result = (sinR/Radians) * self … … 417 423 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 418 424 419 def asarray(self): 420 return self._array 425 def asarray(self, *args): 426 if args: return Numeric.asarray(self._array, *args) 427 else: return self._array 421 428 422 429 def tolist(self): … … 425 432 def _SVfromRadianAxis(Klass, Radians, Axis): 426 433 Radians *= .5 427 cosR, sinR = math.cos(Radians), math.sin(Radians)434 cosR, sinR = Numeric.cos(Radians), Numeric.sin(Radians) 428 435 Quat = Numeric.asarray([cosR] + list(Axis), Klass.NumericType) 429 436 Quat[1:] *= sinR / Numeric.innerproduct(Quat[1:], Quat[1:]) … … 441 448 def fromRadianAxis(Klass, Radians, Axis): 442 449 """ 443 >>> ra = Quaternion.fromRadianAxis( math.pi/6., (0., 0., 1.)); ra450 >>> ra = Quaternion.fromRadianAxis(Numeric.pi/6., (0., 0., 1.)); ra 444 451 <Quaternion: 0.965925826289 + 0.0i + 0.0j + 0.258819045103k> 445 452 """ … … 455 462 """ 456 463 cosR, Axis = _VectorDotCross3(v0, v1) 457 s = math.sqrt(2.*(cosR+1))464 s = Numeric.sqrt(2.*(cosR+1)) 458 465 Quat = Numeric.asarray((s/2.,) + Axis, Klass.NumericType) 459 466 Quat[1:] /= s … … 492 499 def toRadianAxis(self): 493 500 """ 494 >>> ra = Quaternion.fromRadianAxis( math.pi/6., (0., 0., 1.))501 >>> ra = Quaternion.fromRadianAxis(Numeric.pi/6., (0., 0., 1.)) 495 502 >>> ra.toRadianAxis() 496 503 (0.52359877559829859, array([ 0., 0., 1.])) … … 499 506 """ 500 507 try: 501 Radians = math.acos(self._array[0])502 RadialFactor = 1./ math.sin(Radians)508 Radians = Numeric.arccos(self._array[0]) 509 RadialFactor = 1./Numeric.sin(Radians) 503 510 return 2. * Radians, RadialFactor * self._array[1:] 504 511 except ValueError: trunk/RBRapier/RBRapier/Tools/Transformations.py
r356 r362 26 26 import Numeric 27 27 import LinearAlgebra 28 import math29 28 from Vector import * 30 29 … … 33 32 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 34 33 35 _rad2deg = 180.0/math.pi 36 _deg2rad = math.pi/180.0 34 _rad2deg = 180.0/Numeric.pi 35 _deg2rad = Numeric.pi/180.0 36 _NumericType = Numeric.Float 37 37 38 38 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 77 77 >>> n = c.Add(Rotate(23, (7,11,13))) 78 78 >>> c 79 <Composite: [<Identity>, <Translation: [1.0, 2.0, 3.0, 1.0]>, <Scale: [2.0, 3.0, 4.0, 1.0]>, <Rotation: Angle=23.0, Axis=[0.3801878 1261549794, 0.59743799125292529, 0.70606308057163902, 1.0]>] >79 <Composite: [<Identity>, <Translation: [1.0, 2.0, 3.0, 1.0]>, <Scale: [2.0, 3.0, 4.0, 1.0]>, <Rotation: Angle=23.0, Axis=[0.38018780946731567, 0.59743797779083252, 0.70606309175491333, 1.0]>] > 80 80 >>> c.Inverse() 81 <Composite: [<Rotation: Angle=23.0, Axis=[-0.3801878 1261549794, -0.59743799125292529, -0.70606308057163902, 1.0]>, <Scale: [0.5, 0.33333333333333331, 0.25, 1.0]>, <Translation: [-1.0, -2.0, -3.0, 1.0]>, <Identity>] >81 <Composite: [<Rotation: Angle=23.0, Axis=[-0.38018780946731567, -0.59743797779083252, -0.70606309175491333, 1.0]>, <Scale: [0.5, 0.3333333432674408, 0.25, 1.0]>, <Translation: [-1.0, -2.0, -3.0, 1.0]>, <Identity>] > 82 82 >>> (c * c.Inverse()).asArray4x4() 83 array([[ 1.00000000e+000, -5.55111512e-017, -1.38777878e-017, 2.22044605e-016],84 [ -1.59594560e-016, 1.00000000e+000, -4.16333634e-017, 4.44089210e-016],85 [ -5.55111512e-017, -2.77555756e-017, 1.00000000e+000, -4.44089210e-016],83 array([[ 9.99999999e-001, 1.24926288e-010, 1.19565441e-010, 1.52539870e-010], 84 [ 2.81084066e-010, 1.00000003e+000, -1.15097085e-009, -5.50221717e-008], 85 [ 4.78261764e-010, -2.04617046e-009, 9.99999998e-001, 8.76708395e-009], 86 86 [ 0.00000000e+000, 0.00000000e+000, 0.00000000e+000, 1.00000000e+000]]) 87 87 >>> n = c.Add(Skew(2,3,4,5,6,7)) … … 91 91 >>> n = c.Add(Perspective()) 92 92 >>> c.asArray4x4() 93 array([[ 44.2963 7035, 125.91233004, -57.83760114, -29.67837026],94 [ 201.84505 034, 24.85095453, -347.25496342, -180.08552595],95 [ 549.7268 1569, 552.42082222, -107.8104291 , -54.78268816],96 [ 0. , 0. , 1.2222222 2, 1.11111111]])93 array([[ 44.29636998, 125.91233332, -57.83760035, -29.67837068], 94 [ 201.84505811, 24.85095591, -347.25496638, -180.08553265], 95 [ 549.72683721, 552.42084495, -107.81043034, -54.78269031], 96 [ 0. , 0. , 1.22222221, 1.11111116]]) 97 97 >>> c.asInverse4x4() 98 array([[-1.0173620 8e-002, 9.93235478e-004, 2.27417469e-003, 1.36462579e-003],99 [ 9.069072 59e-003, -1.47085544e-003, -1.90716743e-004, -5.55521148e-003],100 [-1.225602 74e-002, -5.60517254e-003, 3.04564707e-003, -1.08567057e+000],101 [ 1.34816 302e-002, 6.16568980e-003, -3.35021177e-003, 2.09423763e+000]])98 array([[-1.01736204e-002, 9.93235414e-004, 2.27417457e-003, 1.36462590e-003], 99 [ 9.06907225e-003, -1.47085536e-003, -1.90716711e-004, -5.55521140e-003], 100 [-1.22560268e-002, -5.60517231e-003, 3.04564689e-003, -1.08567050e+000], 101 [ 1.34816287e-002, 6.16568918e-003, -3.35021138e-003, 2.09423744e+000]]) 102 102 """ 103 103 … … 136 136 def asArray4x4(self): 137 137 """Returns the transformation in 4x4 Numeric array form""" 138 r = Numeric.identity(4, Numeric.Float32)138 r = Numeric.identity(4, _NumericType) 139 139 for xform in self.collection: 140 140 r = Numeric.dot(r, xform.asArray4x4()) … … 169 169 170 170 def __init__(self, matrix=None): 171 if matrix: self.matrix = Numeric.asarray(matrix, Numeric.Float32)172 else: self.matrix = Numeric.identity(4, Numeric.Float32)171 if matrix: self.matrix = Numeric.asarray(matrix, _NumericType) 172 else: self.matrix = Numeric.identity(4, _NumericType) 173 173 assert self.matrix.shape == (4,4) 174 174 … … 208 208 209 209 def asArray4x4(self): 210 return Numeric.identity(4, Numeric.Float32)210 return Numeric.identity(4, _NumericType) 211 211 212 212 def asInverse4x4(self): 213 return Numeric.identity(4, Numeric.Float32)213 return Numeric.identity(4, _NumericType) 214 214 215 215 def Inverse(self): … … 235 235 """ 236 236 237 Direction = Vector3HProperty('Direction' )237 Direction = Vector3HProperty('Direction', NumericType=_NumericType) 238 238 239 239 def __init__(self, Direction=(0,0,0)): … … 244 244 245 245 def asArray4x4(self): 246 result = Numeric.identity(4, Numeric.Float32)246 result = Numeric.identity(4, _NumericType) 247 247 result[:, 3] = self.Direction 248 248 return result 249 249 250 250 def asInverse4x4(self): 251 result = Numeric.identity(4, Numeric.Float32)251 result = Numeric.identity(4, _NumericType) 252 252 result[:, 3] = -self.Direction 253 253 return result … … 275 275 """ 276 276 277 Scale = Vector3HProperty('Scale', (1.,1.,1.,1.) )277 Scale = Vector3HProperty('Scale', (1.,1.,1.,1.), NumericType=_NumericType) 278 278 279 279 def __init__(self, Scale=1.0): … … 289 289 290 290 def asArray4x4(self): 291 result = Numeric.identity(4, Numeric.Float32)291 result = Numeric.identity(4, _NumericType) 292 292 for idx in range(4): result[idx,idx] = self.Scale[idx] 293 293 return result 294 294 295 295 def asInverse4x4(self): 296 result = Numeric.identity(4, Numeric.Float32)296 result = Numeric.identity(4, _NumericType) 297 297 for idx in range(4): result[idx,idx] = 1./self.Scale[idx] 298 298 return result … … 328 328 array([[ 0.81983177, -0.45634205, 0.34587252, 0. ], 329 329 [ 0.51993083, 0.8463271 , -0.11576859, 0. ], 330 [-0.2398912 1, 0.27474056, 0.93111215, 0. ],330 [-0.23989122, 0.27474055, 0.93111215, 0. ], 331 331 [ 0. , 0. , 0. , 1. ]]) 332 332 >>> Rotate(37, [2, 3, 5]).asInverse4x4() 333 array([[ 0.8198317 7, 0.51993083, -0.23989121, 0. ],334 [-0.45634205, 0.8463271 , 0.27474056, 0. ],333 array([[ 0.81983178, 0.51993083, -0.23989121, 0. ], 334 [-0.45634205, 0.84632711, 0.27474056, 0. ], 335 335 [ 0.34587252, -0.11576859, 0.93111215, 0. ], 336 336 [ 0. , 0. , 0. , 1. ]]) 337 337 >>> Rotate(37, [1., 2., 3.]).Axis 338 <[0.2672612 419124244, 0.53452248382484879, 0.80178372573727319, 1.0]>338 <[0.26726123690605164, 0.53452247381210327, 0.80178368091583252, 1.0]> 339 339 >>> Rotate(30, [1., 2., 3.]).Angle 340 340 30.0 … … 342 342 0.52359877559829882 343 343 >>> Rotate(30, [1., 2., 3.]) 344 <Rotation: Angle=30.0, Axis=[0.2672612 419124244, 0.53452248382484879, 0.80178372573727319, 1.0]>344 <Rotation: Angle=30.0, Axis=[0.26726123690605164, 0.53452247381210327, 0.80178368091583252, 1.0]> 345 345 >>> a = Rotate(30, [1., 2., 3.]); a 346 <Rotation: Angle=30.0, Axis=[0.2672612 419124244, 0.53452248382484879, 0.80178372573727319, 1.0]>346 <Rotation: Angle=30.0, Axis=[0.26726123690605164, 0.53452247381210327, 0.80178368091583252, 1.0]> 347 347 >>> ai = a.Inverse(); ai 348 <Rotation: Angle=30.0, Axis=[-0.2672612 419124244, -0.53452248382484879, -0.80178372573727319, 1.0]>348 <Rotation: Angle=30.0, Axis=[-0.26726126670837402, -0.53452253341674805, -0.80178374052047729, 1.0]> 349 349 >>> (a * ai).asArray4x4() 350 array([[ 1.00000000e+000, 5.55111512e-017, 0.00000000e+000, 0.00000000e+000],351 [ 5.55111512e-017, 1.00000000e+000, -5.55111512e-017, 0.00000000e+000],352 [ 0.00000000e+000, -5.55111512e-017, 1.00000000e+000, 0.00000000e+000],350 array([[ 1.00000000e+000, 2.39797163e-008, -2.63590731e-008, 0.00000000e+000], 351 [-2.55925432e-008, 9.99999998e-001, 9.66679894e-009, 0.00000000e+000], 352 [ 2.70206916e-008, -1.20927169e-008, 1.00000000e+000, 0.00000000e+000], 353 353 [ 0.00000000e+000, 0.00000000e+000, 0.00000000e+000, 1.00000000e+000]]) 354 354 >>> (ai * a).asArray4x4() 355 array([[ 1.00000000e+000, -2.08166817e-017, -5.55111512e-017, 0.00000000e+000],356 [-2. 08166817e-017, 1.00000000e+000, 0.00000000e+000, 0.00000000e+000],357 [ -5.55111512e-017, 0.00000000e+000, 1.00000000e+000, 0.00000000e+000],355 array([[ 1.00000000e+000, 2.34966624e-008, -2.58865884e-008, 0.00000000e+000], 356 [-2.60755971e-008, 9.99999999e-001, 1.43609231e-008, 0.00000000e+000], 357 [ 2.35488830e-008, -1.52871791e-008, 1.00000000e+000, 0.00000000e+000], 358 358 [ 0.00000000e+000, 0.00000000e+000, 0.00000000e+000, 1.00000000e+000]]) 359 359 """ 360 360 361 Axis = UnitVector3HProperty('Axis' )361 Axis = UnitVector3HProperty('Axis', NumericType=_NumericType) 362 362 363 363 def __init__(self, angle=0.0, axis=(0.0, 0.0, 1.0)): … … 377 377 u = self.Axis[:-1] 378 378 uut = Numeric.outerproduct(u, u) 379 M = Numeric.identity(3, Numeric.Float32) - uut380 S = Numeric.asarray([[0., -u[2], u[1]], [u[2], 0., -u[0]], [-u[1], u[0], 0.]], Numeric.Float32)379 M = Numeric.identity(3, _NumericType) - uut 380 S = Numeric.asarray([[0., -u[2], u[1]], [u[2], 0., -u[0]], [-u[1], u[0], 0.]], _NumericType) 381 381 radians = self.Radians 382 R = uut + math.cos(radians) * M + math.sin(radians) * S383 result = Numeric.identity(4, Numeric.Float32)382 R = uut + Numeric.cos(radians) * M + Numeric.sin(radians) * S 383 result = Numeric.identity(4, _NumericType) 384 384 result[:3,:3] = R 385 385 return result … … 393 393 """ 394 394 >>> l = LookAt((13.,-12.,11.), (1.,2.,3.), (1.,1.,1.)); l 395 <LookAt: Center=[1.0, 2.0, 3.0] Eye=[13.0, -12.0, 11.0] Up=[0.5773502 6918962584, 0.57735026918962584, 0.57735026918962584]>395 <LookAt: Center=[1.0, 2.0, 3.0] Eye=[13.0, -12.0, 11.0] Up=[0.57735025882720947, 0.57735025882720947, 0.57735025882720947]> 396 396 >>> l.asArray4x4() 397 array([[ 0.6415330 3, 0.11664237, -0.7581754 , 1.39970842],398 [ 0.4816635 , 0.7079873 2, 0.51648255, -3.4470858],399 [ 0.5970223 1, -0.69652603, 0.39801488, -20.49776612],397 array([[ 0.64153302, 0.11664237, -0.75817537, 1.39970833], 398 [ 0.4816635 , 0.70798737, 0.51648253, -3.44708487], 399 [ 0.59702235, -0.69652605, 0.3980149 , -20.49776715], 400 400 [ 0. , 0. , 0. , 1. ]]) 401 401 """ … … 405 405 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 406 406 407 Eye = Vector3Property('Eye', (0.,0.,1.) )408 Center = Vector3Property('Center', (0.,0.,0.) )409 Up = UnitVector3Property('Up', (0.,1.,0.) )407 Eye = Vector3Property('Eye', (0.,0.,1.), NumericType=_NumericType) 408 Center = Vector3Property('Center', (0.,0.,0.), NumericType=_NumericType) 409 Up = UnitVector3Property('Up', (0.,1.,0.), NumericType=_NumericType) 410 410 411 411 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 432 432 U_ = S.Cross3(L) 433 433 434 result = Numeric.identity(4, Numeric.Float32)434 result = Numeric.identity(4, _NumericType) 435 435 result[0,:-1] = S 436 436 result[1,:-1] = U_ 437 437 result[2,:-1] = -L 438 xlate = Numeric.identity(4, Numeric.Float32)438 xlate = Numeric.identity(4, _NumericType) 439 439 xlate[:-1,3] = -E 440 440 return Numeric.dot(result, xlate) … … 447 447 <Spherical LookAt: Center=[0.0, 0.0, 0.0] RhoThetaPhi=(10.0, 45.0, 45.0) Up=[0.0, 1.0, 0.0]> 448 448 >>> s.asArray4x4() 449 array([[ 0.70710678, 0. , -0.70710678, 0.],450 [ -0.5 , 0.70710678, -0.5 , 0.],451 [ 0.5 , 0.70710678, 0.5 , -10.],452 [ 0. , 0. , 0. , 1.]])449 array([[ 7.07106769e-001, 0.00000000e+000, -7.07106769e-001, 0.00000000e+000], 450 [-4.99999970e-001, 7.07106769e-001, -4.99999970e-001, -2.11174211e-007], 451 [ 5.00000000e-001, 7.07106769e-001, 5.00000000e-001, -9.99999991e+000], 452 [ 0.00000000e+000, 0.00000000e+000, 0.00000000e+000, 1.00000000e+000]]) 453 453 >>> s.Eye 454 <[5.0, 7.07106781 18654755, 4.9999999999999991]>454 <[5.0, 7.0710678100585937, 5.0]> 455 455 """ 456 456 … … 460 460 461 461 _RhoThetaPhi = 1., 0., 90 462 Center = Vector3Property('Center', (0.,0.,0.) )463 Spherical = Vector3Property('Spherical', (0.,0.,1.) )464 Up = UnitVector3Property('Up', (0.,1.,0.) )462 Center = Vector3Property('Center', (0.,0.,0.), NumericType=_NumericType) 463 Spherical = Vector3Property('Spherical', (0.,0.,1.), NumericType=_NumericType) 464 Up = UnitVector3Property('Up', (0.,1.,0.), NumericType=_NumericType) 465 465 466 466 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 477 477 def _SetRhoThetaPhi(self, (row,theta,fi)): 478 478 self._RhoThetaPhi = row,theta,fi 479 rowsinfi = row* math.sin(fi)480 x,y,z = (rowsinfi* math.cos(theta),row*math.cos(fi),rowsinfi*math.sin(theta))479 rowsinfi = row*Numeric.sin(fi) 480 x,y,z = (rowsinfi*Numeric.cos(theta),row*Numeric.cos(fi),rowsinfi*Numeric.sin(theta)) 481 481 self.Spherical = x,y,z 482 482 def _GetRhoThetaPhi(self): … … 560 560 result = {} 561 561 for key,value in kw.iteritems(): 562 result[key] = math.tan(value * _deg2rad)562 result[key] = Numeric.tan(value * _deg2rad) 563 563 return result 564 564 … … 622 622 [0, 0, Zs, Zt], 623 623 [0, 0, 0, 1]], 624 Numeric.Float32)624 _NumericType) 625 625 return result 626 626 … … 634 634 [0, 0, Zs, Zt], 635 635 [0, 0, 0, 1]], 636 Numeric.Float32)636 _NumericType) 637 637 return result 638 638 trunk/RBRapier/RBRapier/Tools/Vector.py
r356 r362 25 25 26 26 import Numeric 27 import math28 27 from Foundation.IndexedProperty import IndexedProperty 29 28 … … 32 31 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 33 32 34 _rad2deg = 180.0/math.pi 35 _deg2rad = math.pi/180.0 33 _rad2deg = 180.0/Numeric.pi 34 _deg2rad = Numeric.pi/180.0 35 _NumericType = Numeric.Float32 36 36 37 37 def DotH(v1, v2): … … 91 91 <[0.0, 0.0, 0.0]> 92 92 >>> Vector.DeltaAngle(x,y) 93 90.0 93 90.000002504478161 94 94 >>> Vector.DeltaAngle(x,z) 95 90.0 95 90.000002504478161 96 96 >>> Vector.DeltaAngle(y,z) 97 90.0 97 90.000002504478161 98 98 >>> Vector.DeltaRadians(x,z) 99 1.5707963 26794896699 1.57079637051 100 100 >>> Vector.DeltaRadians(x,y) 101 1.5707963 267948966101 1.57079637051 102 102 >>> Vector.DeltaRadians(z,y) 103 1.5707963 267948966103 1.57079637051 104 104 >>> x * 4 105 105 <[4.0, 0.0, 0.0]> … … 127 127 <[1.0, 1.0, 1.0]> 128 128 >>> x.iNormalize(); x 129 <[0.5773502 6918962584, 0.57735026918962584, 0.57735026918962584]>129 <[0.57735025882720947, 0.57735025882720947, 0.57735025882720947]> 130 130 """ 131 131 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 133 133 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 134 134 135 NumericType = Numeric.Float32135 NumericType = _NumericType 136 136 Default = Numeric.asarray((0.,0.,0.), NumericType) 137 137 … … 140 140 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 141 141 142 def __init__(self, *args): 142 def __init__(self, *args, **kw): 143 NumericType = kw.get('NumericType', None) 144 if NumericType is not None: self.NumericType = NumericType 143 145 if not args: 144 146 self.Set(self.Default) … … 222 224 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 223 225 224 def asarray(self): 225 return self._array 226 def asarray(self, *args): 227 if args: return Numeric.asarray(self._array, *args) 228 else: return self._array 226 229 227 230 def tolist(self): … … 243 246 value = self.Dot(self) 244 247 if squared: return value 245 else: return math.sqrt(value)248 else: return Numeric.sqrt(value) 246 249 247 250 def iNormalize(self): … … 256 259 257 260 def DeltaRadians(self, other): 258 return math.acos(self.Dot(other))261 return Numeric.arccos(self.Dot(other)) 259 262 260 263 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 338 341 <[0.0, 0.0, 0.0, 1.0]> 339 342 >>> VectorH.DeltaAngle(x,y) 340 90.0 343 90.000002504478161 341 344 >>> VectorH.DeltaAngle(x,z) 342 90.0 345 90.000002504478161 343 346 >>> VectorH.DeltaAngle(y,z) 344 90.0 347 90.000002504478161 345 348 >>> VectorH.DeltaRadians(x,z) 346 1.5707963 267948966349 1.57079637051 347 350 >>> VectorH.DeltaRadians(x,y) 348 1.5707963 267948966351 1.57079637051 349 352 >>> VectorH.DeltaRadians(z,y) 350 1.5707963 267948966353 1.57079637051 351 354 >>> x * 4 352 355 <[4.0, 0.0, 0.0, 1.0]> … … 377 380 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 378 381 379 NumericType = Numeric.Float32382 NumericType = _NumericType 380 383 Default = Numeric.asarray((0.,0.,0.,1.), NumericType) 381 384 … … 398 401 def __setitem__(self, key, value): 399 402 self._arrayh[key] = value 400 try: self._arrayh /= self._arrayh[-1 ]403 try: self._arrayh /= self._arrayh[-1:] 401 404 except ZeroDivisionError: pass 402 405 … … 405 408 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 406 409 407 def asarray(self): 408 return self._arrayh 410 def asarray(self, *args): 411 if args: return Numeric.asarray(self._arrayh, *args) 412 else: return self._arrayh 409 413 410 414 def tolist(self): … … 435 439 result = Numeric.asarray(value, self.NumericType) 436 440 # Homogonize 437 try: result /= result[-1 ]441 try: result /= result[-1:] 438 442 except ZeroDivisionError: pass 439 443 return result … … 471 475 A = self._array 472 476 A[key] = value 473 try: A /= A[-1 ]477 try: A /= A[-1:] 474 478 except ZeroDivisionError: pass 475 A /= math.sqrt(Numeric.dot(A, A))479 A /= Numeric.sqrt(Numeric.dot(A, A)) 476 480 477 481 def _simplify(self, value): … … 480 484 result = Numeric.asarray(value, self.NumericType) 481 485 # Normalize 482 result /= math.sqrt(Numeric.dot(result, result))486 result /= Numeric.sqrt(Numeric.dot(result, result)) 483 487 return result 484 488 … … 495 499 A = self._arrayh 496 500 A[key] = value 497 try: A /= A[-1 ]501 try: A /= A[-1:] 498 502 except ZeroDivisionError: pass 499 A[:-1] /= math.sqrt(Numeric.dot(A[:-1], A[:-1]))503 A[:-1] /= Numeric.sqrt(Numeric.dot(A[:-1], A[:-1])) 500 504 501 505 def _simplify(self, value): … … 504 508 result = Numeric.asarray(value, self.NumericType) 505 509 # Homogonize 506 try: result /= result[-1 ]510 try: result /= result[-1:] 507 511 except ZeroDivisionError: pass 508 512 # Normalize 509 result[:-1] /= math.sqrt(Numeric.dot(result[:-1], result[:-1]))513 result[:-1] /= Numeric.sqrt(Numeric.dot(result[:-1], result[:-1])) 510 514 return result 511 515 … … 519 523 520 524 class VectorPropertyMixin(object): 521 def __init__(self, name, default=None, lazy=1, doc='' ):525
