21 #ifndef otbSarBurstExtractionImageFilter_hxx
22 #define otbSarBurstExtractionImageFilter_hxx
27 #include "itkImageScanlineIterator.h"
28 #include "itkImageScanlineConstIterator.h"
29 #include "itkImageRegionIterator.h"
30 #include "itkImageRegionConstIterator.h"
35 template <
class TImage>
41 template <
class TImage>
45 Superclass::GenerateOutputInformation();
48 const ImageType* inputPtr = this->GetInput();
52 if (std::abs(inputPtr->GetSignedSpacing()[1] - 1.) >= std::numeric_limits<double>::epsilon())
53 itkExceptionMacro(
"Can not perform deburst if input image azimuth spacing is not 1.");
56 if (std::abs(inputPtr->GetOrigin()[1] -
static_cast<long>(inputPtr->GetOrigin()[1]) - 0.5) >= std::numeric_limits<double>::epsilon())
57 itkExceptionMacro(
"Can not perform burst extraction if input image azimuth origin is not N.5");
60 auto imd = inputPtr->GetImageMetadata();
66 bool burstExtractionOk = sarSensorModel.
BurstExtraction(m_BurstIndex, m_LinesRecord, m_SamplesRecord, m_AllPixels);
68 if (!burstExtractionOk)
69 itkExceptionMacro(<<
"Could not extract Burst from input image");
74 typename ImageType::RegionType largestPossibleRegion = this->GetInput()->GetLargestPossibleRegion();
75 typename ImageType::PointType origin = this->GetInput()->GetOrigin();
78 long originOffset_samples =
static_cast<long>(this->GetInput()->GetOrigin()[0] - 0.5);
79 long originOffset_lines =
static_cast<long>(this->GetInput()->GetOrigin()[1] - 0.5);
80 unsigned long outputOriginSample = 0;
81 unsigned long outputOriginLine = 0;
83 typename ImageType::SizeType burstSize = largestPossibleRegion.GetSize();
85 if (
static_cast<int>(m_SamplesRecord.first) > originOffset_samples)
87 outputOriginSample = 0;
91 outputOriginSample = originOffset_samples -
static_cast<int>(m_SamplesRecord.first);
94 if (
static_cast<int>(m_LinesRecord.first) > originOffset_lines)
100 outputOriginLine = originOffset_lines -
static_cast<int>(m_LinesRecord.first);
103 long firstOutSample =
static_cast<long>(std::max(
static_cast<long>(m_SamplesRecord.first), originOffset_samples));
104 long secondOutSample =
105 static_cast<long>(std::min(
static_cast<long>(m_SamplesRecord.second),
static_cast<long>(largestPossibleRegion.GetSize()[0] + originOffset_samples - 1)));
107 long firstOutLine =
static_cast<long>(std::max(
static_cast<long>(m_LinesRecord.first), originOffset_lines));
109 static_cast<long>(std::min(
static_cast<long>(m_LinesRecord.second),
static_cast<long>(largestPossibleRegion.GetSize()[1] + originOffset_lines - 1)));
111 burstSize[0] = secondOutSample - firstOutSample + 1;
112 burstSize[1] = secondOutLine - firstOutLine + 1;
114 origin[0] = 0.5 + outputOriginSample;
115 origin[1] = 0.5 + outputOriginLine;
117 outputPtr->SetOrigin(origin);
120 typename ImageType::RegionType outputLargestPossibleRegion = largestPossibleRegion;
121 largestPossibleRegion.SetSize(burstSize);
122 outputPtr->SetLargestPossibleRegion(largestPossibleRegion);
129 imd.Add(
"invalid_pixels",
"yes");
133 imd.Add(
"invalid_pixels",
"no");
137 outputPtr->SetImageMetadata(imd);
140 template <
class TImage>
146 typename RegionType::IndexType index = inputRegion.GetIndex();
148 long originOffset =
static_cast<long>(this->GetInput()->GetOrigin()[1] - 0.5);
149 long originOffset_samples =
static_cast<long>(this->GetInput()->GetOrigin()[0] - 0.5);
151 if (
static_cast<int>(m_SamplesRecord.first) > originOffset_samples)
153 index[0] += m_SamplesRecord.first - originOffset_samples;
155 if (
static_cast<int>(m_LinesRecord.first) > originOffset)
157 index[1] += m_LinesRecord.first - originOffset;
160 inputRegion.SetIndex(index);
167 template <
class TImage>
170 RegionType outputRequestedRegion = this->GetOutput()->GetRequestedRegion();
171 RegionType inputRequestedRegion = OutputRegionToInputRegion(outputRequestedRegion);
175 inputPtr->SetRequestedRegion(inputRequestedRegion);
180 template <
class TImage>
184 RegionType inputRegionForThread = OutputRegionToInputRegion(outputRegionForThread);
186 itk::ImageRegionConstIterator<ImageType> inputIt(this->GetInput(), inputRegionForThread);
187 itk::ImageRegionIterator<ImageType> outputIt(this->GetOutput(), outputRegionForThread);
190 outputIt.GoToBegin();
192 int linesRecordFirst =
static_cast<int>(m_LinesRecord.first);
193 int linesRecordSecond =
static_cast<int>(m_LinesRecord.second);
194 int samplesRecordFirst =
static_cast<int>(m_SamplesRecord.first);
195 int samplesRecordSecond =
static_cast<int>(m_SamplesRecord.second);
197 while (!inputIt.IsAtEnd() && !outputIt.IsAtEnd())
199 typename ImageType::IndexType currentInputIndex = inputIt.GetIndex();
201 this->GetInput()->TransformIndexToPhysicalPoint(currentInputIndex, currentInputPoint);
203 bool lineToKeep =
false;
204 bool sampleToKeep =
false;
207 if (currentInputPoint[1] - 0.5 >= linesRecordFirst && currentInputPoint[1] - 0.5 <= linesRecordSecond)
213 if (currentInputPoint[0] - 0.5 >= samplesRecordFirst && currentInputPoint[0] - 0.5 <= samplesRecordSecond)
219 if (lineToKeep && sampleToKeep)
221 outputIt.Set(inputIt.Get());