itkPluginUtilities.h

Go to the documentation of this file.
00001 #ifndef __itkPluginUtilities_h
00002 #define __itkPluginUtilities_h
00003 
00004 #include "itkImage.h"
00005 #include "itkImageFileReader.h"
00006 #include "itkPluginFilterWatcher.h"
00007 #include <vector>
00008 #include <string>
00009 
00010 namespace itk
00011 {
00012   // Description:
00013   // Get the PixelType and ComponentType from fileName
00014   void GetImageType (std::string fileName,
00015                      ImageIOBase::IOPixelType &pixelType,
00016                      ImageIOBase::IOComponentType &componentType)
00017     {
00018       typedef itk::Image<unsigned char, 3> ImageType;
00019       itk::ImageFileReader<ImageType>::Pointer imageReader =
00020         itk::ImageFileReader<ImageType>::New();
00021       imageReader->SetFileName(fileName.c_str());
00022       imageReader->UpdateOutputInformation();
00023 
00024       pixelType = imageReader->GetImageIO()->GetPixelType();
00025       componentType = imageReader->GetImageIO()->GetComponentType();
00026     }
00027 
00028   // Description:
00029   // Get the PixelTypes and ComponentTypes from fileNames
00030   void GetImageTypes (std::vector<std::string> fileNames,
00031                       std::vector<ImageIOBase::IOPixelType> &pixelTypes,
00032                       std::vector<ImageIOBase::IOComponentType> &componentTypes)
00033     {
00034     pixelTypes.clear();
00035     componentTypes.clear();
00036 
00037     // For each file, find the pixel and component type
00038     for (std::vector<std::string>::size_type i = 0; i < fileNames.size(); i++)
00039       {
00040       ImageIOBase::IOPixelType pixelType;
00041       ImageIOBase::IOComponentType componentType;
00042 
00043       GetImageType (fileNames[i],
00044                     pixelType,
00045                     componentType);
00046       pixelTypes.push_back(pixelType);  
00047       componentTypes.push_back(componentType);  
00048       }
00049     }
00050   
00051 #include "itkContinuousIndex.h"
00052   template <class T>
00053   void AlignVolumeCenters(T *fixed, T *moving, typename T::PointType &origin)
00054   {
00055     // compute the center of fixed
00056     typename T::PointType fixedCenter;
00057     {
00058     itk::ContinuousIndex<double,T::ImageDimension> centerIndex;
00059     typename T::SizeType size = fixed->GetLargestPossibleRegion().GetSize();
00060     for (unsigned int i = 0; i < T::ImageDimension; i++)
00061       {
00062       centerIndex[i] = static_cast<double>((size[i]-1)/2.0);
00063       }    
00064     fixed->TransformContinuousIndexToPhysicalPoint(centerIndex, fixedCenter);
00065     }
00066 
00067     // compute the center of moving
00068     typename T::PointType movingCenter;
00069     {
00070     itk::ContinuousIndex<double,T::ImageDimension> centerIndex;
00071     typename T::SizeType size = moving->GetLargestPossibleRegion().GetSize();
00072     for (unsigned i = 0; i < T::ImageDimension; i++)
00073       {
00074       centerIndex[i] = static_cast<double>((size[i]-1)/2.0);
00075       }    
00076     moving->TransformContinuousIndexToPhysicalPoint(centerIndex, movingCenter);
00077     }
00078 
00079     for (unsigned int j = 0; j < fixedCenter.Size(); j++)
00080       {
00081       origin[j] = moving->GetOrigin()[j] - (movingCenter[j] - fixedCenter[j]);
00082       }
00083   }
00084 
00085 } // end namespace itk
00086 
00087 #endif

Generated on 6 Apr 2011 for Slicer3 by  doxygen 1.6.1