/usr/include/InsightToolkit/Utilities/MetaIO/metaITKUtils.h is in libinsighttoolkit3-dev 3.20.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | /*============================================================================
MetaIO
Copyright 2000-2010 Insight Software Consortium
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
// Utility file - definition of loadImage
// Templated over the Pixel Type
#include "metaTypes.h"
#ifndef ITKMetaIO_METAITKUTILS_H
#define ITKMetaIO_METAITKUTILS_H
#include "metaImage.h"
#include "itkImage.h"
#include "itkProcessObject.h"
#include "itkImageRegionIterator.h"
#if (METAIO_USE_NAMESPACE)
namespace METAIO_NAMESPACE {
#endif
template <class T>
typename itk::Image<T, 3>::Pointer
metaITKUtilLoadImage3D(const char *fname, MET_ValueEnumType _toType,
double _toMinValue=0, double _toMaxValue=0)
{
MetaImage *imIO = new MetaImage();
imIO->Read(fname);
imIO->PrintInfo();
imIO->ConvertElementDataTo(_toType, _toMinValue, _toMaxValue);
typedef itk::Image<T,3> ImageType;
typedef typename ImageType::Pointer ImagePointer;
typedef typename ImageType::SizeType SizeType;
typedef typename ImageType::IndexType IndexType;
typedef typename ImageType::RegionType RegionType;
ImagePointer image = ImageType::New();
SizeType size;
double spacing[3];
size[0] = imIO->DimSize()[0];
size[1] = imIO->DimSize()[1];
if(imIO->NDims()>2)
size[2] = imIO->DimSize()[2];
else
size[2] = 1;
spacing[0] = imIO->ElementSpacing()[0];
spacing[1] = imIO->ElementSpacing()[1];
if(imIO->NDims()>2)
spacing[2] = imIO->ElementSpacing()[2];
else
spacing[2] = imIO->ElementSpacing()[1];
if (spacing[0] == 0)
{
spacing[0] = 1;
}
if (spacing[1] == 0)
{
spacing[1] = 1;
}
if (spacing[2] == 0)
{
spacing[2] = 1;
}
IndexType start;
start.Fill(0);
RegionType region;
region.SetSize(size);
region.SetIndex( start );
image->SetLargestPossibleRegion(region);
image->SetBufferedRegion(region);
image->SetRequestedRegion(region);
image->SetSpacing(spacing);
image->Allocate();
itk::ImageRegionIterator< ImageType > it(image, region);
it.Begin();
for(unsigned int i = 0; !it.IsAtEnd(); i++, ++it)
{
it.Set( static_cast< typename ImageType::PixelType >( imIO->ElementData(i) ));
}
return image;
}
template <class imageT>
bool metaITKUtilSaveImage(const char *fname, const char *dname,
typename imageT::Pointer _im,
MET_ValueEnumType _fromType,
int _numberOfChannels,
MET_ValueEnumType _toType,
double _toMinValue=0, double _toMaxValue=0)
{
int i;
int nd = _im->GetImageDimension();
int * si = new int[nd];
float * sp = new float[nd];
for(i=0; i<nd; i++)
{
si[i] = _im->GetLargestPossibleRegion().GetSize()[i];
sp[i] = _im->GetSpacing()[i];
}
MetaImage imIO(_im->GetImageDimension(), si, sp,
_fromType, _numberOfChannels,
(void *)_im->GetBufferPointer());
delete si;
delete sp;
imIO.ConvertElementDataTo(_toType, _toMinValue, _toMaxValue);
bool res = imIO.Write(fname, dname);
return res;
}
#if (METAIO_USE_NAMESPACE)
};
#endif
#endif
|