21 #ifndef otbResetMarginFilter_hxx
22 #define otbResetMarginFilter_hxx
27 #include "itkProgressReporter.h"
35 template<
typename TImage>
40 Superclass::GenerateOutputInformation();
43 output->SetNumberOfComponentsPerPixel(input->GetNumberOfComponentsPerPixel());
46 template<
typename TImage>
51 itk::ThreadIdType threadId)
53 auto const* input = this->GetInput();
54 auto * output = this->GetOutput();
58 auto curRoi = OutputRegionToInputRegion(outputRegionForThread);
60 auto const& size = outputRegionForThread.GetSize();
61 auto const& index = outputRegionForThread.GetIndex();
62 auto const sizeX = size[0];
63 auto const sizeY = size[1];
64 auto const startX = index[0];
65 auto const startY = index[1];
66 itk::IndexValueType
const endX = startX + sizeX;
67 itk::IndexValueType
const endY = startY + sizeY;
69 auto const nBand = output->GetNumberOfComponentsPerPixel();
71 itk::IndexValueType thrX1 = curRoi.GetIndex(0);
72 itk::IndexValueType thrX2 = curRoi.GetIndex(0) + curRoi.GetSize(0);
73 itk::IndexValueType thrY1 = curRoi.GetIndex(1);
74 itk::IndexValueType thrY2 = curRoi.GetIndex(1) + curRoi.GetSize(1);
76 assert(startX <= thrX1 &&
"Iterations shall stay within requested region");
77 assert(thrX1 <= thrX2 &&
"Iterations shall stay within requested region");
78 assert(thrX2 <= endX &&
"Iterations shall stay within requested region");
80 assert(startY <= thrY1 &&
"Iterations shall stay within requested region");
81 assert(thrY1 <= thrY2 &&
"Iterations shall stay within requested region");
82 assert(thrY2 <= endY &&
"Iterations shall stay within requested region");
84 auto const full_line = sizeX * nBand;
85 auto const nb_zero_left = (
unsigned long)(thrX1 - startX) * nBand;
86 auto const nb_copy_middle = (
unsigned long)(thrX2 - thrX1) * nBand;
87 auto const nb_zero_right = (
unsigned long)(endX - thrX2) * nBand;
88 assert(nb_zero_left + nb_copy_middle + nb_zero_right == full_line);
92 const unsigned long inLineOff = nBand * input->GetBufferedRegion().GetSize(0);
93 const unsigned long outLineOff = nBand * output->GetBufferedRegion().GetSize(0);
94 bool hasContiguousLines( sizeX == output->GetBufferedRegion().GetSize(0) );
96 outData += nBand * output->ComputeOffset(index);
97 if (curRoi.GetNumberOfPixels())
99 inData += nBand * input->ComputeOffset(curRoi.GetIndex());
102 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels() / sizeY );
105 if (hasContiguousLines)
108 std::fill_n(outData, full_line*(thrY1-y), m_Pad);
111 ; ++y, outData+=outLineOff )
113 progress.CompletedPixel();
120 ; ++y, outData+=outLineOff )
125 std::fill_n(outData, full_line, m_Pad);
126 progress.CompletedPixel();
133 ; ++y, inData+=inLineOff, outData+=outLineOff)
135 auto const t1 = std::fill_n(outData, nb_zero_left, m_Pad);
138 auto const t2 = std::copy_n(inData, nb_copy_middle, t1);
139 std::fill_n(t2, nb_zero_right, m_Pad);
140 progress.CompletedPixel();
144 if (hasContiguousLines)
147 std::fill_n(outData, full_line*(endY-y), m_Pad);
150 ; ++y, outData+=outLineOff )
152 progress.CompletedPixel();
159 ; ++y, outData+=outLineOff)
164 std::fill_n(outData, full_line, m_Pad);
165 progress.CompletedPixel();
172 template<
typename TImage>
178 if (!curROI.Crop(srcRegion))
180 curROI.SetIndex(srcRegion.GetIndex() + srcRegion.GetSize());
181 curROI.SetSize({0,0});
188 #endif // otbResetMarginFilter_hxx