[Insight-developers] (no subject)

Parag Chandra Parag@Chandra.com
Fri, 26 Jan 2001 22:12:44 -0500


This is a multi-part message in MIME format.

------=_NextPart_000_003E_01C087E5.1BBB3C90
Content-Type: text/plain;
	charset="gb2312"
Content-Transfer-Encoding: 7bit

Hi,
I checked in some changes to the FileIO classes earlier today. Please do a
cvs update and then you can use the code that I sent you earlier as an
example for how you would read in your jpeg files into itkImages. Basically,
you will subclass from FileIO to create FileIOJpeg. Additionally, you will
need to create a factory responsible for instantiating these FileIOJpeg
objects; I have attached an e-mail that Bill sent me regarding how to do
this. Note that you may need to change the names of the classes from what I
have listed here to conform with the latest style guidelines. Please e-mail
me directly for any further questions regarding the existing FileIO classes.
Also, be aware that matters of file I/O are likely to change significantly
in the coming weeks.

By the way, I assume you are going to be interfacing with the IJG jpeg
library to handle the low level JPEG codec details? If so, last year I wrote
a class to wrap that library; let me know if you would find it useful and I
can send you that as well.

-Parag


----- Original Message -----
From: "chenting" <chenting@graphics.cis.upenn.edu>
To: "Will Schroeder" <will.schroeder@kitware.com>
Cc: "Yinpeng Jin" <yj76@columbia.edu>; "insight-Developers"
<insight-developers@public.kitware.com>
Sent: Friday, January 26, 2001 8:52 PM
Subject: Re: [Insight-developers] (no subject)


> Hi! Will,
> we have already written our segmentation code in vtk and what I am doing
> now is to rewrite it into itk sytle. but it seems that you prefer to
> keep the work in vtk but write code to transfer data from insight to
> vtk(or vtk images), is that right? By the way, I have asked several
> question on fileio, vtk compling and cmakesetup and there is no reponse
> at all. I hope you can check these problems.
> ting
>
> Will Schroeder wrote:
>
> >  Hi Yinpeng-
> >
> > This is an interesting question. I would suggest that the "right" way
> > to do this is to use
> > vtk's classes rather than reimplementing the code in Insight. We ought
> > to build bridges to
> > systems, rather than trying to redo what' been done.
> >
> > On the other hand, there is a certain amount of pain to interface into
> > and out of a system.
> >
> > Comments?
> >
> > Will
> >
> > At 04:37 PM 1/25/2001 -0500, you wrote:
> >
> >> Hi, I am just wondering if it is possible for Kitware people to
> >> check in a Voronoi Diagram algorithm. (it has a very similar format
> >> inside the VTK as vtkDelaunay2D and vtkDelaunay3D). It is required
> >> by our segmentation methods.
> >> Yinpeng
> >
>
>
> _______________________________________________
> Insight-developers mailing list
> Insight-developers@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-developers
>

------=_NextPart_000_003E_01C087E5.1BBB3C90
Content-Type: text/html;
	name="Bill Hoffman's suggestions for replacing itkMaker.htm"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="Bill Hoffman's suggestions for replacing itkMaker.htm"

<META HTTP-EQUIV=3D"Content-Type" =
CONTENT=3D"text/html;charset=3Diso-8859-1">

At 11:01 AM 12/20/00 -0500, Parag Chandra wrote:
Hey Bill,
 
Sorry for the delay. If you modified the ObjectFactory to behave as you have described in your previous e-mail, that would be sufficient for the purposes of this I/O framework. The = only reason I templated Maker over the key type is to keep it as flexible as possible. Although I cannot think of a specific example now, I had originally thought that it might be useful for others to use integers, = or even entirely new classes, as the key type. But having a string key is probably all that will ever be needed.
 
Compiling the factories as DLLs sounds = like a very good idea. I had previously tried to figure out the DynamicLoader class and compile an I/O factory as a DLL, but since I could not get Windows to load this library at runtime, I abandoned the idea. Is there some example for writing such a DLL? It seems that simply placing my source files into a new DLL project in VC++ is enough to get it to compile, but not enough for it to be loaded at runtime.
 

The DynamicLoader works on windows and unix.   The key is that your
DLL/shared library has to have an exported function that looks like
this:

extern "C" ObjectFactoryBase* itkLoad()
{
return new YourFactory;
}

In windows, you have to declspec(export) the function, but
other than that, you can use the wizard in MSC++ to create a dll.


Also, it seems that I am faster than I thought....
I had already made those changes to the object factory in ITK.
See itkCreateObjectFunction.h

So, you should be able to re-work your stuff using the itk object
factories right now.

Just sub class from the BaseFactory, and in your constructor,

Call this function:

  void RegisterOverride(const char* classOverride,
        &nb= sp;         &= nbsp;     const char* overrideClassName,
        &nb= sp;         &= nbsp;     const char* description,
        &nb= sp;         &= nbsp;     bool enableFlag,
        &nb= sp;         &= nbsp;     CreateObjectFunctionBase* createFunction);

Something like this:

MyFactory::MyFactory()
{
RegisterOverride("ImageType", "ImageType", "Create ImageType", true,
            &= nbsp;    CreateObjectFunction<ImageType>::New());
RegisterOverride("ImageType2", "ImageType2", "Create ImageType2", true,
            &= nbsp;    CreateObjectFunction<ImageType2>::New());
}

This assumes that ImageType2 is an itkLightObject sub-class.

You can register your factory as a dll/shared library, or hard code it,
by calling:

itk::ObjectFactoryBase::RegisterFactory(new MyFactory);



To create objects you call:
itk::LightObject* obj =3D itk::ObjectFactoryBase::CreateInstance("ImageType");
then do the safe downcast, or you can use the templated objectfactory class
to use rtti and do the cast for you.


Let me know if you have any trouble.

-Bill

        &nb= sp;       
Thanks,
-Parag
 
----- Original Message -----
From: Bill Hoffman
To: Parag Chandra ; insight-Developers<= /a> ; Will Schroeder =
Sent: Tuesday, December 19, 2000 10:29 AM
Subject: Re: [Insight-developers] One possible framework for = Image I/O...

Hi Parag,

I have been looking at your Maker class.   The article on
pluggable factories was quite good.   I do think that with
slight modification the ObjectFactory could be used for
what you want.  This would avoid the confusion of having = several
ways of doing something in the same system.  

Although the ObjectFactory can use RTTI, it is not required.
At the end of the day, all you need is the virtual function

itkObject* CreateInstance(const char*);


I have recently added some features to the vtk object factory,
that I plan to add to the itk object factory.   Would it be = sufficient
for your needs if ObjectFactory allowed you to register creation
objects based on a string, that CreateInstance would use?
Why does your key have to be templated?



/**
 *   protected function used by sub classes of = ObjectFactory to register
 *   creation objects with a given string = name.   This would be put
 *   into a map, and used when CreateInstance is called = with
 *   classOverride as the string.
  */
void ObjectFactory::RegisterOverride(const char* classOverride,
            &= nbsp;           const = char* overrideClassName,
            &= nbsp;           const = char* description,
            &= nbsp;           int = enableFlag, 
            &= nbsp;           = CreateObject* createObject);

The CreateObject, would be very similar to the itkCommand object, = except
it would have a function that returned objects instead of just an
Execute function.


The advantage of working with the itk ObjectFactory framework , is that = \
it supports dynamic loading and registration of factories.
You could create a dll with your MetaImage ObjectFactory sub class, = with
all the registered CreateObjects for the keys you want to create, = then
just put it in ITK_AUTOLOAD_PATH, and any pre-compiled itk executable =
would be able to load MetaImages.  It allows the system to be = both
Open (you can add stuff at run time)  and Closed (the executable is = compiled, and the interface is locked in).



-Bill



2. I felt that itkMaker was necessary = because there does not seem to be a
way to use ObjectFactory to instantiate subclasses based on a = user-supplied
key value. ObjectFactory seems to use RTTI to automatically determine = which
class to instantiate and = return.
------=_NextPart_000_003E_01C087E5.1BBB3C90--