Skip to content

Commit c2d3fe3

Browse files
Liang YuGitHub Enterprise
authored andcommitted
write TopoLayers rasters in parallel (#784)
* write TopoLayers rasters in parallel
1 parent 74899e6 commit c2d3fe3

File tree

3 files changed

+53
-37
lines changed

3 files changed

+53
-37
lines changed

cxx/isce3/Sources.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ geocode/GeocodePolygon.cpp
4747
geometry/geometry.cpp
4848
geometry/RTC.cpp
4949
geometry/Topo.cpp
50+
geometry/TopoLayers.cpp
5051
geometry/metadataCubes.cpp
5152
image/ResampSlc.cpp
5253
io/gdal/Dataset.cpp

cxx/isce3/geometry/TopoLayers.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "TopoLayers.h"
2+
3+
#include <iterator>
4+
#include <variant>
5+
#include <vector>
6+
7+
namespace isce3::geometry {
8+
9+
void TopoLayers::writeData(size_t xidx, size_t yidx)
10+
{
11+
std::vector<std::variant<double *, float *, short *>>
12+
valarrays{&_x[0], &_y[0], &_z[0], &_inc[0], &_hdg[0], &_localInc[0],
13+
&_localPsi[0], &_sim[0], &_mask[0]};
14+
15+
std::vector<isce3::io::Raster *> rasters{_xRaster, _yRaster, _zRaster,
16+
_incRaster, _hdgRaster, _localIncRaster, _localPsiRaster,
17+
_simRaster, _maskRaster};
18+
19+
#pragma omp parallel for
20+
for (auto i = 0; i < valarrays.size(); ++i)
21+
{
22+
if (rasters[i])
23+
{
24+
std::visit([&](const auto& ptr) {
25+
rasters[i]->setBlock(ptr, xidx, yidx, _width, _length);
26+
}, valarrays[i]);
27+
}
28+
}
29+
}
30+
31+
}

cxx/isce3/geometry/TopoLayers.h

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
//-*- C++ -*-
2-
//-*- coding: utf-8 -*-
3-
//
4-
// Author: Bryan V. Riel, Joshua Cohen
5-
// Copyright 2017-2018
6-
71
#pragma once
82

93
#include "forward.h"
104

115
#include <valarray>
126
#include <string>
7+
138
#include <isce3/io/Raster.h>
149

1510
class isce3::geometry::TopoLayers {
@@ -89,9 +84,9 @@ class isce3::geometry::TopoLayers {
8984
GDT_Float32, "ISCE");
9085
_simRaster = new isce3::io::Raster(outdir + "/simamp.rdr", width, length, 1,
9186
GDT_Float32, "ISCE");
92-
87+
9388
// Optional mask raster
94-
if (computeMask) {
89+
if (computeMask) {
9590
_maskRaster = new isce3::io::Raster(outdir + "/mask.rdr", width, length, 1,
9691
GDT_Byte, "ISCE");
9792
} else {
@@ -149,36 +144,36 @@ class isce3::geometry::TopoLayers {
149144
std::valarray<float> & sim() { return _sim; }
150145
std::valarray<short> & mask() { return _mask; }
151146
std::valarray<double> & crossTrack() { return _crossTrack; }
152-
147+
153148
// Set values for a single index
154149
void x(size_t row, size_t col, double value) {
155150
_x[row*_width+col] = value;
156151
}
157-
152+
158153
void y(size_t row, size_t col, double value) {
159154
_y[row*_width + col] = value;
160155
}
161-
156+
162157
void z(size_t row, size_t col, double value) {
163158
_z[row*_width + col] = value;
164159
}
165-
160+
166161
void inc(size_t row, size_t col, float value) {
167162
_inc[row*_width + col] = value;
168163
}
169-
164+
170165
void hdg(size_t row, size_t col, float value) {
171166
_hdg[row*_width + col] = value;
172167
}
173-
168+
174169
void localInc(size_t row, size_t col, float value) {
175170
_localInc[row*_width + col] = value;
176171
}
177-
172+
178173
void localPsi(size_t row, size_t col, float value) {
179174
_localPsi[row*_width + col] = value;
180175
}
181-
176+
182177
void sim(size_t row, size_t col, float value) {
183178
_sim[row*_width + col] = value;
184179
}
@@ -195,31 +190,31 @@ class isce3::geometry::TopoLayers {
195190
double x(size_t row, size_t col) const {
196191
return _x[row*_width+col];
197192
}
198-
193+
199194
double y(size_t row, size_t col) const {
200195
return _y[row*_width + col];
201196
}
202-
197+
203198
double z(size_t row, size_t col) const {
204199
return _z[row*_width + col];
205200
}
206-
201+
207202
float inc(size_t row, size_t col) const {
208203
return _inc[row*_width + col];
209204
}
210-
205+
211206
float hdg(size_t row, size_t col) const {
212207
return _hdg[row*_width + col];
213208
}
214-
209+
215210
float localInc(size_t row, size_t col) const {
216211
return _localInc[row*_width + col];
217212
}
218-
213+
219214
float localPsi(size_t row, size_t col) const {
220215
return _localPsi[row*_width + col];
221216
}
222-
217+
223218
float sim(size_t row, size_t col) const {
224219
return _sim[row*_width + col];
225220
}
@@ -233,20 +228,8 @@ class isce3::geometry::TopoLayers {
233228
}
234229

235230
// Write data with rasters
236-
void writeData(size_t xidx, size_t yidx) {
237-
_xRaster->setBlock(_x, xidx, yidx, _width, _length);
238-
_yRaster->setBlock(_y, xidx, yidx, _width, _length);
239-
_zRaster->setBlock(_z, xidx, yidx, _width, _length);
240-
_incRaster->setBlock(_inc, xidx, yidx, _width, _length);
241-
_hdgRaster->setBlock(_hdg, xidx, yidx, _width, _length);
242-
_localIncRaster->setBlock(_localInc, xidx, yidx, _width, _length);
243-
_localPsiRaster->setBlock(_localPsi, xidx, yidx, _width, _length);
244-
_simRaster->setBlock(_sim, xidx, yidx, _width, _length);
245-
if (_maskRaster) {
246-
_maskRaster->setBlock(_mask, xidx, yidx, _width, _length);
247-
}
248-
}
249-
231+
void writeData(size_t xidx, size_t yidx);
232+
250233
private:
251234
// The valarrays for the actual data
252235
std::valarray<double> _x;
@@ -277,4 +260,5 @@ class isce3::geometry::TopoLayers {
277260
// Directory for placing rasters
278261
std::string _topodir;
279262
bool _haveRasters;
263+
280264
};

0 commit comments

Comments
 (0)