21 #ifndef otbScalarBufferToImageFileWriter_hxx
22 #define otbScalarBufferToImageFileWriter_hxx
27 #include "itkImageRegionIterator.h"
28 #include "itkImageRegionIteratorWithIndex.h"
32 template <
class TBufferType,
class TOutputPixelType>
34 : m_Buffer(nullptr), m_NumberOfChannels(0), m_InverseXSpacing(false)
41 template <
class TBufferType,
class TOutputPixelType>
45 if ((m_ImageSize[0] == 0) || (m_ImageSize[1] == 0))
47 itkExceptionMacro(
"Invalid output image size, Size can't be null.");
50 if (m_NumberOfChannels == 0)
52 itkExceptionMacro(
"Invalid output image number of channels.");
58 lRegion.SetIndex(lId);
59 lRegion.SetSize(m_ImageSize);
62 lImage->SetRegions(lRegion);
63 lImage->SetNumberOfComponentsPerPixel(m_NumberOfChannels);
67 lPix.SetSize(m_NumberOfChannels);
68 lPix.Fill(itk::NumericTraits<OutputPixelType>::Zero);
69 lImage->FillBuffer(lPix);
72 if (m_InverseXSpacing ==
false)
74 itk::ImageRegionIterator<ImageType> it(lImage, lRegion);
78 while (it.IsAtEnd() ==
false)
80 for (
unsigned int i = 0; i < m_NumberOfChannels; ++i)
92 itk::ImageRegionIteratorWithIndex<ImageType> it(lImage, lRegion);
96 while (it.IsAtEnd() ==
false)
99 cpt = (m_ImageSize[1] - 1 - index[1]) * m_NumberOfChannels * m_ImageSize[0] + m_NumberOfChannels * index[0];
101 for (
unsigned int i = 0; i < m_NumberOfChannels; ++i)
111 m_Writer->SetInput(lImage);
115 template <
class TBufferType,
class TOutputPixelType>
118 Superclass::PrintSelf(os, indent);
119 os << indent <<
"FileName" << m_Writer->GetFileName() << std::endl;
120 os << indent <<
"Size" << m_ImageSize << std::endl;
121 os << indent <<
"NumberOfChannels" << m_NumberOfChannels << std::endl;