Hi VTK users,
Initially I thought applying a transformation to one cell of a vtkPolyData would propagate positional changes to other vtkPolyData’s sharing the same points, but I am mistaken.
In the example below there are 6 points and two vtkPolygon objects, of which points 1 and 2 are shared between polygon1 and polygon2. The two objects are initially connected, but when I apply a rotation to polygon1, the two objects are then split at the middle because polygon2 is not updated with positional changes to two shared points.
Could I ask if anyone is familiar on how to update multiple polygons, such that if the points in one object is transformed, other objects sharing the same points are also updated? I initially thought vtkPolygon() held a reference to vtkPoints(), and updates were communicated throughout.
The example below is a proof of concept I’m building off, but eventually it will help me with creating an unstructured mesh with 100’s of panels and animation. End use case is to model beam deformations (in case there’s a better way to represent the solution).
import vtk
# Allocations
renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
points = vtk.vtkPoints()
polygon1 = vtk.vtkPolygon()
cell1 = vtk.vtkCellArray()
data1 = vtk.vtkPolyData()
transform1 = vtk.vtkTransform()
polyTransform1 = vtk.vtkTransformPolyDataFilter()
mapper1 = vtk.vtkPolyDataMapper()
actor1 = vtk.vtkActor()
polygon2 = vtk.vtkPolygon()
cell2 = vtk.vtkCellArray()
data2 = vtk.vtkPolyData()
transform2 = vtk.vtkTransform()
polyTransform2 = vtk.vtkTransformPolyDataFilter()
mapper2 = vtk.vtkPolyDataMapper()
actor2 = vtk.vtkActor()
# define points
points.InsertNextPoint(0.0, 0.0, 0.0) # 0
points.InsertNextPoint(2.0, 0.0, 0.0) # 1
points.InsertNextPoint(2.0, 1.0, 0.0) # 2
points.InsertNextPoint(0.0, 1.0, 0.0) # 3
points.InsertNextPoint(4.0, 0.0, 0.0) # 4
points.InsertNextPoint(4.0, 1.0, 0.0) # 5
# Create polygons
polygon1.GetPointIds().SetNumberOfIds(4)
polygon1.GetPointIds().SetId(0, 0)
polygon1.GetPointIds().SetId(1, 1)
polygon1.GetPointIds().SetId(2, 2)
polygon1.GetPointIds().SetId(3, 3)
cell1.InsertNextCell(polygon1)
polygon2.GetPointIds().SetNumberOfIds(4)
polygon2.GetPointIds().SetId(0, 1)
polygon2.GetPointIds().SetId(1, 4)
polygon2.GetPointIds().SetId(2, 5)
polygon2.GetPointIds().SetId(3, 2)
cell2.InsertNextCell(polygon2)
data1.SetPoints(points)
data2.SetPoints(points)
data1.SetPolys(cell1)
data2.SetPolys(cell2)
polyTransform1.SetInputData(data1)
polyTransform1.SetTransform(transform1)
polyTransform2.SetInputData(data2)
polyTransform2.SetTransform(transform2)
mapper1.SetInputData(polyTransform1.GetOutput())
mapper2.SetInputData(polyTransform2.GetOutput())
actor1.SetMapper(mapper1)
actor2.SetMapper(mapper2)
# apply rotation to cell1
transform1.RotateY(30.0)
polyTransform1.Update()
polyTransform2.Update()
renderWindow.AddRenderer(renderer)
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
renderer.AddActor(actor1)
renderer.AddActor(actor2)
renderWindow.Render()
renderWindowInteractor.Initialize()
renderWindowInteractor.Start()