[Insight-users] passing itkImage to a function ...C++ template problem

Luis Ibanez luis.ibanez at kitware.com
Fri Oct 15 13:19:09 EDT 2004


Hi Lagaffe,

The error is that your create a templated class where the
template paramter is supposed to be an ImageType, but you
are instantiating it using the *ReaderType*.



Please replace

      BasicTransformation< ReaderType > *basic;


with

      BasicTransformation< ImageType > *basic;



ALSO, from your code, it seems that you are
using "basic" without allocating it.  I guess
that you probably intended to do:


    typedef BasicTransformation<ImageType> MyClassType;
    MyClassType * basic = new MyClassType;





  Regards,


      Luis


-----------------------------------------
Mr Gaffe wrote:

> Thanks luis for your help,
>  
> I read the tutorial, but I still have a compilation problem... I change 
> my class to a template file as you said (it is really more simple), this 
> is the code:
>  
> // BasicTransformation.h
> template <class TImage> class BasicTransformation
> {
> public:
>  template <class TImage> void doSomething(const *TImage image);
>  BasicTransformation (void);
>  ~BasicTransformation (void);
> };
> // BasicTransformation.txx
> #include "BasicTransformation.h"
> BasicTransformation<TImage>::BasicTransformation(void) {
>  
> }
> BasicTransformation<TImage>::~BasicTransformation(void)
> {
> 
> }
> template <class TImage> void 
> BasicTransformation<TImage>::doSomething(const *TImage image){
> ...
> start ITK Pipeline with :  image->getOutput() 
> ..
> }
> // My main function in MyApp.cpp
>  
> int main(int argc, char **argv) {
>  
>  typedef itk::Image<unsigned short,3> ImageType;
>  typedef itk::ImageFileReader<ImageType> ReaderType;
>  ReaderType::Pointer reader= ReaderType::New();
>  reader->SetFileName("t2w_1.hdr");
>  
>  // Basic Transformation
>  BasicTransformation<ReaderType> *basic;
>  basic->doSomething(reader->GetOutput);
>  
> ==> Error during compilation: impossible to deduce TImage template 
> argument with TImage=ReaderType
>  
> If you have any idea, I will appreciate,
> Lagaffe
> 
> */Luis Ibanez <luis.ibanez at kitware.com>/* wrote:
> 
> 
> 
>     Hi Lagaffe,
> 
> 
>     Your class BasicTransformation seems to be ok,
>     however, you have to manage it as a templated class.
> 
>     That is, it must be in a .txx file and it will only
>     get instantiated when you define the actual types.
> 
> 
>     Your code will be much simpler is you just create
>     BasicTransformation as a templated class, and use
>     the ImageType as the template parameter.
> 
>     Something like
> 
> 
> 
>     template
>     class BasicTransformation
>     {
>     public:
>     void myFunction(const * TImage);
>     };
> 
> 
> 
> 
>     You are *strongly* encouraged to look at the Tutorial
>     sessions:
> 
>     http://www.itk.org/HTML/Tutorials.htm
> 
>     in particular to
> 
>     http://www.itk.org/CourseWare/Training/GettingStarted-V.pdf
> 
>     where the integration of ITK classes inside non-ITK
>     applications is discussed in detail.
> 
> 
>     Plea! se let us know if you have further questions,
> 
> 
>     Thanks
> 
> 
>     Luis
> 
> 
> 
>     ----------------
>     Mr Gaffe wrote:
> 
>      > Hello,
>      > I a new to itk and I try to create my own class which can do some
>     basic
>      > itk transformation with templated itk object, and I failed, I really
>      > don't know how to do this.
>      >
>      > In my .h declaration I did:
>      >
>      > class BasicTransformation
>      >
>      > {
>      >
>      > public:
>      >
>      > template void
>      > myFunction(itk::Image imageData);
>      >
>      > }
>      >
>      > -> it doesn't compile, because I have to define all the template
>     values
>      > ? (so I don't understand how to use the template, since I had to
>     specify
>      > so early, my function have to work with different itkImage type ...).
>      >
>      > If I specify the type it compile but it is not very interresting...
>      >
>      > template void
>      > myFunction(itk::Image imageData);
>      >
>      > -> What is very weard is that if I use an ImageSource, it compiles
>      > without specify the type of ImageSource .... (at this time
>     started to
>      > begin mad :-)
>      >
>      > template void
>      > volumeRendering(itk::ImageSource imageSource);
>      >
>      > So,
>      >
>      > -> 1 - can someone could explain to me how to pass a itk object to a
>      > function in another class, please .
>      >
>      > ->2 - In my processing class is it better to have an itkImage to
>     begin
>      > the process or an ImageSource ?
>      >
>      >
>      > Thanks for help
>      >
>      > Lagaffe
>      >
>      >
>      > _______________________________________________
>      > Insight-users mailing list
>      > Insight-users at itk.org
>      > http://www.itk.org/mailman/listinfo/insight-users
> 
> 
> 
> 
> ------------------------------------------------------------------------
> Créez gratuitement votre Yahoo! Mail avec *100 Mo de stockage !*
> Créez votre Yahoo! Mail 
> <http://fr.rd.yahoo.com/mail/taglines/*http://fr.rd.yahoo.com/evt=25917/*http://fr.rd.yahoo.com/mail/mail_taglines_100/default/*http://fr.benefits.yahoo.com/>
> 
> *Le nouveau Yahoo! Messenger est arrivé !* Découvrez toutes les 
> nouveautés pour dialoguer instantanément avec vos amis. Téléchargez 
> GRATUITEMENT ici ! 
> <http://fr.rd.yahoo.com/mail/taglines/*http://fr.rd.yahoo.com/evt=26111/*http://fr.rd.yahoo.com/messenger/mail_taglines/default/*http://fr.messenger.yahoo.com> 
> 






More information about the Insight-users mailing list