Hello!!!
I’m trying to use vtkInformation to share “metadata” between items in a vtk pipeline. I’m pretty comfortable setting/getting the keys, values etc., but I’ve demonstrated some behavior that surprised me and I’d like some confirmation that what I’m seeing is correct and expected - and that I’m not goofing up…
Here’s a minimal use case. using a vtkSPhereSUrce and an Elevation filter I create a vtkPolyData with two point fields and I set one of the point fields as the active field. When I complete the pipeline and display the sphere, it is colored using the active field. So far, so good.
Now when I grab the vtkInformation object from the vtkPolyData I EXPCTED to see some information objects contaiing the FIELD_ACTIVE_ATTRIBUTE, BOUNDING_BOX etc. but these vtkInformation objects basically have no values set.
I EXPECTED that VTK was using these vtkInformation to control which field the display is colored by, but it seems not? Or am I doing someting wrong in my example (below).
When run, this code generates values of 0, 0, 0, None for the FIELD_ASSOCIATION, FIELD_ATTRIBUTE_TYPE, FIELD_ACTIVE_ATTRIBUTE and BOUNDING_BOX information
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
from vtkmodules.vtkFiltersCore import vtkElevationFilter
from vtkmodules.vtkFiltersSources import vtkSphereSource
from vtkmodules.vtkRenderingCore import (
vtkRenderWindow,
vtkRenderWindowInteractor,
vtkRenderer,
vtkActor,
vtkDataSetMapper,
)
from vtkmodules.numpy_interface import dataset_adapter as dsa
def main():
# Origin and radius
origin=[0.,0.,0.]
radius=0.1
# Set up a sphere source and set its origina and radius
sphere = vtkSphereSource()
sphere.SetCenter(origin[0], origin[1], origin[2])
sphere.SetRadius(radius)
sphere.SetPhiResolution(12)
sphere.SetThetaResolution(12)
# Create an Elevation filter at the lowest Z extent of the sphere
# We'll use to create a Point field of distance from every point on the sphere to the plane
# and we'll use the field to color code the sphere with a fringe
elevation = vtkElevationFilter()
elevation.SetInputConnection(sphere.GetOutputPort())
elevation.SetLowPoint(origin[0], origin[1], origin[2]-radius)
elevation.SetHighPoint(origin[0], origin[1], origin[2]+radius)
elevation.Update()
poly=elevation.GetOutputDataObject(0)
#poly_np=dsa.WrapDataObject(poly)
#p_data=poly_np.PointData
#print('Point Data : {}'.format(p_data.keys()))
poly.GetPointData().SetActiveScalars('Elevation')
#poly.GetPointData().SetActiveScalars('Normals')
poly.ComputeBounds()
info=poly.GetInformation()
print('Field Association : {}'.format(info.Get(poly.FIELD_ASSOCIATION())))
print('Field Attribute Type : {}'.format(info.Get(poly.FIELD_ATTRIBUTE_TYPE())))
print('Field Active Attribute : {}'.format(info.Get(poly.FIELD_ACTIVE_ATTRIBUTE())))
print('Bounding Box : {}'.format(info.Get(poly.BOUNDING_BOX())))
# Create a mapper and connect to the output of the elevation filter
sphere_mapper = vtkDataSetMapper()
sphere_mapper.SetInputConnection(elevation.GetOutputPort())
# Create an actor and connect to the the mapper sphere
sphere_actor = vtkActor()
sphere_actor.SetMapper(sphere_mapper)
# Render window, renderer and interactor
renderer=vtkRenderer()
renwin=vtkRenderWindow()
renwin.AddRenderer(renderer)
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renwin)
# Add the sphere actor and the glyph actor to the renderer
# This is the renderer extracted from the ExternalVTKWidget that is linked to the Apex graphics system
renderer.AddActor(sphere_actor)
# Render
iren.Initialize()
renwin.Render()
iren.Start()
if __name__=='__main__':
main()