isce3 0.25.0
Loading...
Searching...
No Matches
SubSwaths.h
1//-*- C++ -*-
2//-*- coding: utf-8 -*-
3
4#pragma once
5
6#include <string>
7#include <vector>
8#include <isce3/core/Matrix.h>
9#include <isce3/except/Error.h>
10
11namespace isce3 { namespace product {
12
23class SubSwaths {
24
25public:
26 // Construct a new SubSwaths object.
27 inline SubSwaths() :
28 _rlength(1),
29 _rwidth(1) {};
30
38 inline SubSwaths(const int length, const int width, const int n = 1) :
39 _rlength(length),
40 _rwidth(width) {
41 numSubSwaths(n);
42 }
43
53 inline SubSwaths(const int length, const int width,
54 const std::vector<isce3::core::Matrix<int>> & v) :
55 _rlength(length),
56 _rwidth(width) {
58 }
59
61 inline int numSubSwaths() const { return _validSamplesArraysVect.size(); }
63 inline void numSubSwaths(const int n) {
64 if (n <= 0) {
65 std::string error_msg =
66 "ERROR the number of sub-swaths must be greater than zero";
67 throw isce3::except::OutOfRange(ISCE_SRCINFO(), error_msg);
68 }
69 _validSamplesArraysVect.resize(n, isce3::core::Matrix<int>());
70 validate();
71 };
72
80 const isce3::core::Matrix<int>& getValidSamplesArray(const int n) const;
81
92 void setValidSamplesArray(const int n, const isce3::core::Matrix<int>& v);
93
103 const std::vector<isce3::core::Matrix<int>>& getValidSamplesArraysVect() const{
104 return _validSamplesArraysVect;
105 };
106
117 _validSamplesArraysVect = v;
118 validate();
119 };
120
144 int getSampleSubSwath(const int azimuth_index, const int range_index) const;
145
169 int operator()(const int azimuth_index, const int range_index) const {
170 return getSampleSubSwath(azimuth_index, range_index);
171 };
172
174 inline int length() const { return _rlength; }
175
177 inline void length(const int & t) {
178 _rlength = t;
179 validate();
180 }
181
183 inline int width() const { return _rwidth; }
184
186 inline void width(const int & t) {
187 _rwidth = t;
188 validate();
189 }
190
191private:
192
194 int _rlength;
195
197 int _rwidth;
198
201 std::vector<isce3::core::Matrix<int>> _validSamplesArraysVect;
202
204 inline void validate();
205};
206
207// Validation of SubSwaths attributes
208void
209isce3::product::SubSwaths::validate() {
210
211 std::string error_str = "";
212
213 if (length() <= 0)
214 {
215 error_str += "Number of azimuth lines must be positive. \n";
216 }
217
218 if (width() <= 0)
219 {
220 error_str += "Number of range samples must be positive. \n";
221 }
222
223 for (int s = 0; s < _validSamplesArraysVect.size(); ++s) {
224 if (_validSamplesArraysVect[s].size() == 0) {
225 continue;
226 }
227 if (_validSamplesArraysVect[s].width() != 2) {
228 error_str += "The valid samples array of sub-swath ";
229 error_str += std::to_string(s + 1);
230 error_str += " does not have two columns. The";
231 error_str += " columns should represent the indices";
232 error_str += " of the first valid range sample and next";
233 error_str += " sample after the last valid sample";
234 error_str += " for each azimuth line, respectively.\n";
235 continue;
236 }
237 if (_validSamplesArraysVect[s].length() != length()) {
238 error_str += "The valid samples array of sub-swath ";
239 error_str += std::to_string(s + 1);
240 error_str += " has ";
241 error_str += std::to_string(_validSamplesArraysVect[s].length());
242 error_str += " lines whereas the number of azimuth lines is ";
243 error_str += std::to_string(length());
244 error_str += ".\n";
245 }
246 bool flag_informed_error_negative = false;
247 bool flag_informed_error_width = false;
248 for (int i = 0; i < length(); ++i) {
249
250 for (int j = 0; j < 2; ++j) {
251
254 if (_validSamplesArraysVect[s](i, j) < 0 and
255 !flag_informed_error_negative) {
256 error_str += "The valid samples array of sub-swath ";
257 error_str += std::to_string(s + 1);
258 error_str += " has negative indices. For example,";
259 error_str += " the array element at azimuth line ";
260 error_str += std::to_string(i);
261 error_str += " and column ";
262 error_str += std::to_string(j);
263 error_str += " has value ";
264 error_str += std::to_string(_validSamplesArraysVect[s](i, j));
265 error_str += ".\n";
266 }
267 if (_validSamplesArraysVect[s](i, j) > width() and
268 !flag_informed_error_width) {
269 error_str += "The valid samples array of sub-swath ";
270 error_str += std::to_string(s + 1);
271 error_str += " has invalid range indices.";
272 error_str += " The array element at azimuth line ";
273 error_str += std::to_string(i);
274 error_str += " and column ";
275 error_str += std::to_string(j);
276 error_str += " has value ";
277 error_str += std::to_string(_validSamplesArraysVect[s](i, j));
278 error_str += " which is invalid for the sub-swath with ";
279 error_str += std::to_string(width());
280 error_str += " range samples.\n";
281 flag_informed_error_width = true;
282 }
283
284 }
285
286 // If both error messages were shown to the user, exit loop
287 if (flag_informed_error_negative and flag_informed_error_width) {
288 break;
289 }
290 }
291 }
292
293 if (! error_str.empty())
294 {
295 throw isce3::except::InvalidArgument(ISCE_SRCINFO(), error_str);
296 }
297}
298
299
300}}
Data structure for a 2D row-major matrix.
Definition Matrix.h:23
SubSwaths(const int length, const int width, const std::vector< isce3::core::Matrix< int > > &v)
Construct a new SubSwaths object.
Definition SubSwaths.h:53
void numSubSwaths(const int n)
Set number of sub-swaths.
Definition SubSwaths.h:63
void length(const int &t)
Set the radar grid length.
Definition SubSwaths.h:177
int operator()(const int azimuth_index, const int range_index) const
Test if a radar sample belongs to a sub-swath or if it is invalid.
Definition SubSwaths.h:169
void width(const int &t)
Set the radar grid width.
Definition SubSwaths.h:186
const isce3::core::Matrix< int > & getValidSamplesArray(const int n) const
Get valid samples for a sub-swath's array indexed from 1 (1st sub-swath)
Definition SubSwaths.cpp:11
int width() const
Get the radar grid width.
Definition SubSwaths.h:183
int length() const
Get the radar grid length.
Definition SubSwaths.h:174
SubSwaths(const int length, const int width, const int n=1)
Construct a new SubSwaths object.
Definition SubSwaths.h:38
void setValidSamplesArraysVect(const std::vector< isce3::core::Matrix< int > > &v)
Set valid samples sub-swaths vector of arrays.
Definition SubSwaths.h:116
void setValidSamplesArray(const int n, const isce3::core::Matrix< int > &v)
Set valid samples for a sub-swath's array indexed from 1 (1st sub-swath)
Definition SubSwaths.cpp:30
const std::vector< isce3::core::Matrix< int > > & getValidSamplesArraysVect() const
Get valid samples sub-swaths vector of arrays.
Definition SubSwaths.h:103
int getSampleSubSwath(const int azimuth_index, const int range_index) const
Test if a radar sample belongs to a sub-swath or if it is invalid.
Definition SubSwaths.cpp:58
int numSubSwaths() const
Get number of sub-swaths.
Definition SubSwaths.h:61
The isce3::product namespace.
Definition forward.h:3
base interpolator is an abstract base class
Definition BinarySearchFunc.cpp:5

Generated for ISCE3.0 by doxygen 1.13.2.