1
2 // This is brl/bseg/bstm/ocl/pro/processes/bstm_ocl_update_change_process.cxx
3 //:
4 // \file
5 // \brief A process for change detection
6 //
7 // \author Ali Osman Ulusoy
8 // \date May 15, 2013
9
10 #include <fstream>
11 #include <iostream>
12 #include <algorithm>
13 #include <sstream>
14 #include <bprb/bprb_func_process.h>
15 #include <bstm/ocl/bstm_opencl_cache.h>
16 #include <bstm/ocl/algo/bstm_ocl_change_detection.h>
17 #include <bstm/bstm_scene.h>
18 #include <bstm/bstm_block.h>
19 #include <bstm/bstm_data_base.h>
20 #include <bstm/ocl/bstm_ocl_util.h>
21 #include <bstm/bstm_util.h>
22 #include "vil/vil_image_view.h"
23
24 // brdb stuff
25 #include <brdb/brdb_value.h>
26
27 // directory utility
28 #include "vul/vul_timer.h"
29 #include <vcl_where_root_dir.h>
30 #ifdef _MSC_VER
31 # include "vcl_msvc_warnings.h"
32 #endif
33 #include <bocl/bocl_device.h>
34 #include <bocl/bocl_kernel.h>
35
36 namespace bstm_ocl_update_change_process_globals
37 {
38 constexpr unsigned n_inputs_ = 7;
39 constexpr unsigned n_outputs_ = 1;
40 }
41
bstm_ocl_update_change_process_cons(bprb_func_process & pro)42 bool bstm_ocl_update_change_process_cons(bprb_func_process& pro)
43 {
44 using namespace bstm_ocl_update_change_process_globals;
45
46 // process takes 9 inputs and two outputs
47 std::vector<std::string> input_types_(n_inputs_);
48 input_types_[0] = "bocl_device_sptr";
49 input_types_[1] = "bstm_scene_sptr";
50 input_types_[2] = "bstm_opencl_cache_sptr";
51 input_types_[3] = "vpgl_camera_double_sptr";
52 input_types_[4] = "vil_image_view_base_sptr"; //img
53 input_types_[5] = "vil_image_view_base_sptr"; //mask
54 input_types_[6] = "float"; // time
55
56 brdb_value_sptr empty_mask = new brdb_value_t<vil_image_view_base_sptr>(new vil_image_view<unsigned char>(1,1));
57 pro.set_input(5, empty_mask);
58
59 std::vector<std::string> output_types_(n_outputs_);
60 output_types_[0] = "vil_image_view_base_sptr"; // prob of change image
61 bool good = pro.set_input_types(input_types_) && pro.set_output_types(output_types_);
62
63 return good;
64 }
65
bstm_ocl_update_change_process(bprb_func_process & pro)66 bool bstm_ocl_update_change_process(bprb_func_process& pro)
67 {
68 using namespace bstm_ocl_update_change_process_globals;
69 if ( pro.n_inputs() < n_inputs_ ) {
70 std::cout << pro.name() << ": The input number should be " << n_inputs_<< std::endl;
71 return false;
72 }
73
74 // get the inputs
75 unsigned i = 0;
76 bocl_device_sptr device = pro.get_input<bocl_device_sptr>(i++);
77 bstm_scene_sptr scene = pro.get_input<bstm_scene_sptr>(i++);
78 bstm_opencl_cache_sptr opencl_cache = pro.get_input<bstm_opencl_cache_sptr>(i++);
79 vpgl_camera_double_sptr cam = pro.get_input<vpgl_camera_double_sptr>(i++);
80 vil_image_view_base_sptr img = pro.get_input<vil_image_view_base_sptr>(i++);
81 vil_image_view_base_sptr mask_img = pro.get_input<vil_image_view_base_sptr>(i++);
82 auto time = pro.get_input<float>(i++);
83
84 // img dims
85 unsigned ni=img->ni();
86 unsigned nj=img->nj();
87
88 // allocate two output images
89 auto* vis_img = new vil_image_view<float>(ni, nj);
90
91 // check to see which type of change detection to do, either two pass, or regular
92 vul_timer t;
93
94 // store scene smaprt pointer
95 bstm_ocl_update_change::update_change( *vis_img,
96 device,
97 scene,
98 opencl_cache,
99 cam,
100 img,
101 mask_img,
102 time);
103 std::cout<<" change time: "<<t.all()<<" ms"<<std::endl;
104
105 // set outputs
106 i=0;
107 pro.set_output_val<vil_image_view_base_sptr>(i++, vis_img);
108 return true;
109 }
110