def CreateLookupTableVTKYellow(size): nc = vtk.vtkNamedColors() myColors = vtk.vtkColorSeries() myColors.SetColorSchemeByName('VTKYellowColors') myColors.AddColor(nc.GetColor3ub('aureoline_yellow')) myColors.AddColor(nc.GetColor3ub('banana')) myColors.AddColor(nc.GetColor3ub('cadmium_lemon')) myColors.AddColor(nc.GetColor3ub('cadmium_yellow')) myColors.AddColor(nc.GetColor3ub('cadmium_yellow_light')) myColors.AddColor(nc.GetColor3ub('gold')) myColors.AddColor(nc.GetColor3ub('goldenrod')) myColors.AddColor(nc.GetColor3ub('goldenrod_dark')) myColors.AddColor(nc.GetColor3ub('goldenrod_light')) myColors.AddColor(nc.GetColor3ub('goldenrod_pale')) myColors.AddColor(nc.GetColor3ub('light_goldenrod')) myColors.AddColor(nc.GetColor3ub('melon')) myColors.AddColor(nc.GetColor3ub('naples_yellow_deep')) myColors.AddColor(nc.GetColor3ub('yellow')) myColors.AddColor(nc.GetColor3ub('yellow_light')) numberOfColors = myColors.GetNumberOfColors() print('Number of colors:', numberOfColors) lut = vtk.vtkLookupTable() if size == 0: lut.SetNumberOfTableValues(numberOfColors) else: lut.SetNumberOfTableValues(size) lut.SetTableRange(0, lut.GetNumberOfTableValues()) for i in range(lut.GetNumberOfTableValues()): color = myColors.GetColorRepeating(i) c = [color.GetRed(), color.GetGreen(), color.GetBlue(), 255] lut.SetTableValue(i, [x / 255.0 for x in c]) return lut
def __init__(self, file_in, traj_file=False, steps_input=5): self.color_series = vtk.vtkColorSeries() self.color_series.SetColorScheme( self.color_series.BREWER_SEQUENTIAL_YELLOW_ORANGE_BROWN_9 ) #set the color theme if not traj_file: self.traj_mode = False if file_in[-3:] == "pdb": self.pdb = pdb.Pdb() self.pdb.ReadFileGMX(file_in) #self.pdb.BringToPositiveCorner() self.marching_cubes = False self.univ = False elif file_in[-3:] == "gro": self.univ = MDAnalysis.Universe(file_in) else: self.traj_mode = True self.univ = MDAnalysis.Universe(file_in, traj_file) self.univ_gro = MDAnalysis.Universe( file_in ) #only load gro file to read coordinates and velocities from. not trajectory self.steps = steps_input # number of steps to consider in the analysis in the whole trajectory file. self.gauss_mean = True # in gaussian curvature case = True / in mean curvature case = False self.test = [] self.test_lines = vtk.vtkCellArray() self.test_points = vtk.vtkPoints()
def CreateLookupTableVTKGrey(size): nc = vtk.vtkNamedColors() myColors = vtk.vtkColorSeries() myColors.SetColorSchemeByName('VTKGreyColors') myColors.AddColor(nc.GetColor3ub('cold_grey')) myColors.AddColor(nc.GetColor3ub('dim_grey')) myColors.AddColor(nc.GetColor3ub('grey')) myColors.AddColor(nc.GetColor3ub('light_grey')) myColors.AddColor(nc.GetColor3ub('slate_grey')) myColors.AddColor(nc.GetColor3ub('slate_grey_dark')) myColors.AddColor(nc.GetColor3ub('slate_grey_light')) myColors.AddColor(nc.GetColor3ub('warm_grey')) numberOfColors = myColors.GetNumberOfColors() print('Number of colors:', numberOfColors) lut = vtk.vtkLookupTable() if size == 0: lut.SetNumberOfTableValues(numberOfColors) else: lut.SetNumberOfTableValues(size) lut.SetTableRange(0, lut.GetNumberOfTableValues()) for i in range(lut.GetNumberOfTableValues()): color = myColors.GetColorRepeating(i) c = [color.GetRed(), color.GetGreen(), color.GetBlue(), 255] lut.SetTableValue(i, [x / 255.0 for x in c]) return lut
def CreateLookupTableVTKCyan(size): nc = vtk.vtkNamedColors() myColors = vtk.vtkColorSeries() myColors.SetColorSchemeByName('VTKCyanColors') myColors.AddColor(nc.GetColor3ub('aquamarine')) myColors.AddColor(nc.GetColor3ub('aquamarine_medium')) myColors.AddColor(nc.GetColor3ub('cyan')) myColors.AddColor(nc.GetColor3ub('cyan_white')) myColors.AddColor(nc.GetColor3ub('turquoise')) myColors.AddColor(nc.GetColor3ub('turquoise_dark')) myColors.AddColor(nc.GetColor3ub('turquoise_medium')) myColors.AddColor(nc.GetColor3ub('turquoise_pale')) numberOfColors = myColors.GetNumberOfColors() print('Number of colors:', numberOfColors) lut = vtk.vtkLookupTable() if size == 0: lut.SetNumberOfTableValues(numberOfColors) else: lut.SetNumberOfTableValues(size) lut.SetTableRange(0, lut.GetNumberOfTableValues()) for i in range(lut.GetNumberOfTableValues()): color = myColors.GetColorRepeating(i) c = [color.GetRed(), color.GetGreen(), color.GetBlue(), 255] lut.SetTableValue(i, [x / 255.0 for x in c]) return lut
def CreateLookupTableVTKMagenta(size): nc = vtk.vtkNamedColors() myColors = vtk.vtkColorSeries() myColors.SetColorSchemeByName('VTKMagentaColors') myColors.AddColor(nc.GetColor3ub('blue_violet')) myColors.AddColor(nc.GetColor3ub('cobalt_violet_deep')) myColors.AddColor(nc.GetColor3ub('magenta')) myColors.AddColor(nc.GetColor3ub('orchid')) myColors.AddColor(nc.GetColor3ub('orchid_dark')) myColors.AddColor(nc.GetColor3ub('orchid_medium')) myColors.AddColor(nc.GetColor3ub('permanent_red_violet')) myColors.AddColor(nc.GetColor3ub('plum')) myColors.AddColor(nc.GetColor3ub('purple')) myColors.AddColor(nc.GetColor3ub('purple_medium')) myColors.AddColor(nc.GetColor3ub('ultramarine_violet')) myColors.AddColor(nc.GetColor3ub('violet')) myColors.AddColor(nc.GetColor3ub('violet_dark')) myColors.AddColor(nc.GetColor3ub('violet_red')) myColors.AddColor(nc.GetColor3ub('violet_red_medium')) myColors.AddColor(nc.GetColor3ub('violet_red_pale')) numberOfColors = myColors.GetNumberOfColors() print('Number of colors:', numberOfColors) lut = vtk.vtkLookupTable() if size == 0: lut.SetNumberOfTableValues(numberOfColors) else: lut.SetNumberOfTableValues(size) lut.SetTableRange(0, lut.GetNumberOfTableValues()) for i in range(lut.GetNumberOfTableValues()): color = myColors.GetColorRepeating(i) c = [color.GetRed(), color.GetGreen(), color.GetBlue(), 255] lut.SetTableValue(i, [x / 255.0 for x in c]) return lut
def CreateLookupTableVTKOrange(size): nc = vtk.vtkNamedColors() myColors = vtk.vtkColorSeries() myColors.SetColorSchemeByName('VTKOrangeColors') myColors.AddColor(nc.GetColor3ub('cadmium_orange')) myColors.AddColor(nc.GetColor3ub('cadmium_red_light')) myColors.AddColor(nc.GetColor3ub('carrot')) myColors.AddColor(nc.GetColor3ub('dark_orange')) myColors.AddColor(nc.GetColor3ub('mars_orange')) myColors.AddColor(nc.GetColor3ub('mars_yellow')) myColors.AddColor(nc.GetColor3ub('orange')) myColors.AddColor(nc.GetColor3ub('orange_red')) myColors.AddColor(nc.GetColor3ub('yellow_ochre')) numberOfColors = myColors.GetNumberOfColors() print('Number of colors:', numberOfColors) lut = vtk.vtkLookupTable() if size == 0: lut.SetNumberOfTableValues(numberOfColors) else: lut.SetNumberOfTableValues(size) lut.SetTableRange(0, lut.GetNumberOfTableValues()) for i in range(lut.GetNumberOfTableValues()): color = myColors.GetColorRepeating(i) c = [color.GetRed(), color.GetGreen(), color.GetBlue(), 255] lut.SetTableValue(i, [x / 255.0 for x in c]) return lut
def MakeLUT(scalarRange): """ Make a lookup table using a predefined color series. :param scalarRange: The range of the scalars to be coloured. :return: A lookup table. """ colorSeries = vtk.vtkColorSeries() # Select a color scheme. # for i in range(0,62): # colorSeries.SetColorScheme(i) # print('Colour scheme {:2d}: {:s}'.format(colorSeries.GetColorScheme(), colorSeries.GetColorSchemeName())) # Colour scheme 61: Brewer Qualitative Set3 colorSeries.SetColorScheme(61) # We use this colour series to create the transfer function. lut = vtk.vtkColorTransferFunction() lut.SetColorSpaceToHSV() numColors = colorSeries.GetNumberOfColors() for i in range(0, numColors): color = vtk.vtkColor3ub(colorSeries.GetColor(i)) c = list() for j in range(0, 3): c.append(color[j] / 255.0) t = scalarRange[0] + (scalarRange[1] - scalarRange[0]) / (numColors - 1) * i lut.AddRGBPoint(t, *c) return lut
def ShowPolyData(in_polydata, caption=""): """Visualize the in_polydata surface which has scalar values which will be colour-coded. """ if True: color_series = vtk.vtkColorSeries() color_series.SetColorScheme( color_series.BREWER_DIVERGING_SPECTRAL_10) #set the color theme lut = vtk.vtkColorTransferFunction() lut.SetColorSpaceToHSV() num_colors = color_series.GetNumberOfColors() d_color = [0.0, 0.0, 0.0] scalar_range = [0.0, 0.0] #[-0.002,0.001] # in_polydata.GetPointData().GetScalars().GetRange(scalar_range) # for i in range(num_colors): # color = color_series.GetColor(i) # d_color[0] = color[0] / 255.0 # d_color[1] = color[1] / 255.0 # d_color[2] = color[2] / 255.0 # t= scalar_range[0] + (scalar_range[1] - scalar_range[0]) * i / (num_colors - 1) # lut.AddRGBPoint(t, d_color[0], d_color[1], d_color[2]); ##Create a mapper and actor mapper = vtk.vtkPolyDataMapper() # mapper.UseLookupTableScalarRangeOn() mapper.SetInputData( in_polydata) #SetInputConnection() is for algorithm not polydata # mapper.SetLookupTable(lut) # mapper.SetScalarRange(scalar_range) actor = vtk.vtkActor() actor.SetMapper(mapper) ##Create a scalar bar actor scalarBar = vtk.vtkScalarBarActor() scalarBar.SetLookupTable(mapper.GetLookupTable()) scalarBar.SetNumberOfLabels(5) ##Create text actor text_actor = vtk.vtkTextActor() text_actor.SetInput(caption) text_actor.GetTextProperty().SetFontSize(20) text_actor.GetTextProperty().SetColor(0.5, 0.5, 0.5) text_actor.SetPosition(100, 16) renderer = vtk.vtkRenderer() renderer.SetBackground([0.5, 0.5, 0.5]) renderer.AddActor(actor) renderer.AddActor2D(scalarBar) renderer.AddActor2D(text_actor) #### window = vtk.vtkRenderWindow() interactor = vtk.vtkRenderWindowInteractor() interactor.SetInteractorStyle(molar.pdb_viewer.PdbInteractorStyle()) interactor.SetRenderWindow(window) window.SetSize(1800, 1200) window.AddRenderer(renderer) window.Render() interactor.Start()
def visualize3D(self, axis=0): ########################################################### # VISUALIZATION ########################################################### # This is a bit annoying: ensure a proper color-lookup. colorSeries = vtk.vtkColorSeries() colorSeries.SetColorScheme( vtk.vtkColorSeries.BREWER_DIVERGING_SPECTRAL_10) lut = vtk.vtkColorTransferFunction() lut.SetColorSpaceToHSV() nColors = colorSeries.GetNumberOfColors() for i in range(0, nColors): color = colorSeries.GetColor(i) color = [c / 255.0 for c in color] t = self.zMin + float(self.zMax - self.zMin) / (nColors - 1) * i lut.AddRGBPoint(t, color[0], color[1], color[2]) # Mapper. # mapper = vtk.vtkPolyDataMapper() # mapper.SetInputConnection(self.map2D.GetOutputPort()) # mapper.ScalarVisibilityOn() # mapper.SetScalarModeToUsePointData() # mapper.SetLookupTable(lut) # mapper.SetColorModeToMapScalars() mapper = vtk.vtkDataSetMapper() mapper.SetInputData(self.map3D) mapper.SetScalarRange(self.map3D.GetScalarRange()) mapper.SetLookupTable(lut) mapper.SetColorModeToMapScalars() # Actor. actor = vtk.vtkActor() actor.SetMapper(mapper) # Renderer. renderer = vtk.vtkRenderer() renderer.SetBackground([0.5] * 3) # Axis if axis == 1: transform = vtk.vtkTransform() transform.Translate(0.0, 0.0, 0.0) transform.Scale(2., 2., 2.) axes = vtk.vtkAxesActor() # The axes are positioned with a user transform axes.SetUserTransform(transform) renderer.AddActor(axes) # Render window and interactor. renderWindow = vtk.vtkRenderWindow() renderWindow.SetWindowName('Psi') renderWindow.AddRenderer(renderer) renderer.AddActor(actor) interactor = vtk.vtkRenderWindowInteractor() interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera()) interactor.SetRenderWindow(renderWindow) renderWindow.Render() interactor.Start()
def MakeLogLUT(lut): # Make the lookup using a Brewer palette. colorSeries = vtk.vtkColorSeries() colorSeries.SetNumberOfColors(8) colorSeriesEnum = colorSeries.BREWER_DIVERGING_SPECTRAL_8 colorSeries.SetColorScheme(colorSeriesEnum) lut.SetScaleToLog10() colorSeries.BuildLookupTable(lut, colorSeries.ORDINAL) lut.SetNanColor(1, 0, 0, 1)
def GetAllColorSchemes(): ''' Get all the color scheme names. :return: a map of the names keyed on their index. ''' colorSchemes = dict() colorSeries = vtk.vtkColorSeries() for i in range(colorSeries.GetNumberOfColorSchemes()): colorSeries.SetColorScheme(i) colorSchemes[i] = colorSeries.GetColorSchemeName() return colorSchemes
def __init__(self): cs = vtk.vtkColorSeries() sizes = list() for i in range(0, cs.GetNumberOfColorSchemes()): cs.SetColorScheme(i) sizes.append(cs.GetNumberOfColors()) vc = list() for j in range(0, cs.GetNumberOfColors()): vc.append(cs.GetColor(j)) self.cs_colors[i] = [cs.GetColorSchemeName(), vc] self.max_colors = max(sizes)
def MakeLUT(color_scheme=0): """ Make a lookup table. :param color_scheme: Select the type of lookup table. :return: The lookup table. """ colors = vtk.vtkNamedColors() if color_scheme == 1: # A lookup table of 256 colours ranging from # deep blue (water) to yellow-white (mountain top) # is used to color map this figure. lut = vtk.vtkLookupTable() lut.SetHueRange(0.7, 0) lut.SetSaturationRange(1.0, 0) lut.SetValueRange(0.5, 1.0) elif color_scheme == 2: # Make the lookup table with a preset number of colours. colorSeries = vtk.vtkColorSeries() colorSeries.SetNumberOfColors(8) colorSeries.SetColorSchemeName('Hawaii') colorSeries.SetColor(0, colors.GetColor3ub("turquoise_blue")) colorSeries.SetColor(1, colors.GetColor3ub("sea_green_medium")) colorSeries.SetColor(2, colors.GetColor3ub("sap_green")) colorSeries.SetColor(3, colors.GetColor3ub("green_dark")) colorSeries.SetColor(4, colors.GetColor3ub("tan")) colorSeries.SetColor(5, colors.GetColor3ub("beige")) colorSeries.SetColor(6, colors.GetColor3ub("light_beige")) colorSeries.SetColor(7, colors.GetColor3ub("bisque")) lut = vtk.vtkLookupTable() colorSeries.BuildLookupTable(lut, colorSeries.ORDINAL) lut.SetNanColor(1, 0, 0, 1) else: # Make the lookup using a Brewer palette. colorSeries = vtk.vtkColorSeries() colorSeries.SetNumberOfColors(8) colorSeriesEnum = colorSeries.BREWER_DIVERGING_BROWN_BLUE_GREEN_8 colorSeries.SetColorScheme(colorSeriesEnum) lut = vtk.vtkLookupTable() colorSeries.BuildLookupTable(lut, colorSeries.ORDINAL) lut.SetNanColor(1, 0, 0, 1) return lut
def get_lookup_table(colorSeriesEnum=15): """ creates a color lookup table @param colorSeriesEnum the number of the predefined color table, see VTKColorSeriesPatches.html @return A vtkLookupTable @todo I don't know how to modify the number of colors used (or how to interpolate between) """ colorSeries = vtk.vtkColorSeries() colorSeries.SetColorScheme(colorSeriesEnum) lut = vtk.vtkLookupTable() colorSeries.BuildLookupTable(lut, vtk.vtkColorSeries.ORDINAL) return lut
def imageComparison(self, mod, created, imagePath, doInteract): if self.haveVTK() and self.haveVTKExtension(): from vtk import vtkColorSeries self.startRenderTest() # mod = smtk.model.Model(mod) #[mod.addCell(x) for x in self.mgr.findEntitiesOfType(smtk.model.CELL_ENTITY, False)] # Color faces but not edges or vertices flist = [created.value(i) for i in range(created.numberOfValues())] cs = vtkColorSeries() cs.SetColorScheme(vtkColorSeries.BREWER_QUALITATIVE_SET1) clist = [cs.GetColor(i) for i in range(cs.GetNumberOfColors())] faceColors = [(c.GetRed() / 255., c.GetGreen() / 255., c.GetBlue() / 255., 1.0) for c in clist] for fi in range(len(flist)): flist[fi].setFloatProperty('color', faceColors[fi % len(faceColors)]) [ v.setFloatProperty('color', [0, 0, 0, 1]) for v in self.mgr.findEntitiesOfType(smtk.model.VERTEX, True) ] [ e.setFloatProperty('color', [0, 0, 0, 1]) for e in self.mgr.findEntitiesOfType(smtk.model.EDGE, True) ] ms, vs, mp, ac = self.addModelToScene(mod) ac.GetProperty().SetLineWidth(2) ac.GetProperty().SetPointSize(6) self.renderer.SetBackground(1.0, 1.0, 1.0) cam = self.renderer.GetActiveCamera() cam.SetFocalPoint(5, 5, 0) cam.SetPosition(5, 5, 5) cam.SetViewUp(0, 1, 0) self.renderer.ResetCamera() self.renderWindow.Render() smtk.testing.INTERACTIVE = doInteract # Skip the image match if we don't have a baseline. # This allows the test to succeed even on systems without the test # data but requires a match on systems with the test data. self.assertImageMatchIfFileExists(imagePath, 70) # self.assertImageMatch(imagePath) self.interact() else: self.assertFalse( self.haveVTKExtension(), 'Could not import vtk. Python path is {pp}'.format( pp=sys.path))
def __init__(self): self.types = {} self.autogen_used = 0 self.colors = [] colorScheme = vtk.vtkColorSeries() for i in [1, 2, 3]: colorScheme.SetColorSchemeByName( "Brewer Qualitative Set{}".format(i)) for i in range(colorScheme.GetNumberOfColors()): c = colorScheme.GetColor(i) if np.any(np.array(c) != 0): self.colors.append(np.array(c) / 255.0)
def CreateLookupTableVTKWhite(size): nc = vtk.vtkNamedColors() myColors = vtk.vtkColorSeries() myColors.SetColorSchemeByName('VTKWhiteColors') myColors.AddColor(nc.GetColor3ub('antique_white')) myColors.AddColor(nc.GetColor3ub('azure')) myColors.AddColor(nc.GetColor3ub('bisque')) myColors.AddColor(nc.GetColor3ub('blanched_almond')) myColors.AddColor(nc.GetColor3ub('cornsilk')) myColors.AddColor(nc.GetColor3ub('eggshell')) myColors.AddColor(nc.GetColor3ub('floral_white')) myColors.AddColor(nc.GetColor3ub('gainsboro')) myColors.AddColor(nc.GetColor3ub('ghost_white')) myColors.AddColor(nc.GetColor3ub('honeydew')) myColors.AddColor(nc.GetColor3ub('ivory')) myColors.AddColor(nc.GetColor3ub('lavender')) myColors.AddColor(nc.GetColor3ub('lavender_blush')) myColors.AddColor(nc.GetColor3ub('lemon_chiffon')) myColors.AddColor(nc.GetColor3ub('linen')) myColors.AddColor(nc.GetColor3ub('mint_cream')) myColors.AddColor(nc.GetColor3ub('misty_rose')) myColors.AddColor(nc.GetColor3ub('moccasin')) myColors.AddColor(nc.GetColor3ub('navajo_white')) myColors.AddColor(nc.GetColor3ub('old_lace')) myColors.AddColor(nc.GetColor3ub('papaya_whip')) myColors.AddColor(nc.GetColor3ub('peach_puff')) myColors.AddColor(nc.GetColor3ub('seashell')) myColors.AddColor(nc.GetColor3ub('snow')) myColors.AddColor(nc.GetColor3ub('thistle')) myColors.AddColor(nc.GetColor3ub('titanium_white')) myColors.AddColor(nc.GetColor3ub('wheat')) myColors.AddColor(nc.GetColor3ub('white')) myColors.AddColor(nc.GetColor3ub('white_smoke')) myColors.AddColor(nc.GetColor3ub('zinc_white')) numberOfColors = myColors.GetNumberOfColors() print('Number of colors:', numberOfColors) lut = vtk.vtkLookupTable() if size == 0: lut.SetNumberOfTableValues(numberOfColors) else: lut.SetNumberOfTableValues(size) lut.SetTableRange(0, lut.GetNumberOfTableValues()) for i in range(lut.GetNumberOfTableValues()): color = myColors.GetColorRepeating(i) c = [color.GetRed(), color.GetGreen(), color.GetBlue(), 255] lut.SetTableValue(i, [x / 255.0 for x in c]) return lut
def imageComparison(self, mod, edges, imagePath, doInteract): if self.haveVTK() and self.haveVTKExtension(): from vtk import vtkColorSeries self.startRenderTest() # mod = smtk.model.Model(mod) #[mod.addCell(x) for x in self.resource.findEntitiesOfType(smtk.model.CELL_ENTITY, False)] # Color faces but not edges or vertices cs = vtkColorSeries() cs.SetColorScheme(vtkColorSeries.BREWER_QUALITATIVE_SET1) clist = [cs.GetColor(i) for i in range(cs.GetNumberOfColors())] edgeColors = [(c.GetRed() / 255., c.GetGreen() / 255., c.GetBlue() / 255., 1.0) for c in clist] ents = self.resource.findEntitiesOfType( smtk.model.CELL_ENTITY, False) for ei in range(len(ents)): ents[ei].setFloatProperty( 'color', edgeColors[ei % len(edgeColors)]) print(ents[ei].name(), ' color ', edgeColors[ei % len(edgeColors)]) #[v.setFloatProperty('color', [0,0,0,1]) for v in self.resource.findEntitiesOfType(smtk.model.VERTEX, True)] #[e.setFloatProperty('color', [0,0,0,1]) for e in self.resource.findEntitiesOfType(smtk.model.EDGE, True)] ms, vs, mp, ac = self.addModelToScene(mod) ac.GetProperty().SetLineWidth(2) ac.GetProperty().SetPointSize(6) self.renderer.SetBackground(1.0, 1.0, 1.0) cam = self.renderer.GetActiveCamera() cam.SetFocalPoint(5, 5, 0) cam.SetPosition(5, 5, 5) cam.SetViewUp(0, 1, 0) self.renderer.ResetCamera() self.renderWindow.Render() # smtk.testing.INTERACTIVE = doInteract # Skip the image match if we don't have a baseline. # This allows the test to succeed even on systems without the test # data but requires a match on systems with the test data. # self.assertImageMatchIfFileExists(imagePath, 70) # self.assertImageMatch(imagePath) self.interact() else: self.assertFalse( self.haveVTKExtension(), 'Could not import vtk. Python path is {pp}'.format(pp=sys.path))
def CreateLookupTableVTKGreen(size): nc = vtk.vtkNamedColors() myColors = vtk.vtkColorSeries() myColors.SetColorSchemeByName('VTKGreenColors') myColors.AddColor(nc.GetColor3ub('chartreuse')) myColors.AddColor(nc.GetColor3ub('chrome_oxide_green')) myColors.AddColor(nc.GetColor3ub('cinnabar_green')) myColors.AddColor(nc.GetColor3ub('cobalt_green')) myColors.AddColor(nc.GetColor3ub('emerald_green')) myColors.AddColor(nc.GetColor3ub('forest_green')) myColors.AddColor(nc.GetColor3ub('green')) myColors.AddColor(nc.GetColor3ub('green_dark')) myColors.AddColor(nc.GetColor3ub('green_pale')) myColors.AddColor(nc.GetColor3ub('green_yellow')) myColors.AddColor(nc.GetColor3ub('lawn_green')) myColors.AddColor(nc.GetColor3ub('lime_green')) myColors.AddColor(nc.GetColor3ub('mint')) myColors.AddColor(nc.GetColor3ub('olive')) myColors.AddColor(nc.GetColor3ub('olive_drab')) myColors.AddColor(nc.GetColor3ub('olive_green_dark')) myColors.AddColor(nc.GetColor3ub('permanent_green')) myColors.AddColor(nc.GetColor3ub('sap_green')) myColors.AddColor(nc.GetColor3ub('sea_green')) myColors.AddColor(nc.GetColor3ub('sea_green_dark')) myColors.AddColor(nc.GetColor3ub('sea_green_medium')) myColors.AddColor(nc.GetColor3ub('sea_green_light')) myColors.AddColor(nc.GetColor3ub('spring_green')) myColors.AddColor(nc.GetColor3ub('spring_green_medium')) myColors.AddColor(nc.GetColor3ub('terre_verte')) myColors.AddColor(nc.GetColor3ub('viridian_light')) myColors.AddColor(nc.GetColor3ub('yellow_green')) numberOfColors = myColors.GetNumberOfColors() print('Number of colors:', numberOfColors) lut = vtk.vtkLookupTable() if size == 0: lut.SetNumberOfTableValues(numberOfColors) else: lut.SetNumberOfTableValues(size) lut.SetTableRange(0, lut.GetNumberOfTableValues()) for i in range(lut.GetNumberOfTableValues()): color = myColors.GetColorRepeating(i) c = [color.GetRed(), color.GetGreen(), color.GetBlue(), 255] lut.SetTableValue(i, [x / 255.0 for x in c]) return lut
def CreateLookupTableVTKBlue(size): nc = vtk.vtkNamedColors() myColors = vtk.vtkColorSeries() myColors.SetColorSchemeByName('VTKBlueColors') myColors.AddColor(nc.GetColor3ub('alice_blue')) myColors.AddColor(nc.GetColor3ub('blue')) myColors.AddColor(nc.GetColor3ub('blue_light')) myColors.AddColor(nc.GetColor3ub('blue_medium')) myColors.AddColor(nc.GetColor3ub('cadet')) myColors.AddColor(nc.GetColor3ub('cobalt')) myColors.AddColor(nc.GetColor3ub('cornflower')) myColors.AddColor(nc.GetColor3ub('cerulean')) myColors.AddColor(nc.GetColor3ub('dodger_blue')) myColors.AddColor(nc.GetColor3ub('indigo')) myColors.AddColor(nc.GetColor3ub('manganese_blue')) myColors.AddColor(nc.GetColor3ub('midnight_blue')) myColors.AddColor(nc.GetColor3ub('navy')) myColors.AddColor(nc.GetColor3ub('peacock')) myColors.AddColor(nc.GetColor3ub('powder_blue')) myColors.AddColor(nc.GetColor3ub('royal_blue')) myColors.AddColor(nc.GetColor3ub('slate_blue')) myColors.AddColor(nc.GetColor3ub('slate_blue_dark')) myColors.AddColor(nc.GetColor3ub('slate_blue_light')) myColors.AddColor(nc.GetColor3ub('slate_blue_medium')) myColors.AddColor(nc.GetColor3ub('sky_blue')) myColors.AddColor(nc.GetColor3ub('sky_blue_deep')) myColors.AddColor(nc.GetColor3ub('sky_blue_light')) myColors.AddColor(nc.GetColor3ub('steel_blue')) myColors.AddColor(nc.GetColor3ub('steel_blue_light')) myColors.AddColor(nc.GetColor3ub('turquoise_blue')) myColors.AddColor(nc.GetColor3ub('ultramarine')) numberOfColors = myColors.GetNumberOfColors() print('Number of colors:', numberOfColors) lut = vtk.vtkLookupTable() if size == 0: lut.SetNumberOfTableValues(numberOfColors) else: lut.SetNumberOfTableValues(size) lut.SetTableRange(0, lut.GetNumberOfTableValues()) for i in range(lut.GetNumberOfTableValues()): color = myColors.GetColorRepeating(i) c = [color.GetRed(), color.GetGreen(), color.GetBlue(), 255] lut.SetTableValue(i, [x / 255.0 for x in c]) return lut
def CreateLookupTableVTKBrown(size): nc = vtk.vtkNamedColors() myColors = vtk.vtkColorSeries() myColors.SetColorSchemeByName('VTKBrownColors') myColors.AddColor(nc.GetColor3ub('beige')) myColors.AddColor(nc.GetColor3ub('brown')) myColors.AddColor(nc.GetColor3ub('brown_madder')) myColors.AddColor(nc.GetColor3ub('brown_ochre')) myColors.AddColor(nc.GetColor3ub('burlywood')) myColors.AddColor(nc.GetColor3ub('burnt_sienna')) myColors.AddColor(nc.GetColor3ub('burnt_umber')) myColors.AddColor(nc.GetColor3ub('chocolate')) myColors.AddColor(nc.GetColor3ub('deep_ochre')) myColors.AddColor(nc.GetColor3ub('flesh')) myColors.AddColor(nc.GetColor3ub('flesh_ochre')) myColors.AddColor(nc.GetColor3ub('gold_ochre')) myColors.AddColor(nc.GetColor3ub('greenish_umber')) myColors.AddColor(nc.GetColor3ub('khaki')) myColors.AddColor(nc.GetColor3ub('khaki_dark')) myColors.AddColor(nc.GetColor3ub('light_beige')) myColors.AddColor(nc.GetColor3ub('peru')) myColors.AddColor(nc.GetColor3ub('rosy_brown')) myColors.AddColor(nc.GetColor3ub('raw_sienna')) myColors.AddColor(nc.GetColor3ub('raw_umber')) myColors.AddColor(nc.GetColor3ub('sepia')) myColors.AddColor(nc.GetColor3ub('sienna')) myColors.AddColor(nc.GetColor3ub('saddle_brown')) myColors.AddColor(nc.GetColor3ub('sandy_brown')) myColors.AddColor(nc.GetColor3ub('tan')) myColors.AddColor(nc.GetColor3ub('van_dyke_brown')) numberOfColors = myColors.GetNumberOfColors() print('Number of colors:', numberOfColors) lut = vtk.vtkLookupTable() if size == 0: lut.SetNumberOfTableValues(numberOfColors) else: lut.SetNumberOfTableValues(size) lut.SetTableRange(0, lut.GetNumberOfTableValues()) for i in range(lut.GetNumberOfTableValues()): color = myColors.GetColorRepeating(i) c = [color.GetRed(), color.GetGreen(), color.GetBlue(), 255] lut.SetTableValue(i, [x / 255.0 for x in c]) return lut
def CreateLookupTableVTKRed(size): nc = vtk.vtkNamedColors() myColors = vtk.vtkColorSeries() myColors.SetColorSchemeByName('VTKRedColors') myColors.AddColor(nc.GetColor3ub('alizarin_crimson')) myColors.AddColor(nc.GetColor3ub('brick')) myColors.AddColor(nc.GetColor3ub('cadmium_red_deep')) myColors.AddColor(nc.GetColor3ub('coral')) myColors.AddColor(nc.GetColor3ub('coral_light')) myColors.AddColor(nc.GetColor3ub('deep_pink')) myColors.AddColor(nc.GetColor3ub('english_red')) myColors.AddColor(nc.GetColor3ub('firebrick')) myColors.AddColor(nc.GetColor3ub('geranium_lake')) myColors.AddColor(nc.GetColor3ub('hot_pink')) myColors.AddColor(nc.GetColor3ub('indian_red')) myColors.AddColor(nc.GetColor3ub('light_salmon')) myColors.AddColor(nc.GetColor3ub('madder_lake_deep')) myColors.AddColor(nc.GetColor3ub('maroon')) myColors.AddColor(nc.GetColor3ub('pink')) myColors.AddColor(nc.GetColor3ub('pink_light')) myColors.AddColor(nc.GetColor3ub('raspberry')) myColors.AddColor(nc.GetColor3ub('red')) myColors.AddColor(nc.GetColor3ub('rose_madder')) myColors.AddColor(nc.GetColor3ub('salmon')) myColors.AddColor(nc.GetColor3ub('tomato')) myColors.AddColor(nc.GetColor3ub('venetian_red')) numberOfColors = myColors.GetNumberOfColors() print('Number of colors:', numberOfColors) lut = vtk.vtkLookupTable() if size == 0: lut.SetNumberOfTableValues(numberOfColors) else: lut.SetNumberOfTableValues(size) lut.SetTableRange(0, lut.GetNumberOfTableValues()) for i in range(lut.GetNumberOfTableValues()): color = myColors.GetColorRepeating(i) c = [color.GetRed(), color.GetGreen(), color.GetBlue(), 255] lut.SetTableValue(i, [x / 255.0 for x in c]) return lut
def _addPlotObject(self, line): """ A helper method for inserting a line, handling color automatically, into the graph. Args: line[chigger.graph.Line]: The line object to add to this graph. """ # Initialize the line (this creates the vtk object) if line.needsInitialize(): line.initialize() # Set the line color, if not set by the user if not line.isOptionValid('color'): # Colors if self._vtkcolorseries is None: self._vtkcolorseries = vtk.vtkColorSeries() if self.isOptionValid('color_scheme'): scheme = eval('vtk.vtkColorSeries.' + self.getOption('color_scheme').upper()) self._vtkcolorseries.SetColorScheme(scheme) n_lines = len(self._plots) n_colors = self._vtkcolorseries.GetNumberOfColors() if n_lines >= n_colors: mooseutils.mooseWarning( 'The number of lines exceeds the number of available ' 'line colors.') c = self._vtkcolorseries.GetColorRepeating(n_lines) b = self.getOption('background') # If the color matches the background, flip it if (c[0] == b[0]) and (c[1] == b[1]) and (c[2] == c[2]): c[0] = 1 - c[0] c[1] = 1 - c[1] c[2] = 1 - c[2] line.setOption('color', c) self._plots.append(line)
def MakeLUT(): ''' Make a lookup table using vtkColorSeries. :return: An indexed lookup table. ''' # Make the lookup table. colorSeries = vtk.vtkColorSeries() # Select a color scheme. #colorSeriesEnum = colorSeries.BREWER_DIVERGING_BROWN_BLUE_GREEN_9 #colorSeriesEnum = colorSeries.BREWER_DIVERGING_SPECTRAL_10 #colorSeriesEnum = colorSeries.BREWER_DIVERGING_SPECTRAL_3 #colorSeriesEnum = colorSeries.BREWER_DIVERGING_PURPLE_ORANGE_9 #colorSeriesEnum = colorSeries.BREWER_SEQUENTIAL_BLUE_PURPLE_9 #colorSeriesEnum = colorSeries.BREWER_SEQUENTIAL_BLUE_GREEN_9 colorSeriesEnum = colorSeries.BREWER_QUALITATIVE_SET3 #colorSeriesEnum = colorSeries.CITRUS colorSeries.SetColorScheme(colorSeriesEnum) lut = vtk.vtkLookupTable() colorSeries.BuildLookupTable(lut) lut.SetNanColor(0,0,0,1) return lut
def MakeLUT(): ''' Make a lookup table using vtkColorSeries. :return: An indexed lookup table. ''' # Make the lookup table. colorSeries = vtk.vtkColorSeries() # Select a color scheme. #colorSeriesEnum = colorSeries.BREWER_DIVERGING_BROWN_BLUE_GREEN_9 #colorSeriesEnum = colorSeries.BREWER_DIVERGING_SPECTRAL_10 #colorSeriesEnum = colorSeries.BREWER_DIVERGING_SPECTRAL_3 #colorSeriesEnum = colorSeries.BREWER_DIVERGING_PURPLE_ORANGE_9 #colorSeriesEnum = colorSeries.BREWER_SEQUENTIAL_BLUE_PURPLE_9 #colorSeriesEnum = colorSeries.BREWER_SEQUENTIAL_BLUE_GREEN_9 colorSeriesEnum = colorSeries.BREWER_QUALITATIVE_SET3 #colorSeriesEnum = colorSeries.CITRUS colorSeries.SetColorScheme(colorSeriesEnum) lut = vtk.vtkLookupTable() colorSeries.BuildLookupTable(lut) lut.SetNanColor(1, 0, 0, 1) return lut
def __init__(self, name=None): """Constructor @type name: str @param name: Graph name, defaults to None """ self._name = name self._directed = False self._vertex_dict = {} self._edge_dict = {} self._weights = vtk.vtkDoubleArray() self._weights.SetName('Weights') self._weights.SetNumberOfComponents(1) self._labels = vtk.vtkStringArray() self._labels.SetNumberOfComponents(1) self._labels.SetName('labels') self._graph = vtk.vtkMutableDirectedGraph() self._color_picker = vtk.vtkColorSeries() self._color_dict = {} self._colors = [] self._vertex_types = 1
def _addPlotObject(self, line): """ A helper method for inserting a line, handling color automatically, into the graph. Args: line[chigger.graph.Line]: The line object to add to this graph. """ # Initialize the line (this creates the vtk object) if line.needsInitialize(): line.initialize() # Set the line color, if not set by the user if not line.isOptionValid('color'): # Colors if self._vtkcolorseries is None: self._vtkcolorseries = vtk.vtkColorSeries() if self.isOptionValid('color_scheme'): scheme = eval('vtk.vtkColorSeries.' + self.getOption('color_scheme').upper()) self._vtkcolorseries.SetColorScheme(scheme) n_lines = len(self._plots) n_colors = self._vtkcolorseries.GetNumberOfColors() if n_lines >= n_colors: mooseutils.mooseWarning('The number of lines exceeds the number of available ' 'line colors.') c = self._vtkcolorseries.GetColorRepeating(n_lines) b = self.getOption('background') # If the color matches the background, flip it if (c[0] == b[0]) and (c[1] == b[1]) and (c[2] == c[2]): c[0] = 1 - c[0] c[1] = 1 - c[1] c[2] = 1 - c[2] line.setOption('color', c) self._plots.append(line)
def create_lookup_table(tableIdx=15, numberOfColors=256): """ creates a color lookup table @param tableIdx index of the predefined color table, see VTKColorSeriesPatches.html @param numberOfColors number of colors interpolated from the predefined table @return A vtkLookupTable """ colorSeries = vtk.vtkColorSeries() colorSeries.SetColorScheme(tableIdx) lut_ = colorSeries.CreateLookupTable(vtk.vtkColorSeries.ORDINAL) n = lut_.GetNumberOfTableValues() lut = vtk.vtkLookupTable() lut.SetNumberOfTableValues(numberOfColors) for i in range(0, numberOfColors): psi = (n - 1) * (float(i) / numberOfColors) i0 = np.floor(psi) theta = psi - i0 col = (1 - theta) * np.array(lut_.GetTableValue( int(i0))) + theta * np.array(lut_.GetTableValue(int(i0) + 1)) lut.SetTableValue(i, col) return lut
slicer2 = vtk.vtkImageReslice() slicer2.SetInputData(img2) slicer2.SetOutputDimensionality(2) slicer2.SetResliceAxesOrigin(center_X,center_Y,center_Z) slicer2.SetResliceAxesDirectionCosines(dir_X,dir_Y,dir_Z) # lookup table ''' table = vtk.vtkWindowLevelLookupTable() range_l = img1.GetOutput().GetScalarRange[0] range_h = img1.GetOutput().GetScalarRange[1] print range_h print range_l ''' colorSeries = vtk.vtkColorSeries() colorSeriesEnum = colorSeries.BREWER_QUALITATIVE_SET3 colorSeries.SetColorScheme(colorSeriesEnum) lut = vtk.vtkLookupTable() colorSeries.BuildLookupTable(lut) lut.SetNanColor(1,0,0,1) # lut = vtk.vtkWindowLevelLookupTable() lut.SetWindow(1000) lut.SetLevel(500) mapper1 = vtk.vtkDataSetMapper() mapper1.SetInputData(slicer1.GetOutput()) mapper1.SetLookupTable(lut)
subdivisionFilter = vtk.vtkLoopSubdivisionFilter() subdivisionFilter.SetNumberOfSubdivisions(2) #set the order subdivisionFilter.SetInputData(polydata) subdivisionFilter.Update() mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(subdivisionFilter.GetOutputPort()) actor = vtk.vtkActor() actor.SetMapper(mapper) ##### visualizations ### ## color lookup table ## lut = vtk.vtkColorTransferFunction() lut.SetColorSpaceToHSV() color_series = vtk.vtkColorSeries() #color_series.SetColorScheme(color_series.BREWER_SEQUENTIAL_YELLOW_ORANGE_BROWN_3) color_series.SetColorScheme( getattr(color_series,args.color) ) print "\ncolor scheme name: ",color_series.GetColorSchemeName() num_colors = color_series.GetNumberOfColors() d_color=[0.0,0.0,0.0] if args.range: scalar_range = [-args.range,args.range] else: scalar_range = [0.0,0.0] polydata.GetPointData().GetScalars().GetRange(scalar_range) print "\ninput scalar range:",scalar_range for i in range(num_colors): color = color_series.GetColor(i) d_color[0] = color[0] / 255.0 d_color[1] = color[1] / 255.0
def main(): colors = vtk.vtkNamedColors() # We store background colors in a vector. Then we extract the red, green and # blue components later when coloring the reneder background. rendererColors = list() colorSeries = vtk.vtkColorSeries() colorSeries.SetColorSchemeByName('Brewer Qualitative Pastel2') rendererColors.append(colorSeries.GetColor(0)) rendererColors.append(colorSeries.GetColor(1)) rendererColors.append(colorSeries.GetColor(2)) rendererColors.append(colorSeries.GetColor(3)) renderWindow = vtk.vtkRenderWindow() renderWindowInteractor = vtk.vtkRenderWindowInteractor() renderWindowInteractor.SetRenderWindow(renderWindow) # Define viewport ranges xmins = [0, 0.5, 0, 0.5] xmaxs = [0.5, 1, 0.5, 1] ymins = [0, 0, 0.5, 0.5] ymaxs = [0.5, 0.5, 1, 1] # Using the superclass for the sources sources = list() for i in range(0, 4): if i == 0: # Create a sphere sphereSource = vtk.vtkSphereSource() sphereSource.SetCenter(0.0, 0.0, 0.0) sphereSource.Update() sources.append(sphereSource) elif i == 1: # Create a cone coneSource = vtk.vtkConeSource() coneSource.SetCenter(0.0, 0.0, 0.0) coneSource.Update() sources.append(coneSource) elif i == 2: # Create a cube cubeSource = vtk.vtkCubeSource() cubeSource.SetCenter(0.0, 0.0, 0.0) cubeSource.Update() sources.append(cubeSource) else: # Create a cylinder cylinderSource = vtk.vtkCylinderSource() cylinderSource.SetCenter(0.0, 0.0, 0.0) cylinderSource.Update() sources.append(cylinderSource) mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(sources[i].GetOutputPort()) actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetColor(colors.GetColor3d('Tomato')) renderer = vtk.vtkRenderer() renderer.AddActor(actor) r = rendererColors[i].GetRed() / 255.0 g = rendererColors[i].GetGreen() / 255.0 b = rendererColors[i].GetBlue() / 255.0 renderer.SetBackground(r, g, b) renderWindow.AddRenderer(renderer) if i == 0: camera = renderer.GetActiveCamera() camera.Azimuth(30) camera.Elevation(30) else: renderer.SetActiveCamera(camera) renderer.SetViewport(xmins[i], ymins[i], xmaxs[i], ymaxs[i]) renderer.ResetCamera() renderWindow.Render() renderWindow.SetWindowName('ShareCamera') renderWindowInteractor.Start()
def testStackedPlot(self): "Test if stacked plots can be built with python" # Set up a 2D scene, add an XY chart to it view = vtk.vtkContextView() view.GetRenderer().SetBackground(1.0,1.0,1.0) view.GetRenderWindow().SetSize(400,300) chart = vtk.vtkChartXY() view.GetScene().AddItem(chart) # Create a table with some data in it table = vtk.vtkTable() arrMonthLabels = vtk.vtkStringArray() arrMonthPositions = vtk.vtkDoubleArray() arrMonth = vtk.vtkIntArray() arrMonth.SetName("Month") arrBooks = vtk.vtkIntArray() arrBooks.SetName("Books") arrNew = vtk.vtkIntArray() arrNew.SetName("New / Popular") arrPeriodical = vtk.vtkIntArray() arrPeriodical.SetName("Periodical") arrAudiobook = vtk.vtkIntArray() arrAudiobook.SetName("Audiobook") arrVideo = vtk.vtkIntArray() arrVideo.SetName("Video") numMonths = 12 for i in range(0,numMonths): arrMonthLabels.InsertNextValue(month_labels[i]) arrMonthPositions.InsertNextValue(float(i)) arrMonth.InsertNextValue(i) arrBooks.InsertNextValue(book[i]) arrNew.InsertNextValue(new_popular[i]) arrPeriodical.InsertNextValue(periodical[i]) arrAudiobook.InsertNextValue(audiobook[i]) arrVideo.InsertNextValue(video[i]) table.AddColumn(arrMonth) table.AddColumn(arrBooks) table.AddColumn(arrNew) table.AddColumn(arrPeriodical) table.AddColumn(arrAudiobook) table.AddColumn(arrVideo) # Set up the X Labels chart.GetAxis(1).SetCustomTickPositions(arrMonthPositions, arrMonthLabels) chart.GetAxis(1).SetMaximum(11) chart.GetAxis(1).SetBehavior(vtk.vtkAxis.FIXED) chart.SetShowLegend(True) # Create the stacked plot stack = chart.AddPlot(3) stack.SetUseIndexForXSeries(True) stack.SetInputData(table) stack.SetInputArray(1,"Books") stack.SetInputArray(2,"New / Popular") stack.SetInputArray(3,"Periodical") stack.SetInputArray(4,"Audiobook") stack.SetInputArray(5,"Video") # Set up a nice color series colorSeries = vtk.vtkColorSeries() colorSeries.SetColorScheme(2) stack.SetColorSeries(colorSeries) view.GetRenderWindow().SetMultiSamples(0) view.GetRenderWindow().Render() img_file = "TestStackedPlot.png" vtk.test.Testing.compareImage(view.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25) vtk.test.Testing.interact()
def main(): cellName = get_program_parameters() # Store the cell class names in a dictionary. cellMap = dict() cellMap[vtk.vtkCellTypes.GetClassNameFromTypeId( vtk.VTK_LINE)] = vtk.VTK_LINE cellMap[vtk.vtkCellTypes.GetClassNameFromTypeId( vtk.VTK_QUADRATIC_EDGE)] = vtk.VTK_QUADRATIC_EDGE cellMap[vtk.vtkCellTypes.GetClassNameFromTypeId( vtk.VTK_CUBIC_LINE)] = vtk.VTK_CUBIC_LINE cellMap[vtk.vtkCellTypes.GetClassNameFromTypeId( vtk.VTK_TRIANGLE)] = vtk.VTK_TRIANGLE cellMap[vtk.vtkCellTypes.GetClassNameFromTypeId( vtk.VTK_QUADRATIC_TRIANGLE)] = vtk.VTK_QUADRATIC_TRIANGLE cellMap[vtk.vtkCellTypes.GetClassNameFromTypeId( vtk.VTK_QUAD)] = vtk.VTK_QUAD cellMap[vtk.vtkCellTypes.GetClassNameFromTypeId( vtk.VTK_QUADRATIC_QUAD)] = vtk.VTK_QUADRATIC_QUAD cellMap[vtk.vtkCellTypes.GetClassNameFromTypeId( vtk.VTK_TETRA)] = vtk.VTK_TETRA cellMap[vtk.vtkCellTypes.GetClassNameFromTypeId( vtk.VTK_HEXAHEDRON)] = vtk.VTK_HEXAHEDRON cellMap[vtk.vtkCellTypes.GetClassNameFromTypeId( vtk.VTK_WEDGE)] = vtk.VTK_WEDGE cellMap[vtk.vtkCellTypes.GetClassNameFromTypeId( vtk.VTK_PYRAMID)] = vtk.VTK_PYRAMID cellMap[vtk.vtkCellTypes.GetClassNameFromTypeId( vtk.VTK_QUADRATIC_WEDGE)] = vtk.VTK_QUADRATIC_WEDGE cellMap[vtk.vtkCellTypes.GetClassNameFromTypeId( vtk.VTK_QUADRATIC_PYRAMID)] = vtk.VTK_QUADRATIC_PYRAMID cellMap[vtk.vtkCellTypes.GetClassNameFromTypeId( vtk.VTK_QUADRATIC_HEXAHEDRON)] = vtk.VTK_QUADRATIC_HEXAHEDRON cellMap[vtk.vtkCellTypes.GetClassNameFromTypeId( vtk.VTK_QUADRATIC_TETRA)] = vtk.VTK_QUADRATIC_TETRA if cellName not in cellMap: print('Cell type ', cellName, ' is not supported.') return source = vtk.vtkCellTypeSource() source.SetCellType(cellMap[cellName]) source.Update() print('Cell: ', cellName) originalPoints = source.GetOutput().GetPoints() points = vtk.vtkPoints() points.SetNumberOfPoints(source.GetOutput().GetNumberOfPoints()) rng = vtk.vtkMinimalStandardRandomSequence() rng.SetSeed(5070) # for testing for i in range(0, points.GetNumberOfPoints()): perturbation = [0.0] * 3 for j in range(0, 3): rng.Next() perturbation[j] = rng.GetRangeValue(-0.1, 0.1) currentPoint = [0.0] * 3 originalPoints.GetPoint(i, currentPoint) points.SetPoint(i, currentPoint[0] + perturbation[0], currentPoint[1] + perturbation[1], currentPoint[2] + perturbation[2]) source.GetOutput().SetPoints(points) numCells = source.GetOutput().GetNumberOfCells() print('Number of cells: ', numCells) idArray = vtk.vtkIntArray() idArray.SetNumberOfTuples(numCells) for i in range(0, numCells): idArray.InsertTuple1(i, i + 1) idArray.SetName('Ids') source.GetOutput().GetCellData().AddArray(idArray) source.GetOutput().GetCellData().SetActiveScalars('Ids') shrink = vtk.vtkShrinkFilter() shrink.SetInputConnection(source.GetOutputPort()) shrink.SetShrinkFactor(.8) tessellate = vtk.vtkTessellatorFilter() tessellate.SetInputConnection(shrink.GetOutputPort()) tessellate.SetMaximumNumberOfSubdivisions(3) # Create a lookup table to map cell data to colors. lut = vtk.vtkLookupTable() colorSeries = vtk.vtkColorSeries() seriesEnum = colorSeries.BREWER_QUALITATIVE_SET3 colorSeries.SetColorScheme(seriesEnum) colorSeries.BuildLookupTable(lut, colorSeries.ORDINAL) # Fill in a few known colors, the rest will be generated if needed. colors = vtk.vtkNamedColors() # Create a mapper and actor. mapper = vtk.vtkDataSetMapper() mapper.SetInputConnection(source.GetOutputPort()) mapper.SetInputConnection(shrink.GetOutputPort()) mapper.SetScalarRange(0, numCells + 1) mapper.SetLookupTable(lut) mapper.SetScalarModeToUseCellData() mapper.SetResolveCoincidentTopologyToPolygonOffset() if (source.GetCellType() == vtk.VTK_QUADRATIC_PYRAMID or source.GetCellType() == vtk.VTK_QUADRATIC_WEDGE): mapper.SetInputConnection(shrink.GetOutputPort()) else: mapper.SetInputConnection(tessellate.GetOutputPort()) actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().EdgeVisibilityOn() # actor.GetProperty().SetLineWidth(3) textProperty = vtk.vtkTextProperty() textProperty.SetFontSize(20) textProperty.SetJustificationToCentered() textProperty.SetColor(colors.GetColor3d('Lamp_Black')) textMapper = vtk.vtkTextMapper() textMapper.SetInput(cellName) textMapper.SetTextProperty(textProperty) textActor = vtk.vtkActor2D() textActor.SetMapper(textMapper) textActor.SetPosition(320, 20) # Create a renderer, render window, and interactor. renderer = vtk.vtkRenderer() renderWindow = vtk.vtkRenderWindow() renderWindow.SetWindowName('CellTypeSource') renderWindow.AddRenderer(renderer) renderWindowInteractor = vtk.vtkRenderWindowInteractor() renderWindowInteractor.SetRenderWindow(renderWindow) # Add the actors to the scene. renderer.AddViewProp(textActor) renderer.AddActor(actor) renderer.SetBackground(colors.GetColor3d('Silver')) renderer.ResetCamera() renderer.GetActiveCamera().Azimuth(30) renderer.GetActiveCamera().Elevation(30) renderer.ResetCameraClippingRange() # Render and interact. renderWindow.SetSize(640, 480) renderWindow.Render() renderWindowInteractor.Start()
def main(filename, curvature=0, scalarRange=None, scheme=None): print("Loading", filename) reader = vtk.vtkXMLPolyDataReader() reader.SetFileName(filename) curvaturesFilter = vtk.vtkCurvatures() curvaturesFilter.SetInputConnection(reader.GetOutputPort()) if curvature == 0: curvaturesFilter.SetCurvatureTypeToMinimum() elif curvature == 1: curvaturesFilter.SetCurvatureTypeToMaximum() elif curvature == 2: curvaturesFilter.SetCurvatureTypeToGaussian() else: curvaturesFilter.SetCurvatureTypeToMean() curvaturesFilter.Update() # Get scalar range from command line if present, otherwise use # range of computed curvature if scalarRange is None: scalarRange = curvaturesFilter.GetOutput().GetScalarRange() # Build a lookup table if scheme is None: scheme = 16 colorSeries = vtk.vtkColorSeries() colorSeries.SetColorScheme(scheme) print("Using color scheme #:", colorSeries.GetColorScheme(), \ "is", colorSeries.GetColorSchemeName()) lut = vtk.vtkColorTransferFunction() lut.SetColorSpaceToHSV() # Use a color series to create a transfer function numColors = colorSeries.GetNumberOfColors() for i in range(numColors): color = colorSeries.GetColor(i) dColor = [color[0] / 255.0, color[1] / 255.0, color[2] / 255.0] t = scalarRange[0] + (scalarRange[1] - scalarRange[0]) / (numColors - 1) * i lut.AddRGBPoint(t, dColor[0], dColor[1], dColor[2]) # Create a mapper and actor mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(curvaturesFilter.GetOutputPort()) mapper.SetLookupTable(lut) mapper.SetScalarRange(scalarRange) actor = vtk.vtkActor() actor.SetMapper(mapper) # Create a scalar bar print("Displaying", curvaturesFilter.GetOutput().GetPointData().GetScalars().GetName()) scalarBarActor = vtk.vtkScalarBarActor() scalarBarActor.SetLookupTable(mapper.GetLookupTable()) scalarBarActor.SetTitle( curvaturesFilter.GetOutput().GetPointData().GetScalars().GetName()) scalarBarActor.SetNumberOfLabels(5) # Create a renderer, render window, and interactor renderer = vtk.vtkRenderer() renderWindow = vtk.vtkRenderWindow() renderWindow.AddRenderer(renderer) renderWindowInteractor = vtk.vtkRenderWindowInteractor() renderWindowInteractor.SetRenderWindow(renderWindow) # Add the actors to the scene renderer.AddActor(actor) renderer.AddActor2D(scalarBarActor) renderer.SetBackground(.1, .2, .3) # Background color blue # Render and interact renderWindow.Render() renderWindowInteractor.Start()
def TestLookupTables(lutMode): ''' Test various combinations of lookup tables. :param: lutMode - if True the tables are ordinal, categorical otherwise. :return: True if all tests passed. ''' lutUtilities = LUTUtilities() lut1 = vtk.vtkLookupTable() lut2 = vtk.vtkLookupTable() colorSeries = vtk.vtkColorSeries() colorSeriesEnum = colorSeries.SPECTRUM colorSeries.SetColorScheme(colorSeriesEnum) colorSeries.BuildLookupTable(lut1) colorSeries.BuildLookupTable(lut2) if lutMode: lut1.IndexedLookupOff() lut2.IndexedLookupOff() lut1.SetNanColor(1, 0, 0, 1) lut2.SetNanColor(1, 0, 0, 1) if not lutMode: # For the annotation just use a letter of the alphabet. values1 = vtk.vtkVariantArray() values2 = vtk.vtkVariantArray() str = "abcdefghijklmnopqrstuvwxyz" for i in range(lut1.GetNumberOfTableValues()): values1.InsertNextValue(vtk.vtkVariant(str[i])) for i in range(lut2.GetNumberOfTableValues()): values2.InsertNextValue(vtk.vtkVariant(str[i])) for i in range(values1.GetNumberOfTuples()): lut1.SetAnnotation(i, values1.GetValue(i).ToString()) for i in range(values2.GetNumberOfTuples()): lut2.SetAnnotation(i, values2.GetValue(i).ToString()) # Are they the same? res = True res &= TestTables(lut1, lut2) # Different size lut2.SetNumberOfTableValues(5) res &= TestTables(lut1, lut2, False) lut2.SetNumberOfTableValues(lut1.GetNumberOfTableValues()) res &= TestTables(lut1, lut2) if lutMode: # Different range lut2.SetTableRange(1, 2) res &= TestTables(lut1, lut2, False) tr = lut1.GetTableRange() lut2.SetTableRange(tr) res &= TestTables(lut1, lut2) # Different color colorSeriesEnum = colorSeries.COOL colorSeries.SetColorScheme(colorSeriesEnum) lut3 = vtk.vtkLookupTable() colorSeries.BuildLookupTable(lut3) lut3.IndexedLookupOff() res &= TestTables(lut1, lut3, False) # One indexed, the other ordinal. lut1.IndexedLookupOn() res &= TestTables(lut1, lut2, False) else: # Different color colorSeriesEnum = colorSeries.COOL colorSeries.SetColorScheme(colorSeriesEnum) lut3 = vtk.vtkLookupTable() colorSeries.BuildLookupTable(lut3) values = vtk.vtkVariantArray() str = "abcdefghijklmnopqrstuvwxyz" for i in range(lut3.GetNumberOfTableValues()): values.InsertNextValue(vtk.vtkVariant(str[i])) for i in range(values.GetNumberOfTuples()): lut3.SetAnnotation(i, values.GetValue(i).ToString()) colorSeries.BuildLookupTable(lut3) res &= TestTables(lut1, lut3, False) # Different annotations. lut2.ResetAnnotations() for i in range(values.GetNumberOfTuples()): if i % 3 == 0: continue lut2.SetAnnotation(i, values.GetValue(i).ToString()) res &= TestTables(lut1, lut2, False) # No annotations lut1.ResetAnnotations() lut2.ResetAnnotations() res &= TestTables(lut1, lut2) # One indexed, the other ordinal. lut1.IndexedLookupOff() res &= TestTables(lut1, lut2, False) return res
def testStackedPlot(self): "Test if stacked plots can be built with python" # Set up a 2D scene, add an XY chart to it view = vtk.vtkContextView() view.GetRenderer().SetBackground(1.0,1.0,1.0) view.GetRenderWindow().SetSize(400,300) chart = vtk.vtkChartXY() view.GetScene().AddItem(chart) # Create a table with some data in it table = vtk.vtkTable() arrMonthLabels = vtk.vtkStringArray() arrMonthPositions = vtk.vtkDoubleArray() arrMonth = vtk.vtkIntArray() arrMonth.SetName("Month") arrBooks = vtk.vtkIntArray() arrBooks.SetName("Books") arrNew = vtk.vtkIntArray() arrNew.SetName("New / Popular") arrPeriodical = vtk.vtkIntArray() arrPeriodical.SetName("Periodical") arrAudiobook = vtk.vtkIntArray() arrAudiobook.SetName("Audiobook") arrVideo = vtk.vtkIntArray() arrVideo.SetName("Video") numMonths = 12 for i in range(0,numMonths): arrMonthLabels.InsertNextValue(month_labels[i]) arrMonthPositions.InsertNextValue(float(i)) arrMonth.InsertNextValue(i) arrBooks.InsertNextValue(book[i]) arrNew.InsertNextValue(new_popular[i]) arrPeriodical.InsertNextValue(periodical[i]) arrAudiobook.InsertNextValue(audiobook[i]) arrVideo.InsertNextValue(video[i]) table.AddColumn(arrMonth) table.AddColumn(arrBooks) table.AddColumn(arrNew) table.AddColumn(arrPeriodical) table.AddColumn(arrAudiobook) table.AddColumn(arrVideo) # Set up the X Labels chart.GetAxis(1).SetCustomTickPositions(arrMonthPositions, arrMonthLabels) chart.GetAxis(1).SetMaximum(11) chart.GetAxis(1).SetBehavior(vtk.vtkAxis.FIXED) # Create the stacked plot stack = chart.AddPlot(3) stack.SetUseIndexForXSeries(True) stack.SetInputData(table) stack.SetInputArray(1,"Books") stack.SetInputArray(2,"New / Popular") stack.SetInputArray(3,"Periodical") stack.SetInputArray(4,"Audiobook") stack.SetInputArray(5,"Video") # Set up a nice color series colorSeries = vtk.vtkColorSeries() colorSeries.SetColorScheme(2) stack.SetColorSeries(colorSeries) view.GetRenderWindow().SetMultiSamples(0) view.GetRenderWindow().Render() img_file = "TestStackedPlot.png" vtk.test.Testing.compareImage(view.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25) vtk.test.Testing.interact()
def main(): # Basic stuff setup # Set up the renderer, window, and interactor colors = vtk.vtkNamedColors() ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) renWin.SetSize(640, 480) iRen = vtk.vtkRenderWindowInteractor() iRen.SetRenderWindow(renWin) # Create a cone with an elliptical base whose major axis is in the # X-direction. coneSource = vtk.vtkConeSource() coneSource.SetCenter(0.0, 0.0, 0.0) coneSource.SetRadius(5.0) coneSource.SetHeight(15.0) coneSource.SetDirection(0, 1, 0) coneSource.SetResolution(60) coneSource.Update() transform = vtk.vtkTransform() transform.Scale(1.0, 1.0, 0.75) transF = vtk.vtkTransformPolyDataFilter() transF.SetInputConnection(coneSource.GetOutputPort()) transF.SetTransform(transform) bounds = transF.GetOutput().GetBounds() elevation = vtk.vtkElevationFilter() elevation.SetInputConnection(transF.GetOutputPort()) elevation.SetLowPoint(0, bounds[2], 0) elevation.SetHighPoint(0, bounds[3], 0) bandedContours = vtk.vtkBandedPolyDataContourFilter() bandedContours.SetInputConnection(elevation.GetOutputPort()) bandedContours.SetScalarModeToValue() bandedContours.GenerateContourEdgesOn() bandedContours.GenerateValues(11, elevation.GetScalarRange()) # Make a lookup table using a color series. colorSeries = vtk.vtkColorSeries() colorSeries.SetColorScheme(vtk.vtkColorSeries.BREWER_DIVERGING_SPECTRAL_11) lut = vtk.vtkLookupTable() colorSeries.BuildLookupTable(lut, vtk.vtkColorSeries.ORDINAL) coneMapper = vtk.vtkPolyDataMapper() coneMapper.SetInputConnection(bandedContours.GetOutputPort()) coneMapper.SetScalarRange(elevation.GetScalarRange()) coneMapper.SetLookupTable(lut) coneActor = vtk.vtkActor() coneActor.SetMapper(coneMapper) # Contouring contourLineMapper = vtk.vtkPolyDataMapper() contourLineMapper.SetInputData(bandedContours.GetContourEdgesOutput()) contourLineMapper.SetScalarRange(elevation.GetScalarRange()) contourLineMapper.SetResolveCoincidentTopologyToPolygonOffset() contourLineActor = vtk.vtkActor() contourLineActor.SetMapper(contourLineMapper) contourLineActor.GetProperty().SetColor(colors.GetColor3d('DimGray')) # Set up the Orientation Marker Widget. prop_assembly = MakeAnnotatedCubeActor(colors) om1 = vtk.vtkOrientationMarkerWidget() om1.SetOrientationMarker(prop_assembly) om1.SetInteractor(iRen) om1.SetDefaultRenderer(ren) om1.On() om1.InteractiveOn() xyzLabels = ['X', 'Y', 'Z'] scale = [1.0, 1.0, 1.0] axes = MakeAxesActor(scale, xyzLabels) om2 = vtk.vtkOrientationMarkerWidget() om2.SetOrientationMarker(axes) # Position lower right in the viewport. om2.SetViewport(0.8, 0, 1.0, 0.2) om2.SetInteractor(iRen) om2.EnabledOn() om2.InteractiveOn() ren.AddActor(coneActor) ren.AddActor(contourLineActor) ren.SetBackground2(colors.GetColor3d('RoyalBlue')) ren.SetBackground(colors.GetColor3d('MistyRose')) ren.GradientBackgroundOn() ren.GetActiveCamera().Azimuth(45) ren.GetActiveCamera().Pitch(-22.5) ren.ResetCamera() renWin.SetSize(600, 600) renWin.Render() renWin.SetWindowName('ColoredAnnotatedCube') renWin.Render() iRen.Start()