[Insight-users] How to transfer Itk parameters to sub-function?

Ariel Hernán Curiale curiale at gmail.com
Mon Oct 29 07:47:53 EDT 2012


I prefer to use a template function like this:
template <class PixelType, unsigned int Dimension> int DoIt(itk::SmartPointer<PixelType,Dimension> img)
or 
template<class TImage>  int DoIt(itk::SmartPointer<TImage> img)

and inside the function creates the propers typedef using the dimension and pixel type of the template for example.

I hate use a global typedef but if you want to use them,  you need to move the typedef how say Dženan Zukić.


Saludos
__________________________________
| Ariel Hernán Curiale Ph.D Student
| ETSI Telecomunicación
| Universidad de Valladolid
| Campus Miguel Delibes
| 47011 Valladolid, Spain
| Phone: 983-423000 ext. 5590
| Web: www.curiale.com.ar
|_________________________________

El 29/10/2012, a las 10:55, Dženan Zukić escribió:

> typedef must come before its use, that is before function. You should make it just after all the includes.
>  typedef itk::ImageFileReader<T_Image> T_Reader;
> 
> On Sat, Oct 27, 2012 at 6:48 PM, flydps <flydps at 163.com> wrote:
> Hi, friends!
> I am trying to write sub function with Itk. But I am puzzled by how to get the Itk typedef parameters for the sub-function. The function I want to realize is as follow, but how can I transfer the information of  "pReader" to my sub-function "OutputOldImageWidth"?
>  
>  
>  
>  
>  
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
>  
> #include <iostream>
> //Subfuntion to get image width
> void OutputOldImageWidth(T_Reader::Pointer pReader);
>  
> void OutputOldImageWidth(T_Reader::Pointer pReader)
> {
>   const T_Image::RegionType& inputRegion = 
>                               pReader->GetOutput()->GetLargestPossibleRegion();
>   const T_Image::SizeType& vnInputSize = inputRegion.GetSize();
>   unsigned int nOldWidth = vnInputSize[0];
>   unsigned int nOldHeight = vnInputSize[1];
>   printf("\nThe old width of image is %d",nOldWidth);
>  }
> /////////////////////////////////////
>  
> int main( int argc, char * argv[] )
> {
>   if( argc != 3 ) 
>   { 
>     std::cerr << "Usage: "
>               << std::endl
>               << argv[0]
>               << " inputImageFile outputImageFile "
>               << std::endl;
>  
>     return EXIT_FAILURE;
>   }
>  
>   // Typedef's for pixel, image, reader and writer types
>   typedef unsigned char T_InputPixel;
>   typedef unsigned char T_OutputPixel;
>  
>   typedef itk::Image<T_InputPixel, 2> T_Image;
>   typedef itk::ImageFileReader<T_Image> T_Reader;
>   typedef unsigned char T_WritePixel;
>   typedef itk::Image<T_WritePixel, 2> T_WriteImage;
>   typedef itk::ImageFileWriter<T_WriteImage> T_Writer;
>  
>  
>   // Prepare the reader and update it right away to know the sizes beforehand.
>  
>   T_Reader::Pointer pReader = T_Reader::New();
>   pReader->SetFileName( argv[1] );
>   pReader->Update();
>  
>   
>   //****************** Call subfunction to get the image width.
>  OutputOldImageWidth(T_Reader::Pointer pReader)
>  
>  
>   // Write the result
>   T_Writer::Pointer pWriter = T_Writer::New();
>   pWriter->SetFileName(argv[2]);
>   pWriter->SetInput(pReader->GetOutput());
>   pWriter->Update();
>  
>   return EXIT_SUCCESS;
> }
>  
> Thank you!
>  
> flydps
> 
> _____________________________________
> 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.php
> 
> 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
> 
> 
> _____________________________________
> 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.php
> 
> 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/20121029/ada541f8/attachment.htm>


More information about the Insight-users mailing list