-
Notifications
You must be signed in to change notification settings - Fork 5
/
genmaps.py
56 lines (40 loc) · 1.12 KB
/
genmaps.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
# Generates the file namedMaps.cpp used by
# openframeworks addon ofxColorMap.
#
# Extracts color maps from matplotlib (pylab).
#
import pylab
import inspect
import numpy
import sys
print """
#include "ofxColorMap.h"
map<string, ofxColorMap::ColorMap> ofxColorMap::createNamedMaps() {
map<string, ColorMap> m;
"""
discrete_n = 10
for name,colormap in pylab.cm.cmap_d.iteritems():
if not type(colormap) is pylab.matplotlib.colors.LinearSegmentedColormap:
continue
print "{"
for channel in ('red','green','blue'):
assert(channel in colormap._segmentdata.keys())
print "ColorMapChannel",channel[0],";",
d = colormap._segmentdata[channel]
if inspect.isfunction(d):
newd = []
x = numpy.linspace(0,1,discrete_n)
y = numpy.clip(numpy.array(d(x), dtype=numpy.float), 0, 1)
for i in xrange(discrete_n):
newd.append((x[i], y[i], y[i]))
d = newd
for i in d:
print channel[0],".push_back(ofVec3f(",
print str.join(",",map(str,i)),
print "));",
print
print "ColorMap a; a.push_back(r); a.push_back(g); a.push_back(b);"
print "m[\"%s\"] = a;"%(name)
print "}"
print "return m;"
print "}"