isce3  0.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
TopoLayers.h
1 //-*- C++ -*-
2 //-*- coding: utf-8 -*-
3 //
4 // Author: Bryan V. Riel, Joshua Cohen
5 // Copyright 2017-2018
6 
7 #pragma once
8 
9 #include "forward.h"
10 
11 #include <valarray>
12 #include <string>
13 #include <isce3/io/Raster.h>
14 
16 
17  public:
18  // Default constructor
19  TopoLayers() : _length(0.0), _width(0.0), _haveRasters(false) {}
20  // Constructors
21  TopoLayers(size_t length, size_t width) : _length(length), _width(width),
22  _haveRasters(false) {
23  _x.resize(length*width);
24  _y.resize(length*width);
25  _z.resize(length*width);
26  _inc.resize(length*width);
27  _hdg.resize(length*width);
28  _localInc.resize(length*width);
29  _localPsi.resize(length*width);
30  _sim.resize(length*width);
31  _mask.resize(length*width);
32  _crossTrack.resize(length*width);
33  }
34  // Destructor
35  ~TopoLayers() {
36  if (_haveRasters) {
37  delete _xRaster;
38  delete _yRaster;
39  delete _zRaster;
40  delete _incRaster;
41  delete _hdgRaster;
42  delete _localIncRaster;
43  delete _localPsiRaster;
44  delete _simRaster;
45  if (_maskRaster) {
46  delete _maskRaster;
47  }
48  }
49  }
50 
51  // Set new block sizes
52  void setBlockSize(size_t length, size_t width) {
53  _length = length;
54  _width = width;
55  _x.resize(length*width);
56  _y.resize(length*width);
57  _z.resize(length*width);
58  _inc.resize(length*width);
59  _hdg.resize(length*width);
60  _localInc.resize(length*width);
61  _localPsi.resize(length*width);
62  _sim.resize(length*width);
63  _mask.resize(length*width);
64  _crossTrack.resize(length*width);
65  }
66 
67  // Get sizes
68  inline size_t length() const { return _length; }
69  inline size_t width() const { return _width; }
70 
71  // Initialize rasters
72  void initRasters(const std::string & outdir, size_t width, size_t length,
73  bool computeMask = false) {
74 
75  // Initialize the standard output rasters
76  _xRaster = new isce3::io::Raster(outdir + "/x.rdr", width, length, 1,
77  GDT_Float64, "ISCE");
78  _yRaster = new isce3::io::Raster(outdir + "/y.rdr", width, length, 1,
79  GDT_Float64, "ISCE");
80  _zRaster = new isce3::io::Raster(outdir + "/z.rdr", width, length, 1,
81  GDT_Float64, "ISCE");
82  _incRaster = new isce3::io::Raster(outdir + "/inc.rdr", width, length, 1,
83  GDT_Float32, "ISCE");
84  _hdgRaster = new isce3::io::Raster(outdir + "/hdg.rdr", width, length, 1,
85  GDT_Float32, "ISCE");
86  _localIncRaster = new isce3::io::Raster(outdir + "/localInc.rdr", width, length, 1,
87  GDT_Float32, "ISCE");
88  _localPsiRaster = new isce3::io::Raster(outdir + "/localPsi.rdr", width, length, 1,
89  GDT_Float32, "ISCE");
90  _simRaster = new isce3::io::Raster(outdir + "/simamp.rdr", width, length, 1,
91  GDT_Float32, "ISCE");
92 
93  // Optional mask raster
94  if (computeMask) {
95  _maskRaster = new isce3::io::Raster(outdir + "/mask.rdr", width, length, 1,
96  GDT_Byte, "ISCE");
97  } else {
98  _maskRaster = nullptr;
99  }
100 
101  // Update sizes
102  _width = width;
103  _length = length;
104 
105  // Indicate that we have initialized rasters
106  _haveRasters = true;
107  }
108 
109  // Set rasters (plus mask raster) from externally created rasters
110  void setRasters(isce3::io::Raster & xRaster, isce3::io::Raster & yRaster,
111  isce3::io::Raster & zRaster, isce3::io::Raster & incRaster,
112  isce3::io::Raster & hdgRaster, isce3::io::Raster & localIncRaster,
113  isce3::io::Raster & localPsiRaster, isce3::io::Raster & simRaster) {
114  _xRaster = &xRaster;
115  _yRaster = &yRaster;
116  _zRaster = &zRaster;
117  _incRaster = &incRaster;
118  _hdgRaster = &hdgRaster;
119  _localIncRaster = &localIncRaster;
120  _localPsiRaster = &localPsiRaster;
121  _simRaster = &simRaster;
122  }
123 
124  // Set rasters (plus mask raster) from externally created rasters
125  void setRasters(isce3::io::Raster & xRaster, isce3::io::Raster & yRaster,
126  isce3::io::Raster & zRaster, isce3::io::Raster & incRaster,
127  isce3::io::Raster & hdgRaster, isce3::io::Raster & localIncRaster,
128  isce3::io::Raster & localPsiRaster, isce3::io::Raster & simRaster,
129  isce3::io::Raster & maskRaster) {
130  _xRaster = &xRaster;
131  _yRaster = &yRaster;
132  _zRaster = &zRaster;
133  _incRaster = &incRaster;
134  _hdgRaster = &hdgRaster;
135  _localIncRaster = &localIncRaster;
136  _localPsiRaster = &localPsiRaster;
137  _simRaster = &simRaster;
138  _maskRaster = &maskRaster;
139  }
140 
141  // Get array references
142  std::valarray<double> & x() { return _x; }
143  std::valarray<double> & y() { return _y; }
144  std::valarray<double> & z() { return _z; }
145  std::valarray<float> & inc() { return _inc; }
146  std::valarray<float> & hdg() { return _hdg; }
147  std::valarray<float> & localInc() { return _localInc; }
148  std::valarray<float> & localPsi() { return _localPsi; }
149  std::valarray<float> & sim() { return _sim; }
150  std::valarray<short> & mask() { return _mask; }
151  std::valarray<double> & crossTrack() { return _crossTrack; }
152 
153  // Set values for a single index
154  void x(size_t row, size_t col, double value) {
155  _x[row*_width+col] = value;
156  }
157 
158  void y(size_t row, size_t col, double value) {
159  _y[row*_width + col] = value;
160  }
161 
162  void z(size_t row, size_t col, double value) {
163  _z[row*_width + col] = value;
164  }
165 
166  void inc(size_t row, size_t col, float value) {
167  _inc[row*_width + col] = value;
168  }
169 
170  void hdg(size_t row, size_t col, float value) {
171  _hdg[row*_width + col] = value;
172  }
173 
174  void localInc(size_t row, size_t col, float value) {
175  _localInc[row*_width + col] = value;
176  }
177 
178  void localPsi(size_t row, size_t col, float value) {
179  _localPsi[row*_width + col] = value;
180  }
181 
182  void sim(size_t row, size_t col, float value) {
183  _sim[row*_width + col] = value;
184  }
185 
186  void mask(size_t row, size_t col, short value) {
187  _mask[row*_width + col] = value;
188  }
189 
190  void crossTrack(size_t row, size_t col, double value) {
191  _crossTrack[row*_width + col] = value;
192  }
193 
194  // Get values for a single index
195  double x(size_t row, size_t col) const {
196  return _x[row*_width+col];
197  }
198 
199  double y(size_t row, size_t col) const {
200  return _y[row*_width + col];
201  }
202 
203  double z(size_t row, size_t col) const {
204  return _z[row*_width + col];
205  }
206 
207  float inc(size_t row, size_t col) const {
208  return _inc[row*_width + col];
209  }
210 
211  float hdg(size_t row, size_t col) const {
212  return _hdg[row*_width + col];
213  }
214 
215  float localInc(size_t row, size_t col) const {
216  return _localInc[row*_width + col];
217  }
218 
219  float localPsi(size_t row, size_t col) const {
220  return _localPsi[row*_width + col];
221  }
222 
223  float sim(size_t row, size_t col) const {
224  return _sim[row*_width + col];
225  }
226 
227  short mask(size_t row, size_t col) const {
228  return _mask[row*_width + col];
229  }
230 
231  double crossTrack(size_t row, size_t col) const {
232  return _crossTrack[row*_width + col];
233  }
234 
235  // 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 
250  private:
251  // The valarrays for the actual data
252  std::valarray<double> _x;
253  std::valarray<double> _y;
254  std::valarray<double> _z;
255  std::valarray<float> _inc;
256  std::valarray<float> _hdg;
257  std::valarray<float> _localInc;
258  std::valarray<float> _localPsi;
259  std::valarray<float> _sim;
260  std::valarray<short> _mask;
261  std::valarray<double> _crossTrack; // internal usage only; not saved to Raster
262 
263  // Raster pointers for each layer
264  isce3::io::Raster * _xRaster;
265  isce3::io::Raster * _yRaster;
266  isce3::io::Raster * _zRaster;
267  isce3::io::Raster * _incRaster;
268  isce3::io::Raster * _hdgRaster;
269  isce3::io::Raster * _localIncRaster;
270  isce3::io::Raster * _localPsiRaster;
271  isce3::io::Raster * _simRaster;
272  isce3::io::Raster * _maskRaster;
273 
274  // Dimensions
275  size_t _length, _width;
276 
277  // Directory for placing rasters
278  std::string _topodir;
279  bool _haveRasters;
280 };
void setBlock(T *buffer, size_t xidx, size_t yidx, size_t iowidth, size_t iolength, size_t band=1)
Write block of data to given band from buffer, vector, or valarray.
Definition: Raster.icc:424
Definition: TopoLayers.h:15
Data structure meant to handle Raster I/O operations.
Definition: Raster.h:34

Generated for ISCE3.0 by doxygen 1.8.5.