What version of VTK supports vtkNew automatic casting?

Viewed 117

A question

Older versions of VTK require Get() or GetPointer() to access a vtkNew<vtkClass> element. Newer versions do not, as used on the Vtk example web sight.

What version did this change in?
Would it be helpful for people to know about this change? rhetorical
It does make the samples easier to read. Hopefully this question is helpful to someone.

Background

This is helpful to using the VTK examples website.

I am compiling a VTK example on Ubuntu 20.04 with the vtk7 packages and have the following compile errors,

ProteinRibbons.cxx:37:20: error: cannot convert ‘vtkNew’ to ‘vtkMapper*’

I came across this discourse post when searching for this error.

At first, I thought this was due to differences is the vtkChemistry module. However, I later discovered that I needed to replace the lines,

- actor->SetMapper(polyDataMapper);
+actor->SetMapper(polyDataMapper.Get());

with some motivating information from the Discourse post (after being discourage that people think everyone in the world is using a duck-typed language).

Below is a list of packages,

$ sudo dpkg -l | grep -i vtk7
ii  libvtk7-dev                                7.1.1+dfsg2-2ubuntu1                        amd64        VTK header files
ii  libvtk7-java                               7.1.1+dfsg2-2ubuntu1                        amd64        Visualization Toolkit - A high level 3D visualization library - java
ii  libvtk7-jni                                7.1.1+dfsg2-2ubuntu1                        amd64        Visualization Toolkit - A high level 3D visualization library - java
ii  libvtk7-qt-dev                             7.1.1+dfsg2-2ubuntu1                        amd64        VTK header files, containing Qt files
ii  libvtk7.1p                                 7.1.1+dfsg2-2ubuntu1                        amd64        VTK libraries
ii  libvtk7.1p-qt                              7.1.1+dfsg2-2ubuntu1                        amd64        VTK libraries, Qt files
ii  python3-vtk7                               7.1.1+dfsg2-2ubuntu1                        amd64        Python bindings for VTK
ii  tcl-vtk7                                   7.1.1+dfsg2-2ubuntu1                        amd64        Tcl bindings for VTK
ii  vtk7                                       7.1.1+dfsg2-2ubuntu1                        amd64        Binaries for VTK7
ii  vtk7-doc                                   7.1.1+dfsg2-2ubuntu1                        all          VTK class reference documentation
ii  vtk7-examples                              7.1.1+dfsg2-2ubuntu1                        all          VTK examples

I then investigated the vtkNew.h in Ubuntu 20.04 (version 7) and a git copy I have (version 9).

vtkNew.h v7.1.1

 * Automatic casting is intentionally unavailable, calling GetPointer() will
 * return a raw pointer. Users of this method should ensure that they do not
 * return this pointer if the vtkNew will go out of scope without
 * incrementing its reference count using vtkSmartPointer or similar.

vtkNew.h v9.0.0-3086-gd3fe17811e

 * Automatic casting to raw pointer is available for convenience, but
 * users of this method should ensure that they do not
 * return this pointer if the vtkNew will go out of scope without
 * incrementing its reference count.
1 Answers

Use git blame gives,

00bf5f3d3ac   * Automatic casting to raw pointer is available for convenience, but
00bf5f3d3ac   * users of this method should ensure that they do not
6a7e5148ed5   * return this pointer if the vtkNew will go out of scope without
00bf5f3d3ac   * incrementing its reference count.

Looks primarily commit 00bf5f3d3ac. Gives message,

$ git log --oneline 00bf5f3d3ac~1..00bf5f3d3ac
00bf5f3d3a Add implicit raw pointer conversion to vtkNew
$ git describe 00bf5f3d3a
v8.0.0.rc2-219-g00bf5f3d3a

So this is version 8 and after. The info is helpful to developers on other systems that want to use the VTK examples. Ubuntu 22.04 will have an option for VTK9, so select that in a few months if you found this Q/A.


Covid-19 beta spike protein

6vsb spike protein as viewed with working example.

Related