[Insight-developers] ITK ObjectFactory mysterious, frustrating. (was TransformIO problem)
Luis Ibanez
luis.ibanez at kitware.com
Thu Nov 3 12:54:42 EDT 2011
Hi Ken,
Yeap, we should apply to the Transform Factories the same
reorganization that Brad King did for the ImageIO Factories.
In summary:
1) Get rid of the centralized method that register all factories
( in this case the "RegisterDefaultTransforms()" )
2) Configure a file that will register the proper factories on the
Application code (e.g. in applications that use ITK, not in
ITK itself).
3) Modify the Transform Reader and Writers to not rely on
the transforms being registered before hand.
The key files to get inspiration from are:
a) Modules/IO/ImageBase/include/itkImageFileReader.hxx
lines 113-118:
#if !defined(SPECIFIC_IMAGEIO_MODULE_TEST)
if ( m_UserSpecifiedImageIO == false ) //try creating via factory
{
m_ImageIO =
ImageIOFactory::CreateImageIO(this->GetFileName().c_str(),
ImageIOFactory::ReadMode);
}
#endif
b) Modules/IO/ImageBase/include/itkImageFileWriter.hxx
lines 126-148
c) ITK/CMake/itkImageIOFactoryRegisterManager.h.in
and its configuration in
ITK/CMake/UseITK.cmake
ITK/CMakeLists.txt
d) From the TransformFactoryBase class,
remove the method:
RegisterDefaultTransforms();
e) Note that the file
itkImageIOFactoryRegisterManager.h
in included at the end of the Image reader and writer
more specifically at:
itkImageFileReader.h:193:#include "itkImageIOFactoryRegisterManager.h"
itkImageFileWriter.h:227:#include "itkImageIOFactoryRegisterManager.h"
In this way, the reader and writer can trigger the registration
of known factories that were selected at configuration time,
and in this way breaking the cycle of having a single point
in the source code, where a function has to know about all
the possible ImageIO formats.
-----
These setting, are such, that when you configure an
application that is based on ITK, the application binary
directory will end up containing a directory with name:
ITKIOFactoryRegistration
inside, you will find the file:
itkImageIOFactoryRegisterManager.h
That will do the factory registration for the ImageIO
classes whose Modules were enabled at the time
that ITK was configured.
---
A similar arrangement should be done for the
Transforms....
Luis
--------------------------------------------------------
On Wed, Nov 2, 2011 at 5:14 PM, Williams, Norman K
<norman-k-williams at uiowa.edu> wrote:
> I noticed that in the TransformBase tests
>
> itkTransformFactoryBaseTest.cxx calls
> itk::TransformFactoryBase::RegisterDefaultTransforms();
>
> The other tests (for Reader & Writer) do not.
>
> Some of the tests in BRAINSResample were failing, claiming that the
> ObjectFactory couldn't create an instance of AffineTransformDouble_3_3.
>
> If I add itk::TransformFactoryBase::RegisterDefaultTransforms(); to the
> main function, the BRAINSResample tests succeed.
>
> Without it, RegisterDefaultTransform gets called from
> itk::TransformFactoryBase::GetFactory(), but only after trying to call
> ObjectFactoryBase::CreateInstance -- down in the exception code!
>
> I'm trying out a patch, but it depends on the call toe
> TransformFactoryBase::GetFactory() having the side effect of registering
> all the transform types. This is disturbing to me because it depends on
> side effects!
>
> So it seems like there's a few problems with the Transform Factory: The
> initialization isn't thread safe, and it isn't getting done before it's
> needed.
>
> Isn't there a better way to make sure that RegisterDefaultTransforms gets
> called?
> --
> Kent Williams norman-k-williams at uiowa.edu
>
>
>
>
>
>
> ________________________________
> Notice: This UI Health Care e-mail (including attachments) is covered by the Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential and may be legally privileged. If you are not the intended recipient, you are hereby notified that any retention, dissemination, distribution, or copying of this communication is strictly prohibited. Please reply to the sender that you have received the message in error, then delete it. Thank you.
> ________________________________
>
More information about the Insight-developers
mailing list