1 // This is brl/bseg/bstm/pro/processes/bstm_describe_scene_process.cxx
2 //:
3 // \file
4 // \brief A process for descibing a Multi-BSTM scene. Returns data path,
5 // appearance model, and the resolution of inidiviual voxels (for the first
6 // block in the scene -- if the scene has blocks with different resolutions this
7 // will not be reflected)
8 //
9 // \author Raphael Kargon
10 // \date 04 Aug 2017
11
12 #include <iostream>
13 #include <string>
14 #include <vector>
15 #ifdef _MSC_VER
16 # include "vcl_msvc_warnings.h"
17 #endif
18
19 #include <bprb/bprb_func_process.h>
20 #include <bstm/bstm_data_traits.h>
21 #include <bstm/bstm_util.h>
22 #include <bstm_multi/bstm_multi_typedefs.h>
23 #include <bstm_multi/space_time_scene.h>
24
25 namespace bstm_multi_describe_scene_process_globals {
26 constexpr unsigned n_inputs_ = 1;
27 constexpr unsigned n_outputs_ = 3;
28 }
29
bstm_multi_describe_scene_process_cons(bprb_func_process & pro)30 bool bstm_multi_describe_scene_process_cons(bprb_func_process &pro) {
31 using namespace bstm_multi_describe_scene_process_globals;
32
33 // process takes 1 input
34 std::vector<std::string> input_types_(n_inputs_);
35 input_types_[0] = "bstm_multi_scene_sptr";
36
37 // process has 2 outputs:
38 std::vector<std::string> output_types_(n_outputs_);
39 output_types_[0] = "vcl_string"; // path to model data
40 output_types_[1] = "vcl_string"; // appearance model type
41 output_types_[2] = "double"; // voxel x size of first block
42 output_types_[3] = "double"; // voxel y size of first block
43 output_types_[4] = "double"; // voxel z size of first block
44 output_types_[5] = "double"; // voxel t size of first block
45 return pro.set_input_types(input_types_) &&
46 pro.set_output_types(output_types_);
47 }
48
bstm_multi_describe_scene_process(bprb_func_process & pro)49 bool bstm_multi_describe_scene_process(bprb_func_process &pro) {
50 using namespace bstm_multi_describe_scene_process_globals;
51
52 if (pro.n_inputs() < n_inputs_) {
53 std::cout << pro.name() << ": The input number should be " << n_inputs_
54 << std::endl;
55 return false;
56 }
57 // get the inputs
58 bstm_multi_scene_sptr scene = pro.get_input<bstm_multi_scene_sptr>(0);
59 if (!scene) {
60 std::cout << " null scene in bstm_multi_describe_scene_process\n";
61 return false;
62 }
63 // std::cout << *scene;
64
65 // verifies that a scene has a valid appearance, spits out data type and
66 // appearance type size
67 // NOTE: some data traits are commented out because they don't work (yet) on
68 // BSTM
69 std::vector<std::string> valid_types;
70 valid_types.push_back(bstm_data_traits<BSTM_MOG3_GREY>::prefix());
71 // valid_types.push_back(bstm_data_traits<BSTM_MOG3_GREY_16>::prefix());
72 valid_types.push_back(bstm_data_traits<BSTM_GAUSS_RGB>::prefix());
73 valid_types.push_back(bstm_data_traits<BSTM_MOG6_VIEW_COMPACT>::prefix());
74 valid_types.push_back(bstm_data_traits<BSTM_MOG6_VIEW>::prefix());
75 valid_types.push_back(bstm_data_traits<BSTM_GAUSS_RGB_VIEW>::prefix());
76 // valid_types.push_back(bstm_data_traits<BSTM_GAUSS_UV_VIEW>::prefix());
77 std::string data_type;
78 int appTypeSize;
79 bstm_util::verify_appearance(
80 scene->appearances(), valid_types, data_type, appTypeSize);
81 std::cout << "DATA_TYPE:" << data_type << std::endl;
82
83 vgl_vector_3d<double> voxel_sizes;
84 double voxel_time_range = 0;
85
86 // obtain the resolution of first block we run into
87 const std::map<bstm_block_id, bstm_multi_block_metadata> &blks =
88 scene->blocks();
89 if (blks.begin() != blks.end()) {
90 const bstm_multi_block_metadata &blk = blks.begin()->second;
91
92 vgl_vector_3d<double> voxel_sizes =
93 blk.bbox().max_point() - blk.bbox().min_point();
94 double voxel_time_range = blk.bbox_t().first - blk.bbox_t().second;
95
96 for (auto ste : blk.subdivisions_) {
97 switch (ste) {
98 case STE_SPACE:
99 voxel_sizes /= 8.0;
100 break;
101 case STE_TIME:;
102 voxel_time_range /= 32.0;
103 break;
104 }
105 }
106 } else {
107 // if scene has no blocks, no point in getting resolution
108 std::cout << "Scene has no blocks, resolution will be returned as zero."
109 << std::endl;
110 }
111
112 // set model dir as output
113 std::string dataPath = scene->data_path();
114 int i = 0;
115 pro.set_output_val<std::string>(i++, dataPath);
116 pro.set_output_val<std::string>(i++, data_type);
117 pro.set_output_val<double>(i++, voxel_sizes.x());
118 pro.set_output_val<double>(i++, voxel_sizes.y());
119 pro.set_output_val<double>(i++, voxel_sizes.z());
120 pro.set_output_val<double>(i++, voxel_time_range);
121 return true;
122 }
123