<br>A solution is to define the supported transform types as global typedefs, e.g.:<br><br><span style="font-family: courier new,monospace;">typedef itk::AffineTransform< double, iImgDimension > AffineTransformType;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">const unsigned int SpaceDimension = iImgDimension;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">const unsigned int SplineOrder = 3;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">typedef double CoordinateRepType;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">typedef itk::BSplineDeformableTransform<CoordinateRepType,SpaceDimension,SplineOrder> BSplineTransformType;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">itk::TransformFactory<BSplineTransformType>::RegisterTransform();</span><br style="font-family: courier new,monospace;">
<br><br>These types can be used in main() and other functions (there can be a function for each transform type). This is one of those functions:<br>
<br>
<span style="font-family: courier new,monospace;">BSplineTransformType::Pointer getBSplineXFM( itk::TransformFileReader::TransformListType *transforms )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> BSplineTransformType::Pointer xfm, xfmRead;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> // Then use an STL iterator on the list of transforms and apply</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> // the proper casting of the resulting transform.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> itk::TransformFileReader::TransformListType::const_iterator transformIt;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> transformIt = --(transforms->end()); // get last transform in list</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> if( ! strcmp( (*transformIt)->GetNameOfClass(),"BSplineDeformableTransform"))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> xfmRead = static_cast<BSplineTransformType*>( (*transformIt).GetPointer() );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> xfm = dynamic_cast<BSplineTransformType*>( xfmRead.GetPointer() );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> return xfm;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<br>
<br>This is a small snippet of the main() code that chooses which function to call:<br><br><span style="font-family: courier new,monospace;">// The transform reader is not template and therefore it returns a list<br>// of transforms. However, the reader can instantiate the appropriate<br>
// transform class while reading the file, but it is up to the user to<br>// do the appropriate cast.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">AffineTransformType::Pointer xfmAffine;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">BSplineTransformType::Pointer xfmBspline;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">if( ! affinePath.empty() )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> xfmAffine = getAffineXFM( transformReader->GetTransformList() );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">if( ! bsplinePath.empty() )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> xfmBspline = getBSplineXFM( transformReader->GetTransformList() );</span><br style="font-family: courier new,monospace;"><br>...<br><br><br>What would this look like using a factory method? Can the factory programming style be easily gleaned from the IO classes or examples?<br>
<br>Thanks,<br>Darren<br><br><br><br><br><br><br><div class="gmail_quote">On Mon, Oct 19, 2009 at 10:48 AM, Luis Ibanez <span dir="ltr"><<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi Darren,<br>
<br>
What do you call an "Unkown" transform ?<br>
<br>
An ITK transform of a well defined type, but whose actual type is not currently<br>
known to the application user ?<br></blockquote><div><br><br>Yes.<br><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
If so, then you (as a developer) will have to implement a cascade of<br>
reading attempts for all the Transform types that are supported by<br>
your application.<br>
<br>
The factory makes easier for you to register all those potential<br>
readers, and to try them in sequence.<br>
<br>
This is a similar situation to reading an image from a file without<br>
knowing in advance what is the specific pixel type of that image.<br>
<br>
<br>
I have to admit that the resulting code is not going to be pretty....<br>
<br>
However, the only way to simplify it would be to have a predefined<br>
list of the transform that your application support, and then package<br>
the reading process into a single function.<br>
<br>
<br>
Regards,<br>
<br>
<br>
Luis<br>
<br>
<br>
---------------------------------------------------------------------------------------------<br>
<div><div></div><div class="h5">On Tue, Oct 13, 2009 at 6:01 PM, Darren Weber<br>
<<a href="mailto:darren.weber.lists@gmail.com">darren.weber.lists@gmail.com</a>> wrote:<br>
><br>
> With regard to reading a transform file, using itk::TransformFileReader,<br>
> given the example:<br>
> examples/IO/TransformReadWrite.cxx<br>
><br>
> This example uses the following code to register and read a known<br>
> BSplineTransformType, i.e.:<br>
><br>
> typedef itk::BSplineDeformableTransform<double,3,5> BSplineTransformType;<br>
> ...<br>
> itk::TransformFileReader::Pointer reader;<br>
> reader = itk::TransformFileReader::New();<br>
> // Some transforms (like the BSpline transform) might not be registered<br>
> // with the factory so we add them manually.<br>
> itk::TransformFactory<BSplineTransformType>::RegisterTransform();<br>
> reader->SetFileName( "Transforms.meta" );<br>
> try<br>
> {<br>
> reader->Update();<br>
> }<br>
> catch( itk::ExceptionObject & excp )<br>
> {<br>
> std::cerr << "Error while reading the transform file" << std::endl;<br>
> std::cerr << excp << std::endl;<br>
> std::cerr << "[FAILED]" << std::endl;<br>
> return EXIT_FAILURE;<br>
> }<br>
><br>
><br>
> Now let's assume a transform file contains an unknown transform type.<br>
><br>
> What is the role of the transform factory? Is it required to read a<br>
> transform file? Is it possible to read a unknown transform file and<br>
> register a given transform type with the transform factory after reading the<br>
> file?<br>
><br>
> Suppose the transform file contains a BSplineTransformType, but the<br>
> parameters are unknown. Is it possible to read this transform file?<br>
><br>
> TIA and take care,<br>
> Darren<br>
><br>
><br>
</div></div>> _____________________________________<br>
> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Please keep messages on-topic and check the ITK FAQ at:<br>
> <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
><br>
><br>
</blockquote></div><br>