vtkSmartPointer and vtkNew in VTK's API. Best practices?

These comments are more general but strongly support best practice.

I think we should always take advantage of compiler optimizations and newer ways of doing things. When I first started using VTK in 2000 there was another visualisation suite (IBM?) that we looked at, however for many reasons, VTK was better, mainly because it was open source and many new features and fixes were happening. From this period onwards VTK became the dominant Visualisation Suite, mainly because of the way Kitware developed it and because of the fact it was open source. A quick look at the literature finds this one paper Comparing and evaluating computer graphics and visualization software with this comment “The VTK prevails on top in many of the aspects we compared and evaluated.” So VTK has to maintain its competitive advantage and to do this it must change and evolve getting better and better.

VTK has to evolve to more fully utilise C++11 and in the future C++14/17… Compilers are getting smarter at optimising and there are newer programmers who understand and want to use the features of modern C++. So it is not a bad thing to evolve VTK to take advantage of more modern C++. Sure old code will break and need fixing but it should run better and be easier to maintain. Also this process often uncovers subtle bugs.

VTK 8.90 is a moving feast at present but we are keeping up with the changes in VTKExamples in respect to C++! Mostly through doing something like this where changes are needed:

#include <vtkVersion.h>

#if VTK_MAJOR_VERSION > 8 || VTK_MAJOR_VERSION == 8 && VTK_MINOR_VERSION >= 90
#include "vtkShaderProperty.h"
#endif
...
 // Modify the vertex shader to pass the position of the vertex
#if VTK_MAJOR_VERSION > 8 || VTK_MAJOR_VERSION == 8 && VTK_MINOR_VERSION >= 90
  vtkShaderProperty* sp = actor->GetShaderProperty();
  sp->AddVertexShaderReplacement(
#else
  mapper->AddShaderReplacement(
    vtkShader::Vertex,
#endif

However for Python, we cannot do this.

The VTKExamples are also a good testing ground for new features.

1 Like