[vtk-developers] My vtk class override not being used when an override already exists.

Marcus D. Hanwell marcus.hanwell at kitware.com
Wed Feb 13 08:50:25 EST 2013


On Tue, Feb 12, 2013 at 8:54 PM, Kathleen S. Biagas <biagas2 at llnl.gov> wrote:
> Trying to come up to speed with current VTK master, and ran across
> issues trying to override vtk classes.
>
> One thing I noticed was that I could not override the classes I was
> interested in without first building VTK with VTK_ALL_NEW_OBJECT_FACTORY
> enabled.  So my first question is:  are more classes going to be opened
> up for overriding within the new scheme of things without having to set
> this flag?  Or will this flag be enabled by default in the future?  We
> eventually want our code to compile with a user's preinstalled VTK, and
> there wouldn't be a guarantee this flag would have been used.

I would be interested in knowing which classes you are interested in
overriding that were not. There are several new macros now, and as you
discovered the default one no longer uses the object factory without
the build flag you mentioned. The plan was to leave that off by
default, and add more classes where runtime overrides are needed.
>
> The other thing I noticed was a change in behavior.  To illustrate, I
> copied the TestObjectFactory.cxx from Common/Core/Testing/cxx, and
> modified it to override vtkCamera instead of vtkPoints.
>
> When built against an older version of VTK, say 5.8, the results show
> that when vtkCamera is instantiated, the correct version (either
> vtkTestCamera or vtkTestCamera2) is succesfully created. Running through
> the vtkOverrideInformationCollection printing OverrideWithName, only two
> are shown: vtkTestCamera and vtkTestCamera2.
>
> When built against latest version of master, the results show that when
> vtkCamera is instantiated, a vtkOpenGLCamera is created instead of
> either of the registered overrides in the test (vtkTestCamera or
> vtkTestCamera2). Running through the vtkOverrideInformationCollection,
> and printing the OverrideWithName, three are shown: vtkOpenGLCamera,
> vtkTestCamera and vtkTestCamera2.
>
That is because the old VTK didn't use the object factory for the
default overrides, and so you could come in and add an additional
override. Now that we use the object factory internally that is
generally the first. As far as I can tell the object factory mechanism
has always returned the first match by default, and will only provide
a list if you use that part of the API.
>
> In the new scheme of things, how would I go about ensuring my override
> takes precedence over any default ones? eg vtkTestCamera over
> vtkOpenGLCamera?

The object factory API would need to be modified in some way, this
functionality has never been present. The old hardwired factory
classes for particular kits would first check the object factory, and
if nothing was returned construct the class that was set at compile
time. This meant that effectively you could override the builtin
class, but only once.

It would be great to know more about what you are doing, and what
classes you are thinking of in VTK that you would like to override.

Marcus



More information about the vtk-developers mailing list