Skip to content

Commit 65cc0e4

Browse files
gshiromaGitHub Enterprise
authored andcommitted
add test for self-intersecting area elements and add code to handle self intersection (divide polygon into two triangles). (#878)
1 parent 92c2431 commit 65cc0e4

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

cxx/isce3/geocode/GeocodeCov.cpp

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2617,6 +2617,62 @@ void Geocode<T>::_runBlock(
26172617
isce3::geometry::areaProjIntegrateSegment(y10_cut, y00_cut, x10_cut,
26182618
x00_cut, size_y, size_x, w_arr, w_total, plane_orientation);
26192619

2620+
bool flag_self_intersecting_area_element = false;
2621+
2622+
// test for self-intersection
2623+
for (int yy = 0; yy < size_y; ++yy) {
2624+
for (int xx = 0; xx < size_x; ++xx) {
2625+
double w = w_arr(yy, xx);
2626+
if (w * w_total < 0 && abs(w) > 0.00001) {
2627+
flag_self_intersecting_area_element = true;
2628+
break;
2629+
}
2630+
}
2631+
if (flag_self_intersecting_area_element) {
2632+
break;
2633+
}
2634+
}
2635+
2636+
if (flag_self_intersecting_area_element) {
2637+
/*
2638+
If self-intersecting, divide area element (geogrid pixel) into
2639+
two triangles and integrate them separately.
2640+
*/
2641+
isce3::core::Matrix<double> w_arr_1(size_y, size_x);
2642+
w_arr_1.fill(0);
2643+
double w_total_1 = 0;
2644+
isce3::geometry::areaProjIntegrateSegment(y00_cut, y01_cut, x00_cut,
2645+
x01_cut, size_y, size_x, w_arr_1, w_total_1, plane_orientation);
2646+
isce3::geometry::areaProjIntegrateSegment(y01_cut, y11_cut, x01_cut,
2647+
x11_cut, size_y, size_x, w_arr_1, w_total_1, plane_orientation);
2648+
isce3::geometry::areaProjIntegrateSegment(y11_cut, y00_cut, x11_cut,
2649+
x00_cut, size_y, size_x, w_arr_1, w_total_1, plane_orientation);
2650+
2651+
isce3::core::Matrix<double> w_arr_2(size_y, size_x);
2652+
w_arr_2.fill(0);
2653+
double w_total_2 = 0;
2654+
isce3::geometry::areaProjIntegrateSegment(y00_cut, y11_cut, x00_cut,
2655+
x11_cut, size_y, size_x, w_arr_2, w_total_2, plane_orientation);
2656+
isce3::geometry::areaProjIntegrateSegment(y11_cut, y10_cut, x11_cut,
2657+
x10_cut, size_y, size_x, w_arr_2, w_total_2, plane_orientation);
2658+
isce3::geometry::areaProjIntegrateSegment(y10_cut, y00_cut, x10_cut,
2659+
x00_cut, size_y, size_x, w_arr_2, w_total_2, plane_orientation);
2660+
2661+
w_total = 0;
2662+
/*
2663+
The new weight array `w_arr` is the sum of the absolute values of both
2664+
triangles weighted arrays `w_arr_1` and `w_arr_2`. The integrated
2665+
total `w_total` is updated accordingly.
2666+
*/
2667+
for (int yy = 0; yy < size_y; ++yy) {
2668+
for (int xx = 0; xx < size_x; ++xx) {
2669+
w_arr(yy, xx) = std::min(
2670+
abs(w_arr_1(yy, xx)) + abs(w_arr_2(yy, xx)), 1.0);
2671+
w_total += w_arr(yy, xx);
2672+
}
2673+
}
2674+
}
2675+
26202676
double nlooks = 0;
26212677
float area_total = 0;
26222678
std::vector<T_out> cumulative_sum(nbands, 0);
@@ -2630,7 +2686,7 @@ void Geocode<T>::_runBlock(
26302686
double w = w_arr(yy, xx);
26312687
int y = yy + y_min;
26322688
int x = xx + x_min;
2633-
if (w == 0 || w * w_total < 0)
2689+
if (w == 0)
26342690
continue;
26352691
else if (y - offset_y < 0 || x - offset_x < 0 ||
26362692
y >= ybound || x >= xbound) {

0 commit comments

Comments
 (0)