1 // This is brl/bseg/boxm2/cpp/pro/processes/boxm2_cpp_batch_update_nonsurface_model_process.cxx
2 #include <iostream>
3 #include <fstream>
4 #include <bprb/bprb_func_process.h>
5 //:
6 // \file
7 // \brief Processes to update the scene using a set of data blocks in a batch mode
8 //
9 // \author Ozge C. Ozcanli
10 // \date May 12, 2011
11
12 #ifdef _MSC_VER
13 # include "vcl_msvc_warnings.h"
14 #endif
15 #include <boxm2/io/boxm2_stream_cache.h>
16 #include <boxm2/io/boxm2_cache.h>
17 #include <boxm2/boxm2_scene.h>
18 #include <boxm2/boxm2_data_base.h>
19
20 //brdb stuff
21 #include <brdb/brdb_value.h>
22 #include <boxm2/boxm2_util.h>
23
24 #include <boxm2/cpp/algo/boxm2_synoptic_function_functors.h>
25 #include <boxm2/cpp/algo/boxm2_data_serial_iterator.h>
26
27 //: run batch update
28 namespace boxm2_cpp_batch_update_nonsurface_model_process_globals
29 {
30 constexpr unsigned n_inputs_ = 3;
31 constexpr unsigned n_outputs_ = 0;
32 }
33
boxm2_cpp_batch_update_nonsurface_model_process_cons(bprb_func_process & pro)34 bool boxm2_cpp_batch_update_nonsurface_model_process_cons(bprb_func_process& pro)
35 {
36 using namespace boxm2_cpp_batch_update_nonsurface_model_process_globals;
37
38 //process takes 3 inputs
39 // 0) scene
40 // 1) cache
41 // 2) stream cache
42 std::vector<std::string> input_types_(n_inputs_);
43 input_types_[0] = "boxm2_scene_sptr";
44 input_types_[1] = "boxm2_cache_sptr";
45 input_types_[2] = "boxm2_stream_cache_sptr";
46 // process has 0 output:
47 std::vector<std::string> output_types_(n_outputs_);
48
49 return pro.set_input_types(input_types_) && pro.set_output_types(output_types_);
50 }
51
boxm2_cpp_batch_update_nonsurface_model_process(bprb_func_process & pro)52 bool boxm2_cpp_batch_update_nonsurface_model_process(bprb_func_process& pro)
53 {
54 using namespace boxm2_cpp_batch_update_nonsurface_model_process_globals;
55
56 if ( pro.n_inputs() < n_inputs_ ) {
57 std::cout << pro.name() << ": The number of inputs should be " << n_inputs_<< std::endl;
58 return false;
59 }
60 //get the inputs
61 unsigned i = 0;
62 boxm2_scene_sptr scene =pro.get_input<boxm2_scene_sptr>(i++);
63 boxm2_cache_sptr cache= pro.get_input<boxm2_cache_sptr>(i++);
64 boxm2_stream_cache_sptr str_cache = pro.get_input<boxm2_stream_cache_sptr>(i++);
65
66 // assumes that the data of each image has been created in the data models previously
67 // (but unused:) int alphaTypeSize = (int)boxm2_data_info::datasize(boxm2_data_traits<BOXM2_ALPHA>::prefix());
68 // iterate the scene block by block and write to output
69 std::vector<boxm2_block_id> blk_ids = scene->get_block_ids();
70 std::vector<boxm2_block_id>::iterator id;
71 for (id = blk_ids.begin(); id != blk_ids.end(); id++) {
72 boxm2_data_base * alpha = cache->get_data_base(scene,*id,boxm2_data_traits<BOXM2_ALPHA>::prefix(),0,true);
73
74 // pass num_bytes = 0 to make sure disc is read if not already in memory
75 boxm2_data_base * entropy_histo_air = cache->get_data_base(scene,*id,boxm2_data_traits<BOXM2_AUX0>::prefix("entropy_histo_air"),alpha->buffer_length(),false);
76 boxm2_compute_empty_model_gradient_functor data_functor;
77 data_functor.init_data(entropy_histo_air, str_cache);
78 int histo_entropy_airTypeSize = (int)boxm2_data_info::datasize(boxm2_data_traits<BOXM2_AUX0>::prefix());
79 // check for invalid parameters
80 if( histo_entropy_airTypeSize == 0 ) {
81 //This should never happen, it will result in division by zero later
82 std::cout << "ERROR: histo_entropy_airTypeSize == 0 in " << __FILE__ << __LINE__ << std::endl;
83 return false;
84 }
85
86 int data_buff_length = (int)(entropy_histo_air->buffer_length()/histo_entropy_airTypeSize);
87 boxm2_data_serial_iterator<boxm2_compute_empty_model_gradient_functor>(data_buff_length,data_functor);
88
89 cache->remove_data_base(scene,*id,boxm2_data_traits<BOXM2_AUX0>::prefix("entropy_histo_air"));
90 }
91 return true;
92 }
93