[Insight-developers] ITK ObjectFactory mysterious, frustrating. (was TransformIO problem)

Xiaoxiao Liu xiaoxiao.liu at kitware.com
Thu Nov 3 14:28:00 EDT 2011


Hi Luis,

I think you and kent are talking about different factories:
TransformIOFactory (luis)   vs. TransformFactory (kent).
The former one is regarding matlab, txt, hdf5 formats; the latter refers to
 various transforms: Euler, affine, composite....

 When I refactored the transform IO modules a couple of weeks ago, I
already took care of the part of separating the IO factory registers
for different IO formats ( http://review.source.kitware.com/#change,3112):
  1)  When ITK is used as a whole package in another application, all three
IO formats (matlab, txt, hdf5) will be registered  via IO Factory Manager (
http://review.source.kitware.com/#patch,sidebyside,3112,1,CMake/UseITK.cmake
),
so that, users do not need (they still could if they want to) to manually
register the IO factories ;
 2) And within each IO format module,  their tests  register the specific
IO factories explicitly in th code.


I assume each Transform IO type (txt/matlab/hdf5)  will need to handle all
transform types(affine/euler/bspline...), that is why we need to register
all the
transform factories at once in
TransformFactoryBase. TransformFactoryBase::RegisterDefaultTransforms() is
called the constructor of TransformFileWriter  in
itkTransformFileWriter.cxx.


Hope this helps.

-Xiaoxiao





On Thu, Nov 3, 2011 at 12:54 PM, Luis Ibanez <luis.ibanez at kitware.com>wrote:

> 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.
> > ________________________________
> >
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-developers
>



-- 


---------------------------------------------
*Xiaoxiao Liu*, Ph.D.
R & D Engineer
Kitware Inc <http://www.kitware.com/>.
Clifton Park, NY
Phone: (518) 881-4924  or  (518) 371-3971 x124
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20111103/6650d728/attachment.htm>


More information about the Insight-developers mailing list