[Insight-users] Specializing ITK classes into libraries to speed up compilation
Parag Chandra
pchandra@radonc.unc.edu
Tue, 18 Feb 2003 10:30:11 -0500
Thanks for your help Luis. I timed the compilation using my non-templated
library vs. using plain ITK classes, and there was no difference. I don't
want to 'de-template' all of ITK in order for this approach to work, so I'm
just going to go back to using plain ITK classes.
-Parag
----- Original Message -----
From: "Luis Ibanez" <luis.ibanez@kitware.com>
To: "Parag Chandra" <pchandra@radonc.unc.edu>
Cc: "ITK Mailing List" <insight-users@public.kitware.com>
Sent: Tuesday, February 18, 2003 1:37 AM
Subject: Re: [Insight-users] Specializing ITK classes into libraries to
speed up compilation
>
> Hi Parag,
>
> Slow compilation is certainly the price to pay
> for the flexibility of Generic Programming.
>
> Building libraries can help you on this, but only
> if you managed to hide ITK headers from your code.
>
> Unfortunately deriving from itk classes will not
> do the trick since the ITK headers will have to
> to be compiled along with the headers of your
> classes.
>
> You may want to do something like encapsulate ITK
> classes inside C++ non templated classes. Make sure
> that the ITK headers are not included in the headers
> of your encapsulating class, but rather on their
> respective cxx files. This means that ITK classes
> (at least the templated ones) should not be member
> variables of your encapsulating class.
>
> If you need to pass objects like ITK images around
> you could use the fact that the itkDataObject is
> not templated and is the base class of the image.
> You could in this way, pass pointers to itkDataObject
> and downcast them inside the .cxx files using
> dynamic_cast.
>
> Please let us know if you find any problem with
> this approach.
>
> Thanks
>
>
> Luis
>
>
> ---------------------------------
>
>
> Parag Chandra wrote:
> > Hey all,
> >
> > I have noticed that the more ITK classes I include in my program, the
> > longer my program takes to build. In fact, the build time seems to be
> > pretty constant even if I do something as simple as adding a comment to
> > the main source file, and I suspect this is because all the ITK classes
> > have to be constantly recompiled. What I have started to do is create a
> > library of classes that are simple specializations of the ITK classes
> > that I use, templated over the only type of image that I use (<double,
> > 2>). So I have a set of classes sort of like this:
> >
> > namespace aks {
> > namespace double2 {
> > class Image : public itk::Image<double, 2>
> > {
> > // define standard class typedefs, New macro, default constructor
> > };
> >
> > class ImageReader : public itk::ImageFileReader<aks::double2::Image>
> > {
> > // define standard class typedefs, New macro, default constructor
> > };
> >
> > etc.
> > }
> > }
> >
> > that I can then compile into a library. It works, but I have only done
> > this for a couple of classes so far, so I do not see any noticeable
> > speedup in compilation time just yet. What I was wondering is if anyone
> > else out there has tried something like this and could comment before I
> > (potentially) waste my time in vain. I think at one point there was even
> > some discussion on the ITK mailing list regarding this sort of thing,
> > but I don't think anything ever came of it so maybe others have already
> > decided it's not worth the time.
> >
> > Thanks,
> > Parag Chandra
>
>
>
>