VTK/Developers Corner

From KitwarePublic
< VTK
Revision as of 22:23, 19 November 2009 by Francoisbertel (talk | contribs) (New page: == Developers Corner == * If you work with Paraview and VTK, the recommended procedure is to use the same source tree for both projects. That is, build Paraview from .../src/Paraview and V...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Developers Corner

  • If you work with Paraview and VTK, the recommended procedure is to use the same source tree for both projects. That is, build Paraview from .../src/Paraview and VTK from .../src/Paraview/VTK.
  • You should use vtkGetObjectMacro and vtkCxxSetObjectMacro to set and get member variables that are custom types. This allows VTK's mechanisms to keep the reference count correct by automatically registering and unregistering your objects. An example using a custom class member variable is here.

Pitfalls

  • When using the Set*Macro's, you must initialize the variable that is being set in the constructor. The Set*Macro does a check to see if the value has changed before changing it (so that it can update the Modified variable), so if the value is uninitialized, this will cause an error in some memory checking tools (such as valgrind).
  • When trying to use an abstract class, such as

<source lang="cpp"> vtkSmartPointer<vtkPointSet> PointSet = vtkSmartPointer<vtkPointSet>::New(); </source> you will see <source lang="text"> error: invalid conversion from 'vtkDataObject*' to 'vtkPointSet*' </source> To fix this, use a subclass instead.

  • You are getting

<source lang="text"> Generic Warning: In /home/doriad/src/ParaView3/VTK/Common/vtkDebugLeaks.cxx, line 296 Deleting unknown object: vtkObject </source> and <source lang="text"> vtkDebugLeaks has detected LEAKS! Class "vtkYourClass" has N instances still around. </source>

This could mean one of two things. Either 1) you are actually doing something wrong by trying to manually delete a smart pointer or the equivalent or 2) You have forgotten to add: <source lang="cpp"> vtkCxxRevisionMacro(vtkYourClass, "$Revision: 1.1 $"); </source> to your .cxx file and

<source lang="cpp"> vtkTypeRevisionMacro(vtkYourClass,vtkObject); </source> to your .h file.

You must do this because vtkDebugLeaks uses the VTK factory mechanism to keep track of references.

Examples for Developers