Thanks for your reply. I write the code and debug for a long time but still not able to get the colorized sphere. Here is my code:
# Load the data
nc = vtk.vtkNamedColors()
test = BTL_GL.BTL_GL()
pcd, pc, pc_color = test.GL_NonFlat()
# The sphere model
sphere = vtk.vtkSphereSource()
sphere.SetPhiResolution(5)
sphere.SetThetaResolution(5)
sphere.SetRadius(0.0025 * 2)
Points = vtk.vtkPoints()
Colors = vtk.vtkUnsignedCharArray()
Colors.SetNumberOfComponents(3)
Colors.SetName(“Colors”)
Colors.InsertNextTuple3(255,0,0)
for i in range(len(pc)):
Points.InsertNextPoint(pc[i, 0], pc[i, 1], pc[i, 2])
Colors.InsertNextTuple3(pc_color[i, 0] / 255, pc_color[i, 1] / 255, pc_color[i, 2] / 255)
polydata = vtk.vtkPolyData()
polydata.SetPoints(Points)
sphere.GetOutput().GetCellData().SetScalars(Colors)
sphere.Update()
appendData = vtk.vtkAppendPolyData()
appendData.AddInputConnection(sphere.GetOutputPort())
appendData.Update()
point_mapper = vtk.vtkGlyph3DMapper()
point_mapper.SetInputData(polydata)
point_mapper.SetSourceConnection(appendData.GetOutputPort())
# Set background color
actor = vtk.vtkActor()
actor.SetMapper(point_mapper)
actor.GetProperty().LightingOff()
actor.GetProperty().BackfaceCullingOn()
ren = vtk.vtkRenderer()
ren.SetBackground(.2, .3, .4)
ren.AddActor(actor)
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
# Interactor
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renWin)
# Begin Interaction
renWin.Render()
renderWindowInteractor.Start()