1 // This is brl/bseg/bstm/cpp/pro/processes/bstm_cpp_merge_tt_process.cxx
2 #include <iostream>
3 #include <fstream>
4 #include <bprb/bprb_func_process.h>
5 //:
6 // \file
7 // \brief A process for merging the time trees.
8 //
9 // \author Ali Osman Ulusoy
10 // \date June 17, 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_merge_tt_function.h>
23
24 #include <boxm2/basic/boxm2_array_1d.h>
25
26 namespace bstm_cpp_merge_tt_process_globals
27 {
28 constexpr unsigned n_inputs_ = 4;
29 constexpr unsigned n_outputs_ = 0;
30 }
31
bstm_cpp_merge_tt_process_cons(bprb_func_process & pro)32 bool bstm_cpp_merge_tt_process_cons(bprb_func_process& pro)
33 {
34 using namespace bstm_cpp_merge_tt_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"; //p_threshold
42 input_types_[3] = "float"; //time
43
44
45 // process has 0 output:
46 // output[0]: scene sptr
47 std::vector<std::string> output_types_(n_outputs_);
48
49 bool good = pro.set_input_types(input_types_) && pro.set_output_types(output_types_);
50 return good;
51 }
52
bstm_cpp_merge_tt_process(bprb_func_process & pro)53 bool bstm_cpp_merge_tt_process(bprb_func_process& pro)
54 {
55
56 using namespace bstm_cpp_merge_tt_process_globals;
57
58 if ( pro.n_inputs() < n_inputs_ ) {
59 std::cout << pro.name() << ": The input number should be " << n_inputs_<< std::endl;
60 return false;
61 }
62
63 //get the inputs
64 unsigned i = 0;
65 bstm_scene_sptr scene =pro.get_input<bstm_scene_sptr>(i++);
66 bstm_cache_sptr cache= pro.get_input<bstm_cache_sptr>(i++);
67 auto p_threshold =pro.get_input<float>(i++);
68 auto time =pro.get_input<float>(i++);
69
70
71 bool foundAppDataType = false, foundNumobsDataType = false;
72
73 std::vector<std::string> apps = scene->appearances();
74 for (const auto & app : apps) {
75 if ( app == bstm_data_traits<BSTM_MOG6_VIEW_COMPACT>::prefix() )
76 {
77 foundAppDataType = true;
78 }
79 else if ( app == bstm_data_traits<BSTM_NUM_OBS_VIEW_COMPACT>::prefix() )
80 {
81 foundNumobsDataType = true;
82 }
83 }
84 if (!foundAppDataType || !foundNumobsDataType ) {
85 std::cout<<"bstm_cpp_merge_tt_process_ERROR: scene doesn't have BSTM_MOG6_VIEW_COMPACT or BSTM_NUM_OBS_VIEW_COMPACT data type"<<std::endl;
86 return false;
87 }
88
89 std::map<bstm_block_id, bstm_block_metadata> blocks = scene->blocks();
90 std::map<bstm_block_id, bstm_block_metadata>::iterator blk_iter;
91 for (blk_iter = blocks.begin(); blk_iter != blocks.end(); ++blk_iter)
92 {
93 bstm_block_id id = blk_iter->first;
94
95 //skip block if it doesn't contain curr time.
96 bstm_block_metadata mdata = blk_iter->second;
97 double local_time;
98 if(!mdata.contains_t(time,local_time))
99 continue;
100 std::cout<<"Merging Block: "<<id<<std::endl;
101
102 bstm_block * blk = cache->get_block(id);
103 bstm_time_block* blk_t = cache->get_time_block(id);
104 bstm_data_base * alph = cache->get_data_base(id,bstm_data_traits<BSTM_ALPHA>::prefix());
105 int num_el = alph->buffer_length() / bstm_data_traits<BSTM_ALPHA>::datasize();
106 bstm_data_base * mog = cache->get_data_base(id, bstm_data_traits<BSTM_MOG6_VIEW_COMPACT>::prefix(), bstm_data_traits<BSTM_MOG6_VIEW_COMPACT>::datasize() * num_el);
107 bstm_data_base * num_obs = cache->get_data_base(id, bstm_data_traits<BSTM_NUM_OBS_VIEW_COMPACT>::prefix(),bstm_data_traits<BSTM_NUM_OBS_VIEW_COMPACT>::datasize() * num_el );
108
109 std::vector<bstm_data_base*> datas;
110 datas.push_back(alph);
111 datas.push_back(mog);
112 datas.push_back(num_obs);
113
114 //refine block and datas
115 bstm_merge_tt_blk( blk_t, blk, datas, p_threshold);
116 }
117
118 std::cout << "Finished merging scene..." << std::endl;
119 return true;
120 }
121