21 #ifndef otbTileImageFilter_hxx
22 #define otbTileImageFilter_hxx
25 #include "itkImageRegionIterator.h"
29 template <
class TImage>
32 this->DynamicMultiThreadingOn();
35 template <
class TImage>
40 template <
class TImage>
43 Superclass::PrintSelf(os, indent);
44 os << indent <<
"Layout: " << m_Layout << std::endl;
47 template <
class TImage>
51 Superclass::GenerateOutputInformation();
54 unsigned int numberOfImages = m_Layout[0] * m_Layout[1];
57 if (numberOfImages != this->GetNumberOfInputs())
59 itkExceptionMacro(<<
"Layout has " << numberOfImages <<
" tiles, but only " << this->GetNumberOfInputs() <<
" inputs are found.");
62 typename ImageType::SpacingType spacing = this->GetInput()->GetSignedSpacing();
63 unsigned int nbComp = this->GetInput()->GetNumberOfComponentsPerPixel();
65 m_ColumnsSizes.clear();
69 for (
unsigned int col = 0; col < m_Layout[0]; ++col)
71 for (
unsigned int row = 0; row < m_Layout[1]; ++row)
74 const ImageType* currentTile = this->GetInput(col + row * m_Layout[0]);
75 typename ImageType::SizeType currentSize = currentTile->GetLargestPossibleRegion().GetSize();
80 m_RowsSizes.push_back(currentSize[1]);
84 m_ColumnsSizes.push_back(currentSize[0]);
88 if (currentSize[1] != m_RowsSizes[row] || currentSize[0] != m_ColumnsSizes[col])
90 itkExceptionMacro(<<
"Inconsistent sizes in layout detected!");
93 if (spacing != currentTile->GetSignedSpacing())
95 itkExceptionMacro(<<
"Inconsistent spacings in layout detected!");
98 if (nbComp != currentTile->GetNumberOfComponentsPerPixel())
100 itkExceptionMacro(<<
"Inconsistent number of components in layout detected!");
106 typename ImageType::SizeType totalSize;
109 for (
unsigned int i = 0; i < m_Layout[0]; ++i)
111 totalSize[0] += m_ColumnsSizes[i];
114 for (
unsigned int i = 0; i < m_Layout[1]; ++i)
116 totalSize[1] += m_RowsSizes[i];
120 typename ImageType::RegionType outRegion;
121 outRegion.SetSize(totalSize);
125 ImageType* outputPtr = this->GetOutput();
128 outputPtr->CopyInformation(this->GetInput());
131 outputPtr->SetLargestPossibleRegion(outRegion);
134 template <
class TImage>
138 RegionType outRegion = this->GetOutput()->GetRequestedRegion();
141 unsigned int numberOfImages = m_Layout[0] * m_Layout[1];
147 for (
unsigned int i = 0; i < numberOfImages; ++i)
151 RegionType inRegion = OutputRegionToInputRegion(i, outRegion);
156 inputTile->SetRequestedRegion(inRegion);
160 template <
class TImage>
164 ImageType* outputPtr = this->GetOutput();
167 unsigned int numberOfImages = m_Layout[0] * m_Layout[1];
169 for (
unsigned int i = 0; i < numberOfImages; ++i)
171 const ImageType* inputTile = this->GetInput(i);
173 RegionType inRegion = OutputRegionToInputRegion(i, outputRegionForThread);
174 RegionType outRegion = InputRegionToOutputRegion(i, inRegion);
178 if (inRegion.GetNumberOfPixels() > 0)
184 itk::ImageRegionConstIterator<ImageType> inIt(inputTile, inRegion);
185 itk::ImageRegionIterator<ImageType> outIt(outputPtr, outRegion);
190 while (!inIt.IsAtEnd() && !outIt.IsAtEnd())
192 outIt.Set(inIt.Get());
200 template <
class TImage>
204 const ImageType* tile = this->GetInput(tileIndex);
206 unsigned int tileYIndex = tileIndex / m_Layout[0];
207 unsigned int tileXIndex = tileIndex % m_Layout[0];
210 typename RegionType::IndexType regionIndex = out2inRegion.GetIndex();
213 for (
unsigned int i = 0; i < tileXIndex; ++i)
215 regionIndex[0] -= m_ColumnsSizes.at(i);
218 for (
unsigned int i = 0; i < tileYIndex; ++i)
220 regionIndex[1] -= m_RowsSizes.at(i);
223 out2inRegion.SetIndex(regionIndex);
227 if (!out2inRegion.Crop(tile->GetLargestPossibleRegion()))
229 typename RegionType::IndexType nullIndex;
231 out2inRegion.SetIndex(nullIndex);
235 out2inRegion.SetSize(nullSize);
241 template <
class TImage>
247 unsigned int tileYIndex = tileIndex / m_Layout[0];
248 unsigned int tileXIndex = tileIndex % m_Layout[0];
251 typename RegionType::IndexType regionIndex = out2inRegion.GetIndex();
255 for (
unsigned int i = 0; i < tileXIndex; ++i)
257 regionIndex[0] += m_ColumnsSizes.at(i);
260 for (
unsigned int i = 0; i < tileYIndex; ++i)
262 regionIndex[1] += m_RowsSizes.at(i);
265 out2inRegion.SetIndex(regionIndex);
268 if (!out2inRegion.Crop(this->GetOutput()->GetLargestPossibleRegion()))
272 out2inRegion.SetSize(nullSize);
void GenerateInputRequestedRegion() override
ImageType::SizeType SizeType
void GenerateOutputInformation() override
~TileImageFilter() override
void DynamicThreadedGenerateData(const RegionType &outputRegionForThread) override
RegionType InputRegionToOutputRegion(unsigned int tileIndex, const RegionType &requestedRegion)
ImageType::RegionType RegionType
void PrintSelf(std::ostream &os, itk::Indent indent) const override
RegionType OutputRegionToInputRegion(unsigned int tileIndex, const RegionType &requestedRegion)
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.