<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hey Jack,<div><br></div><div>You can, indeed, just create one actor and then change the underlying data and force the scene to update. The key is to call Modified() on the data structure before calling Render() so the pipeline knows the data changed and will update the intermediate filters.</div><div><br></div><div>If you're working in Python you have the option of either changing coordinates (or some other info) in the VTK data structures themselves, or keeping around something like a Numpy array which is referenced by the VTK structures and just updating that. The latter method (changing the info in memory that the VTK structures reference) is usually faster.</div><div><br></div><div>Here's a little example I modified to show the two options. The BULK=True test just modifies the underlying data directly and is about 4x faster on my machine than BULK=False. (Sorry it's not very pretty, but hopefully it gets the point across. The differences are more dramatic between the two methods with a high vert count.)</div><div><br></div><div>-Eric</div><div><br></div><div># =======================</div><div><div>import numpy</div><div>import vtk</div><div>import vtk.util.numpy_support as VN</div><div><br></div><div># Number of diffusing vertices</div><div>num_verts = 100000</div><div><br></div><div># If BULK == True, then changing point coordinates by changing</div><div># <span class="Apple-tab-span" style="white-space:pre">        </span>underlying numpy array</div><div># If BULK == False, then setting polydata point coordinates directly</div><div>BULK = True</div><div># BULK = False</div><div><br></div><div># Initial point coordinates</div><div>centers = numpy.random.rand(num_verts, 3)</div><div><br></div><div># Comment this out if setting coordinates individually</div><div>if BULK:</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>centers_vtk = VN.numpy_to_vtk(centers)</div><div><br></div><div>vert_ids = vtk.vtkIntArray()</div><div>vert_ids.SetNumberOfComponents(1)</div><div>vert_ids.SetNumberOfValues(num_verts)</div><div>vert_ids.SetName("vert_ids")</div><div><br></div><div>points = vtk.vtkPoints()</div><div>points.SetNumberOfPoints(num_verts)</div><div><br></div><div>verts = vtk.vtkCellArray()</div><div>verts.Allocate(verts.EstimateSize(1, num_verts), 1000)</div><div>verts.InsertNextCell(num_verts)</div><div><br></div><div># Assign values to the various arrays</div><div><br></div><div>if BULK:</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>points.SetData(centers_vtk)</div><div><br></div><div>for ii in range(num_verts):</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>p = centers[ii,:]</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if not BULK:</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>points.SetPoint(ii, p[0], p[1], p[2])</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vert_ids.SetValue(ii, ii)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>verts.InsertCellPoint(ii)</div><div><br></div><div><br></div><div># Build the vtkPolyData</div><div>poly = vtk.vtkPolyData()</div><div>poly.SetPoints(points)</div><div>poly.SetVerts(verts)</div><div>poly.GetPointData().AddArray(vert_ids)</div><div>poly.GetPointData().SetActiveScalars('vert_ids')</div><div><br></div><div># Generate a lookup table</div><div>lut = vtk.vtkLookupTable()</div><div>lut.SetValueRange(0.5, 1.0)</div><div>lut.SetSaturationRange(0.1, 1.0)</div><div>lut.SetHueRange(0.4,0.6)</div><div>lut.SetRampToLinear()</div><div>lut.Build()</div><div><br></div><div>mapper = vtk.vtkPolyDataMapper()</div><div>mapper.SetInput(poly)</div><div>mapper.SetLookupTable(lut)</div><div>mapper.ScalarVisibilityOn()</div><div>mapper.SelectColorArray('vert_ids')</div><div>mapper.SetScalarRange(poly.GetPointData().GetScalars().GetRange())</div><div><br></div><div>actor = vtk.vtkActor()</div><div>actor.SetMapper(mapper)</div><div><br></div><div>ren = vtk.vtkRenderer()</div><div>ren.AddActor(actor)</div><div>renWin = vtk.vtkRenderWindow()</div><div>renWin.AddRenderer(ren)</div><div>renWin.SetSize(400,400)</div><div>iren = vtk.vtkRenderWindowInteractor()</div><div>istyle = vtk.vtkInteractorStyleTrackballCamera()</div><div>iren.SetInteractorStyle(istyle)</div><div>iren.SetRenderWindow(renWin)</div><div>ren.ResetCamera()</div><div>renWin.Render()</div><div><br></div><div># Diffuse points</div><div>for tt in range(100):</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span># Update coordinate centers array</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>centers += 0.002*numpy.random.randn(num_verts, 3)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if not BULK:</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>for ii in range(num_verts):</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>points.SetPoint(ii, centers[ii,0], centers[ii,1], centers[ii,2])</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span># This Modified() call is what tells the pipeline the</div><div><span class="Apple-tab-span" style="white-space:pre">        </span># data has changed, so it needs to fire again for the new Render()</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>poly.Modified()</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>renWin.Render()</div><div><br></div><div>iren.Start()</div><div><br></div><div><br></div><br><br></div><div><br><div><div>On May 20, 2011, at 2:11 PM, Guest, Jackie wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<div>
<!-- Converted from text/plain format --><p><font size="2">First Post so bare with me;<br>
<br>
I am animating a large number of actors over time using the python vtk wrapper...<br>
<br>
like this...<br>
<br>
while animate:<br>
&nbsp;&nbsp;&nbsp; for actors<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; actor.setposition(x,y,z)<br>
&nbsp;&nbsp;&nbsp; ren.render()<br>
<br>
This seems to be the only way to reset the pipeline in this environment.&nbsp; Is there a way<br>
to create one actor (say and unstructured grid)...change the point ids or modify the mapper<br>
to reset point locations then re-render the scene.&nbsp; More speed is our goal.<br>
<br>
Thanks...Jack&nbsp;<br>
</font>
</p>

</div>
_______________________________________________<br>Powered by <a href="http://www.kitware.com">www.kitware.com</a><br><br>Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br><br>Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</a><br><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</a><br></blockquote></div><br></div></body></html>