<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hi all !</div><div>I am trying to animate a mesh deformation with quite a large number of nodes (about 300000).</div><div>For
now the best solution I have found is to make a list containing the
vtkpoints for each animation frame and loop by changing the vtkpoints of
the displayed polydata (or unstructuredgrid).</div><div>On a simple
model without applying any color to the cells I can obtain an animation
rate of about 50fps wich is a good frame rate for me.</div><div>But if I apply colors with a PolyData.GetCellData().SetScalars() the framerate goes down to 13fps.</div><div>Does
anybody knows if it could be a better method to display mesh animation
or to improve the display rate of a mesh with colors ?</div><div><br></div><div>Here below is the python code I use.<br></div><div>It draws a disk of 800x400 nodes and if you press on F1 it animates a kind of sinus wave.</div><div>First
it calculate each frame, then it display the animation without color
and finally it display the animation with random color on cells.</div><div><br></div><div>Thanks !<br></div><div><br></div><div>############################<br><br>import vtk<br>import math<br>from time import time<br>import random<br><br>############################<br># Creating disk mesh<br>disk = vtk.vtkDiskSource()<br>disk.SetInnerRadius(0.1)<br>disk.SetOuterRadius(2.0)<br>disk.SetRadialResolution(400)<br>disk.SetCircumferentialResolution(800)<br>disk.Update()<br>PolyData = disk.GetOutput()<br><br>print("%d nodes" % PolyData.GetNumberOfPoints())<br>print("%d elms" % PolyData.GetNumberOfCells())<br><br># Setup actor and mapper<br>mapper = vtk.vtkPolyDataMapper()<br>mapper.SetInputData(PolyData)<br>actor = vtk.vtkActor()<br>actor.SetMapper(mapper)<br> <br># Setup render window, renderer, interactor and camera<br>renderer = vtk.vtkRenderer()<br>renderWindow = vtk.vtkRenderWindow()<br>renderWindow.AddRenderer(renderer)<br>renderWindowInteractor = vtk.vtkRenderWindowInteractor()<br>renderWindowInteractor.SetRenderWindow(renderWindow)<br>style = vtk.vtkInteractorStyleTrackballCamera()<br>renderWindowInteractor.SetInteractorStyle(style)<br>camera = vtk.vtkCamera()<br>camera.Elevation(-45)<br>renderer.SetActiveCamera(camera)<br><br>#################################<br><br>def KeyPress(object, event):<br> if object.GetInteractor().GetKeySym() == "F1":<br> # Calculate each frame and store the vtkPoints into vtkPointsList<br> PolyData = disk.GetOutput()<br> vtkPointsList = {}<br> <br> print("Calculate...")<br> <br> for ph in range(0, 360, 20):<br> start_time = time()<br> vtkPointsList[ph] = vtk.vtkPoints()<br> vtkPointsList[ph].DeepCopy(PolyData.GetPoints())<br> for i in range(0, PolyData.GetNumberOfPoints()):<br> NodePos = vtkPointsList[ph].GetPoint(i)<br> vtkPointsList[ph].SetPoint(i, NodePos[0], NodePos[1], 0.3 * math.sin(NodePos[0] * 2 + ph * math.pi / 180))<br> PolyData.SetPoints(vtkPointsList[ph])<br> renderWindow.Render()<br> <br> print("Done. Animate.")<br> <br> # First animation without color<br> start_time = time()<br> for ph in range(0, 360, 20):<br> PolyData.SetPoints(vtkPointsList[ph])<br> renderWindow.Render()<br> print("%.2f FPS" % (18 / (time() - start_time)))<br> <br> # Activate cells colors<br> ELMcolors = vtk.vtkUnsignedCharArray()<br> ELMcolors.SetNumberOfComponents(3)<br> ELMcolors.SetName("Colors")<br> for i in range(0, PolyData.GetNumberOfCells()):<br> ELMcolors.InsertNextTuple([random.random() * 255, random.random() * 255, random.random() * 255])<br> PolyData.GetCellData().SetScalars(ELMcolors)<br> <br> # Second animation with color<br> start_time = time()<br> for ph in range(0, 360, 20):<br> PolyData.SetPoints(vtkPointsList[ph])<br> renderWindow.Render()<br> print("%.2f FPS" % (18 / (time() - start_time)))<br> <br>####################################<br> <br>style.AddObserver("KeyPressEvent", KeyPress)<br><br>renderer.AddActor(actor)<br>renderWindow.Render()<br>renderer.ResetCamera()<br>renderWindowInteractor.Start()<br><br>############################</div></div></div></div></div></div>
</div>