[Insight-users] template instantiations

suresh suresh " <suresh_kb@rediffmail.com
14 Nov 2002 12:40:03 -0000


Hi harri,

A possible solution for ur problem.

Indeed  we also faced this problem for our development.
Even we used a third party class library for image input which 
also exposes the image data as an array and the type as an enum 
value.

Here is what we did ..

1. First  identify the ITK classes that are going to be used.Put 
them in the pipe line.
2. declare a abstract base class which acts as an interface for 
the above Pipeline. This interface should only accept you 
structure type. and no ITK objects.
3. define all this in a templated class exposing the 
functionalities as methods.Derive this template class from the 
above interface.

Now crete one more class or a function which is basically a 
wrapper for switch case with all possible data types as  cases and 
the wrapper template class instantiations creatd on heap and 
assign the pointer to th interface pointer.

Here is some psuedo code...

take the case of a segmentation filter...
say ur struct is called as BSIMAGE

interface ISeg
{
void setInputImage(BSIMAGE* )
BSIMAGE* DoSegmentation()
.
.  // like this all methods will accept only ur specifc structure 
and returns the same or some basic C types
.
}

template<typename TPixelType> // here there can be few more 
args.
class SegImpl : public ISeg
{
// define all your methods.
}

and the selector can be like this..
ISeg* pSeg = NULL:
switch(type){
case TYPE1:
 		pSeg = new SegImpl<type1>;
 		break;
case TYPE1:
 		pSeg = new SegImpl<type2>;
 		break;
default:
 		// an error handler.
}
pSeg->SetInput(...)
pSeg->DoSeg(...).


I feel this approach may solve your problem to certain extent.

PS: I suggest u to look at the MultiResMIRegistration example to 
get some idea on grouping of ITK classes and defining as 
interface.

Please let me know  your comments and experience on using this.

Thanks

suresh