contrib/brl/bseg/bbgm/pro/processes/bbgm_save_image_of_process.cxx
Go to the documentation of this file.
00001 // This is brl/bseg/bbgm/pro/processes/bbgm_save_image_of_process.cxx
00002 #include <bprb/bprb_func_process.h>
00003 //:
00004 // \file
00005 
00006 #include <vcl_iostream.h>
00007 #include <bbgm/bbgm_image_of.h>
00008 #include <bbgm/bbgm_image_sptr.h>
00009 #include <brdb/brdb_value.h>
00010 #include <vbl/io/vbl_io_smart_ptr.h>
00011 
00012 //: Process construct function
00013 bool bbgm_save_image_of_process_cons(bprb_func_process& pro)
00014 {
00015   vcl_vector<vcl_string> in_types(2);
00016   in_types[0]="vcl_string";//path for saved distribution image
00017   in_types[1]="bbgm_image_sptr";//pointer to distribution image
00018   pro.set_input_types(in_types);
00019   return true;
00020 }
00021 
00022 //: Process execute function
00023 bool bbgm_save_image_of_process(bprb_func_process& pro)
00024 {
00025   // Sanity check
00026   if (!pro.verify_inputs()) {
00027     vcl_cerr << "In bbgm_save_image_of_process::execute - invalid inputs\n";
00028     return false;
00029   }
00030 
00031   vcl_string binary_filename = pro.get_input<vcl_string>(0);
00032 
00033   vsl_b_ofstream ostr(binary_filename);
00034   if (!ostr) {
00035     vcl_cerr << "Failed to load background image from "
00036              << binary_filename << vcl_endl;
00037     return false;
00038   }
00039 
00040   vsl_b_ostream& bos = static_cast<vsl_b_ostream&>(ostr);
00041 
00042   bbgm_image_sptr bgm = pro.get_input<bbgm_image_sptr>(1);
00043   if (!bgm) {
00044     vcl_cerr << "Null background image\n";
00045     return false;
00046   }
00047 
00048   vsl_b_write(bos, bgm);
00049 
00050   return true;
00051 }
00052