isce3 0.25.0
Loading...
Searching...
No Matches
SubSwaths.h
1#pragma once
2
3#include <vector>
4#include <thrust/device_vector.h>
5
6#include <isce3/core/Common.h>
7#include <isce3/product/SubSwaths.h>
8
9
10namespace isce3::cuda::product {
11
14class BaseSubSwaths {
15protected:
16 // Length of radar grid
17 size_t _length = 0;
18
19 // Width of radar grid
20 size_t _width = 0;
21
22 // Number of subswaths
23 unsigned int _n_subswaths = 0;
24
25public:
26 /* Default constructor has no subswaths and results in no masking */
27 CUDA_HOST BaseSubSwaths() {}
28
35 CUDA_HOST BaseSubSwaths(const isce3::product::SubSwaths& cpu_subswaths):
36 _length(cpu_subswaths.length()),
37 _width(cpu_subswaths.width())
38 {
39 // CPU subswath defaults the number of subswaths to 1 even if the RSLC
40 // has no subswaths.
41 // Need to check if samples array is empty to determine if number of
42 // subswaths is zero.
43 const auto sz_1st_subswath = cpu_subswaths.getValidSamplesArray(1).size();
44 if (cpu_subswaths.numSubSwaths() == 1 and sz_1st_subswath == 0)
45 _n_subswaths = 0;
46 else
47 _n_subswaths = cpu_subswaths.numSubSwaths();
48 }
49
56 CUDA_HOST BaseSubSwaths(const size_t length, const size_t width,
57 unsigned int n_subswaths):
58 _length(length),
59 _width(width),
60 _n_subswaths(n_subswaths) {}
61
65 CUDA_HOSTDEV size_t length() const { return _length; }
66
70 CUDA_HOSTDEV size_t width() const { return _width; }
71
75 CUDA_HOSTDEV unsigned int n_subswaths() const { return _n_subswaths; }
76};
77
78
83class OwnerSubSwaths : public BaseSubSwaths {
84private:
85 /* device_vector holding all subswath starts.
86 * Has dimensions 1 x (number of subswaths * slc length) */
87 thrust::device_vector<int> _valid_start_samples;
88
89 /* device_vector holding all subswath stops.
90 * Has dimensions 1 x (number of subswaths * slc length) */
91 thrust::device_vector<int> _valid_stop_samples;
92
93public:
97 CUDA_HOST OwnerSubSwaths(): BaseSubSwaths() {}
98
103 CUDA_HOST OwnerSubSwaths(const isce3::product::SubSwaths& cpu_subswaths);
104
108 CUDA_HOST int* ptr_to_valid_start()
109 {
110 return thrust::raw_pointer_cast(_valid_start_samples.data());
111 }
112
116 CUDA_HOST const int* ptr_to_valid_start() const
117 {
118 return thrust::raw_pointer_cast(_valid_start_samples.data());
119 }
120
124 CUDA_HOST int* ptr_to_valid_stop()
125 {
126 return thrust::raw_pointer_cast(_valid_stop_samples.data());
127 }
128
132 CUDA_HOST const int* ptr_to_valid_stop() const
133 {
134 return thrust::raw_pointer_cast(_valid_stop_samples.data());
135 }
136};
137
138
143class ViewSubSwaths : public BaseSubSwaths {
144private:
152 int* _valid_start_view = nullptr;
153 int* _valid_stop_view = nullptr;
154
155public:
160 CUDA_HOST ViewSubSwaths(): BaseSubSwaths() {}
161
166 /* if const OwnerSubSwaths& as parameter then
167 * error: the object has type qualifiers that are not compatible with the member function "isce3::cuda::product::OwnerSubSwaths::ptr_to_valid_stop"
168 */
169 CUDA_HOST ViewSubSwaths(OwnerSubSwaths& owner_subswaths);
170
177 CUDA_DEV bool contains(const int index_aztime, const int index_srange) const
178 {
179 // _n_subswaths == 0 indicates no SubSwaths i.e. no masking so return
180 // true
181 if (_n_subswaths == 0)
182 return true;
183
184 // Check if az and srg in bounds of radar grid, return false if out of
185 // bounds
186 if (index_aztime < 0 || index_aztime >= _length || index_srange < 0 ||
187 index_srange >= _width)
188 return false;
189
190 for (unsigned int i_subswath = 0; i_subswath < _n_subswaths; ++i_subswath)
191 {
192 // Compute pointer arithmetic offset of each subswath
193 const auto swath_offset = i_subswath * _length;
194
195 // Get start of current subswath block
196 const auto subswath_rg_start = *(_valid_start_view + swath_offset + index_aztime);
197
198 // Get stop of current subswath block
199 const auto subswath_rg_stop = *(_valid_stop_view + swath_offset + index_aztime);
200
201 if (index_srange >= subswath_rg_start && index_srange < subswath_rg_stop)
202 return true;
203 }
204
205 return false;
206 }
207};
208
209} // end namespace isce3::cuda::product
CUDA_HOST BaseSubSwaths(const isce3::product::SubSwaths &cpu_subswaths)
Construct with an existing CPU subswath object.
Definition SubSwaths.h:35
CUDA_HOST BaseSubSwaths(const size_t length, const size_t width, unsigned int n_subswaths)
Construct a BaseSubSwaths object with specified parameters.
Definition SubSwaths.h:56
CUDA_HOSTDEV size_t width() const
Get the width of the radar grid.
Definition SubSwaths.h:70
CUDA_HOSTDEV size_t length() const
Get the length of the radar grid.
Definition SubSwaths.h:65
CUDA_HOSTDEV unsigned int n_subswaths() const
Get the number of subswaths.
Definition SubSwaths.h:75
Owner subswaths class for use in GPU geocode.
Definition SubSwaths.h:83
CUDA_HOST int * ptr_to_valid_stop()
Get pointer to device_vector of sample stops.
Definition SubSwaths.h:124
CUDA_HOST int * ptr_to_valid_start()
Get pointer to device_vector of sample starts.
Definition SubSwaths.h:108
CUDA_HOST OwnerSubSwaths()
Default constructor initializing no subswaths so no masking occurs.
Definition SubSwaths.h:97
CUDA_HOST const int * ptr_to_valid_start() const
Get const pointer to device_vector of sample starts.
Definition SubSwaths.h:116
CUDA_HOST const int * ptr_to_valid_stop() const
Get const pointer to device_vector of sample stops.
Definition SubSwaths.h:132
CUDA_HOST ViewSubSwaths()
Default constructor uninitialized with an owner needed for test harness.
Definition SubSwaths.h:160
CUDA_DEV bool contains(const int index_aztime, const int index_srange) const
Check if a specific index is contained within the subswaths.
Definition SubSwaths.h:177
Sub-swaths metadata of a SAR dataset.
Definition SubSwaths.h:23
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 numSubSwaths() const
Get number of sub-swaths.
Definition SubSwaths.h:61

Generated for ISCE3.0 by doxygen 1.13.2.