1 // This is brl/bseg/bstm_multi/pro/processes/bstm_multi_add_block_process.cxx
2 
3 //:
4 // \file bstm_multi_add_block_process.cxx
5 // \brief  A process for adding a block to a scene. Caller specifies all
6 // metadata, including subdivisions. Block is only added if there is no existing
7 // block with the same ID.
8 //
9 // \author Raphael Kargon
10 // \date 04 Aug 2017
11 
12 #include <iostream>
13 #include <map>
14 #include <string>
15 #include <utility>
16 #include <vector>
17 #ifdef _MSC_VER
18 #  include "vcl_msvc_warnings.h"
19 #endif
20 #include "vgl/vgl_box_3d.h"
21 
22 #include <bprb/bprb_func_process.h>
23 #include <bstm_multi/bstm_multi_block.h>
24 #include <bstm_multi/bstm_multi_typedefs.h>
25 #include <bstm_multi/space_time_scene.h>
26 
27 namespace {
28 constexpr unsigned n_inputs_ = 21;
29 constexpr unsigned n_outputs_ = 0;
30 }
31 
bstm_add_block_process_cons(bprb_func_process & pro)32 bool bstm_add_block_process_cons(bprb_func_process &pro) {
33   std::vector<std::string> input_types_(::n_inputs_);
34   int i = 0;
35   input_types_[i++] = "bstm_multi_scene_sptr";
36 
37   input_types_[i++] = "int"; // index i
38   input_types_[i++] = "int"; // index j
39   input_types_[i++] = "int"; // index k
40   input_types_[i++] = "int"; // index t
41 
42   input_types_[i++] = "double"; // min i
43   input_types_[i++] = "double"; // min j
44   input_types_[i++] = "double"; // min k
45   input_types_[i++] = "double"; // min t
46 
47   input_types_[i++] = "double"; // max i
48   input_types_[i++] = "double"; // max j
49   input_types_[i++] = "double"; // max k
50   input_types_[i++] = "double"; // max t
51 
52   input_types_[i++] = "vcl_string"; // subdivisions as comma-separated set of
53                                     // 'space' or 'time' values.
54   input_types_[i++] = "float";      // max_mb
55   input_types_[i++] = "float";      // p_init
56   input_types_[i++] = "unsigned";   // init tree depth
57   input_types_[i++] = "unsigned";   // init time tree depth
58 
59   std::vector<std::string> output_types_(::n_outputs_);
60 
61   return pro.set_input_types(input_types_) &&
62          pro.set_output_types(output_types_);
63 }
64 
bstm_add_block_process(bprb_func_process & pro)65 bool bstm_add_block_process(bprb_func_process &pro) {
66   if (pro.n_inputs() < ::n_inputs_) {
67     std::cout << pro.name() << ": The input number should be " << ::n_inputs_
68              << std::endl;
69     return false;
70   }
71   // get the inputs
72   unsigned i = 0;
73   bstm_multi_scene_sptr scene = pro.get_input<bstm_multi_scene_sptr>(i++);
74   int index_i = pro.get_input<int>(i++);
75   int index_j = pro.get_input<int>(i++);
76   int index_k = pro.get_input<int>(i++);
77   int index_t = pro.get_input<int>(i++);
78 
79   // Scene bounds
80   auto min_x = pro.get_input<double>(i++);
81   auto min_y = pro.get_input<double>(i++);
82   auto min_z = pro.get_input<double>(i++);
83   auto min_t = pro.get_input<double>(i++);
84 
85   auto max_x = pro.get_input<double>(i++);
86   auto max_y = pro.get_input<double>(i++);
87   auto max_z = pro.get_input<double>(i++);
88   auto max_t = pro.get_input<double>(i++);
89 
90   std::string subdivisions_str = pro.get_input<std::string>(i++);
91   std::vector<space_time_enum> subdivisions =
92       parse_subdivisions(subdivisions_str);
93 
94   auto max_data_size = pro.get_input<float>(i++);
95   auto p_init = pro.get_input<float>(i++);
96 
97   bstm_block_id id(index_i, index_j, index_k, index_t);
98   std::map<bstm_block_id, bstm_multi_block_metadata> &blks = scene->blocks();
99   if (blks.count(id)) {
100     std::cout << "block already exists" << std::endl;
101     return false;
102   }
103   blks[id] = bstm_multi_block_metadata(
104       id,
105       vgl_box_3d<double>(min_x, min_y, min_z, max_x, max_y, max_z),
106       std::pair<double, double>(min_t, max_t),
107       max_data_size,
108       p_init,
109       subdivisions,
110       2);
111 
112   return true;
113 }
114