How to pass parameters to vtk constructor?

Generally, we use vtkSmartPointer to create a object as:

vtkSmartPointer<vtkConeSource> cone = vtkSmartPointer<vtkConeSource>::New();

After reading the source code of vtkConeSource, I find it accept a parameter in the constructor:

protected:
    vtkConeSource(int res=6);

Then, how can I pass the parameter to vtkConeSource?

vtkSmartPointer<vtkConeSource>::New(6) is wrong.

It is protected and is the default resolution. Use SetResolution() to change the resolution. There are other parameters of the cone that you can also change, see: vtkConeSource. There are also some links to vtk-examples using vtkConeSource.

Regarding protected constructors, this may give you more information: What are practical uses of a protected constructor?.

Btw, this contstructor parameter is very old code and should be deprecated to avoid these kind of misunderstanding.

git tells me it was commited in 1995 by @ken-martin :slight_smile:

Yes 100%

2 Likes

Note that there are also bits of documentation, usually in the .cxx file but I think even occasionally in the .h file, which refers to these construction parameters… lots of clean up to do