Is it possible to easily color the clipped faces of glyph3D the same color as the glyph (colored by a scalar)? Maybe I’m missing something obvious. Here’s a minimal test. Instead of white faces, I’d like them to match the glyph color.
from vtk import *
def main():
sphereSource = vtkSphereSource()
sphereSource.SetRadius(1.0)
cell_data = vtkFloatArray()
cell_data.SetName("cell_data")
cell_data.InsertNextValue( 0. )
cell_data.InsertNextValue( 1. )
points = vtkPoints()
points.InsertNextPoint(-1.5, 0, 0)
points.InsertNextPoint(1.5, 0, 0)
ugrid = vtkUnstructuredGrid()
ugrid.SetPoints(points)
ugrid.GetPointData().AddArray(cell_data)
ugrid.GetPointData().SetActiveScalars("cell_data")
glyph = vtkGlyph3D()
glyph.SetInputData(ugrid)
glyph.SetSourceConnection(sphereSource.GetOutputPort())
glyph.SetInputData(ugrid)
glyph.SetIndexModeToScalar()
glyph.ScalingOff()
glyph.Update() # don't forget!
planeXY = vtkPlane()
planeXY.SetOrigin(0,0,0)
planeXY.SetNormal(0,0, -1)
clipXY = vtkClipPolyData()
clipXY.SetInputData(glyph.GetOutput())
clipXY.SetClipFunction(planeXY)
clipXY.Update()
mapper = vtkPolyDataMapper()
mapper.SetInputConnection(clipXY.GetOutputPort())
mapper.SetColorModeToMapScalars()
mapper.ScalarVisibilityOn()
mapper.ColorByArrayComponent("cell_data", 1)
actor = vtkActor()
actor.SetMapper(mapper)
# ----- Now the caps
cap_edges = vtkFeatureEdges()
polydata = clipXY.GetOutput()
cap_edges.SetInputData(polydata)
cap_edges.BoundaryEdgesOn()
cap_edges.FeatureEdgesOff()
cap_edges.NonManifoldEdgesOff()
cap_edges.ManifoldEdgesOff()
cap_strips = vtkStripper()
cap_strips.SetInputConnection(cap_edges.GetOutputPort())
cap_strips.Update()
# Change the polylines into polygons
cap_pd = vtkPolyData()
cap_pd.SetPoints(cap_strips.GetOutput().GetPoints())
cap_pd.SetPolys(cap_strips.GetOutput().GetLines())
cap_mapper = vtkPolyDataMapper()
cap_mapper.SetInputData(cap_pd)
cap_actor = vtkActor()
cap_actor.SetMapper(cap_mapper)
#-----------
ren = vtkRenderer()
ren.AddActor(actor)
ren.AddActor(cap_actor)
renWin = vtkRenderWindow()
renWin.SetSize(640,640)
renWin.AddRenderer(ren)
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
ren.ResetCamera()
renWin.Render()
iren.Start()
if name == ‘main’:
main()