Search code examples
vtk

what is the role of Update( ) in VTK?


I m a new in vtk and i want to know what is the role of Update here , we can just use vtkNew sphereSource; and its will work

vtkNew<vtkSphereSource> sphereSource;
  sphereSource->Update();

Solution

  • It asks the algorithm to do the actual computation (see the doc). It is because VTK is lazy evaluated, so output is computed only when required. It allows you to change algorithm parameters without triggering unneeded computations.

    Example:

    vtkNew<vtkSphereSource> sphereSource;
    sphereSource->Update(); // compute sphere with default
    vtkPolyData* sphere = sphereSource->GetOutput();
    sphereSource->SetThetaResolution(100); // change from default. Does not trigger any computation.
    vtkPolyData* oldSphere = sphereSource->GetOutput(); // old output, source still not recomputed
    sphereSource->Update(); // compute new sphere
    vtkPolyData* sphere100 = sphereSource->GetOutput(); // new output