def __init__(self, width, height, colormap, color, parent_interactor=None, on_save=None, on_cancel=None): self.render_window = vtk.vtkRenderWindow() self.render_window.SetWindowName("Color Picker") self.render_window.SetNumberOfLayers(3) self.render_window.SetSize(width, height) self.color_renderer = vtk.vtkRenderer() self.parent_interactor = parent_interactor if colormap is None: colormap = "default" if not vcs.iscolormap(colormap): colormap = vcs.getcolormap(colormap) self.colormap = colormap self.colors = [[int(c / 100.0 * 255.0) for c in colormap.index[i]] for i in range(len(colormap.index))] self.actor = make_color_plane(16, 16, self.colors) self.color_renderer.SetViewport([.1, .1, .9, .9]) self.color_renderer.SetBackground((.5, .5, .5)) self.color_renderer.AddActor(self.actor) self.color_renderer.InteractiveOff() self.color_renderer.SetLayer(1) bg = vtk.vtkRenderer() bg.SetBackground(1, 1, 1) bg.SetViewport([0, 0, 1, 1]) bg.SetLayer(0) self.render_window.AddRenderer(bg) self.render_window.AddRenderer(self.color_renderer) inter = vtk.vtkRenderWindowInteractor() self.style = vtk.vtkInteractorStyleUser() inter.SetInteractorStyle(self.style) inter.SetRenderWindow(self.render_window) manager = vcs.vtk_ui.manager.get_manager(inter) self.render_window.AddRenderer(manager.renderer) self.render_window.AddRenderer(manager.actor_renderer) manager.elevate() self.render_window.Render() self.on_save = on_save self.on_cancel = on_cancel maps = vcs.elements["colormap"] current_state = None states = [] self.colormaps = [] for ind, mapname in enumerate(maps.keys()): states.append(ButtonState(label=mapname)) if colormap.name == mapname: current_state = ind self.colormaps.append(maps[mapname]) self.colormap_button = Button(inter, states=states, action=self.change_map, left=10, top=10) self.colormap_button.set_state(current_state) self.save_button = Button(inter, action=self.save, label="Choose Color", left=int(width * .75) - 10, top=int(height * .85)) self.cancel_button = Button(inter, action=self.cancel, label="Cancel", left=10, top=int(height * .85)) self.colormap_button.show() self.save_button.show() self.cancel_button.show() self.make_current() self.selectedMapper = vtk.vtkDataSetMapper() self.selectedActor = vtk.vtkActor() self.selectedActor.SetMapper(self.selectedMapper) self.selectedActor.GetProperty().EdgeVisibilityOn() self.selectedActor.GetProperty().SetEdgeColor(0, 0, 0) self.selectedActor.GetProperty().SetLineWidth(3) self.color = color # Make sure the current color is selected self.selectCell(color) self.color_renderer.AddActor(self.selectedActor) self.click_handler = inter.AddObserver( vtk.vtkCommand.LeftButtonReleaseEvent, self.clickEvent) def noop(obj, event): pass self.char_handler = inter.AddObserver(vtk.vtkCommand.CharEvent, noop)
def __init__(self, width, height, colormap, color, parent_interactor=None, on_save=None, on_cancel=None): self.render_window = vtk.vtkRenderWindow() self.render_window.SetWindowName("Color Picker") self.render_window.SetNumberOfLayers(3) self.render_window.SetSize(width, height) self.color_renderer = vtk.vtkRenderer() self.parent_interactor = parent_interactor if colormap is None: colormap = "default" if not vcs.iscolormap(colormap): colormap = vcs.getcolormap(colormap) self.colormap = colormap self.colors = [[int(c / 100.0 * 255.0) for c in colormap.index[i]] for i in range(len(colormap.index))] self.actor = make_color_plane(16, 16, self.colors) self.color_renderer.SetViewport([.1, .1, .9, .9]) self.color_renderer.SetBackground((.5, .5, .5)) self.color_renderer.AddActor(self.actor) self.color_renderer.InteractiveOff() self.color_renderer.SetLayer(1) bg = vtk.vtkRenderer() bg.SetBackground(1,1,1) bg.SetViewport([0,0,1,1]) bg.SetLayer(0) self.render_window.AddRenderer(bg) self.render_window.AddRenderer(self.color_renderer) inter = vtk.vtkRenderWindowInteractor() self.style = vtk.vtkInteractorStyleUser() inter.SetInteractorStyle(self.style) inter.SetRenderWindow(self.render_window) manager = vcs.vtk_ui.manager.get_manager(inter) self.render_window.AddRenderer(manager.renderer) self.render_window.AddRenderer(manager.actor_renderer) manager.elevate() self.render_window.Render() self.on_save = on_save self.on_cancel = on_cancel maps = vcs.elements["colormap"] current_state = None states = [] self.colormaps = [] for ind, mapname in enumerate(maps.keys()): states.append(ButtonState(label=mapname)) if colormap.name == mapname: current_state = ind self.colormaps.append(maps[mapname]) self.colormap_button = Button(inter, states=states, action=self.change_map, left = 10, top=10) self.colormap_button.set_state(current_state) self.save_button = Button(inter, action=self.save, label="Choose Color", left=int(width * .75) - 10, top=int(height * .85)) self.cancel_button = Button(inter, action=self.cancel, label="Cancel", left=10, top=int(height * .85)) self.colormap_button.show() self.save_button.show() self.cancel_button.show() self.make_current() self.selectedMapper = vtk.vtkDataSetMapper() self.selectedActor = vtk.vtkActor() self.selectedActor.SetMapper(self.selectedMapper); self.selectedActor.GetProperty().EdgeVisibilityOn(); self.selectedActor.GetProperty().SetEdgeColor(0,0,0); self.selectedActor.GetProperty().SetLineWidth(3); self.color = color # Make sure the current color is selected self.selectCell(color) self.color_renderer.AddActor(self.selectedActor) self.click_handler = inter.AddObserver(vtk.vtkCommand.LeftButtonReleaseEvent, self.clickEvent) def noop(obj, event): pass self.char_handler = inter.AddObserver(vtk.vtkCommand.CharEvent, noop)
def test(): import vcs import cdms2 import os import support # import vcs and cu bg = support.bg f = cdms2.open(os.path.join(vcs.sample_data, 'clt.nc')) s = f('clt') # get slab clt x = vcs.init() # construct vcs canvas x.plot(s, 'default', 'isofill', 'quick', bg=bg) # plot slab the old way support.check_plot(x) if bg == 0: x.geometry(450, 337, 0, 0) # change the geometry x.flush() support.check_plot(x) x.getcolormapname() # get the active colormap name x.setcolormap("AMIP") # change the colormap support.check_plot(x) cont = False for anarg in sys.argv: if anarg in ['--extended', '--full', '-E', '-F']: cont = True break if cont is False: print '\n************* PARTIAL TEST *****************' print 'FOR COMPLETE TEST OF THIS MODULE USE ' print ' -F (--full) or -E (--extended) option' print '************* PARTIAL TEST *****************\n' sys.exit() ############################################################ # Change the color map cell 31. # ############################################################ colors = {} cols = [31, 47, 63, 79, 95, 111, 127, 143, 159, 175, 191] for c in cols: colors[c] = [int(float(c - 16) / (191 - 16) * 100.), ] * 3 for c in cols: vals = colors[c] x.setcolorcell(c, vals[0], vals[1], vals[2]) support.check_plot(x) for c in colors.keys(): okvals = colors[c] vals = x.getcolorcell(c) if vals != okvals: raise Exception( "Error setting color %i, should have been : %s, but is %s" % (c, str(okvals), str(vals))) ################################################################## # Retrieve the color map RGB values for the given cell numbers. # ################################################################## ################################################################## # Using colormap objects. # ################################################################## # show the list of line secondary objects c = x.getcolormap('AMIP') # get 'quick' colormap object # check to see if it is a secondary object if not vcs.issecondaryobject(c): raise Exception("Error did not get colormap as secondary obj") else: # check to see if it is a line if not vcs.iscolormap(c): raise Exception("Error object created is not colormap") a = x.listelements('colormap') # show list of xyvsy r = x.createcolormap('new') # create colormap a2 = x.listelements('colormap') # show list of xyvsy if a2 == a: raise "error cm not created or not added to list" x.removeobject(r) # remove xyvsy 'test2' a3 = x.listelements('colormap') # show list of xyvsy if a3 != a: raise Exception("error cm not removed") c3 = x.createcolormap('new') # create a new colormap object from default x.setcolormap('new') # change the colormap to 'new' colormap c3.index # show just the colormap RGB values for c in colors.keys(): vals = colors[c] c3.index[c] = vals # change color cell for c in colors.keys(): okvals = colors[c] vals = x.getcolorcell(c) if vals != okvals: raise Exception( "Error setting color %i, should have been : %s, but is %s" % (c, str(okvals), str(vals))) c3.script('test.scr', 'w') # save 'new' colormap as a VCS script c3.script('test', 'w') # save 'new' colormap as a Python script if support.dogui is True: x.colormapgui() # display the colormap GUI print '***************************************************************************************' print '****** ******' print '****** C O L O R M A P T E S T C O M P L E T E D S U C E S S F U L L Y ******' print '****** ******' print '***************************************************************************************'
def test(): import vcs, cdms2 as cdms, time, os, sys, support # import vcs and cu bg = support.bg f = cdms.open( os.path.join(cdms.__path__[0], '..', '..', '..', '..', 'sample_data', 'clt.nc')) s = f('clt') # get slab clt x = vcs.init() # construct vcs canvas x.plot(s, 'default', 'isofill', 'quick', bg=bg) # plot slab the old way support.check_plot(x) if bg == 0: x.geometry(450, 337, 0, 0) # change the geometry x.flush() support.check_plot(x) x.getcolormapname() # get the active colormap name x.setcolormap("AMIP") # change the colormap support.check_plot(x) cont = False for anarg in sys.argv: if anarg in ['--extended', '--full', '-E', '-F']: cont = True break if cont is False: print '\n************* PARTIAL TEST *****************' print 'FOR COMPLETE TEST OF THIS MODULE USE ' print ' -F (--full) or -E (--extended) option' print '************* PARTIAL TEST *****************\n' sys.exit() ############################################################ # Change the color map cell 31. # ############################################################ colors = {} cols = [31, 47, 63, 79, 95, 111, 127, 143, 159, 175, 191] for c in cols: colors[c] = [ int(float(c - 16) / (191 - 16) * 100.), ] * 3 for c in cols: vals = colors[c] x.setcolorcell(c, vals[0], vals[1], vals[2]) support.check_plot(x) for c in colors.keys(): okvals = colors[c] vals = x.getcolorcell(c) if vals != okvals: raise Exception, "Error setting color %i, should have been : %s, but is %s" % ( c, str(okvals), str(vals)) ################################################################## # Retrieve the color map RGB values for the given cell numbers. # ################################################################## ################################################################## # Using colormap objects. # ################################################################## objs = x.listelements( 'colormap') # show the list of line secondary objects c2 = x.getcolormap() # get 'default' colormap object c = x.getcolormap('AMIP') # get 'quick' colormap object if not vcs.issecondaryobject( c): # check to see if it is a secondary object raise Exception, "Error did not get colormap as secondary obj" else: if not vcs.iscolormap(c): # check to see if it is a line raise Exception, "Error object created is not colormap" a = x.listelements('colormap') # show list of xyvsy r = x.createcolormap('new') # create colormap a2 = x.listelements('colormap') # show list of xyvsy if a2 == a: raise "error cm not created or not added to list" x.removeobject(r) # remove xyvsy 'test2' a3 = x.listelements('colormap') # show list of xyvsy if a3 != a: raise Exception, "error cm not removed" c3 = x.createcolormap('new') # create a new colormap object from default x.setcolormap('new') # change the colormap to 'new' colormap c3.index # show just the colormap RGB values for c in colors.keys(): vals = colors[c] c3.index[c] = vals # change color cell for c in colors.keys(): okvals = colors[c] vals = x.getcolorcell(c) if vals != okvals: raise Exception, "Error setting color %i, should have been : %s, but is %s" % ( c, str(okvals), str(vals)) c3.script('test.scr', 'w') # save 'new' colormap as a VCS script c3.script('test', 'w') # save 'new' colormap as a Python script if support.dogui is True: x.colormapgui() # display the colormap GUI print '***************************************************************************************' print '****** ******' print '****** C O L O R M A P T E S T C O M P L E T E D S U C E S S F U L L Y ******' print '****** ******' print '***************************************************************************************'
def cmap(self, value): if not vcs.iscolormap(value): value = vcs.getcolormap(value) self._real_map = value self._cmap = vcs.createcolormap(Cp_name_src=self._real_map.name) self.update_table()