File: ColorScalars.py

package info (click to toggle)
pyvtk 0.4.66-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 276 kB
  • ctags: 344
  • sloc: python: 2,034; makefile: 86; sh: 1
file content (43 lines) | stat: -rw-r--r-- 1,405 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
"""

Copyright 2001 Pearu Peterson all rights reserved,
Pearu Peterson <pearu@ioc.ee>          
Permission to use, modify, and distribute this software is given under the
terms of the LGPL.  See http://www.fsf.org

NO WARRANTY IS EXPRESSED OR IMPLIED.  USE AT YOUR OWN RISK.
$Revision: 1.1 $
$Date: 2001/05/20 12:51:29 $
Pearu Peterson
"""

__version__ = "$Id: ColorScalars.py,v 1.1 2001/05/20 12:51:29 pearu Exp $"

import common
import DataSetAttr
import string

class ColorScalars(DataSetAttr.DataSetAttr):
    """Holds VTK color scalars.
    """
    def __init__(self,scalars,name=None):
        self.name = self._get_name(name)
        self.scalars = self.get_n_seq_seq(scalars,self.default_value)
    def to_string(self,format='ascii'):
        ret = ['COLOR_SCALARS %s %s'%(self.name,len(self.scalars[0]))]
        seq = self.scalars
        if format=='binary':
            if not common.is_int255(seq):
                seq = self.float01_to_int255(seq)
            ret.append(self.seq_to_string(seq,format,'unsigned char'))
        else:
            if not common.is_float01(seq):
                seq = self.int255_to_float01(seq)
            ret.append(self.seq_to_string(seq,format,'float'))
        return string.join(ret,'\n')
    def get_size(self):
        return len(self.scalars)

if __name__ == "__main__":
    print ColorScalars([[3,3],[4,3],240,3,2]).to_string()