Annotation of python/pyvtk/lib/Normals.py, revision 1.1

1.1     ! pearu       1: #!/usr/bin/env python
        !             2: """
        !             3: 
        !             4: Copyright 2001 Pearu Peterson all rights reserved,
        !             5: Pearu Peterson <pearu@ioc.ee>          
        !             6: Permission to use, modify, and distribute this software is given under the
        !             7: terms of the LGPL.  See http://www.fsf.org
        !             8: 
        !             9: NO WARRANTY IS EXPRESSED OR IMPLIED.  USE AT YOUR OWN RISK.
        !            10: $Revision:$
        !            11: $Date: 2000/07/31 07:04:03 $
        !            12: Pearu Peterson
        !            13: """
        !            14: 
        !            15: import DataSetAttr
        !            16: import math
        !            17: 
        !            18: class Normals(DataSetAttr.DataSetAttr):
        !            19:     """Holds VTK Normals.
        !            20:     """
        !            21:     def __init__(self,normals,name=None):
        !            22:         self.name = self._get_name(name)
        !            23:         seq = []
        !            24:         for v in self.get_3_tuple_list(normals,(self.default_value,)*3):
        !            25:             n = math.sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2])
        !            26:             if n==1:
        !            27:                 seq.append(v)
        !            28:             else:
        !            29:                 seq.append(tuple([c/n for c in v]))
        !            30:         self.normals = seq
        !            31:     def to_string(self,format='ascii'):
        !            32:         t = self.get_datatype(self.normals)
        !            33:         ret = ['NORMALS %s %s'%(self.name,t)]
        !            34:         ret.append(self.seq_to_string(self.normals,format,t))
        !            35:         return '\n'.join(ret)
        !            36:     def get_size(self):
        !            37:         return len(self.normals)
        !            38: 
        !            39: if __name__ == "__main__":
        !            40:     print Normals([[3,3],[4,3.],240,3,2]).to_string()

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>