def josh(colors, target): print "josh", colors, target # all_colors = [(name, float(X), float(Y), float(Z)) # for name, X, Y, Z in csv.reader(open(colorcsv))] all_colors = [(name, float(X), float(Y), float(Z)) for name, X, Y, Z in colors] # background is marked SUPPORT support_i = [ i for i, color in enumerate(all_colors) if color[0] == 'SUPPORT' ] if len(support_i) > 0: support = np.array(all_colors[support_i[0]][1:]) del all_colors[support_i[0]] else: support = None tg, hull_i = geometry.tetgen_of_hull( [(X, Y, Z) for name, X, Y, Z in all_colors]) colors = [all_colors[i] for i in hull_i] print("thrown out: " + ", ".join( set(zip(*all_colors)[0]).difference(zip(*colors)[0]))) # targets = [(name, float(X), float(Y), float(Z), float(BG)) # for name, X, Y, Z, BG in csv.reader(open(targetcsv))] # for target in targets: name, X, Y, Z, BG = target target_point = support + (np.array([X, Y, Z]) - support) / (1 - BG) tet_i, bcoords = geometry.containing_tet(tg, target_point) if tet_i == None: print "%s: Not in gamut" % target[0] # not in gamut else: names = [colors[i][0] for i in tg.tets[tet_i]] print "%s:" % target[0], names, bcoords
from traits.api import HasTraits, Range, Instance, \ on_trait_change from traitsui.api import View, Item, HGroup from tvtk.pyface.scene_editor import SceneEditor from mayavi.tools.mlab_scene_model import \ MlabSceneModel from mayavi.core.ui.mayavi_scene import MayaviScene import tetgen, geometry from pprint import pprint import random,csv all_colors = [(name, float(X), float(Y), float(Z)) for name, X, Y, Z in csv.reader(open('data/XYZcolorlist.csv'))] tg, hull_i = geometry.tetgen_of_hull([(X,Y,Z) for name, X, Y, Z in all_colors]) colors = [all_colors[i] for i in hull_i] print ("thrown out: " + ", ".join(set(zip(*all_colors)[0]).difference(zip(*colors)[0]))) class Visualization(HasTraits): scene = Instance(MlabSceneModel, ()) X = Range(0., 100., 0.) Y = Range(0.01, 100., 1.) Z = Range(0., 100., 0.) x = Range(0., 1., 0.) y = Range(0.01, 1., 1) selected_tet = -1 def __init__(self): # Do not forget to call the parent's __init__