Changeset 362

Show
Ignore:
Timestamp:
11/05/02 18:18:45 (6 years ago)
Author:
sholloway
Message:

*** empty log message ***

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/RBRapier/RBRapier/Formats/Lightwave/MeshedObject.py

    r360 r362  
    3434from RBRapier.Tools.Geometry.Analysis import TriangleMesh 
    3535from RBRapier.Tools.Geometry.Analysis import LocalityRemapper 
     36from RBRapier.Tools.Geometry.ConvexPolygonTesselation import TesselateConvexPolygon 
    3637 
    3738from RBRapier.Renderer.Geometry import VertexArrays 
     
    158159            else: 
    159160                mesh = MeshFactory() 
    160                 bTODOPrinted = 0 
    161161                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) 
    170165                        if face:  
    171166                            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 
    178169 
    179170                if __debug__:  
     
    196187 
    197188        for data in self.Normals.data: 
    198             data[:] /= Numeric.sum(data*data
     189            data[:] /= Numeric.sqrt(Numeric.sum(data*data)
    199190 
    200191    def SimpleTraversals(self): 
  • trunk/RBRapier/RBRapier/Formats/Wavefront/MeshedObject.py

    r349 r362  
    3434from RBRapier.Tools.Geometry.Analysis import TriangleMesh 
    3535from RBRapier.Tools.Geometry.Analysis import LocalityRemapper 
     36from RBRapier.Tools.Geometry.ConvexPolygonTesselation import TesselateConvexPolygon 
    3637 
    3738from RBRapier.Renderer.Geometry import VertexArrays 
     
    163164            else: 
    164165                mesh = MeshFactory() 
    165                 bTODOPrinted = 0 
    166166                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) 
    175170                if __debug__:  
    176171                    print '%-20s[%6d]: ' % (Group.Names[0], len(mesh.Faces)*3), 
  • trunk/RBRapier/RBRapier/Renderer/SequenceMgr.py

    r351 r362  
    6161        elif isinstance(getattr(Element, 'Execute', None), types.MethodType): 
    6262            ElementFn = Element.Execute 
     63        elif isinstance(getattr(Element, 'Select', None), types.MethodType): 
     64            ElementFn = Element.Select 
    6365        self.Elements.insert(idx, (priority, ElementFn, Element)) 
    6466 
  • trunk/RBRapier/RBRapier/Tools/Geometry/Analysis/TriangleMesh.py

    r360 r362  
    180180    <FaceEdgeMesh |edges|=13 |faces|=6> 
    181181    >>> face = mesh.Faces[0]; face 
    182     <Mesh&EdgedFace v=(0, 1, 2)> 
     182    <FaceEdgeMesh&EdgedFace v=(0, 1, 2)> 
    183183    >>> face.OtherVertex(0,1) 
    184184    2 
    185185    >>> face.GetEdge(2,1) 
    186     <Mesh&Edge ev=(1, 2)> 
     186    <FaceEdgeMesh&Edge ev=(1, 2)> 
    187187    """ 
    188188 
  • trunk/RBRapier/RBRapier/Tools/Geometry/Analysis/TriangleStripifier.py

    r355 r362  
    295295    Origional can be found at http://developer.nvidia.com/view.asp?IO=nvtristrip_library. 
    296296 
    297     >>> mesh = Mesh.Mesh() 
     297    >>> mesh = Mesh.FaceEdgeMesh(); mesh.CleanFaces = 1 
    298298    >>> rows = [range(0,4), range(4,8), range(8,12), range(12,16)] 
    299299    >>> r0 = rows[0] 
     
    301301    ...    _MakeSimpleMesh(mesh, _ConjoinMeshData(r0, r1)); r0=r1 
    302302    >>> mesh 
    303     <Mesh |edges|=33 |faces|=18> 
     303    <FaceEdgeMesh |edges|=33 |faces|=18> 
    304304    >>> stripifier = TriangleStripifier() 
    305305    >>> r = stripifier.Stripify(mesh) 
    306     >>> stripifier.TriangleList, stripifier.TriangleFans, 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]]) 
     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]]) 
    308308    >>> stripifier.Selector.MinStripLength = 100 
    309309    >>> r = stripifier.Stripify(mesh) 
    310     >>> stripifier.TriangleList, stripifier.TriangleFans, 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], [], []
     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], []
    312312    >>> del stripifier.Selector.MinStripLength 
    313313    """ 
     
    341341         
    342342    __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() 
    343353 
    344354    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    423433        stripId = _Counter() 
    424434        FacesComplete = 0. 
    425         self.Strips = result = [] 
     435        #result = [] 
    426436 
    427437        try: 
     
    468478 
    469479                # And commit it to the resultset 
    470                 result.extend(BestExperiment) 
    471480                for each in BestExperiment: 
    472481                    FacesComplete += each.Commit() 
     482                    yield each 
     483                #result.extend(BestExperiment) 
    473484 
    474485                # and update anyone watching 
     
    477488            pass 
    478489 
    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 
    484496 
    485497#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    520532 
    521533    startmesh = time.clock() 
    522     mesh = Mesh.Mesh() 
     534    mesh = Mesh.FaceEdgeMesh() 
    523535    r0 = rows[0] 
    524536    for r1 in rows[1:]: 
  • trunk/RBRapier/RBRapier/Tools/Projections.py

    r356 r362  
    133133    <Orthographic: l=-2.0, r=3.0, b=5.0, t=8.0, n=-9.0, f=-2.0 > 
    134134    >>> 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') 
    140139    """ 
    141140 
     
    230229    <Frustm: l=-2.0, r=3.0, b=5.0, t=8.0, n=-9.0, f=-2.0 > 
    231230    >>> 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') 
    237235    """ 
    238236 
     
    270268    <Persepctive: ViewAngle=30.0, Aspect=1.234, n=0.5, f=23.2 > 
    271269    >>> proj.asArray4x4() 
    272     array([[ 4.6053507 ,  0.        ,  0.        ,  0.        ], 
    273            [ 0.        ,  3.73205081,  0.        ,  0.        ], 
    274            [ 0.        ,  0.        , -1.04405286, -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'
    276274    >>> proj.AspectRatio 
    277275    1.2339999999999995 
  • trunk/RBRapier/RBRapier/Tools/Quaternion.py

    r356 r362  
    4343 
    4444#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     45#~ Constants / Variables / Etc.  
     46#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     47 
     48_NumericType = Numeric.Float 
     49 
     50#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    4551#~ Definitions  
    4652#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    109115    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    110116 
    111     NumericType = Numeric.Float32 
     117    NumericType = _NumericType 
    112118     
    113119    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    258264        value = Numeric.innerproduct(self._array, self._array) 
    259265        if squared: return value 
    260         else: return math.sqrt(value) 
     266        else: return Numeric.sqrt(value) 
    261267 
    262268    def Normalize(self): 
     
    315321        0.52359877559829859 
    316322        """ 
    317         return 2. * math.acos(Numeric.innerproduct(self._array, other._array)) 
     323        return 2. * Numeric.arccos(Numeric.innerproduct(self._array, other._array)) 
    318324 
    319325    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    325331        """ 
    326332        try:  
    327             return 2. * _rad2deg * math.acos(self._array[0]) 
     333            return 2. * _rad2deg * Numeric.arccos(self._array[0]) 
    328334        except ValueError: return 0. 
    329335    def setAngle(self, value): 
     
    345351        """ 
    346352        try:  
    347             return 2. * math.acos(self._array[0]) 
     353            return 2. * Numeric.arccos(self._array[0]) 
    348354        except ValueError: return 0. 
    349355    def setRadians(self, value): 
     
    351357        >>> aa = Quaternion.fromAngleAxis(30., (0., 0., 1.)); aa 
    352358        <Quaternion: 0.965925826289 + 0.0i + 0.0j + 0.258819045103k> 
    353         >>> aa.Radians = math.pi/4.; aa 
     359        >>> aa.Radians = Numeric.pi/4.; aa 
    354360        <Quaternion: 0.923879532511 + 0.0i + 0.0j + 0.382683432365k> 
    355361        >>> aa.Radians 
     
    379385    def Log(self): 
    380386        """ 
    381         >>> ra = Quaternion.fromRadianAxis(math.pi/3., (1.,0.,0.)); ra 
     387        >>> ra = Quaternion.fromRadianAxis(Numeric.pi/3., (1.,0.,0.)); ra 
    382388        <Quaternion: 0.866025403784 + 0.5i + 0.0j + 0.0k> 
    383389        >>> ra.Log() 
     
    386392        <Quaternion: 0.866025403784 + 0.5i + 0.0j + 0.0k> 
    387393        """ 
    388         Radians = math.acos(self._array[0]) 
    389         sinR = math.sin(Radians) 
     394        Radians = Numeric.arccos(self._array[0]) 
     395        sinR = Numeric.sin(Radians) 
    390396        if sinR > 0: 
    391397            result = (Radians/sinR) * self 
     
    397403    def Exp(self, power=1.): 
    398404        """ 
    399         >>> ra = Quaternion.fromRadianAxis(math.pi/3., (1.,0.,0.)); ra 
     405        >>> ra = Quaternion.fromRadianAxis(Numeric.pi/3., (1.,0.,0.)); ra 
    400406        <Quaternion: 0.866025403784 + 0.5i + 0.0j + 0.0k> 
    401407        >>> ra.Exp() 
     
    404410        <Quaternion: 0.0 + 0.5i + 0.0j + 0.0k> 
    405411        """ 
    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) 
    408414        if Radians > 0: 
    409415            result = (sinR/Radians) * self 
     
    417423    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    418424 
    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 
    421428 
    422429    def tolist(self): 
     
    425432    def _SVfromRadianAxis(Klass, Radians, Axis): 
    426433        Radians *= .5 
    427         cosR, sinR = math.cos(Radians), math.sin(Radians) 
     434        cosR, sinR = Numeric.cos(Radians), Numeric.sin(Radians) 
    428435        Quat = Numeric.asarray([cosR] + list(Axis), Klass.NumericType) 
    429436        Quat[1:] *= sinR / Numeric.innerproduct(Quat[1:], Quat[1:]) 
     
    441448    def fromRadianAxis(Klass, Radians, Axis): 
    442449        """ 
    443         >>> ra = Quaternion.fromRadianAxis(math.pi/6., (0., 0., 1.)); ra 
     450        >>> ra = Quaternion.fromRadianAxis(Numeric.pi/6., (0., 0., 1.)); ra 
    444451        <Quaternion: 0.965925826289 + 0.0i + 0.0j + 0.258819045103k> 
    445452        """ 
     
    455462        """ 
    456463        cosR, Axis = _VectorDotCross3(v0, v1) 
    457         s = math.sqrt(2.*(cosR+1)) 
     464        s = Numeric.sqrt(2.*(cosR+1)) 
    458465        Quat = Numeric.asarray((s/2.,) + Axis, Klass.NumericType) 
    459466        Quat[1:] /= s 
     
    492499    def toRadianAxis(self): 
    493500        """ 
    494         >>> ra = Quaternion.fromRadianAxis(math.pi/6., (0., 0., 1.)) 
     501        >>> ra = Quaternion.fromRadianAxis(Numeric.pi/6., (0., 0., 1.)) 
    495502        >>> ra.toRadianAxis() 
    496503        (0.52359877559829859, array([ 0.,  0.,  1.])) 
     
    499506        """ 
    500507        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) 
    503510            return 2. * Radians, RadialFactor * self._array[1:] 
    504511        except ValueError:  
  • trunk/RBRapier/RBRapier/Tools/Transformations.py

    r356 r362  
    2626import Numeric 
    2727import LinearAlgebra 
    28 import math 
    2928from Vector import * 
    3029 
     
    3332#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    3433 
    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 
    3737 
    3838#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    7777    >>> n = c.Add(Rotate(23, (7,11,13))) 
    7878    >>> 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.38018781261549794, 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]>] > 
    8080    >>> c.Inverse() 
    81     <Composite: [<Rotation: Angle=23.0, Axis=[-0.38018781261549794, -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>] > 
    8282    >>> (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], 
    8686           [ 0.00000000e+000,  0.00000000e+000,  0.00000000e+000,  1.00000000e+000]]) 
    8787    >>> n = c.Add(Skew(2,3,4,5,6,7)) 
     
    9191    >>> n = c.Add(Perspective()) 
    9292    >>> c.asArray4x4() 
    93     array([[  44.29637035,  125.91233004,  -57.83760114,  -29.67837026], 
    94            [ 201.84505034,   24.85095453, -347.25496342, -180.08552595], 
    95            [ 549.72681569,  552.42082222, -107.8104291 ,  -54.78268816], 
    96            [   0.        ,    0.        ,    1.22222222,    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]]) 
    9797    >>> c.asInverse4x4() 
    98     array([[-1.01736208e-002,  9.93235478e-004,  2.27417469e-003,  1.36462579e-003], 
    99            [ 9.06907259e-003, -1.47085544e-003, -1.90716743e-004, -5.55521148e-003], 
    100            [-1.22560274e-002, -5.60517254e-003,  3.04564707e-003, -1.08567057e+000], 
    101            [ 1.34816302e-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]]) 
    102102    """ 
    103103 
     
    136136    def asArray4x4(self): 
    137137        """Returns the transformation in 4x4 Numeric array form""" 
    138         r = Numeric.identity(4, Numeric.Float32
     138        r = Numeric.identity(4, _NumericType
    139139        for xform in self.collection: 
    140140            r = Numeric.dot(r, xform.asArray4x4()) 
     
    169169 
    170170    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
    173173        assert self.matrix.shape == (4,4) 
    174174 
     
    208208 
    209209    def asArray4x4(self): 
    210         return Numeric.identity(4, Numeric.Float32
     210        return Numeric.identity(4, _NumericType
    211211 
    212212    def asInverse4x4(self): 
    213         return Numeric.identity(4, Numeric.Float32
     213        return Numeric.identity(4, _NumericType
    214214 
    215215    def Inverse(self): 
     
    235235    """ 
    236236 
    237     Direction = Vector3HProperty('Direction'
     237    Direction = Vector3HProperty('Direction', NumericType=_NumericType
    238238 
    239239    def __init__(self, Direction=(0,0,0)): 
     
    244244 
    245245    def asArray4x4(self): 
    246         result = Numeric.identity(4, Numeric.Float32
     246        result = Numeric.identity(4, _NumericType
    247247        result[:, 3] = self.Direction 
    248248        return result 
    249249 
    250250    def asInverse4x4(self): 
    251         result = Numeric.identity(4, Numeric.Float32
     251        result = Numeric.identity(4, _NumericType
    252252        result[:, 3] = -self.Direction 
    253253        return result 
     
    275275    """ 
    276276 
    277     Scale = Vector3HProperty('Scale', (1.,1.,1.,1.)
     277    Scale = Vector3HProperty('Scale', (1.,1.,1.,1.), NumericType=_NumericType
    278278 
    279279    def __init__(self, Scale=1.0): 
     
    289289 
    290290    def asArray4x4(self): 
    291         result = Numeric.identity(4, Numeric.Float32
     291        result = Numeric.identity(4, _NumericType
    292292        for idx in range(4): result[idx,idx] = self.Scale[idx] 
    293293        return result 
    294294 
    295295    def asInverse4x4(self): 
    296         result = Numeric.identity(4, Numeric.Float32
     296        result = Numeric.identity(4, _NumericType
    297297        for idx in range(4): result[idx,idx] = 1./self.Scale[idx] 
    298298        return result 
     
    328328    array([[ 0.81983177, -0.45634205,  0.34587252,  0.        ], 
    329329           [ 0.51993083,  0.8463271 , -0.11576859,  0.        ], 
    330            [-0.23989121,  0.27474056,  0.93111215,  0.        ], 
     330           [-0.23989122,  0.27474055,  0.93111215,  0.        ], 
    331331           [ 0.        ,  0.        ,  0.        ,  1.        ]]) 
    332332    >>> Rotate(37, [2, 3, 5]).asInverse4x4() 
    333     array([[ 0.81983177,  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.        ], 
    335335           [ 0.34587252, -0.11576859,  0.93111215,  0.        ], 
    336336           [ 0.        ,  0.        ,  0.        ,  1.        ]]) 
    337337    >>> Rotate(37, [1., 2., 3.]).Axis 
    338     <[0.2672612419124244, 0.53452248382484879, 0.80178372573727319, 1.0]> 
     338    <[0.26726123690605164, 0.53452247381210327, 0.80178368091583252, 1.0]> 
    339339    >>> Rotate(30, [1., 2., 3.]).Angle 
    340340    30.0 
     
    342342    0.52359877559829882 
    343343    >>> Rotate(30, [1., 2., 3.]) 
    344     <Rotation: Angle=30.0, Axis=[0.2672612419124244, 0.53452248382484879, 0.80178372573727319, 1.0]> 
     344    <Rotation: Angle=30.0, Axis=[0.26726123690605164, 0.53452247381210327, 0.80178368091583252, 1.0]> 
    345345    >>> a = Rotate(30, [1., 2., 3.]); a 
    346     <Rotation: Angle=30.0, Axis=[0.2672612419124244, 0.53452248382484879, 0.80178372573727319, 1.0]> 
     346    <Rotation: Angle=30.0, Axis=[0.26726123690605164, 0.53452247381210327, 0.80178368091583252, 1.0]> 
    347347    >>> ai = a.Inverse(); ai 
    348     <Rotation: Angle=30.0, Axis=[-0.2672612419124244, -0.53452248382484879, -0.80178372573727319, 1.0]> 
     348    <Rotation: Angle=30.0, Axis=[-0.26726126670837402, -0.53452253341674805, -0.80178374052047729, 1.0]> 
    349349    >>> (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], 
    353353           [ 0.00000000e+000,  0.00000000e+000,  0.00000000e+000,  1.00000000e+000]]) 
    354354    >>> (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], 
    358358           [ 0.00000000e+000,  0.00000000e+000,  0.00000000e+000,  1.00000000e+000]]) 
    359359    """ 
    360360 
    361     Axis = UnitVector3HProperty('Axis'
     361    Axis = UnitVector3HProperty('Axis', NumericType=_NumericType
    362362 
    363363    def __init__(self, angle=0.0, axis=(0.0, 0.0, 1.0)): 
     
    377377        u = self.Axis[:-1] 
    378378        uut = Numeric.outerproduct(u, u) 
    379         M = Numeric.identity(3, Numeric.Float32) - uut 
    380         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
    381381        radians = self.Radians 
    382         R = uut + math.cos(radians) * M + math.sin(radians) * S 
    383         result = Numeric.identity(4, Numeric.Float32
     382        R = uut + Numeric.cos(radians) * M + Numeric.sin(radians) * S 
     383        result = Numeric.identity(4, _NumericType
    384384        result[:3,:3] = R 
    385385        return result 
     
    393393    """ 
    394394    >>> 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.57735026918962584, 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]> 
    396396    >>> l.asArray4x4() 
    397     array([[  0.64153303,   0.11664237,  -0.7581754 ,   1.39970842], 
    398            [  0.4816635 ,   0.70798732,   0.51648255,  -3.4470858 ], 
    399            [  0.59702231,  -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], 
    400400           [  0.        ,   0.        ,   0.        ,   1.        ]]) 
    401401    """ 
     
    405405    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    406406 
    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
    410410 
    411411    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    432432        U_ = S.Cross3(L) 
    433433 
    434         result = Numeric.identity(4, Numeric.Float32
     434        result = Numeric.identity(4, _NumericType
    435435        result[0,:-1] = S 
    436436        result[1,:-1] = U_ 
    437437        result[2,:-1] = -L 
    438         xlate = Numeric.identity(4, Numeric.Float32
     438        xlate = Numeric.identity(4, _NumericType
    439439        xlate[:-1,3] = -E 
    440440        return Numeric.dot(result, xlate) 
     
    447447    <Spherical LookAt: Center=[0.0, 0.0, 0.0] RhoThetaPhi=(10.0, 45.0, 45.0) Up=[0.0, 1.0, 0.0]> 
    448448    >>> 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]]) 
    453453    >>> s.Eye 
    454     <[5.0, 7.0710678118654755, 4.9999999999999991]> 
     454    <[5.0, 7.0710678100585937, 5.0]> 
    455455    """ 
    456456 
     
    460460 
    461461    _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
    465465 
    466466    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    477477    def _SetRhoThetaPhi(self, (row,theta,fi)): 
    478478        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)) 
    481481        self.Spherical = x,y,z 
    482482    def _GetRhoThetaPhi(self): 
     
    560560        result = {} 
    561561        for key,value in kw.iteritems():  
    562             result[key] = math.tan(value * _deg2rad) 
     562            result[key] = Numeric.tan(value * _deg2rad) 
    563563        return result 
    564564 
     
    622622            [0, 0, Zs, Zt], 
    623623            [0, 0, 0, 1]],  
    624             Numeric.Float32
     624            _NumericType
    625625        return result 
    626626 
     
    634634            [0, 0, Zs, Zt], 
    635635            [0, 0, 0, 1]],  
    636             Numeric.Float32
     636            _NumericType
    637637        return result 
    638638 
  • trunk/RBRapier/RBRapier/Tools/Vector.py

    r356 r362  
    2525 
    2626import Numeric 
    27 import math 
    2827from Foundation.IndexedProperty import IndexedProperty  
    2928 
     
    3231#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    3332 
    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 
    3636 
    3737def DotH(v1, v2): 
     
    9191    <[0.0, 0.0, 0.0]> 
    9292    >>> Vector.DeltaAngle(x,y) 
    93     90.0 
     93    90.000002504478161 
    9494    >>> Vector.DeltaAngle(x,z) 
    95     90.0 
     95    90.000002504478161 
    9696    >>> Vector.DeltaAngle(y,z) 
    97     90.0 
     97    90.000002504478161 
    9898    >>> Vector.DeltaRadians(x,z) 
    99     1.5707963267948966 
     99    1.57079637051 
    100100    >>> Vector.DeltaRadians(x,y) 
    101     1.5707963267948966 
     101    1.57079637051 
    102102    >>> Vector.DeltaRadians(z,y) 
    103     1.5707963267948966 
     103    1.57079637051 
    104104    >>> x * 4 
    105105    <[4.0, 0.0, 0.0]> 
     
    127127    <[1.0, 1.0, 1.0]> 
    128128    >>> x.iNormalize(); x 
    129     <[0.57735026918962584, 0.57735026918962584, 0.57735026918962584]> 
     129    <[0.57735025882720947, 0.57735025882720947, 0.57735025882720947]> 
    130130    """ 
    131131    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    133133    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    134134 
    135     NumericType = Numeric.Float32 
     135    NumericType = _NumericType 
    136136    Default = Numeric.asarray((0.,0.,0.), NumericType) 
    137137 
     
    140140    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    141141 
    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 
    143145        if not args: 
    144146            self.Set(self.Default) 
     
    222224    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    223225 
    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 
    226229 
    227230    def tolist(self): 
     
    243246        value = self.Dot(self) 
    244247        if squared: return value 
    245         else: return math.sqrt(value) 
     248        else: return Numeric.sqrt(value) 
    246249 
    247250    def iNormalize(self): 
     
    256259 
    257260    def DeltaRadians(self, other): 
    258         return math.acos(self.Dot(other)) 
     261        return Numeric.arccos(self.Dot(other)) 
    259262 
    260263    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    338341    <[0.0, 0.0, 0.0, 1.0]> 
    339342    >>> VectorH.DeltaAngle(x,y) 
    340     90.0 
     343    90.000002504478161 
    341344    >>> VectorH.DeltaAngle(x,z) 
    342     90.0 
     345    90.000002504478161 
    343346    >>> VectorH.DeltaAngle(y,z) 
    344     90.0 
     347    90.000002504478161 
    345348    >>> VectorH.DeltaRadians(x,z) 
    346     1.5707963267948966 
     349    1.57079637051 
    347350    >>> VectorH.DeltaRadians(x,y) 
    348     1.5707963267948966 
     351    1.57079637051 
    349352    >>> VectorH.DeltaRadians(z,y) 
    350     1.5707963267948966 
     353    1.57079637051 
    351354    >>> x * 4 
    352355    <[4.0, 0.0, 0.0, 1.0]> 
     
    377380    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    378381 
    379     NumericType = Numeric.Float32 
     382    NumericType = _NumericType 
    380383    Default = Numeric.asarray((0.,0.,0.,1.), NumericType) 
    381384 
     
    398401    def __setitem__(self, key, value):  
    399402        self._arrayh[key] = value 
    400         try: self._arrayh /= self._arrayh[-1
     403        try: self._arrayh /= self._arrayh[-1:
    401404        except ZeroDivisionError: pass 
    402405 
     
    405408    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    406409 
    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 
    409413 
    410414    def tolist(self): 
     
    435439        result = Numeric.asarray(value, self.NumericType) 
    436440        # Homogonize 
    437         try: result /= result[-1
     441        try: result /= result[-1:
    438442        except ZeroDivisionError: pass 
    439443        return result  
     
    471475        A = self._array 
    472476        A[key] = value 
    473         try: A /= A[-1
     477        try: A /= A[-1:
    474478        except ZeroDivisionError: pass 
    475         A /= math.sqrt(Numeric.dot(A, A)) 
     479        A /= Numeric.sqrt(Numeric.dot(A, A)) 
    476480 
    477481    def _simplify(self, value): 
     
    480484        result = Numeric.asarray(value, self.NumericType) 
    481485        # Normalize 
    482         result /= math.sqrt(Numeric.dot(result, result)) 
     486        result /= Numeric.sqrt(Numeric.dot(result, result)) 
    483487        return result 
    484488 
     
    495499        A = self._arrayh 
    496500        A[key] = value 
    497         try: A /= A[-1
     501        try: A /= A[-1:
    498502        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])) 
    500504 
    501505    def _simplify(self, value): 
     
    504508        result = Numeric.asarray(value, self.NumericType) 
    505509        # Homogonize 
    506         try: result /= result[-1
     510        try: result /= result[-1:
    507511        except ZeroDivisionError: pass 
    508512        # Normalize 
    509         result[:-1] /= math.sqrt(Numeric.dot(result[:-1], result[:-1])) 
     513        result[:-1] /= Numeric.sqrt(Numeric.dot(result[:-1], result[:-1])) 
    510514        return result 
    511515 
     
    519523 
    520524class VectorPropertyMixin(object): 
    521     def __init__(self, name, default=None, lazy=1, doc=''): 
     525