1 // This is brl/bpro/core/vpgl_pro/processes/vpgl_load_affine_camera_process.cxx 2 #include <iostream> 3 #include <bprb/bprb_func_process.h> 4 //: 5 // \file 6 7 #include <bprb/bprb_parameters.h> 8 #ifdef _MSC_VER 9 # include "vcl_msvc_warnings.h" 10 #endif 11 #include "vpgl/vpgl_camera.h" 12 #include "vpgl/vpgl_affine_camera.h" 13 14 //: initialization vpgl_load_affine_camera_process_cons(bprb_func_process & pro)15bool vpgl_load_affine_camera_process_cons(bprb_func_process& pro) 16 { 17 //this process takes one input: the filename 18 bool ok=false; 19 std::vector<std::string> input_types; 20 input_types.emplace_back("vcl_string"); 21 input_types.emplace_back("double"); // view distance 22 input_types.emplace_back("double"); // viewing direction (x) 23 input_types.emplace_back("double"); // viewing direction (y) 24 input_types.emplace_back("double"); // viewing direction (z) 25 ok = pro.set_input_types(input_types); 26 if (!ok) return ok; 27 28 // set default values for new parameter view direction to keep backwards-compatibility 29 // the view direction will be flipped to make the dot product with the input direction positive 30 // this is needed due to the abiguity in the viewing direction of an affine camera as defined by the projection matrix alone 31 brdb_value_sptr default_view_x = new brdb_value_t<double>(0.0); 32 pro.set_input(2, default_view_x); 33 brdb_value_sptr default_view_y = new brdb_value_t<double>(0.0); 34 pro.set_input(3, default_view_y); 35 brdb_value_sptr default_view_z = new brdb_value_t<double>(-1.0); 36 pro.set_input(4, default_view_z); 37 38 std::vector<std::string> output_types; 39 output_types.emplace_back("vpgl_camera_double_sptr"); // label image 40 ok = pro.set_output_types(output_types); 41 if (!ok) return ok; 42 43 return true; 44 45 } 46 47 //: Execute the process vpgl_load_affine_camera_process(bprb_func_process & pro)48bool vpgl_load_affine_camera_process(bprb_func_process& pro) 49 { 50 if (pro.n_inputs() != 5) { 51 std::cout << "vpgl_load_affine_camera_process: The input number should be 2" << std::endl; 52 return false; 53 } 54 // get the inputs 55 std::string camera_filename = pro.get_input<std::string>(0); 56 auto dist = pro.get_input<double>(1); 57 auto look_x = pro.get_input<double>(2); 58 auto look_y = pro.get_input<double>(3); 59 auto look_z = pro.get_input<double>(4); 60 std::ifstream ifs(camera_filename.c_str()); 61 if (!ifs.is_open()) { 62 std::cerr << "Failed to open file " << camera_filename << '\n'; 63 return false; 64 } 65 vnl_matrix_fixed<double,3,4> affine_matrix; 66 ifs >> affine_matrix; 67 ifs.close(); 68 //vpgl_camera_double_sptr procam = new vpgl_affine_camera<double>(affine_matrix); 69 auto* procam = new vpgl_affine_camera<double>(affine_matrix); 70 procam->set_viewing_distance(dist); 71 procam->orient_ray_direction(vgl_vector_3d<double>(look_x, look_y, look_z)); 72 pro.set_output_val<vpgl_camera_double_sptr>(0, procam); 73 74 return true; 75 } 76