00001 //: 00002 // \file 00003 #include <bprb/bprb_func_process.h> 00004 #include <vgl/vgl_polygon.h> 00005 #include <vgl/io/vgl_io_polygon.h> 00006 #include <vil/vil_image_view.h> 00007 00008 #include <bmdl/bmdl_mesh.h> 00009 00010 bool trace_boundaries(vil_image_view_base_sptr label_img, vcl_string fpath) 00011 { 00012 if (label_img->pixel_format() != VIL_PIXEL_FORMAT_UINT_32) { 00013 vcl_cout << "bmdl_trace_boundaries_process::the Label Image pixel format" << label_img->pixel_format() << " undefined" << vcl_endl; 00014 return false; 00015 } 00016 00017 vil_image_view<unsigned int>* img = static_cast<vil_image_view<unsigned int>* > (label_img.as_pointer()); 00018 vcl_vector<vgl_polygon<double> > polygons = 00019 bmdl_mesh::trace_boundaries(*img); 00020 00021 // save polygons 00022 vsl_b_ofstream os(fpath); 00023 unsigned char ver = 1; //version(); 00024 vsl_b_write(os, ver); 00025 vsl_b_write(os, polygons.size()); 00026 for (unsigned i = 0; i < polygons.size(); i++) { 00027 vsl_b_write(os, polygons[i]); 00028 } 00029 00030 return true; 00031 } 00032 00033 bool bmdl_trace_boundaries_process(bprb_func_process& pro) 00034 { 00035 // Sanity check 00036 if (pro.n_inputs()< 2) { 00037 vcl_cout << "lidar_roi_process: The input number should be 2" << vcl_endl; 00038 return false; 00039 } 00040 00041 unsigned int i=0; 00042 vil_image_view_base_sptr img = pro.get_input<vil_image_view_base_sptr>(i++); 00043 vcl_string fpath = pro.get_input<vcl_string>(i++); 00044 00045 if (!img) { 00046 vcl_cout << "bmdl_classify_process -- Label image is not set!\n"; 00047 return false; 00048 } 00049 00050 trace_boundaries(img, fpath); 00051 00052 return true; 00053 } 00054 00055 bool bmdl_trace_boundaries_process_cons(bprb_func_process& pro) 00056 { 00057 vcl_vector<vcl_string> input_types; 00058 input_types.push_back("vil_image_view_base_sptr"); 00059 input_types.push_back("vcl_string"); 00060 return pro.set_input_types(input_types); 00061 }