1 // This is brl/bseg/bbgm/pro/processes/bbgm_load_image_of_process.cxx 2 #include <iostream> 3 #include <bprb/bprb_func_process.h> 4 //: 5 // \file 6 #ifdef _MSC_VER 7 # include "vcl_msvc_warnings.h" 8 #endif 9 #include <bbgm/bbgm_image_of.h> 10 #include <bbgm/bbgm_image_sptr.h> 11 #include <brdb/brdb_value.h> 12 #include <vbl/io/vbl_io_smart_ptr.h> 13 #include <bbgm/bbgm_loader.h> 14 15 //: Process construct function bbgm_load_image_of_process_cons(bprb_func_process & pro)16bool bbgm_load_image_of_process_cons(bprb_func_process& pro) 17 { 18 std::vector<std::string> in_types(1), out_types(1); 19 in_types[0]="vcl_string"; //path to distribution image 20 pro.set_input_types(in_types); 21 out_types[0]="bbgm_image_sptr"; //loaded distribution image 22 pro.set_output_types(out_types); 23 return true; 24 } 25 //: Process execute function bbgm_load_image_of_process(bprb_func_process & pro)26bool bbgm_load_image_of_process(bprb_func_process& pro) 27 { 28 // Sanity check 29 if (!pro.verify_inputs()) { 30 std::cerr << "In bbgm_load_image_of_process::execute - invalid inputs\n"; 31 return false; 32 } 33 34 std::string binary_filename = pro.get_input<std::string>(0); 35 36 vsl_b_ifstream istr(binary_filename); 37 if (!istr) { 38 std::cerr << "Failed to load background image from " 39 << binary_filename << std::endl; 40 return false; 41 } 42 //register different distributions for image content 43 //the registration will only be done once since new instances of 44 //the process are cloned - maybe later make a separate registration step 45 bbgm_loader::register_loaders(); 46 auto& bis = static_cast<vsl_b_istream&>(istr); 47 bbgm_image_sptr image; 48 vsl_b_read(bis, image); 49 50 brdb_value_sptr output0 = new brdb_value_t<bbgm_image_sptr>(image); 51 pro.set_output(0, output0); 52 return true; 53 } 54