<div dir="ltr"><div style>Hi Brad,</div><div><br></div><div style>Thanks again for working on this issue :)</div><div><br></div>I just updated ITKv4 Slicer external project so that ITK master including your topic is now used.<div>
See <a href="http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=21859">http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=21859</a></div><div><br></div><div style>Thanks</div><div style>
Jc</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Apr 3, 2013 at 2:13 PM, Jean-Christophe Fillion-Robin <span dir="ltr"><<a href="mailto:jchris.fillionr@kitware.com" target="_blank">jchris.fillionr@kitware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">1) A possible way of checking this would be to check if an env variable named ITK_OBJECT_FACTORY_BASE_INITIALIZE_VERBOSE is defined to 1, if it is the case, the number of registered factory would be displayed in the "ObjectFactoryBase::Initialize()" methods.<div>
<br></div><div>Then writing a hello world program linking against ITK, would allow to check if the "hello world" string is displayed before or after static initialization.</div><div><br></div><div>
2) I think the addition of a ITKFactoryRegistration shared library would be backward compatible. Application would be either using their inside hack or calling the method provided by ITK allowing to register the factories. Let's also note that all of this would be needed only if the variable <span style="font-size:12.800000190734863px;font-family:arial,sans-serif">ITK_NO_IO_FACTORY_</span><span style="font-size:12.800000190734863px;font-family:arial,sans-serif">REGISTER_MANAGER is set to True.</span></div>
<div><br></div><div><font face="arial, sans-serif">I really think this would benefit every application loading plugin. </font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">3) A different approach would be to check if a given factory is already loaded and ensure that no duplicate factory are registered.</font></div>
<div class="im">
<div><span style="font-size:12.800000190734863px;font-family:arial,sans-serif"><br></span></div><div><span style="font-size:12.800000190734863px;font-family:arial,sans-serif">Let me know what you think.</span></div>
<div><span style="font-size:12.800000190734863px;font-family:arial,sans-serif"><br></span></div><div><span style="font-size:12.800000190734863px;font-family:arial,sans-serif">Thanks</span></div><div><span style="font-size:12.800000190734863px;font-family:arial,sans-serif">Jc</span></div>
</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Apr 3, 2013 at 1:25 PM, Bradley Lowekamp <span dir="ltr"><<a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Bill,<div><br></div><div>There is currently no an obvious way I see to check this. If you call a method of the ObjectFactory to ask how many object are registered, it will do the initialization if it wasn't before.</div>
<div><br></div><div>Now a new method could be added, to check if the ObjectFactory has been initialized. But I recall there was quite a lot of issues with the class on when the initialization should occur and how to check if it needs to be done.</div>
<div><br></div><div>Brad</div><div><div><div><br><div><div>On Apr 3, 2013, at 12:35 PM, Bill Lorensen <<a href="mailto:bill.lorensen@gmail.com" target="_blank">bill.lorensen@gmail.com</a>> wrote:</div><br>
<blockquote type="cite"><div dir="ltr"><div><div>Brad,<br><br></div>Is there a way we can test for this in ITK? Better we find it before our customers.<br><br></div>Bill<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Wed, Apr 3, 2013 at 12:11 PM, Jean-Christophe Fillion-Robin <span dir="ltr"><<a href="mailto:jchris.fillionr@kitware.com" target="_blank">jchris.fillionr@kitware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks Brad for looking at the issue so quickly :)<div><br></div><div>I reviewed your patch in gerrit and posted comment.</div>
<div><br></div><div>Thanks</div><span><font color="#888888">Jc</font></span></div><div><div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Wed, Apr 3, 2013 at 11:33 AM, Bradley Lowekamp <span dir="ltr"><<a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">Hello JC,<div><br></div><div>This is quite an interesting side-effect of the changes I introduced.</div><div><br></div><div>I am glad that you were able to figure this out. For a variety of reasons, it's likely a very bad thing for all that to occur during static initialization in ITK. So it certainly needs to be fixed.</div>
<div><br></div><div>I agree that lazy initialization is the way to go. Unfortunately it needs to be thread safe so its a little more completed.</div><div><br></div><div>ITKv4 performs the factory initialization when the user creates the first ITK object. And that changed with this patch, and need to be fixed.</div>
<div><br></div><div>CONCLUSION:</div><div><br></div><div>Inside ITK, we can not use statically initialized ITK object.</div><div><br></div><div>Brad</div><div><br><div><div><div>On Apr 3, 2013, at 10:54 AM, Jean-Christophe Fillion-Robin <<a href="mailto:jchris.fillionr@kitware.com" target="_blank">jchris.fillionr@kitware.com</a>> wrote:</div>
<br></div><blockquote type="cite"><div><div dir="ltr">Hi Brad, <div><br></div><div>Following commit 4c47e7d [1] of February 19th and commit defb9c1 [2] of March 1st, due to static initialization, the initialization of ObjectFactory now happens when ITK shared library are loaded [3][4].</div>
<div><br></div><div>This caused a regression in Slicer where the ObjectFactory were expected to be loaded while attempting to load an image for the first time. </div><div><br></div><div>In Slicer case, the environment variable ITK_AUTOLOAD_PATH was set during the initialization of the qSlicerCoreApplication, which is now too late.</div>
<div><br></div><div>By commenting line where a new ImageRegionSplitterSlowDimension is instantiated [5][6] and updating the method "GetImageRegionSplitter / GetGlobalDefaultSplitter" to return 0 [7][8], the initialization can happen on demand instead of when ITK libraries are loaded.</div>
<div><br></div><div>An easy solution for us would be to ensure the "ITK_AUTOLOAD_PATH" environment variable is set in the application launcher for Windows and Linux application and set in Info.plist file associated with the application bundle on MacOSX [9]</div>
<div><br></div><div>To provide more details, within Slicer we set the CMake variable ITK_NO_IO_FACTORY_REGISTER_MANAGER before doing an "include(${ITK_USE_FILE}) so that IOFactory are loaded only by calling the method "itkFactoryRegistration" associated with a shared library we named ITKFactoryRegistration. This approach allowed us to disable the automatic registration of factory in selected part of the code. More details here [10]</div>
<div><br></div><div>It seems the new ITK commits 4c47e7d and defb9c1 prevent from completely leveraging the use of ITK_NO_IO_FACTORY_REGISTER_MANAGER variable, the code should probably be updated to consider this.</div>
<div><br></div><div><br></div><div>Let me know what you think.</div><div><br></div><div>Thanks</div><div>Jc</div><div><div><br></div><div><br></div><div>[1] <a href="https://github.com/Kitware/ITK/commit/4c47e7d" target="_blank">https://github.com/Kitware/ITK/commit/4c47e7d</a></div>
<div>[2] <a href="https://github.com/Kitware/ITK/commit/defb9c1" target="_blank">https://github.com/Kitware/ITK/commit/defb9c1</a></div><div>[3] <a href="https://github.com/Kitware/ITK/blob/4c47e7d672bad5d83b92c2df5f293cca618e2740/Modules/Core/Common/src/itkImageSource.cxx#L27" target="_blank">https://github.com/Kitware/ITK/blob/4c47e7d672bad5d83b92c2df5f293cca618e2740/Modules/Core/Common/src/itkImageSource.cxx#L27</a></div>
<div>[4] <a href="https://github.com/Kitware/ITK/blob/4c47e7d672bad5d83b92c2df5f293cca618e2740/Modules/Core/Common/src/itkObjectFactoryBase.cxx#L142-144" target="_blank">https://github.com/Kitware/ITK/blob/4c47e7d672bad5d83b92c2df5f293cca618e2740/Modules/Core/Common/src/itkObjectFactoryBase.cxx#L142-144</a></div>
<div>[5] <a href="https://github.com/Kitware/ITK/blob/defb9c1d084c8d55df61947587427839f9968ecf/Modules/IO/ImageBase/src/itkImageIOBase.cxx#L760" target="_blank">https://github.com/Kitware/ITK/blob/defb9c1d084c8d55df61947587427839f9968ecf/Modules/IO/ImageBase/src/itkImageIOBase.cxx#L760</a></div>
<div>[6] <a href="https://github.com/Kitware/ITK/blob/4c47e7d672bad5d83b92c2df5f293cca618e2740/Modules/Core/Common/src/itkImageSource.cxx#L27" target="_blank">https://github.com/Kitware/ITK/blob/4c47e7d672bad5d83b92c2df5f293cca618e2740/Modules/Core/Common/src/itkImageSource.cxx#L27</a></div>
<div>[7] <a href="https://github.com/Kitware/ITK/blob/defb9c1d084c8d55df61947587427839f9968ecf/Modules/IO/ImageBase/src/itkImageIOBase.cxx#L765" target="_blank">https://github.com/Kitware/ITK/blob/defb9c1d084c8d55df61947587427839f9968ecf/Modules/IO/ImageBase/src/itkImageIOBase.cxx#L765</a></div>
<div>[8] <a href="https://github.com/Kitware/ITK/blob/4c47e7d672bad5d83b92c2df5f293cca618e2740/Modules/Core/Common/src/itkImageSource.cxx#L32" target="_blank">https://github.com/Kitware/ITK/blob/4c47e7d672bad5d83b92c2df5f293cca618e2740/Modules/Core/Common/src/itkImageSource.cxx#L32</a></div>
<div>[9] <a href="http://www.herzbube.ch/blog/2009/01/how-set-environment-variables-mac-os-x-applications" target="_blank">http://www.herzbube.ch/blog/2009/01/how-set-environment-variables-mac-os-x-applications</a></div>
<div>[10] <a href="https://github.com/Slicer/Slicer/commit/03b8961" target="_blank">https://github.com/Slicer/Slicer/commit/03b8961</a><a href="https://github.com/Kitware/ITK/blob/4c47e7d672bad5d83b92c2df5f293cca618e2740/Modules/Core/Common/src/itkImageSource.cxx#L27" target="_blank"><font color="#222222"><br>
</font><br></a>-- </div><a href="tel:%2B1%20919%20869%208849" value="+19198698849" target="_blank">+1 919 869 8849</a><br>
</div></div></div>
_______________________________________________<br>Powered by <a href="http://www.kitware.com/" target="_blank">www.kitware.com</a><br><br>Visit other Kitware open-source projects at<br><a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>Kitware offers ITK Training Courses, for more information visit:<br><a href="http://kitware.com/products/protraining.php" target="_blank">http://kitware.com/products/protraining.php</a><br><br>Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.itk.org/mailman/listinfo/insight-developers" target="_blank">http://www.itk.org/mailman/listinfo/insight-developers</a><br>
</blockquote></div><br></div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><a href="tel:%2B1%20919%20869%208849" value="+19198698849" target="_blank">+1 919 869 8849</a><br>
</div>
</div></div><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<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://kitware.com/products/protraining.php" target="_blank">http://kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-developers" target="_blank">http://www.itk.org/mailman/listinfo/insight-developers</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Unpaid intern in BillsBasement at noware dot com<br>
</div>
</blockquote></div><br></div></div></div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><a href="tel:%2B1%20919%20869%208849" value="+19198698849" target="_blank">+1 919 869 8849</a><br>
</div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>+1 919 869 8849<br>
</div>