I have a code:
- do not work correctly in release
- do not work correctly in debug without breakpoint
- work correctly in debug with a breakpoint
The code is:
import vtkmodules.all as vtk
render = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(render)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
cubeAnnotation = vtk.vtkAnnotatedCubeActor()
actors = vtk.vtkPropCollection()
cubeAnnotation.GetActors(actors)
cubeActor = list(actors)[0]
colors = vtk.vtkNamedColors()
face_colors = vtk.vtkUnsignedCharArray()
face_colors.SetNumberOfComponents(3)
face_x_plus = colors.GetColor3ub('Red')
face_x_minus = colors.GetColor3ub('Green')
face_y_plus = colors.GetColor3ub('Blue')
face_y_minus = colors.GetColor3ub('Yellow')
face_z_plus = colors.GetColor3ub('Cyan')
face_z_minus = colors.GetColor3ub('Magenta')
face_colors.InsertNextTypedTuple(face_x_minus)
face_colors.InsertNextTypedTuple(face_x_plus)
face_colors.InsertNextTypedTuple(face_y_plus)
face_colors.InsertNextTypedTuple(face_y_minus)
face_colors.InsertNextTypedTuple(face_z_plus)
face_colors.InsertNextTypedTuple(face_z_minus)
cubeActor.GetMapper().GetInput().GetCellData().SetScalars(face_colors)
cubeActor.GetMapper().Update()
cubeActor.Modified()
render.AddActor(cubeActor)
render.ResetCamera()
renWin.Render()
iren.Initialize()
iren.Start()
The breakpoint should be added at cubeActor.GetMapper().GetInput().GetCellData().SetScalars(face_colors)
, and the cube will be visualizated as:
Otherwise, it do show only gray color.
The environment has been tested:
win10 & ubuntu18
vtk 9.1.0
pycharm
It really make me confuzed. Any suggestion is appreciated~~~