Skip to content

Commit 9bea470

Browse files
Liang YugshiromaLiang Yu
authored andcommitted
Additonal block margin for GSLC and CUDA geocode (#833)
* update block margin * revert changes brought by mistake from PR #783 * Update cxx/isce3/geocode/GeocodeCov.cpp * added extra margin for GSLC block interp to address gaps in output block boundaries. changes mirror PR 830 * port extra margin fix to CUDA geocode. std::min/max replaced to account for unsigned size_t Co-authored-by: Gustavo Shiroma <[email protected]> Co-authored-by: Liang Yu <[email protected]>
1 parent 59cdd2c commit 9bea470

File tree

3 files changed

+68
-60
lines changed

3 files changed

+68
-60
lines changed

cxx/isce3/cuda/geocode/Geocode.cu

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "Geocode.h"
2525
#include "MaskedMinMax.h"
2626

27+
#include <cstdio>
2728
using isce3::core::Vec3;
2829
using isce3::io::Raster;
2930

@@ -307,6 +308,16 @@ void Geocode::setBlockRdrCoordGrid(const size_t block_number)
307308
_az_last_line = std::max(static_cast<size_t>(0),
308309
static_cast<size_t>(std::ceil(rdr_y_max) - 1));
309310

311+
// Extra margin for interpolation to avoid gaps between blocks in output
312+
const size_t interp_margin {5};
313+
_range_first_pixel = interp_margin > _range_first_pixel ? 0 : _range_first_pixel - interp_margin;
314+
_range_last_pixel = std::min(_rdr_geom.radarGrid().width() - 1,
315+
_range_last_pixel + interp_margin);
316+
317+
_az_first_line = interp_margin > _az_first_line ? 0 : _az_first_line - interp_margin;
318+
_az_last_line = std::min(_rdr_geom.radarGrid().length() - 1,
319+
_az_last_line+interp_margin);
320+
310321
// check if block entirely masked
311322
bool all_masked = std::isnan(rdr_y_min);
312323

cxx/isce3/geocode/GeocodeCov.cpp

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,6 @@ void Geocode<T>::geocodeInterp(
432432
out_geo_dem_array.fill(std::numeric_limits<float>::quiet_NaN());
433433
}
434434

435-
// First and last line of the data block in radar coordinates
436-
int azimuthFirstLine = radar_grid.length() - 1;
437-
int azimuthLastLine = 0;
438-
439-
// First and last pixel of the data block in radar coordinates
440-
int rangeFirstPixel = radar_grid.width() - 1;
441-
int rangeLastPixel = 0;
442-
443435
// load a block of DEM for the current geocoded grid
444436
isce3::geometry::DEMInterpolator demInterp = isce3::geocode::loadDEM(
445437
demRaster, geogrid, lineStart, geoBlockLength, geogrid.width(),
@@ -450,17 +442,17 @@ void Geocode<T>::geocodeInterp(
450442
std::valarray<double> radarX(blockSize);
451443
std::valarray<double> radarY(blockSize);
452444

453-
int localAzimuthFirstLine = radar_grid.length() - 1;
454-
int localAzimuthLastLine = 0;
455-
int localRangeFirstPixel = radar_grid.width() - 1;
456-
int localRangeLastPixel = 0;
445+
int azimuthFirstLine = radar_grid.length() - 1;
446+
int azimuthLastLine = 0;
447+
int rangeFirstPixel = radar_grid.width() - 1;
448+
int rangeLastPixel = 0;
457449

458450
// Loop over lines, samples of the output grid
459451
#pragma omp parallel for reduction( \
460452
min \
461-
: localAzimuthFirstLine, localRangeFirstPixel) \
453+
: azimuthFirstLine, rangeFirstPixel) \
462454
reduction(max \
463-
: localAzimuthLastLine, localRangeLastPixel)
455+
: azimuthLastLine, rangeLastPixel)
464456

465457
for (size_t kk = 0; kk < geoBlockLength * geogrid.width(); ++kk) {
466458

@@ -525,14 +517,14 @@ void Geocode<T>::geocodeInterp(
525517
rdrX >= radar_grid.width())
526518
continue;
527519

528-
localAzimuthFirstLine = std::min(
529-
localAzimuthFirstLine, static_cast<int>(std::floor(rdrY)));
530-
localAzimuthLastLine = std::max(localAzimuthLastLine,
520+
azimuthFirstLine = std::min(
521+
azimuthFirstLine, static_cast<int>(std::floor(rdrY)));
522+
azimuthLastLine = std::max(azimuthLastLine,
531523
static_cast<int>(std::ceil(rdrY) - 1));
532-
localRangeFirstPixel = std::min(
533-
localRangeFirstPixel, static_cast<int>(std::floor(rdrX)));
534-
localRangeLastPixel = std::max(
535-
localRangeLastPixel, static_cast<int>(std::ceil(rdrX) - 1));
524+
rangeFirstPixel = std::min(
525+
rangeFirstPixel, static_cast<int>(std::floor(rdrX)));
526+
rangeLastPixel = std::max(
527+
rangeLastPixel, static_cast<int>(std::ceil(rdrX) - 1));
536528

537529
// store the adjusted X and Y indices
538530
radarX[blockLine * geogrid.width() + pixel] = rdrX;
@@ -558,11 +550,15 @@ void Geocode<T>::geocodeInterp(
558550
geogrid.width(), geoBlockLength, 1);
559551
}
560552

561-
// Get min and max swath extents from among all threads
562-
azimuthFirstLine = std::min(azimuthFirstLine, localAzimuthFirstLine);
563-
azimuthLastLine = std::max(azimuthLastLine, localAzimuthLastLine);
564-
rangeFirstPixel = std::min(rangeFirstPixel, localRangeFirstPixel);
565-
rangeLastPixel = std::max(rangeLastPixel, localRangeLastPixel);
553+
// Add extra margin for interpolation
554+
int interp_margin = 5;
555+
azimuthFirstLine = std::max(azimuthFirstLine - interp_margin, 0);
556+
rangeFirstPixel = std::max(rangeFirstPixel - interp_margin, 0);
557+
558+
azimuthLastLine = std::min(azimuthLastLine + interp_margin,
559+
static_cast<int>(radar_grid.length() - 1));
560+
rangeLastPixel = std::min(rangeLastPixel + interp_margin,
561+
static_cast<int>(radar_grid.width() - 1));
566562

567563
if (azimuthFirstLine > azimuthLastLine ||
568564
rangeFirstPixel > rangeLastPixel)
@@ -735,7 +731,8 @@ inline void Geocode<T>::_interpolate(
735731

736732
size_t length = geoDataBlock.length();
737733
size_t width = geoDataBlock.width();
738-
int extraMargin = isce3::core::SINC_HALF;
734+
// Add extra margin for interpolation
735+
int interp_margin = 5;
739736

740737
double offsetY =
741738
azimuthFirstLine / radar_grid.prf() + radar_grid.sensingStart();
@@ -753,9 +750,9 @@ inline void Geocode<T>::_interpolate(
753750
double rdrY = radarY[i * width + j] - azimuthFirstLine;
754751
double rdrX = radarX[i * width + j] - rangeFirstPixel;
755752

756-
if (rdrX < extraMargin || rdrY < extraMargin ||
757-
rdrX >= (radarBlockWidth - extraMargin) ||
758-
rdrY >= (radarBlockLength - extraMargin)) {
753+
if (rdrX < interp_margin || rdrY < interp_margin ||
754+
rdrX >= (radarBlockWidth - interp_margin) ||
755+
rdrY >= (radarBlockLength - interp_margin)) {
759756

760757
// set NaN values according to T_out, i.e. real (NaN) or complex
761758
// (NaN, NaN)

cxx/isce3/geocode/geocodeSlc.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,6 @@ void isce3::geocode::geocodeSlc(
5959
}
6060
size_t blockSize = geoBlockLength * geoGrid.width();
6161

62-
// First and last line of the data block in radar coordinates
63-
int azimuthFirstLine = radarGrid.length() - 1;
64-
int azimuthLastLine = 0;
65-
66-
// First and last pixel of the data block in radar coordinates
67-
int rangeFirstPixel = radarGrid.width() - 1;
68-
int rangeLastPixel = 0;
69-
7062
// get a DEM interpolator for a block of DEM for the current geocoded
7163
// grid
7264
isce3::geometry::DEMInterpolator demInterp = isce3::geocode::loadDEM(
@@ -78,18 +70,20 @@ void isce3::geocode::geocodeSlc(
7870
std::valarray<double> radarX(blockSize);
7971
std::valarray<double> radarY(blockSize);
8072

81-
int localAzimuthFirstLine = radarGrid.length() - 1;
82-
int localAzimuthLastLine = 0;
83-
int localRangeFirstPixel = radarGrid.width() - 1;
84-
int localRangeLastPixel = 0;
73+
// First and last line of the data block in radar coordinates
74+
int azimuthFirstLine = radarGrid.length() - 1;
75+
int azimuthLastLine = 0;
76+
int rangeFirstPixel = radarGrid.width() - 1;
77+
int rangeLastPixel = 0;
78+
// First and last pixel of the data block in radar coordinates
8579

8680
size_t geoGridWidth = geoGrid.width();
8781
// Loop over lines, samples of the output grid
88-
#pragma omp parallel for reduction(min \
89-
: localAzimuthFirstLine, \
90-
localRangeFirstPixel) \
91-
reduction(max \
92-
: localAzimuthLastLine, localRangeLastPixel)
82+
#pragma omp parallel for reduction(min \
83+
: azimuthFirstLine, \
84+
rangeFirstPixel) \
85+
reduction(max \
86+
: azimuthLastLine, rangeLastPixel)
9387
for (size_t kk = 0; kk < geoBlockLength * geoGridWidth; ++kk) {
9488

9589
size_t blockLine = kk / geoGridWidth;
@@ -98,8 +92,8 @@ void isce3::geocode::geocodeSlc(
9892
// Global line index
9993
const size_t line = lineStart + blockLine;
10094

101-
// y coordinate in the out put grid
102-
// Assuming geoGrid.startY() and geoGrid.startX() represent the top-left
95+
// y coordinate in the out put grid
96+
// Assuming geoGrid.startY() and geoGrid.startX() represent the top-left
10397
// corner of the first pixel, then 0.5 pixel shift is needed to get
10498
// to the center of each pixel
10599
double y = geoGrid.startY() + geoGrid.spacingY() * (line + 0.5);
@@ -143,27 +137,33 @@ void isce3::geocode::geocodeSlc(
143137
not nativeDoppler.contains(aztime, srange))
144138
continue;
145139

146-
localAzimuthFirstLine = std::min(
147-
localAzimuthFirstLine, static_cast<int>(std::floor(rdrY)));
148-
localAzimuthLastLine =
149-
std::max(localAzimuthLastLine,
140+
azimuthFirstLine = std::min(
141+
azimuthFirstLine, static_cast<int>(std::floor(rdrY)));
142+
azimuthLastLine =
143+
std::max(azimuthLastLine,
150144
static_cast<int>(std::ceil(rdrY) - 1));
151-
localRangeFirstPixel = std::min(localRangeFirstPixel,
145+
rangeFirstPixel = std::min(rangeFirstPixel,
152146
static_cast<int>(std::floor(rdrX)));
153-
localRangeLastPixel = std::max(
154-
localRangeLastPixel, static_cast<int>(std::ceil(rdrX) - 1));
147+
rangeLastPixel = std::max(
148+
rangeLastPixel, static_cast<int>(std::ceil(rdrX) - 1));
155149

156150
// store the adjusted X and Y indices
157151
radarX[blockLine * geoGrid.width() + pixel] = rdrX;
158152
radarY[blockLine * geoGrid.width() + pixel] = rdrY;
159153

160154
} // end loops over lines and pixel of output grid
161155

156+
// Extra margin for interpolation to avoid gaps between blocks in output
157+
int interp_margin = 5;
158+
162159
// Get min and max swath extents from among all threads
163-
azimuthFirstLine = std::min(azimuthFirstLine, localAzimuthFirstLine);
164-
azimuthLastLine = std::max(azimuthLastLine, localAzimuthLastLine);
165-
rangeFirstPixel = std::min(rangeFirstPixel, localRangeFirstPixel);
166-
rangeLastPixel = std::max(rangeLastPixel, localRangeLastPixel);
160+
azimuthFirstLine = std::max(azimuthFirstLine - interp_margin, 0);
161+
rangeFirstPixel = std::max(rangeFirstPixel - interp_margin, 0);
162+
163+
azimuthLastLine = std::min(azimuthLastLine + interp_margin,
164+
static_cast<int>(radarGrid.length() - 1));
165+
rangeLastPixel = std::min(rangeLastPixel + interp_margin,
166+
static_cast<int>(radarGrid.width() - 1));
167167

168168
if (azimuthFirstLine > azimuthLastLine ||
169169
rangeFirstPixel > rangeLastPixel)

0 commit comments

Comments
 (0)