[ITK] confused about itk io factory

Dženan Zukić dzenanz at gmail.com
Tue Mar 22 10:42:39 EDT 2016


Hi Xie,

if you want itk::PNGImageIO, why not instantiate it the standard way:
itk::PNGImageIO::Pointer ioPointer = itk::PNGImageIO::New();

Regards,
Dženan

On Tue, Mar 22, 2016 at 10:37 AM, weiehome at sina.com <weiehome at sina.com>
wrote:

> Hi, Dženan
>
> All i want to do is :
> ImageIOBase* ioPointer = dynamic_cast<ImageIOBase*>(ObjectFactoryBase::CreateInstance(classname).GetPointer());
> when i give classname "class itk::PNGImageIO", this line shall return me a
> ioPointer points to a PNGImageIO instance.  As you explained, the only
> way to get a sub-class pointer is to call a subclass's CreateObject method.
> But what i am looking for this a reflection mechnism so i can create
> objects with classnames.
>
> Is there a way to do that?
>
> btw: i did concern about CPU consumtion in looping registered IO factory
> everytime reading files, that is why i wrote own map of classname and IO
> objects to use setImageIO specificly.
> Best Wishes
> Xie
>
>
> ------------------------------
> weiehome at sina.com
>
>
> *From:* Dženan Zukić <dzenanz at gmail.com>
> *Date:* 2016-03-22 22:14
> *To:* 谢玮宜 <weiehome at sina.com>
> *CC:* community at itk.org
> *Subject:* Re: [ITK] confused about itk io factory
> Hi Xie,
>
> the purpose of CreateInstance method is to be implemented (over-ridden) by
> sub-classes. Each sub-class would create instance of itself. I guess the
> base class just creates an instance of the first registered factory.
>
> Normally, reader->setImageio is not necessary. Try it. The reader asks all
> the imageIOs whether they can read the file  (based on the filename
> extension) until one IO can read. If files have no extension or an
> un-matching extension, than setting imageIO should be used. Also, if you
> will only work with one type of files, you can manually set that imageIO to
> save a few CPU cycles by not checking different imageIOs when opening files.
>
> Regards,
> Dženan
>
> On Tue, Mar 22, 2016 at 4:14 AM, 谢玮宜 <weiehome at sina.com> wrote:
>
>>
>> Dear ITK experts,
>>
>> I recently have some problems with using ITK ImageIO factory functions.
>> When I tried to use ObjectFactoryBase::CreateInstance(const char
>> *itkclassname) with itkclassname like itkPNGImageIO, it is not working.
>> The
>> purpose is to create an image io instance by classname using RTTI.
>> I did debug into the code and then I found itkclassname has to be
>> itkImageIOBase, then it will create always the first ImageIO instance in
>> override map. I got really confused what is the purpose of this API
>> "CreateInstance(classname)".
>>
>> I also print out all registered ImageIO factories and I found gdcmImageIO
>> is
>> in it. So what is the purpose that in example of dicom images reading and
>> write, everytime we have to manually call reader->setImageio(
>> gdcmIO::New())?
>> As I understood, if an imageIO is registered already, the reader will
>> automatically check when it is reading a file to see if the format is
>> supported by an underlying IO.
>>
>> Please correct me. I think I somehow got seriously wrong with the
>> underlying
>> concept of itk IO mechanism.
>> Thank you all in advance!
>>
>> BR,xie
>>
>>
>> _______________________________________________
>> Community mailing list
>> Community at itk.org
>> http://public.kitware.com/mailman/listinfo/community
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20160322/1f6a1dff/attachment.html>


More information about the Community mailing list