1 // This is brl/bseg/bstm/ocl/pro/processes/bstm_ocl_minfo_process.cxx
2 //:
3 // \file
4 // \brief A process computing the MI between two regions in the 4d world. The fixed region is specified with the center of the
5 // box and its dimensions. The relative position of the second regions is specified with rotation (Rodrigues) vector (R_x,R_y,R_z)
6 // and translation (T_x,T_y,T_z). Also, the time frames in which to evaluate these regions must be specified.
7 // A current limitation is that we assume the time frames are contained in the same time block.
8 //
9 // \author Ali Osman Ulusoy
10 // \date Jan 30, 2013
11
12 //directory utility
13 #include <fstream>
14 #include <iostream>
15 #include <algorithm>
16 #include <vcl_where_root_dir.h>
17 #include <bprb/bprb_func_process.h>
18
19 #ifdef _MSC_VER
20 # include "vcl_msvc_warnings.h"
21 #endif
22 #include <bstm/ocl/bstm_opencl_cache.h>
23 #include <bstm/bstm_scene.h>
24 #include <bstm/bstm_block.h>
25 #include <bstm/bstm_data_base.h>
26 #include <bstm/bstm_util.h>
27 #include <bstm/ocl/bstm_ocl_util.h>
28 #include <brdb/brdb_value.h> //brdb stuff
29 #include <bstm/ocl/algo/bstm_ocl_minfo_function.h>
30
31
32
33 namespace bstm_ocl_minfo_process_globals
34 {
35 constexpr unsigned n_inputs_ = 18;
36 constexpr unsigned n_outputs_ = 1;
37 }
38
bstm_ocl_minfo_process_cons(bprb_func_process & pro)39 bool bstm_ocl_minfo_process_cons(bprb_func_process& pro)
40 {
41 using namespace bstm_ocl_minfo_process_globals;
42
43 //process takes 1 input
44 std::vector<std::string> input_types_(n_inputs_);
45 input_types_[0] = "bocl_device_sptr";
46 input_types_[1] = "bstm_scene_sptr";
47 input_types_[2] = "bstm_opencl_cache_sptr";
48 input_types_[3] = "float"; //center x
49 input_types_[4] = "float"; //center y
50 input_types_[5] = "float"; //center z
51 input_types_[6] = "float"; //len x
52 input_types_[7] = "float"; //len y
53 input_types_[8] = "float"; //len z
54 input_types_[9] = "float"; //R_x
55 input_types_[10] = "float"; //R_y
56 input_types_[11] = "float"; //R_z
57 input_types_[12] = "float"; //T_x
58 input_types_[13] = "float"; //T_y
59 input_types_[14] = "float"; //T_z
60 input_types_[15] = "float"; //time frame for fixed template
61 input_types_[16] = "float"; //time frame for relative template
62 input_types_[17] = "int"; //number of bins to quantize histogram
63
64 std::vector<std::string> output_types_(n_outputs_);
65 output_types_[0] = "float";
66
67 return pro.set_input_types(input_types_) && pro.set_output_types(output_types_);
68
69 }
70
bstm_ocl_minfo_process(bprb_func_process & pro)71 bool bstm_ocl_minfo_process(bprb_func_process& pro)
72 {
73 using namespace bstm_ocl_minfo_process_globals;
74
75 if ( pro.n_inputs() < n_inputs_ ) {
76 std::cout << pro.name() << ": The input number should be " << n_inputs_<< std::endl;
77 return false;
78 }
79 //get the inputs
80 unsigned i = 0;
81 bocl_device_sptr device= pro.get_input<bocl_device_sptr>(i++);
82 bstm_scene_sptr scene =pro.get_input<bstm_scene_sptr>(i++);
83 bstm_opencl_cache_sptr opencl_cache= pro.get_input<bstm_opencl_cache_sptr>(i++);
84 auto center_x = pro.get_input<float>(i++);
85 auto center_y = pro.get_input<float>(i++);
86 auto center_z = pro.get_input<float>(i++);
87 auto len_x = pro.get_input<float>(i++);
88 auto len_y = pro.get_input<float>(i++);
89 auto len_z = pro.get_input<float>(i++);
90 auto R_x = pro.get_input<float>(i++);
91 auto R_y = pro.get_input<float>(i++);
92 auto R_z = pro.get_input<float>(i++);
93 auto T_x = pro.get_input<float>(i++);
94 auto T_y = pro.get_input<float>(i++);
95 auto T_z = pro.get_input<float>(i++);
96 auto time_1 = pro.get_input<float>(i++);
97 auto time_2 = pro.get_input<float>(i++);
98 int nbins = pro.get_input<int>(i++);
99
100 //get scene data type and appTypeSize
101 std::string data_type;
102 int apptypesize;
103 std::vector<std::string> valid_types;
104 valid_types.push_back(bstm_data_traits<BSTM_MOG6_VIEW_COMPACT>::prefix());
105 if ( !bstm_util::verify_appearance( *scene, valid_types, data_type, apptypesize ) ) {
106 std::cout<<"bstm_ocl_minfo_process ERROR: scene doesn't have BSTM_MOG6_VIEW_COMPACT data type"<<std::endl;
107 return false;
108 }
109 std::string options = bstm_ocl_util::mog_options(data_type);
110
111 //construct R,T
112 vnl_vector_fixed<double,3> rot_vector (R_x,R_y,R_z);
113 vgl_rotation_3d<double> R(rot_vector);
114 vgl_vector_3d<double> T (T_x,T_y,T_z);
115
116 //construct bounding box
117 vgl_point_3d<double> center(center_x,center_y,center_z);
118 vgl_box_3d<double> bb(center,len_x,len_y,len_z, vgl_box_3d<double>::centre);
119
120 bstm_ocl_minfo_function fn(device,scene,opencl_cache,bb,R,T, time_1, time_2, options, nbins);
121 float mi = fn.evaluate();
122
123 int argIdx = 0;
124 pro.set_output_val<float>(argIdx, mi);
125 return true;
126 }
127