Discussion:
[vtkusers] Animation performance with cell color
Flagada
2018-11-17 19:20:32 UTC
Permalink
Hi all !
I am trying to animate a mesh deformation with quite a large number of
nodes (about 300000).
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).
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.
But if I apply colors with a PolyData.GetCellData().SetScalars() the
framerate goes down to 13fps.
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 ?

Here below is the python code I use.
It draws a disk of 800x400 nodes and if you press on F1 it animates a kind
of sinus wave.
First it calculate each frame, then it display the animation without color
and finally it display the animation with random color on cells.

Thanks !

############################

import vtk
import math
from time import time
import random

############################
# Creating disk mesh
disk = vtk.vtkDiskSource()
disk.SetInnerRadius(0.1)
disk.SetOuterRadius(2.0)
disk.SetRadialResolution(400)
disk.SetCircumferentialResolution(800)
disk.Update()
PolyData = disk.GetOutput()

print("%d nodes" % PolyData.GetNumberOfPoints())
print("%d elms" % PolyData.GetNumberOfCells())

# Setup actor and mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(PolyData)
actor = vtk.vtkActor()
actor.SetMapper(mapper)

# Setup render window, renderer, interactor and camera
renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
style = vtk.vtkInteractorStyleTrackballCamera()
renderWindowInteractor.SetInteractorStyle(style)
camera = vtk.vtkCamera()
camera.Elevation(-45)
renderer.SetActiveCamera(camera)

#################################

def KeyPress(object, event):
if object.GetInteractor().GetKeySym() == "F1":
# Calculate each frame and store the vtkPoints into vtkPointsList
PolyData = disk.GetOutput()
vtkPointsList = {}

print("Calculate...")

for ph in range(0, 360, 20):
start_time = time()
vtkPointsList[ph] = vtk.vtkPoints()
vtkPointsList[ph].DeepCopy(PolyData.GetPoints())
for i in range(0, PolyData.GetNumberOfPoints()):
NodePos = vtkPointsList[ph].GetPoint(i)
vtkPointsList[ph].SetPoint(i, NodePos[0], NodePos[1], 0.3 *
math.sin(NodePos[0] * 2 + ph * math.pi / 180))
PolyData.SetPoints(vtkPointsList[ph])
renderWindow.Render()

print("Done. Animate.")

# First animation without color
start_time = time()
for ph in range(0, 360, 20):
PolyData.SetPoints(vtkPointsList[ph])
renderWindow.Render()
print("%.2f FPS" % (18 / (time() - start_time)))

# Activate cells colors
ELMcolors = vtk.vtkUnsignedCharArray()
ELMcolors.SetNumberOfComponents(3)
ELMcolors.SetName("Colors")
for i in range(0, PolyData.GetNumberOfCells()):
ELMcolors.InsertNextTuple([random.random() * 255, random.random()
* 255, random.random() * 255])
PolyData.GetCellData().SetScalars(ELMcolors)

# Second animation with color
start_time = time()
for ph in range(0, 360, 20):
PolyData.SetPoints(vtkPointsList[ph])
renderWindow.Render()
print("%.2f FPS" % (18 / (time() - start_time)))

####################################

style.AddObserver("KeyPressEvent", KeyPress)

renderer.AddActor(actor)
renderWindow.Render()
renderer.ResetCamera()
renderWindowInteractor.Start()

############################
mmusy
2018-11-21 11:57:07 UTC
Permalink
I only see a drop from 60 fps to 40fps
(with vtk 8.1.1, python 3.6, ubuntu workstation)




--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Ken Martin
2018-11-26 15:55:04 UTC
Permalink
Unfortunately changing the points causes a lot of recomputation for cell
coloring which is what you are using. It is because the changing points
could make a triangle become degenerate (which opengl does not count as a
cell, while VTK does)

If you have the memory on the GPU you could instead create an array of
actors, each with their own mappers and polydata and then loop over them by
changing their visibility (e.g. all are visibleOff except the current time
step). If that fits in memory it should be very fast.
Post by Flagada
Hi all !
I am trying to animate a mesh deformation with quite a large number of
nodes (about 300000).
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).
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.
But if I apply colors with a PolyData.GetCellData().SetScalars() the
framerate goes down to 13fps.
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 ?
Here below is the python code I use.
It draws a disk of 800x400 nodes and if you press on F1 it animates a kind
of sinus wave.
First it calculate each frame, then it display the animation without color
and finally it display the animation with random color on cells.
Thanks !
############################
import vtk
import math
from time import time
import random
############################
# Creating disk mesh
disk = vtk.vtkDiskSource()
disk.SetInnerRadius(0.1)
disk.SetOuterRadius(2.0)
disk.SetRadialResolution(400)
disk.SetCircumferentialResolution(800)
disk.Update()
PolyData = disk.GetOutput()
print("%d nodes" % PolyData.GetNumberOfPoints())
print("%d elms" % PolyData.GetNumberOfCells())
# Setup actor and mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(PolyData)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
# Setup render window, renderer, interactor and camera
renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
style = vtk.vtkInteractorStyleTrackballCamera()
renderWindowInteractor.SetInteractorStyle(style)
camera = vtk.vtkCamera()
camera.Elevation(-45)
renderer.SetActiveCamera(camera)
#################################
# Calculate each frame and store the vtkPoints into vtkPointsList
PolyData = disk.GetOutput()
vtkPointsList = {}
print("Calculate...")
start_time = time()
vtkPointsList[ph] = vtk.vtkPoints()
vtkPointsList[ph].DeepCopy(PolyData.GetPoints())
NodePos = vtkPointsList[ph].GetPoint(i)
vtkPointsList[ph].SetPoint(i, NodePos[0], NodePos[1], 0.3 *
math.sin(NodePos[0] * 2 + ph * math.pi / 180))
PolyData.SetPoints(vtkPointsList[ph])
renderWindow.Render()
print("Done. Animate.")
# First animation without color
start_time = time()
PolyData.SetPoints(vtkPointsList[ph])
renderWindow.Render()
print("%.2f FPS" % (18 / (time() - start_time)))
# Activate cells colors
ELMcolors = vtk.vtkUnsignedCharArray()
ELMcolors.SetNumberOfComponents(3)
ELMcolors.SetName("Colors")
ELMcolors.InsertNextTuple([random.random() * 255, random.random()
* 255, random.random() * 255])
PolyData.GetCellData().SetScalars(ELMcolors)
# Second animation with color
start_time = time()
PolyData.SetPoints(vtkPointsList[ph])
renderWindow.Render()
print("%.2f FPS" % (18 / (time() - start_time)))
####################################
style.AddObserver("KeyPressEvent", KeyPress)
renderer.AddActor(actor)
renderWindow.Render()
renderer.ResetCamera()
renderWindowInteractor.Start()
############################
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
Search the list archives at: http://markmail.org/search/?q=vtkusers
https://public.kitware.com/mailman/listinfo/vtkusers
--
Ken Martin PhD
Distinguished Engineer
Kitware Inc.
101 East Weaver Street
Carrboro, North Carolina
27510 USA

This communication, including all attachments, contains confidential and
legally privileged information, and it is intended only for the use of the
addressee. Access to this email by anyone else is unauthorized. If you are
not the intended recipient, any disclosure, copying, distribution or any
action taken in reliance on it is prohibited and may be unlawful. If you
received this communication in error please notify us immediately and
destroy the original message. Thank you.
Loading...