Discussion:
[vtkusers] Extending vtkOpenGLRenderer
Matthew Troke
2018-11-13 18:00:33 UTC
Permalink
I am adding a new module to VTK that extends vtkOpenGLRenderer (let's call
it vtkMyOpenGLRenderer). I would like to be able to use this in an
application such that when I instantiate a vtkRenderer (such as with
vtkRenderer::New()), it creates a vtkMyOpenGLRenderer. I'm not clear on the
correct way to set this up via CMake. Do I need to create a new backend, or
just enable the object factory?

Matt
--
Matthew Troke
Software Engineer
Office: 1-709-701-0239
Email: ***@avalonholographics.com
--
_This email and any attachments are confidential and may be privileged. Any
unauthorized use, disclosure, copying or distribution of the information
received is prohibited. If you are not the intended recipient please
contact the sender immediately by return email confirming that you have and
will delete all communications related to the email and any attachments
sent to you in error._
Marcus D. Hanwell
2018-11-13 18:52:32 UTC
Permalink
On Tue, Nov 13, 2018 at 1:00 PM Matthew Troke <
Post by Matthew Troke
I am adding a new module to VTK that extends vtkOpenGLRenderer (let's call
it vtkMyOpenGLRenderer). I would like to be able to use this in an
application such that when I instantiate a vtkRenderer (such as with
vtkRenderer::New()), it creates a vtkMyOpenGLRenderer. I'm not clear on the
correct way to set this up via CMake. Do I need to create a new backend, or
just enable the object factory?
This is really just a runtime thing, and you would achieve it by
manipulating the object factory. All the CMake code does is ensure the
appropriate calls are made before any of the classes are instantiated, as
part of your application start up logic you would want to remove the
standard vtkOpenGLRenderer override, and add your own. You don't even need
this to be in a module, it just needs to derive from the vtkRenderer class
so that it is possible to return a vtkRenderer pointer from the static
::New() method.

Hope that makes sense, the entire object factory thing is runtime. We just
added convenience functions in the form of defines passed into the build
system, or calls you can add to your code that is compiled into your
application somewhere.
Matthew Troke
2018-11-13 19:10:20 UTC
Permalink
What I don't understand is how does vtkRenderer::New() know what type of
renderer to create? Normally, this would be a vtkOpenGLRenderer, so
something must be telling VTK to override the class type with
vtkOpenGLRenderer. How do I tell my application to create a
vtkMyOpenGLRenderer instead? I don't know what you mean by "manipulate the
object factory".

Matt

On Tue, Nov 13, 2018 at 3:22 PM Marcus D. Hanwell <
Post by Marcus D. Hanwell
On Tue, Nov 13, 2018 at 1:00 PM Matthew Troke <
Post by Matthew Troke
I am adding a new module to VTK that extends vtkOpenGLRenderer (let's
call it vtkMyOpenGLRenderer). I would like to be able to use this in an
application such that when I instantiate a vtkRenderer (such as with
vtkRenderer::New()), it creates a vtkMyOpenGLRenderer. I'm not clear on the
correct way to set this up via CMake. Do I need to create a new backend, or
just enable the object factory?
This is really just a runtime thing, and you would achieve it by
manipulating the object factory. All the CMake code does is ensure the
appropriate calls are made before any of the classes are instantiated, as
part of your application start up logic you would want to remove the
standard vtkOpenGLRenderer override, and add your own. You don't even need
this to be in a module, it just needs to derive from the vtkRenderer class
so that it is possible to return a vtkRenderer pointer from the static
::New() method.
Hope that makes sense, the entire object factory thing is runtime. We just
added convenience functions in the form of defines passed into the build
system, or calls you can add to your code that is compiled into your
application somewhere.
--
Matthew Troke
Software Engineer
Office: 1-709-701-0239
Email: ***@avalonholographics.com
--
_This email and any attachments are confidential and may be privileged. Any
unauthorized use, disclosure, copying or distribution of the information
received is prohibited. If you are not the intended recipient please
contact the sender immediately by return email confirming that you have and
will delete all communications related to the email and any attachments
sent to you in error._
Matthew Troke
2018-11-13 19:18:35 UTC
Permalink
I think I've figured out that the abstract New() searches all registered
object factories for an override. My question is if you have 2 modules with
object factories that override the same base object, which one wins out?
And can you ensure that a particular override gets chosen?

On Tue, Nov 13, 2018 at 3:40 PM Matthew Troke <
Post by Matthew Troke
What I don't understand is how does vtkRenderer::New() know what type of
renderer to create? Normally, this would be a vtkOpenGLRenderer, so
something must be telling VTK to override the class type with
vtkOpenGLRenderer. How do I tell my application to create a
vtkMyOpenGLRenderer instead? I don't know what you mean by "manipulate the
object factory".
Matt
On Tue, Nov 13, 2018 at 3:22 PM Marcus D. Hanwell <
Post by Marcus D. Hanwell
On Tue, Nov 13, 2018 at 1:00 PM Matthew Troke <
Post by Matthew Troke
I am adding a new module to VTK that extends vtkOpenGLRenderer (let's
call it vtkMyOpenGLRenderer). I would like to be able to use this in an
application such that when I instantiate a vtkRenderer (such as with
vtkRenderer::New()), it creates a vtkMyOpenGLRenderer. I'm not clear on the
correct way to set this up via CMake. Do I need to create a new backend, or
just enable the object factory?
This is really just a runtime thing, and you would achieve it by
manipulating the object factory. All the CMake code does is ensure the
appropriate calls are made before any of the classes are instantiated, as
part of your application start up logic you would want to remove the
standard vtkOpenGLRenderer override, and add your own. You don't even need
this to be in a module, it just needs to derive from the vtkRenderer class
so that it is possible to return a vtkRenderer pointer from the static
::New() method.
Hope that makes sense, the entire object factory thing is runtime. We
just added convenience functions in the form of defines passed into the
build system, or calls you can add to your code that is compiled into your
application somewhere.
--
Matthew Troke
Software Engineer
Office: 1-709-701-0239
--
Matthew Troke
Software Engineer
Office: 1-709-701-0239
Email: ***@avalonholographics.com
--
_This email and any attachments are confidential and may be privileged. Any
unauthorized use, disclosure, copying or distribution of the information
received is prohibited. If you are not the intended recipient please
contact the sender immediately by return email confirming that you have and
will delete all communications related to the email and any attachments
sent to you in error._
Marcus D. Hanwell
2018-11-13 20:34:54 UTC
Permalink
On Tue, Nov 13, 2018 at 2:18 PM Matthew Troke <
Post by Matthew Troke
I think I've figured out that the abstract New() searches all registered
object factories for an override. My question is if you have 2 modules with
object factories that override the same base object, which one wins out?
And can you ensure that a particular override gets chosen?
Take a look at
https://github.com/Kitware/VTK/blob/master/Common/Core/Testing/Cxx/TestObjectFactory.cxx
for the object factory in use, figuring out which override wins, etc.
Loading...