1 // This is brl/bseg/boxm2/cpp/pro/processes/boxm2_cpp_render_cone_expected_image_process.cxx
2 #include <iostream>
3 #include <fstream>
4 #include <bprb/bprb_func_process.h>
5 //:
6 // \file
7 // \brief A process for rendering the scene.
8 //
9 // \author Vishal Jain
10 // \date Mar 10, 2011
11
12 #ifdef _MSC_VER
13 # include "vcl_msvc_warnings.h"
14 #endif
15 #include <boxm2/io/boxm2_cache.h>
16 #include <boxm2/boxm2_scene.h>
17 #include <boxm2/boxm2_block.h>
18 #include <boxm2/boxm2_data_base.h>
19 #include <boxm2/cpp/algo/boxm2_render_functions.h>
20
21 //vil includes
22 #include "vil/vil_save.h"
23 #include "vil/vil_image_view.h"
24 #include "vil/vil_transform.h"
25
26 //brdb stuff
27 #include <brdb/brdb_value.h>
28
29 //directory utility
30 #include <vcl_where_root_dir.h>
31
32 namespace boxm2_cpp_render_cone_expected_image_process_globals
33 {
34 constexpr unsigned n_inputs_ = 5;
35 constexpr unsigned n_outputs_ = 1;
36 std::size_t lthreads[2]={8,8};
37 }
38
boxm2_cpp_render_cone_expected_image_process_cons(bprb_func_process & pro)39 bool boxm2_cpp_render_cone_expected_image_process_cons(bprb_func_process& pro)
40 {
41 using namespace boxm2_cpp_render_cone_expected_image_process_globals;
42
43 //process takes 1 input
44 std::vector<std::string> input_types_(n_inputs_);
45 input_types_[0] = "boxm2_scene_sptr";
46 input_types_[1] = "boxm2_cache_sptr";
47 input_types_[2] = "vpgl_camera_double_sptr";
48 input_types_[3] = "unsigned";
49 input_types_[4] = "unsigned";
50
51
52 // process has 1 output:
53 // output[0]: scene sptr
54 std::vector<std::string> output_types_(n_outputs_);
55 output_types_[0] = "vil_image_view_base_sptr";
56
57 return pro.set_input_types(input_types_) && pro.set_output_types(output_types_);
58 }
59
boxm2_cpp_render_cone_expected_image_process(bprb_func_process & pro)60 bool boxm2_cpp_render_cone_expected_image_process(bprb_func_process& pro)
61 {
62 using namespace boxm2_cpp_render_cone_expected_image_process_globals;
63
64 if ( pro.n_inputs() < n_inputs_ ) {
65 std::cout << pro.name() << ": The input number should be " << n_inputs_<< std::endl;
66 return false;
67 }
68
69 //get the inputs
70 unsigned i = 0;
71 boxm2_scene_sptr scene =pro.get_input<boxm2_scene_sptr>(i++);
72 boxm2_cache_sptr cache= pro.get_input<boxm2_cache_sptr>(i++);
73 vpgl_camera_double_sptr cam= pro.get_input<vpgl_camera_double_sptr>(i++);
74 auto ni=pro.get_input<unsigned>(i++);
75 auto nj=pro.get_input<unsigned>(i++);
76
77 //make sure the scene corresponds to this datatype
78 std::string data_type, num_obs_type, options;
79 if ( scene->has_data_type(boxm2_data_traits<BOXM2_MOG3_GREY>::prefix()) ) {
80 data_type = boxm2_data_traits<BOXM2_MOG3_GREY>::prefix();
81 options=" -D MOG_TYPE_8 ";
82 }
83 else {
84 std::cout<<"boxm2_cpp_render_cone_process ERROR: scene doesn't have BOXM2_GAUSS_RGB data type"<<std::endl;
85 return false;
86 }
87
88 // function call
89 auto * exp_img = new vil_image_view<float>(ni,nj);
90 auto * vis_img = new vil_image_view<float>(ni,nj);
91 exp_img->fill(0.0f);
92 vis_img->fill(1.0f);
93 std::vector<boxm2_block_id> vis_order=scene->get_vis_blocks(reinterpret_cast<vpgl_perspective_camera<double>*>(cam.ptr()));
94 std::vector<boxm2_block_id>::iterator id;
95 for (id = vis_order.begin(); id != vis_order.end(); ++id)
96 {
97 std::cout<<"Cone Rendering Block Id "<<(*id)<<std::endl;
98 boxm2_block * blk = cache->get_block(scene,*id);
99 boxm2_data_base * alph = cache->get_data_base(scene,*id,boxm2_data_traits<BOXM2_GAMMA>::prefix());
100 boxm2_data_base * mog = cache->get_data_base(scene,*id,data_type);
101 std::vector<boxm2_data_base*> datas;
102 datas.push_back(alph);
103 datas.push_back(mog);
104
105 auto *scene_info_wrapper=new boxm2_scene_info_wrapper();
106 scene_info_wrapper->info=scene->get_blk_metadata(*id);
107
108 boxm2_render_cone_exp_image(scene_info_wrapper->info,
109 blk,datas,cam,exp_img,vis_img,ni,nj);
110 }
111
112 //normalize the expected image...
113 normalize_intensity f;
114 vil_transform2<float,float, normalize_intensity>(*vis_img,*exp_img,f);
115
116 vil_save(*vis_img, "f:/vis_img.tiff");
117
118 // store scene smaprt pointer
119 pro.set_output_val<vil_image_view_base_sptr>(0, exp_img);
120 return true;
121 }
122