[Insight-developers] One possible framework for Image I/O...

Parag Chandra Parag@Chandra.com
Wed, 20 Dec 2000 11:01:45 -0500


This is a multi-part message in MIME format.

------=_NextPart_000_016F_01C06A74.3DE91550
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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.

Thanks,
-Parag

----- Original Message -----=20
  From: Bill Hoffman=20
  To: Parag Chandra ; insight-Developers ; Will Schroeder=20
  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.  =20

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

  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=20
   *   classOverride as the string.
    */
  void ObjectFactory::RegisterOverride(const char* classOverride,
                          const char* overrideClassName,
                          const char* description,
                          int enableFlag, =20
                          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=20
  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_016F_01C06A74.3DE91550
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3103.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#fafafa>
<DIV><FONT face=3DArial size=3D2>Hey Bill,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Sorry for the delay. If you modified =
the=20
ObjectFactory to behave as you have described in your previous e-mail, =
that=20
would be sufficient for the purposes of this I/O framework. The only =
reason I=20
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=20
it might be useful for others to use integers, or even entirely new =
classes, as=20
the key type. But having a string key is probably all that will ever be=20
needed.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Compiling the&nbsp;factories as DLLs =
sounds like a=20
very good idea. I had previously tried to figure out the DynamicLoader =
class and=20
compile an I/O factory as a DLL, but since I could not get Windows to =
load this=20
library at runtime, I abandoned the idea. Is there some example for =
writing such=20
a DLL? It seems that simply placing my source files into a new DLL =
project in=20
VC++ is&nbsp;enough to get it to compile, but not enough for it to be =
loaded at=20
runtime.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>-Parag</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>----- Original Message ----- </DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A href=3D"mailto:bill.hoffman@kitware.com" =
title=3Dbill.hoffman@kitware.com>Bill=20
  Hoffman</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
href=3D"mailto:Parag@Chandra.com"=20
  title=3DParag@Chandra.com>Parag Chandra</A> ; <A=20
  href=3D"mailto:insight-developers@public.kitware.com"=20
  title=3Dinsight-developers@public.kitware.com>insight-Developers</A> ; =
<A=20
  href=3D"mailto:will.schroeder@kitware.com" =
title=3Dwill.schroeder@kitware.com>Will=20
  Schroeder</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Tuesday, December 19, =
2000 10:29=20
  AM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Re: =
[Insight-developers] One=20
  possible framework for Image I/O...</DIV>
  <DIV><BR></DIV>Hi Parag,<BR><BR>I have been looking at your Maker=20
  class.&nbsp;&nbsp; The article on<BR>pluggable factories was quite=20
  good.&nbsp;&nbsp; I do think that with<BR>slight modification the=20
  ObjectFactory could be used for<BR>what you want.&nbsp; This would =
avoid the=20
  confusion of having several<BR>ways of doing something in the same=20
  system.&nbsp;&nbsp; <BR><BR>Although the ObjectFactory can use RTTI, =
it is not=20
  required.<BR>At the end of the day, all you need is the virtual =
function=20
  <BR><BR>itkObject* CreateInstance(const char*);<BR><BR><BR>I have =
recently=20
  added some features to the vtk object factory,<BR>that I plan to add =
to the=20
  itk object factory.&nbsp;&nbsp; Would it be sufficient<BR>for your =
needs if=20
  ObjectFactory allowed you to register creation<BR>objects based on a =
string,=20
  that CreateInstance would use?<BR>Why does your key have to be=20
  templated?<BR><BR><BR><BR>/**<BR>&nbsp;*&nbsp;&nbsp; protected =
function used=20
  by sub classes of ObjectFactory to register<BR>&nbsp;*&nbsp;&nbsp; =
creation=20
  objects with a given string name.&nbsp;&nbsp; This would be=20
  put<BR>&nbsp;*&nbsp;&nbsp; into a map, and used when CreateInstance is =
called=20
  with <BR>&nbsp;*&nbsp;&nbsp; classOverride as the string.<BR>&nbsp; =
*/<BR>void=20
  ObjectFactory::RegisterOverride(const char*=20
  =
classOverride,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;=20
  const char*=20
  =
overrideClassName,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;=20
  const char*=20
  =
description,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;=20
  int enableFlag,&nbsp;=20
  =
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  CreateObject* createObject);<BR><BR>The CreateObject, would be very =
similar to=20
  the itkCommand object, except<BR>it would have a function that =
returned=20
  objects instead of just an<BR>Execute function.<BR><BR><BR>The =
advantage of=20
  working with the itk ObjectFactory framework , is that \<BR>it =
supports=20
  dynamic loading and registration of factories.<BR>You could create a =
dll with=20
  your MetaImage ObjectFactory sub class, with<BR>all the registered=20
  CreateObjects for the keys you want to create, then<BR>just put it in=20
  ITK_AUTOLOAD_PATH, and any pre-compiled itk executable <BR>would be =
able to=20
  load MetaImages.&nbsp; It allows the system to be both<BR>Open (you =
can add=20
  stuff at run time)&nbsp; and Closed (the executable is compiled, and =
the=20
  interface is locked in).<BR><BR><BR><BR>-Bill<BR><BR><BR><BR>
  <BLOCKQUOTE cite type=3D"cite">2. I felt that itkMaker was necessary =
because=20
    there does not seem to be a<BR>way to use ObjectFactory to =
instantiate=20
    subclasses based on a user-supplied<BR>key value. ObjectFactory =
seems to use=20
    RTTI to automatically determine which<BR>class to instantiate and=20
  return.</BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_016F_01C06A74.3DE91550--