isce3 0.25.0
Loading...
Searching...
No Matches
SearchTable.icc
1#if !defined(ISCE_UNWRAP_ICU_SEARCHTABLE_ICC)
2#error "SearchTable.icc is an implementation detail of class SearchTable."
3#endif
4
5namespace isce3::unwrap::icu
6{
7
8inline
9SearchTable::SearchTable(
10 const int maxdist,
11 const float ratioDxDy)
12{
13 // Width of square bounding circle with max radius
14 const int w = 2 * maxdist + 1;
15
16 _searchpts = new offset2_t[w*w];
17 _npts = new size_t[maxdist+1];
18
19 // Get ratio squared (must be >1).
20 float ratioSqx, ratioSqy;
21 if (ratioDxDy > 1.f)
22 {
23 ratioSqx = ratioDxDy * ratioDxDy;
24 ratioSqy = 1.f;
25 }
26 else
27 {
28 ratioSqx = 1.f;
29 ratioSqy = 1.f / (ratioDxDy * ratioDxDy);
30 }
31
32 // Calculate squared distance to each point within the square. Distance
33 // contours are elliptical depending on the relative pixel spacing in x & y.
34 auto distSq = new float[w*w];
35 for (int y = -maxdist; y <= maxdist; ++y)
36 {
37 for (int x = -maxdist; x <= maxdist; ++x)
38 {
39 size_t i = (y + maxdist) * w + (x + maxdist);
40 distSq[i] = ratioSqy * float(y*y) + ratioSqx * float(x*x);
41 }
42 }
43
44 // Init mask of visited points (all unvisited except center pixel).
45 auto visited = new bool[w*w];
46 for (size_t i = 0; i < w*w; ++i) { visited[i] = false; }
47 visited[maxdist * w + maxdist] = true;
48
49 // Populate the search table by finding points within the annulus of each
50 // successive search radius.
51 _npts[0] = 0;
52 size_t n = 0;
53 for (int d = 1; d <= maxdist; ++d)
54 {
55 float dSq = float(d*d);
56
57 for (int y = -d; y <= d; ++y)
58 {
59 for (int x = -d; x <= d; ++x)
60 {
61 size_t i = (y + maxdist) * w + (x + maxdist);
62 if (distSq[i] <= dSq && !visited[i])
63 {
64 _searchpts[n] = {x, y};
65 visited[i] = true;
66 ++n;
67 }
68 }
69 }
70
71 _npts[d] = n;
72 }
73
74 delete[] distSq;
75 delete[] visited;
76}
77
78inline
79SearchTable::~SearchTable()
80{
81 delete[] _searchpts;
82 delete[] _npts;
83}
84
85inline
86offset2_t & SearchTable::operator[](
87 const size_t pos) const
88{
89 return _searchpts[pos];
90}
91
92inline
93size_t SearchTable::numPtsInEllipse(
94 const int a) const
95{
96 return _npts[a];
97}
98
99}
100

Generated for ISCE3.0 by doxygen 1.13.2.