VTK/VTK 6 Migration/Factories now require defines: Difference between revisions

From KitwarePublic
< VTK
Jump to navigationJump to search
No edit summary
(Updated with details of new macro)
Line 5: Line 5:
The factory methods now require "auto-initialization" depending on what modules are enabled at VTK configure time. If you are enabling all modules, and building your project without using CMake, you will need some defines in your project in order to make the factories work properly.
The factory methods now require "auto-initialization" depending on what modules are enabled at VTK configure time. If you are enabling all modules, and building your project without using CMake, you will need some defines in your project in order to make the factories work properly.


Try including this snippet in all your code that includes VTK usage, '''BEFORE''' including '''ANY''' VTK header files:
On September 10, 2013 a new macro was added to make this process a little simpler for projects that just want to initialize modules, where ordering ceases to be important but you must still build a source file into your application that has something along with following (with one entry for each module that should be initialized).
 
  #include <vtkAutoInit.h>
  VTK_MODULE_INIT(vtkRenderingOpenGL);
 
This will initialize the vtkRenderingOpenGL object factories, and should be done for each module. If you are using an older version of VTK (6.0 or master from before the date above) than you can try including this snippet in all your code that includes VTK usage, '''BEFORE''' including '''ANY''' VTK header files:


   #define vtkRenderingCore_AUTOINIT 4(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingFreeTypeOpenGL,vtkRenderingOpenGL)
   #define vtkRenderingCore_AUTOINIT 4(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingFreeTypeOpenGL,vtkRenderingOpenGL)

Revision as of 01:53, 11 September 2013

"I've done all this, it compiles and links, but now "New()" returns NULL at runtime"

If you build your project with CMake, and you use the standard find_package(VTK) and include(${VTK_USE_FILE}) then this problem should not occur. (Because the defines will be automatically added for you by virtue of the include(${VTK_USE_FILE})...)

The factory methods now require "auto-initialization" depending on what modules are enabled at VTK configure time. If you are enabling all modules, and building your project without using CMake, you will need some defines in your project in order to make the factories work properly.

On September 10, 2013 a new macro was added to make this process a little simpler for projects that just want to initialize modules, where ordering ceases to be important but you must still build a source file into your application that has something along with following (with one entry for each module that should be initialized).

 #include <vtkAutoInit.h>
 VTK_MODULE_INIT(vtkRenderingOpenGL);

This will initialize the vtkRenderingOpenGL object factories, and should be done for each module. If you are using an older version of VTK (6.0 or master from before the date above) than you can try including this snippet in all your code that includes VTK usage, BEFORE including ANY VTK header files:

 #define vtkRenderingCore_AUTOINIT 4(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingFreeTypeOpenGL,vtkRenderingOpenGL)
 #define vtkRenderingVolume_AUTOINIT 1(vtkRenderingVolumeOpenGL)

See these references (and follow the mailing list threads to their conclusions) for more info: