<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">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. &nbsp;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>On Apr 3, 2013, at 10:54 AM, Jean-Christophe Fillion-Robin &lt;<a href="mailto:jchris.fillionr@kitware.com">jchris.fillionr@kitware.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><div dir="ltr">Hi Brad,&nbsp;<div><br></div><div>Following commit&nbsp;4c47e7d&nbsp;[1]&nbsp;of February 19th and commit defb9c1 [2] of March 1st, due to static initialization, the initialization of ObjectFactory &nbsp;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.&nbsp;</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&nbsp;is instantiated [5][6] and updating the method "GetImageRegionSplitter / GetGlobalDefaultSplitter" to return 0 [7][8], the&nbsp;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&nbsp;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 style="">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 style=""><br></div><div style=""><br></div><div style="">Let me know what you think.</div><div style=""><br></div><div style="">Thanks</div><div style="">Jc</div><div><div><br></div><div><br></div><div>[1]&nbsp;<a href="https://github.com/Kitware/ITK/commit/4c47e7d">https://github.com/Kitware/ITK/commit/4c47e7d</a></div>

<div>[2]&nbsp;<a href="https://github.com/Kitware/ITK/commit/defb9c1">https://github.com/Kitware/ITK/commit/defb9c1</a></div><div>[3]&nbsp;<a href="https://github.com/Kitware/ITK/blob/4c47e7d672bad5d83b92c2df5f293cca618e2740/Modules/Core/Common/src/itkImageSource.cxx#L27">https://github.com/Kitware/ITK/blob/4c47e7d672bad5d83b92c2df5f293cca618e2740/Modules/Core/Common/src/itkImageSource.cxx#L27</a></div>

<div>[4]&nbsp;<a href="https://github.com/Kitware/ITK/blob/4c47e7d672bad5d83b92c2df5f293cca618e2740/Modules/Core/Common/src/itkObjectFactoryBase.cxx#L142-144">https://github.com/Kitware/ITK/blob/4c47e7d672bad5d83b92c2df5f293cca618e2740/Modules/Core/Common/src/itkObjectFactoryBase.cxx#L142-144</a></div>

<div>[5]&nbsp;<a href="https://github.com/Kitware/ITK/blob/defb9c1d084c8d55df61947587427839f9968ecf/Modules/IO/ImageBase/src/itkImageIOBase.cxx#L760">https://github.com/Kitware/ITK/blob/defb9c1d084c8d55df61947587427839f9968ecf/Modules/IO/ImageBase/src/itkImageIOBase.cxx#L760</a></div>

<div>[6]&nbsp;<a href="https://github.com/Kitware/ITK/blob/4c47e7d672bad5d83b92c2df5f293cca618e2740/Modules/Core/Common/src/itkImageSource.cxx#L27">https://github.com/Kitware/ITK/blob/4c47e7d672bad5d83b92c2df5f293cca618e2740/Modules/Core/Common/src/itkImageSource.cxx#L27</a></div>

<div>[7]&nbsp;<a href="https://github.com/Kitware/ITK/blob/defb9c1d084c8d55df61947587427839f9968ecf/Modules/IO/ImageBase/src/itkImageIOBase.cxx#L765">https://github.com/Kitware/ITK/blob/defb9c1d084c8d55df61947587427839f9968ecf/Modules/IO/ImageBase/src/itkImageIOBase.cxx#L765</a></div>

<div>[8]&nbsp;<a href="https://github.com/Kitware/ITK/blob/4c47e7d672bad5d83b92c2df5f293cca618e2740/Modules/Core/Common/src/itkImageSource.cxx#L32">https://github.com/Kitware/ITK/blob/4c47e7d672bad5d83b92c2df5f293cca618e2740/Modules/Core/Common/src/itkImageSource.cxx#L32</a></div>

<div>[9]&nbsp;<a href="http://www.herzbube.ch/blog/2009/01/how-set-environment-variables-mac-os-x-applications">http://www.herzbube.ch/blog/2009/01/how-set-environment-variables-mac-os-x-applications</a></div><div style="">[10]&nbsp;<a href="https://github.com/Slicer/Slicer/commit/03b8961">https://github.com/Slicer/Slicer/commit/03b8961</a><a href="https://github.com/Kitware/ITK/blob/4c47e7d672bad5d83b92c2df5f293cca618e2740/Modules/Core/Common/src/itkImageSource.cxx#L27"><font color="#222222"><br>

</font><br></a>--&nbsp;</div>+1 919 869 8849<br>
</div></div>
_______________________________________________<br>Powered by <a href="http://www.kitware.com">www.kitware.com</a><br><br>Visit other Kitware open-source projects at<br><a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br><br>Kitware offers ITK Training Courses, for more information visit:<br>http://kitware.com/products/protraining.php<br><br>Please keep messages on-topic and check the ITK FAQ at:<br>http://www.itk.org/Wiki/ITK_FAQ<br><br>Follow this link to subscribe/unsubscribe:<br>http://www.itk.org/mailman/listinfo/insight-developers<br></blockquote></div><br></div></body></html>