[Insight-users] problem about template a class with itkimage

Baoyun Li baoyun_li123 at yahoo.com
Fri Feb 26 15:13:44 EST 2010


Hi, Luis:

Thanks a lot. The problem is now solved.


Best regards

Baoyun




________________________________
From: Luis Ibanez <luis.ibanez at kitware.com>
To: Baoyun Li <baoyun_li123 at yahoo.com>
Cc: insight-users at itk.org
Sent: Fri, February 26, 2010 12:35:25 PM
Subject: Re: [Insight-users] problem about template a class with itkimage

Hi Baoyun,


Thanks for your detailed email.


The error message indicates that in line 35 of the file

                              ChanVese.h

You are attempting to directly call the constructor of
an  itk::Image.

This is a common mistake and indicates that you
have a line such as:

                ImageType      myImage;

Instead of properly using Smart Pointers,


The correct line should be something like:

      typename ImageType::Pointer    myImage;


We declared "protected" the constructor and destructor
methods of all the classes that are managed by
SmartPointers, with the explicit intention of catching
this common mistake. (and redirecting you to use the
SmartPointers).


You will find useful to read the "Data Representation"
chapter of the ITK Software Guide:

        http://www.itk.org/ItkSoftwareGuide.pdf

Where these issues are described in detail.



  Regards,



      Luis



-------------------------------------------------------
On Fri, Feb 26, 2010 at 11:30 AM, Baoyun Li <baoyun_li123 at yahoo.com> wrote:
> Dear All:
>
> I am trying to wirte some template class which is templated over
> itkImage with  following class defintion. At this time, I just want my code
> to do somework with the help of itk tools. But something is wrong with my
> constructor an deconstructoer although  I did not do anything using them
> now.
>
> The error message shows me I should not call itkImage constructor or
> destructor since they are protected.  Can somebody tell me the right way to
> do the work.
>
> I have listed the code and error message.
>
> Thanks and my best regards
>
> Baoyun
>
> 1.   The intilization of this class
>
>      typedef ChanVese<InputImageType,InputImageType,float> ChanVeseType;
>       ChanVeseType leveset1;
>
> 2: class definition
> ***************************************************
>
>
> #ifndef _ChanVese_H
> #define _ChanVese_H
>
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkBinaryThresholdImageFilter.h"
> using namespace std;
> template <class TInputImage,class TFeatureImage,class TOutputPixelType>
>    class ChanVese
> {
>
>
>
>    public:
>     itkStaticConstMacro( ImageDimension, unsigned
> int,TInputImage::ImageDimension );
>     typedef TFeatureImage FeatureImageType;
>     typedef typename FeatureImageType::PixelType FeaturePixelType;
>     typedef TInputImage InputImageType;
>     typedef typename InputImageType::PixelType InputPixelType;
>      ChanVese()
>       {
>          std::cout<<"chan vesee desconstructed"<<std::endl;
>       }
>      ~ChanVese()
>      {
>         std::cout<<"chan vesee desconstructed"<<std::endl;
>      }
>
>    } ;
> #endif
>
> ******************************************************
>
> --------------------------------------------------------------------------------------------------
> /home/gtao/tools/ITK/source_3.16/Code/Common/itkImage.txx:34: error:
> 'itk::Image<TPixel, VImageDimension>::Image() [with TPixel = short int,
> unsigned int VImageDimension = 3u]' is protected
> /home/gtao/code/Gui_Segmenation/chan_vesse/v1.5_tumor_pdfmap/source/algorithm/ChanVese.h:35:
> error: within this context
> /home/gtao/code/Gui_Segmenation/chan_vesse/v1.5_tumor_pdfmap/source/test.cxx:490:
> instantiated from here
> /home/gtao/tools/ITK/source_3.16/Code/Common/itkImage.h:287: error:
> 'itk::Image<TPixel, VImageDimension>::~Image() [with TPixel = short int,
> unsigned int VImageDimension = 3u]' is protected
> /home/gtao/code/Gui_Segmenation/chan_vesse/v1.5_tumor_pdfmap/source/algorithm/ChanVese.h:35:
> error: within this context
> /home/gtao/tools/ITK/source_3.16/Code/Common/itkImage.h: In destructor
> 'ChanVese<TInputImage, TFeatureImage, TOutputPixelType>::~ChanVese() [with
> TInputImage = itk::Image<short int, 3u>, TFeatureImage = itk::Image<short
> int, 3u>, TOutputPixelType = float]':
> /home/gtao/code/Gui_Segmenation/chan_vesse/v1.5_tumor_pdfmap/source/test.cxx:490:
> instantiated from here
> /home/gtao/tools/ITK/source_3.16/Code/Common/itkImage.h:287: error:
> 'itk::Image<TPixel, VImageDimension>::~Image() [with TPixel = short int,
> unsigned int VImageDimension = 3u]' is protected
> /home/gtao/code/Gui_Segmenation/chan_vesse/v1.5_tumor_pdfmap/source/algorithm/ChanVese.h:42:
> error: within this context
> ------------------------------------------------------------------------------------------------------
>
>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100226/68a4a855/attachment.htm>


More information about the Insight-users mailing list