[vtkusers] Experience upgrading from 3.2 to 4.x

Tim Hutton T.Hutton at eastman.ucl.ac.uk
Thu Feb 14 09:31:51 EST 2002


Hello vtkusers!

I've just ported my medium-sized (40K lines) application from vtk3.2 to 
vtk4.x. I thought I would share my experiences with you, in case there were 
people out there contemplating it but a bit scared.

The documentation in

http://public.kitware.com/VTK/files/misc/Upgrading.zip

and the FAQ entry 6.7 at

http://public.kitware.com/cgi-bin/vtkfaq?req=show&file=faq06.007.htp

are both useful but don't have enough concrete examples. Hopefully this 
email will help a little, though it is by no means complete. I'm using 
VC++6 + MFC on Win2K and was unable/unwilling to run the script in the zip 
file.

So,

I switched all my include directories to the new VTK ones and recompiled. 
337 errors, not unexpectedly. Most concerned vtkScalars and vtkTCoords 
which have both been removed. Where I was using single value scalars, like 
this:

vtkScalars *scalars = vtkScalars::New();
scalars->SetNumberOfScalars(N_POINTS);
...
polydata->GetPointData()->SetScalars(scalars);
...
scalars->SetScalar(i,2.3);
...

I replaced with:

vtkFloatArray *scalars = vtkFloatArray::New();
scalars->SetNumberOfComponents(1);
scalars->SetNumberOfTuples(N_POINTS);
...
polydata->GetPointData()->SetScalars(scalars);
...
scalars->SetTuple1(i,2.3);
...

OK so far, far fewer errors.

Where I had 2D texture coordinates:

vtkTCoords *tcoords = vtkTCoords::New();
tcoords->SetNumberOfTCoords(N);
...
float p[3];
p[0]=x; p[1]=y;
tcoords->SetTCoord(i,p);
...

I replaced with:

vtkFloatArray *tcoords = vtkTCoords::New();
tcoords->SetNumberOfComponents(2);
tcoords->SetNumberOfTuples(N);
...
float p[2];
p[0]=x; p[1]=y;
tcoords->SetTuple(i,p);
....

All well and good, still fewer errors. Make sure you call 
SetNumberOfComponents *before* SetNumberOfTuples else you'll get problems 
(I did!).

Where I was creating 0-255 image data and had been using:

vtkScalars* scalars = vtkScalars::New();
scalars->SetDataTypeToUnsignedChar();
...

I replaced with:

vtkUnsignedCharArray *scalars = vtkUnsignedCharArray::New()
...

Going well!

When creating RGB images, I had been using:

vtkScalars *scalars = vtkScalars::New();
scalars->SetDataTypeToUnsignedChar();
scalars->SetNumberOfComponents(3);
scalars->SetNumberOfScalars(X*Y);
...
scalars->SetActiveComponent(0);
scalars->SetScalar(i,val1);
scalars->SetActiveComponent(1);
scalars->SetScalar(i,val2);
scalars->SetActiveComponent(2);
scalars->SetScalar(i,val3);
...

I replaced with:

vtkUnsignedCharArray *scalars = vtkUnsignedCharArray::New()
scalars->SetNumberOfComponents(3);
scalars->SetNumberOfScalars(X*Y);
...
scalars->SetComponent(i,0,val1);
scalars->SetComponent(i,1,val2);
scalars->SetComponent(i,2,val3);
...

My remaining errors concerned vtkWin32OffscreenRenderWindow that has been 
removed. Where I had been using:

vtkWin32OffscreenRenderWindow *offscreen = 
vtkWin32OffscreenRenderWindow::New();
...

I replaced with:

vtkWin32OpenGLRenderWindow *offscreen = vtkWin32OpenGLRenderWindow::New();
offscreen->SetOffScreenRendering(1);
...

All done. I'd had to throw in some #include "vtkFloatArray.h" and things 
like that of course. Zero compile errors.

Had to remember to link against the new vtk lib files, so I removed

vtkdll.lib

and added

vtkCommon.lib
vtkGraphics.lib
etc.

Zero link errors. My program is up and running again, no apparant problems. 
Plus now I can use all the new features of vtk4. (And I'm sure it's faster 
but maybe that's my imagination.)

Bye!

Tim.





More information about the vtkusers mailing list