[a34150]: contrib / brl / bbas / volm / pro / processes / volm_create_satellite_site_process.cxx Maximize Restore History

Download this file

volm_create_satellite_site_process.cxx    361 lines (307 with data), 11.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
//This is brl/bbas/volm/pro/processes/volm_create_satellite_site_process.cxx
//:
// \file
#include <bprb/bprb_func_process.h>
#include <bprb/bprb_parameters.h>
#include <vcl_string.h>
#include <vcl_iostream.h>
#include <vcl_cstdio.h> // for std::FILE and std::fopen()
#include <brdb/brdb_value.h>
#include <volm/volm_satellite_resources.h>
#include <volm/volm_satellite_resources_sptr.h>
#include <vgl/vgl_polygon.h>
#include <bkml/bkml_parser.h>
//: sets input and output types
bool volm_create_satellite_resources_process_cons(bprb_func_process& pro)
{
//inputs
vcl_vector<vcl_string> input_types_(2);
input_types_[0] = "vcl_string"; // polygon file (kml) of ROI
input_types_[1] = "float"; // polygon file (kml) of ROI
if (!pro.set_input_types(input_types_))
return false;
//output
vcl_vector<vcl_string> output_types_(1);
output_types_[0] = "volm_satellite_resources_sptr";
return pro.set_output_types(output_types_);
}
bool volm_create_satellite_resources_process(bprb_func_process& pro)
{
//check number of inputs
if (!pro.verify_inputs())
{
vcl_cout << pro.name() << " invalid inputs" << vcl_endl;
return false;
}
//get the inputs
vcl_string poly_file = pro.get_input<vcl_string>(0);
float leaf_size = pro.get_input<float>(1);
// find the bbox of the polygon
vgl_polygon<double> poly = bkml_parser::parse_polygon(poly_file);
vcl_cout << "outer poly has: " << poly[0].size() << " points " << vcl_endl;
// find the bbox of ROI from its polygon
vgl_box_2d<double> bbox;
for (unsigned i = 0; i < poly[0].size(); i++) {
bbox.add(poly[0][i]);
}
vcl_cout << "bbox of ROI: " << bbox << vcl_endl;
volm_satellite_resources_sptr res = new volm_satellite_resources(bbox, leaf_size);
pro.set_output_val<volm_satellite_resources_sptr>(0, res);
return true;
}
bool volm_save_satellite_resources_process_cons(bprb_func_process& pro)
{
//inputs
vcl_vector<vcl_string> input_types_(2);
input_types_[0] = "volm_satellite_resources_sptr";
input_types_[1] = "vcl_string"; // output file to save as binar
if (!pro.set_input_types(input_types_))
return false;
//output
vcl_vector<vcl_string> output_types_(0);
return pro.set_output_types(output_types_);
}
bool volm_save_satellite_resources_process(bprb_func_process& pro)
{
//check number of inputs
if (!pro.verify_inputs())
{
vcl_cout << pro.name() << " invalid inputs" << vcl_endl;
return false;
}
//get the inputs
volm_satellite_resources_sptr res = pro.get_input<volm_satellite_resources_sptr>(0);
vcl_string out_file = pro.get_input<vcl_string>(1);
vsl_b_ofstream ofs(out_file);
res->b_write(ofs);
ofs.close();
pro.set_output_val<volm_satellite_resources_sptr>(0, res);
return true;
}
bool volm_load_satellite_resources_process_cons(bprb_func_process& pro)
{
//inputs
vcl_vector<vcl_string> input_types_(1);
input_types_[0] = "vcl_string";
if (!pro.set_input_types(input_types_))
return false;
//output
vcl_vector<vcl_string> output_types_(1);
output_types_[0] = "volm_satellite_resources_sptr";
return pro.set_output_types(output_types_);
}
bool volm_load_satellite_resources_process(bprb_func_process& pro)
{
//check number of inputs
if (!pro.verify_inputs())
{
vcl_cout << pro.name() << " invalid inputs" << vcl_endl;
return false;
}
//get the inputs
vcl_string res_file = pro.get_input<vcl_string>(0);
volm_satellite_resources_sptr res = new volm_satellite_resources();
vsl_b_ifstream is(res_file);
res->b_read(is);
is.close();
vcl_cout << "there are " << res->resources_size() << " resources in the file!\n";
pro.set_output_val<volm_satellite_resources_sptr>(0, res);
return true;
}
bool volm_query_satellite_resources_process_cons(bprb_func_process& pro)
{
//inputs
vcl_vector<vcl_string> input_types_(9);
input_types_[0] = "volm_satellite_resources_sptr";
input_types_[1] = "double"; // lower left lon
input_types_[2] = "double"; // lower left lat
input_types_[3] = "double"; // upper right lon
input_types_[4] = "double"; // upper right lat
input_types_[5] = "vcl_string"; // output file to print the list
input_types_[6] = "vcl_string"; // the band: PAN or MULTI
input_types_[7] = "bool"; // if TRUE, pick seed images randomly with a certain order of satellites
input_types_[8] = "int"; // number of seed images to pick, if not enough then creates from all available
if (!pro.set_input_types(input_types_))
return false;
//output
vcl_vector<vcl_string> output_types_(1);
output_types_[0] = "unsigned"; // return number of resources that intersect this region
return pro.set_output_types(output_types_);
}
bool volm_query_satellite_resources_process(bprb_func_process& pro)
{
//check number of inputs
if (!pro.verify_inputs())
{
vcl_cout << pro.name() << " invalid inputs" << vcl_endl;
return false;
}
//get the inputs
volm_satellite_resources_sptr res = pro.get_input<volm_satellite_resources_sptr>(0);
double lower_left_lon = pro.get_input<double>(1);
double lower_left_lat = pro.get_input<double>(2);
double upper_right_lon = pro.get_input<double>(3);
double upper_right_lat = pro.get_input<double>(4);
vcl_string out_file = pro.get_input<vcl_string>(5);
vcl_string band = pro.get_input<vcl_string>(6);
bool pick_seed = pro.get_input<bool>(7);
int n_seeds = pro.get_input<int>(8);
unsigned cnt; bool out = false;
if (!pick_seed) {
out = res->query_print_to_file(lower_left_lon, lower_left_lat, upper_right_lon, upper_right_lat, cnt, out_file, band);
pro.set_output_val<unsigned>(0, cnt);
} else {
out = res->query_seeds_print_to_file(lower_left_lon, lower_left_lat, upper_right_lon, upper_right_lat, n_seeds, cnt, out_file, band);
pro.set_output_val<unsigned>(0, cnt);
}
return out;
}
//: sets input and output types
bool volm_add_satellite_resources_process_cons(bprb_func_process& pro)
{
//inputs
vcl_vector<vcl_string> input_types_(2);
input_types_[0] = "volm_satellite_resources_sptr";
input_types_[1] = "vcl_string"; // folder -- will be traversed recursively to find NITF files and add to the resources
if (!pro.set_input_types(input_types_))
return false;
//output
vcl_vector<vcl_string> output_types_(0);
return pro.set_output_types(output_types_);
}
bool volm_add_satellite_resources_process(bprb_func_process& pro)
{
//check number of inputs
if (!pro.verify_inputs())
{
vcl_cout << pro.name() << " invalid inputs" << vcl_endl;
return false;
}
//get the inputs
volm_satellite_resources_sptr res = pro.get_input<volm_satellite_resources_sptr>(0);
vcl_string folder = pro.get_input<vcl_string>(1);
res->add_path(folder);
vcl_cout << " AFTER addition, there are " << res->resources_size() << " resources in the file!\n";
return true;
}
bool volm_pick_nadir_resource_process_cons(bprb_func_process& pro)
{
//inputs
vcl_vector<vcl_string> input_types_(7);
input_types_[0] = "volm_satellite_resources_sptr";
input_types_[1] = "double"; // lower left lon
input_types_[2] = "double"; // lower left lat
input_types_[3] = "double"; // upper right lon
input_types_[4] = "double"; // upper right lat
input_types_[5] = "vcl_string"; // the band: PAN or MULTI
input_types_[6] = "vcl_string"; // satelllite name
if (!pro.set_input_types(input_types_))
return false;
//output
vcl_vector<vcl_string> output_types_(1);
output_types_[0] = "vcl_string"; // full path of the satellite image
return pro.set_output_types(output_types_);
}
bool volm_pick_nadir_resource_process(bprb_func_process& pro)
{
//check number of inputs
if (!pro.verify_inputs())
{
vcl_cout << pro.name() << " invalid inputs" << vcl_endl;
return false;
}
//get the inputs
volm_satellite_resources_sptr res = pro.get_input<volm_satellite_resources_sptr>(0);
double lower_left_lon = pro.get_input<double>(1);
double lower_left_lat = pro.get_input<double>(2);
double upper_right_lon = pro.get_input<double>(3);
double upper_right_lat = pro.get_input<double>(4);
vcl_string band = pro.get_input<vcl_string>(5);
vcl_string sat_name = pro.get_input<vcl_string>(6);
vcl_vector<unsigned> ids;
res->query(lower_left_lon, lower_left_lat, upper_right_lon, upper_right_lat, band, ids);
double largest_view_angle = 0.0;
unsigned id = 0;
for (unsigned i = 0; i < ids.size(); i++) {
if (res->resources_[ids[i]].meta_->satellite_name_.compare(sat_name) == 0) {
vcl_cout << "res: " << res->resources_[ids[i]].name_ << " view azimuth: " << res->resources_[ids[i]].meta_->view_azimuth_ << " view elev: " << res->resources_[ids[i]].meta_->view_elevation_ << '\n';
if (largest_view_angle < res->resources_[ids[i]].meta_->view_elevation_) {
largest_view_angle = res->resources_[ids[i]].meta_->view_elevation_;
id = ids[i];
}
}
}
vcl_cout << "picked: " << res->resources_[id].full_path_ << vcl_endl;
pro.set_output_val<vcl_string>(0, res->resources_[id].full_path_);
return true;
}
// find the PAN counterpart if given a multi band image, and vice versa
bool volm_get_full_path_process_cons(bprb_func_process& pro)
{
//inputs
vcl_vector<vcl_string> input_types_(2);
input_types_[0] = "volm_satellite_resources_sptr";
input_types_[1] = "vcl_string"; // satelllite img name
if (!pro.set_input_types(input_types_))
return false;
//output
vcl_vector<vcl_string> output_types_(1);
output_types_[0] = "vcl_string"; // full path of the satellite whose name is passed
return pro.set_output_types(output_types_);
}
bool volm_get_full_path_process(bprb_func_process& pro)
{
//check number of inputs
if (!pro.verify_inputs())
{
vcl_cout << pro.name() << " invalid inputs" << vcl_endl;
return false;
}
//get the inputs
volm_satellite_resources_sptr res = pro.get_input<volm_satellite_resources_sptr>(0);
vcl_string name = pro.get_input<vcl_string>(1);
vcl_pair<vcl_string, vcl_string> full = res->full_path(name);
pro.set_output_val<vcl_string>(0, full.first);
return true;
}
// find the PAN counterpart if given a multi band image, and vice versa
bool volm_find_res_pair_process_cons(bprb_func_process& pro)
{
//inputs
vcl_vector<vcl_string> input_types_(2);
input_types_[0] = "volm_satellite_resources_sptr";
input_types_[1] = "vcl_string"; // satelllite img name // only the name, don't need the full path
if (!pro.set_input_types(input_types_))
return false;
//output
vcl_vector<vcl_string> output_types_(3);
output_types_[0] = "vcl_string"; // full path of the satellite whose name is passed
output_types_[1] = "vcl_string"; // name of the pair satellite image, process returns false if not found
output_types_[2] = "vcl_string"; // full path of the pair satellite image, process returns false if not found
return pro.set_output_types(output_types_);
}
bool volm_find_res_pair_process(bprb_func_process& pro)
{
//check number of inputs
if (!pro.verify_inputs())
{
vcl_cout << pro.name() << " invalid inputs" << vcl_endl;
return false;
}
//get the inputs
volm_satellite_resources_sptr res = pro.get_input<volm_satellite_resources_sptr>(0);
vcl_string name = pro.get_input<vcl_string>(1);
vcl_pair<vcl_string, vcl_string> full = res->full_path(name);
vcl_string pair_name = res->find_pair(name);
if (pair_name.compare("") == 0) {
pro.set_output_val<vcl_string>(0, "");
pro.set_output_val<vcl_string>(1, "");
pro.set_output_val<vcl_string>(2, "");
return false;
}
vcl_pair<vcl_string, vcl_string> pp = res->full_path(pair_name);
pro.set_output_val<vcl_string>(0, full.first);
pro.set_output_val<vcl_string>(1, pair_name);
pro.set_output_val<vcl_string>(2, pp.first);
return true;
}