1 // This is brl/bseg/bstm/cpp/pro/processes/bstm_cpp_copy_data_to_future_process.cxx
2 #include <iostream>
3 #include <fstream>
4 #include <bprb/bprb_func_process.h>
5 //:
6 // \file
7 // \brief A process for copying the data in the input time step into all future time nodes
8 //
9 // \author Ali Osman Ulusoy
10 // \date October 20, 2013
11
12 #ifdef _MSC_VER
13 # include "vcl_msvc_warnings.h"
14 #endif
15 #include <bstm/io/bstm_cache.h>
16 #include <bstm/io/bstm_lru_cache.h>
17 #include <bstm/bstm_scene.h>
18 #include <bstm/bstm_block.h>
19 #include <bstm/bstm_data_base.h>
20 //brdb stuff
21 #include <brdb/brdb_value.h>
22 #include <bstm/cpp/algo/bstm_copy_data_to_future_function.h>
23
24 #include <bstm/bstm_util.h>
25
26 namespace bstm_cpp_copy_data_to_future_process_globals
27 {
28 constexpr unsigned n_inputs_ = 3;
29 constexpr unsigned n_outputs_ = 0;
30 }
31
bstm_cpp_copy_data_to_future_process_cons(bprb_func_process & pro)32 bool bstm_cpp_copy_data_to_future_process_cons(bprb_func_process& pro)
33 {
34 using namespace bstm_cpp_copy_data_to_future_process_globals;
35
36 //process takes 1 input
37 std::vector<std::string> input_types_(n_inputs_);
38
39 input_types_[0] = "bstm_scene_sptr";
40 input_types_[1] = "bstm_cache_sptr";
41 input_types_[2] = "float"; //time
42
43
44 // process has 0 output:
45 // output[0]: scene sptr
46 std::vector<std::string> output_types_(n_outputs_);
47
48 bool good = pro.set_input_types(input_types_) && pro.set_output_types(output_types_);
49 return good;
50 }
51
bstm_cpp_copy_data_to_future_process(bprb_func_process & pro)52 bool bstm_cpp_copy_data_to_future_process(bprb_func_process& pro)
53 {
54
55 using namespace bstm_cpp_copy_data_to_future_process_globals;
56
57 if ( pro.n_inputs() < n_inputs_ ) {
58 std::cout << pro.name() << ": The input number should be " << n_inputs_<< std::endl;
59 return false;
60 }
61
62 //get the inputs
63 unsigned i = 0;
64 bstm_scene_sptr scene =pro.get_input<bstm_scene_sptr>(i++);
65 bstm_cache_sptr cache= pro.get_input<bstm_cache_sptr>(i++);
66 auto time =pro.get_input<float>(i++);
67
68
69 //bstm app query
70 std::string app_data_type;
71 int apptypesize;
72 std::vector<std::string> valid_types;
73 valid_types.push_back(bstm_data_traits<BSTM_MOG6_VIEW_COMPACT>::prefix());
74 valid_types.push_back(bstm_data_traits<BSTM_MOG3_GREY>::prefix());
75 valid_types.push_back(bstm_data_traits<BSTM_GAUSS_RGB>::prefix());
76 if ( !bstm_util::verify_appearance( *scene, valid_types, app_data_type, apptypesize ) ) {
77 std::cout<<"bstm_cpp_copy_data_to_future_process ERROR: scene doesn't have BSTM_MOG6_VIEW_COMPACT or BSTM_MOG3_GREY or BSTM_GAUSS_RGB data type"<<std::endl;
78 return false;
79 }
80
81 std::string nobs_data_type;
82 int nobstypesize;
83 valid_types.empty();
84 valid_types.push_back(bstm_data_traits<BSTM_NUM_OBS>::prefix());
85 valid_types.push_back(bstm_data_traits<BSTM_NUM_OBS_VIEW_COMPACT>::prefix());
86 valid_types.push_back(bstm_data_traits<BSTM_NUM_OBS_SINGLE>::prefix());
87 if ( !bstm_util::verify_appearance( *scene, valid_types, nobs_data_type, nobstypesize ) ) {
88 std::cout<<"bstm_cpp_copy_data_to_future_process ERROR: scene doesn't have BSTM_NUM_OBS or BSTM_NUM_OBS_VIEW_COMPACT or BSTM_NUM_OBS_SINGLE data type"<<std::endl;
89 return false;
90 }
91
92
93 std::cout<<"Copying data to future..."<<std::endl;
94
95
96 std::map<bstm_block_id, bstm_block_metadata> blocks = scene->blocks();
97 std::map<bstm_block_id, bstm_block_metadata>::iterator blk_iter;
98 for (blk_iter = blocks.begin(); blk_iter != blocks.end(); ++blk_iter)
99 {
100 bstm_block_id id = blk_iter->first;
101
102 //skip block if it doesn't contain curr time.
103 bstm_block_metadata mdata = blk_iter->second;
104 double local_time;
105 if(!mdata.contains_t(time,local_time))
106 continue;
107 std::cout<<"Processsing Block: "<<id<<std::endl;
108
109 bstm_block * blk = cache->get_block(id);
110 bstm_time_block* blk_t = cache->get_time_block(id);
111 bstm_data_base * alph = cache->get_data_base(id,bstm_data_traits<BSTM_ALPHA>::prefix());
112 int num_el = alph->buffer_length() / bstm_data_traits<BSTM_ALPHA>::datasize();
113 bstm_data_base * mog = cache->get_data_base(id, app_data_type, apptypesize * num_el);
114 bstm_data_base * num_obs = cache->get_data_base(id, nobs_data_type,nobstypesize * num_el );
115
116 std::vector<bstm_data_base*> datas;
117 datas.push_back(alph);
118 datas.push_back(mog);
119 datas.push_back(num_obs);
120
121 //refine block and datas
122 if(app_data_type == bstm_data_traits<BSTM_MOG3_GREY>::prefix() && nobs_data_type == bstm_data_traits<BSTM_NUM_OBS>::prefix() )
123 bstm_copy_data_to_future_function<BSTM_MOG3_GREY, BSTM_NUM_OBS> ( blk_t, blk, datas, local_time);
124 else if (app_data_type == bstm_data_traits<BSTM_MOG6_VIEW_COMPACT>::prefix() && nobs_data_type == bstm_data_traits<BSTM_NUM_OBS_VIEW_COMPACT>::prefix() )
125 bstm_copy_data_to_future_function<BSTM_MOG6_VIEW_COMPACT, BSTM_NUM_OBS_VIEW_COMPACT> ( blk_t, blk, datas, local_time);
126 else if (app_data_type == bstm_data_traits<BSTM_GAUSS_RGB>::prefix() && nobs_data_type == bstm_data_traits<BSTM_NUM_OBS_SINGLE>::prefix() )
127 bstm_copy_data_to_future_function<BSTM_GAUSS_RGB, BSTM_NUM_OBS_SINGLE> ( blk_t, blk, datas, local_time);
128 else {
129 std::cerr << "bstm_cpp_copy_data_to_future_process ERROR! Types don't match...." << std::endl;
130 std::cerr << "App type: " << app_data_type << " and nobs: " << nobs_data_type << std::endl;
131 }
132 }
133
134 std::cout << "Finished copying data scene..." << std::endl;
135 return true;
136 }
137