Slicer  4.10
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
itkPluginUtilities.h
Go to the documentation of this file.
1 #ifndef itkPluginUtilities_h
2 #define itkPluginUtilities_h
3 
4 // ITK includes
5 #include <itkContinuousIndex.h>
6 #include <itkImage.h>
7 #include <itkImageFileReader.h>
9 
10 // STD includes
11 #include <vector>
12 #include <string>
13 
14 namespace itk
15 {
16  //-----------------------------------------------------------------------------
18  void GetImageType (std::string fileName,
19  ImageIOBase::IOPixelType &pixelType,
20  ImageIOBase::IOComponentType &componentType)
21  {
22  typedef itk::Image<unsigned char, 3> ImageType;
23  itk::ImageFileReader<ImageType>::Pointer imageReader =
24  itk::ImageFileReader<ImageType>::New();
25  imageReader->SetFileName(fileName.c_str());
26  imageReader->UpdateOutputInformation();
27 
28  pixelType = imageReader->GetImageIO()->GetPixelType();
29  componentType = imageReader->GetImageIO()->GetComponentType();
30  }
31 
32  //-----------------------------------------------------------------------------
34  void GetImageTypes (std::vector<std::string> fileNames,
35  std::vector<ImageIOBase::IOPixelType> &pixelTypes,
36  std::vector<ImageIOBase::IOComponentType> &componentTypes)
37  {
38  pixelTypes.clear();
39  componentTypes.clear();
40 
41  // For each file, find the pixel and component type
42  for (std::vector<std::string>::size_type i = 0; i < fileNames.size(); i++)
43  {
44  ImageIOBase::IOPixelType pixelType;
45  ImageIOBase::IOComponentType componentType;
46 
47  GetImageType (fileNames[i],
48  pixelType,
49  componentType);
50  pixelTypes.push_back(pixelType);
51  componentTypes.push_back(componentType);
52  }
53  }
54 
55  //-----------------------------------------------------------------------------
56  template <class T>
57  void AlignVolumeCenters(T *fixed, T *moving, typename T::PointType &origin)
58  {
59  // compute the center of fixed
60  typename T::PointType fixedCenter;
61  {
62  itk::ContinuousIndex<double,T::ImageDimension> centerIndex;
63  typename T::SizeType size = fixed->GetLargestPossibleRegion().GetSize();
64  for (unsigned int i = 0; i < T::ImageDimension; i++)
65  {
66  centerIndex[i] = static_cast<double>((size[i]-1)/2.0);
67  }
68  fixed->TransformContinuousIndexToPhysicalPoint(centerIndex, fixedCenter);
69  }
70 
71  // compute the center of moving
72  typename T::PointType movingCenter;
73  {
74  itk::ContinuousIndex<double,T::ImageDimension> centerIndex;
75  typename T::SizeType size = moving->GetLargestPossibleRegion().GetSize();
76  for (unsigned i = 0; i < T::ImageDimension; i++)
77  {
78  centerIndex[i] = static_cast<double>((size[i]-1)/2.0);
79  }
80  moving->TransformContinuousIndexToPhysicalPoint(centerIndex, movingCenter);
81  }
82 
83  for (unsigned int j = 0; j < fixedCenter.Size(); j++)
84  {
85  origin[j] = moving->GetOrigin()[j] - (movingCenter[j] - fixedCenter[j]);
86  }
87  }
88 
89 } // end namespace itk
90 
91 #endif
void GetImageTypes(std::vector< std::string > fileNames, std::vector< ImageIOBase::IOPixelType > &pixelTypes, std::vector< ImageIOBase::IOComponentType > &componentTypes)
Get the PixelTypes and ComponentTypes from fileNames.
Simplified inverse ITK transforms.
void GetImageType(std::string fileName, ImageIOBase::IOPixelType &pixelType, ImageIOBase::IOComponentType &componentType)
Get the PixelType and ComponentType from fileName.
void AlignVolumeCenters(T *fixed, T *moving, typename T::PointType &origin)