<div dir="ltr">This is a really interesting solution that looks to have very little overhead and seems to be not that invasive.<div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Mar 2, 2013 at 10:21 PM, David Thompson <span dir="ltr"><<a href="mailto:david.thompson@kitware.com" target="_blank">david.thompson@kitware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
> I have been having some conversations about the factories ... One feedback I already received (from David Camp, LBNL) was that, due to string comparisons used, object factories have a significant impact on performance when creating large number of objects. ... We could potentially revisit the way factories work and optimize it a bit.<br>
<br>
Are you thinking of something like this:<br>
<br>
<a href="http://www.altdevblogaday.com/2011/10/27/quasi-compile-time-string-hashing/" target="_blank">http://www.altdevblogaday.com/2011/10/27/quasi-compile-time-string-hashing/</a><br>
<br>
? I think it would be a useful utility in general (for more than just object overrides).<br>
<span class="HOEnZb"><font color="#888888"><br>
David<br>
</font></span><div class="HOEnZb"><div class="h5">><br>
> On Wed, Feb 13, 2013 at 8:44 PM, Kathleen S. Biagas <<a href="mailto:biagas2@llnl.gov">biagas2@llnl.gov</a>> wrote:<br>
>> On Wed, 2013-02-13 at 08:50 -0500, Marcus D. Hanwell wrote:<br>
>>> On Tue, Feb 12, 2013 at 8:54 PM, Kathleen S. Biagas <<a href="mailto:biagas2@llnl.gov">biagas2@llnl.gov</a>> wrote:<br>
>>>> Trying to come up to speed with current VTK master, and ran across<br>
>>>> issues trying to override vtk classes.<br>
>>>><br>
>>>> One thing I noticed was that I could not override the classes I was<br>
>>>> interested in without first building VTK with VTK_ALL_NEW_OBJECT_FACTORY<br>
>>>> enabled. So my first question is: are more classes going to be opened<br>
>>>> up for overriding within the new scheme of things without having to set<br>
>>>> this flag? Or will this flag be enabled by default in the future? We<br>
>>>> eventually want our code to compile with a user's preinstalled VTK, and<br>
>>>> there wouldn't be a guarantee this flag would have been used.<br>
>>><br>
>>> I would be interested in knowing which classes you are interested in<br>
>>> overriding that were not. There are several new macros now, and as you<br>
>>> discovered the default one no longer uses the object factory without<br>
>>> the build flag you mentioned. The plan was to leave that off by<br>
>>> default, and add more classes where runtime overrides are needed.<br>
>><br>
>> One of the classes we override is vtkDataSetMapper, so that we can<br>
>> instantiate specialized mappers for vtkRectilinearGrids and<br>
>> vtkStructuredGrids. Another is vtkCellDataToPointData, again with<br>
>> specialized handling for vtkStructuredGrids and vtkRectilinearGrids.<br>
>> We also override vtkRectilinearGrid and vtkStructuredGrid to provide<br>
>> implementations with smaller memory footprints.<br>
>><br>
>> These are all handled correctly if we enable VTK_ALL_NEW_OBJECT_FACTORY.<br>
>><br>
>>>><br>
>>>> The other thing I noticed was a change in behavior. To illustrate, I<br>
>>>> copied the TestObjectFactory.cxx from Common/Core/Testing/cxx, and<br>
>>>> modified it to override vtkCamera instead of vtkPoints.<br>
>>>><br>
>>>> When built against an older version of VTK, say 5.8, the results show<br>
>>>> that when vtkCamera is instantiated, the correct version (either<br>
>>>> vtkTestCamera or vtkTestCamera2) is succesfully created. Running through<br>
>>>> the vtkOverrideInformationCollection printing OverrideWithName, only two<br>
>>>> are shown: vtkTestCamera and vtkTestCamera2.<br>
>>>><br>
>>>> When built against latest version of master, the results show that when<br>
>>>> vtkCamera is instantiated, a vtkOpenGLCamera is created instead of<br>
>>>> either of the registered overrides in the test (vtkTestCamera or<br>
>>>> vtkTestCamera2). Running through the vtkOverrideInformationCollection,<br>
>>>> and printing the OverrideWithName, three are shown: vtkOpenGLCamera,<br>
>>>> vtkTestCamera and vtkTestCamera2.<br>
>>>><br>
>>> That is because the old VTK didn't use the object factory for the<br>
>>> default overrides, and so you could come in and add an additional<br>
>>> override. Now that we use the object factory internally that is<br>
>>> generally the first. As far as I can tell the object factory mechanism<br>
>>> has always returned the first match by default, and will only provide<br>
>>> a list if you use that part of the API.<br>
>><br>
>> Aah, understand this aspect now, thanks.<br>
>>>><br>
>>>> In the new scheme of things, how would I go about ensuring my override<br>
>>>> takes precedence over any default ones? eg vtkTestCamera over<br>
>>>> vtkOpenGLCamera?<br>
>>><br>
>>> The object factory API would need to be modified in some way, this<br>
>>> functionality has never been present. The old hardwired factory<br>
>>> classes for particular kits would first check the object factory, and<br>
>>> if nothing was returned construct the class that was set at compile<br>
>>> time. This meant that effectively you could override the builtin<br>
>>> class, but only once.<br>
>>><br>
>>> It would be great to know more about what you are doing, and what<br>
>>> classes you are thinking of in VTK that you would like to override.<br>
>>><br>
>> One of the things we have is a Rendering module, and it overrides things<br>
>> like vtkCamera. Even enabling the VTK_ALL_NEW_OBJECT_FACTORY flag<br>
>> doesn't allow this to work correctly, due to the OpenGL overrides<br>
>> already existing.<br>
>><br>
>> I did a little tweaking of the build for this, making it a proper<br>
>> 'Module' in the VTK sense, following instructions I found on<br>
>> <a href="http://vtk.org/Wiki/VTK/Module_Development#External_modules" target="_blank">http://vtk.org/Wiki/VTK/Module_Development#External_modules</a><br>
>><br>
>> I ran into a problem in that vtkExternalModuleMacros.cmake was not<br>
>> included in the VTK install tree. Is there a specific flag to set<br>
>> during build that allows this to be installed? In the meantime, I<br>
>> copied this file to the installation, but building this code as a<br>
>> vtkModule still doesn't allow the overrides defined by the module to<br>
>> take precedence.<br>
>><br>
>> I thought of using vtkObjectFactory::SetAllEnableFlags(0, "vtkCamera")<br>
>> before registering the rendering module's factory, but wasn't sure if<br>
>> that was overkill ...<br>
>><br>
>> Thanks for the feedback!<br>
>><br>
>> Kathleen<br>
>><br>
>>> Marcus<br>
>><br>
>><br>
>><br>
>> _______________________________________________<br>
>> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>><br>
>> Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>><br>
>> Follow this link to subscribe/unsubscribe:<br>
>> <a href="http://www.vtk.org/mailman/listinfo/vtk-developers" target="_blank">http://www.vtk.org/mailman/listinfo/vtk-developers</a><br>
>><br>
> _______________________________________________<br>
> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://www.vtk.org/mailman/listinfo/vtk-developers" target="_blank">http://www.vtk.org/mailman/listinfo/vtk-developers</a><br>
><br>
<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtk-developers" target="_blank">http://www.vtk.org/mailman/listinfo/vtk-developers</a><br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Robert Maynard
</div></div>