<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Hi Xie,</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">if you want itk::PNGImageIO, why not instantiate it the standard way:</div><div class="gmail_default" style=""><font face="verdana, sans-serif">itk::PNGImageIO::Pointer ioPointer </font><span style="font-family:verdana,sans-serif">= itk::PNGImageIO::New();</span></div><div class="gmail_default" style=""><span style="font-family:verdana,sans-serif"><br></span></div><div class="gmail_default" style=""><span style="font-family:verdana,sans-serif">Regards,</span></div><div class="gmail_default" style=""><font face="verdana, sans-serif">Dženan</font></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 22, 2016 at 10:37 AM, <a href="mailto:weiehome@sina.com">weiehome@sina.com</a> <span dir="ltr"><<a href="mailto:weiehome@sina.com" target="_blank">weiehome@sina.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
<div><span></span>Hi, <span style="font-family:verdana,sans-serif;font-size:small;line-height:19px;background-color:window">Dženan</span></div><div><br></div><div>All i want to do is : <span style="font-family:'';font-size:10.5pt;line-height:1.5;background-color:window">ImageIOBase* ioPointer = dynamic_cast<ImageIOBase*>(ObjectFactoryBase::CreateInstance(classname).GetPointer());</span></div><div><span style="font-family:'';font-size:10.5pt;line-height:1.5;background-color:window">when i give classname "class itk::PNGImageIO", this line shall return me a ioPointer points to a </span><span style="font-size:10.5pt;line-height:1.5;background-color:window">PNGImageIO instance. </span><span style="background-color:window;font-size:10.5pt;line-height:1.5">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.</span></div><div><span style="background-color:window;font-size:10.5pt;line-height:1.5"><br></span></div><div><span style="background-color:window;font-size:10.5pt;line-height:1.5">Is there a way to do that?</span></div><div><span style="background-color:window;font-size:10.5pt;line-height:1.5"><br></span></div><div><span style="background-color:window;font-size:10.5pt;line-height:1.5">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. </span></div><div><span style="font-size:10.5pt;line-height:1.5;background-color:window">Best Wishes</span></div><div><span style="font-size:10.5pt;line-height:1.5;background-color:window">Xie</span></div><div><span style="font-size:10.5pt;line-height:1.5;background-color:window"><br></span></div>
<div><br></div><hr style="width:210px;min-height:1px" color="#b5c4df" size="1" align="left">
<div><span><div style="MARGIN:10px;FONT-FAMILY:verdana;FONT-SIZE:10pt"><div><a href="mailto:weiehome@sina.com" target="_blank">weiehome@sina.com</a></div></div></span></div>
<blockquote style="margin-top:0px;margin-bottom:0px;margin-left:0.5em"><div> </div><div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0cm 0cm 0cm"><div style="PADDING-RIGHT:8px;PADDING-LEFT:8px;FONT-SIZE:12px;FONT-FAMILY:tahoma;COLOR:#000000;BACKGROUND:#efefef;PADDING-BOTTOM:8px;PADDING-TOP:8px"><div><b>From:</b> <a href="mailto:dzenanz@gmail.com" target="_blank">Dženan Zukić</a></div><div><b>Date:</b> 2016-03-22 22:14</div><div><b>To:</b> <a href="mailto:weiehome@sina.com" target="_blank">谢玮宜</a></div><div><b>CC:</b> <a href="mailto:community@itk.org" target="_blank">community@itk.org</a></div><div><b>Subject:</b> Re: [ITK] confused about itk io factory</div></div></div><div><div class="h5"><div><div><div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Hi Xie,</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">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.</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">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.</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Regards,</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Dženan</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 22, 2016 at 4:14 AM, 谢玮宜 <span dir="ltr"><<a href="mailto:weiehome@sina.com" target="_blank">weiehome@sina.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
Dear ITK experts,<br>
<br>
I recently have some problems with using ITK ImageIO factory functions.<br>
When I tried to use ObjectFactoryBase::CreateInstance(const char<br>
*itkclassname) with itkclassname like itkPNGImageIO, it is not working. The<br>
purpose is to create an image io instance by classname using RTTI.<br>
I did debug into the code and then I found itkclassname has to be<br>
itkImageIOBase, then it will create always the first ImageIO instance in<br>
override map. I got really confused what is the purpose of this API<br>
"CreateInstance(classname)".<br>
<br>
I also print out all registered ImageIO factories and I found gdcmImageIO is<br>
in it. So what is the purpose that in example of dicom images reading and<br>
write, everytime we have to manually call reader->setImageio(<br>
gdcmIO::New())?<br>
As I understood, if an imageIO is registered already, the reader will<br>
automatically check when it is reading a file to see if the format is<br>
supported by an underlying IO.<br>
<br>
Please correct me. I think I somehow got seriously wrong with the underlying<br>
concept of itk IO mechanism.<br>
Thank you all in advance!<br>
<br>
BR,xie<br>
<br>
<br>
_______________________________________________<br>
Community mailing list<br>
<a href="mailto:Community@itk.org" target="_blank">Community@itk.org</a><br>
<a href="http://public.kitware.com/mailman/listinfo/community" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/community</a><br>
</blockquote></div><br></div>
</div></div></div></div></blockquote>
</div></blockquote></div><br></div>