contrib/brl/bbas/bxml/bsvg/pro/processes/bsvg_plot_bar_processes.cxx
Go to the documentation of this file.
00001 // This is brl/bbas/bxml/bsvg/pro/processes/bsvg_plot_bar_processes.cxx
00002 #include <bprb/bprb_func_process.h>
00003 //:
00004 // \file
00005 // \brief Processes for plotting bar graphs
00006 //
00007 // \author Ozge Can Ozcanli
00008 // \date July 15, 2009
00009 //
00010 // \verbatim
00011 //  Modifications
00012 //   none yet
00013 // \endverbatim
00014 
00015 #include <brdb/brdb_value.h>
00016 #include <bprb/bprb_parameters.h>
00017 
00018 #include <bxml/bsvg/bsvg_plot.h>
00019 #include <bxml/bxml_write.h>
00020 
00021 //: Constructor
00022 //  initialize a bar plot with no bars, new bars will be added by the add_bar process
00023 bool bsvg_bar_plot_initialize_process_cons(bprb_func_process& pro)
00024 {
00025   //inputs
00026   bool ok=false;
00027   vcl_vector<vcl_string> input_types;
00028   input_types.push_back("float");  // width of the drawing region in the svg file
00029   input_types.push_back("float");  // height
00030   input_types.push_back("vcl_string");  // title of the plot
00031   ok = pro.set_input_types(input_types);
00032   if (!ok) return ok;
00033 
00034   //output
00035   vcl_vector<vcl_string> output_types;
00036   output_types.push_back("bxml_document_sptr");
00037   ok = pro.set_output_types(output_types);
00038   return ok;
00039 }
00040 
00041 bool bsvg_bar_plot_initialize_process(bprb_func_process& pro)
00042 {
00043   // Sanity check
00044   if (pro.n_inputs() < 3) {
00045     vcl_cerr << "dbrec_image_parse_process - invalid inputs\n";
00046     return false;
00047   }
00048 
00049   // get input
00050   unsigned i = 0;
00051   float w = pro.get_input<float>(i++);
00052   float h = pro.get_input<float>(i++);
00053   vcl_string title = pro.get_input<vcl_string>(i++);
00054 
00055   bsvg_plot* p = new bsvg_plot(w, h);
00056   bxml_document_sptr pd = p;
00057   p->set_margin(40);
00058   p->set_font_size(15);
00059   p->add_axes(0, 1, 0, 1);
00060   p->add_title(title);
00061   //p->add_x_increments(0.1f);
00062   p->add_y_increments(0.1f);
00063 
00064   pro.set_output_val<bxml_document_sptr>(0, pd);
00065   return true;
00066 }
00067 
00068 //: Constructor
00069 //  Add a bar to the plot
00070 bool bsvg_bar_plot_add_process_cons(bprb_func_process& pro)
00071 {
00072   //inputs
00073   bool ok=false;
00074   vcl_vector<vcl_string> input_types;
00075   input_types.push_back("bxml_document_sptr");
00076   input_types.push_back("float");  // height
00077   input_types.push_back("vcl_string");  // label
00078   input_types.push_back("vcl_string");  // color
00079   ok = pro.set_input_types(input_types);
00080   if (!ok) return ok;
00081 
00082   //output
00083   vcl_vector<vcl_string> output_types;
00084   ok = pro.set_output_types(output_types);
00085   return ok;
00086 }
00087 
00088 bool bsvg_bar_plot_add_process(bprb_func_process& pro)
00089 {
00090   // Sanity check
00091   if (pro.n_inputs() < 4) {
00092     vcl_cerr << "dbrec_image_parse_process - invalid inputs\n";
00093     return false;
00094   }
00095 
00096   // get input
00097   unsigned i = 0;
00098   bxml_document_sptr doc = pro.get_input<bxml_document_sptr>(i++);
00099   float h = pro.get_input<float>(i++);
00100   vcl_string label = pro.get_input<vcl_string>(i++);
00101   vcl_string color = pro.get_input<vcl_string>(i++);
00102 
00103   bsvg_plot* p = dynamic_cast<bsvg_plot*>(doc.ptr());
00104   p->add_bar(h, label, true, color);
00105   return true;
00106 }
00107 
00108 //: Constructor
00109 bool bsvg_plot_write_process_cons(bprb_func_process& pro)
00110 {
00111   bool ok=false;
00112   vcl_vector<vcl_string> input_types;
00113   input_types.push_back("bxml_document_sptr");
00114   input_types.push_back("vcl_string");  // out file
00115   ok = pro.set_input_types(input_types);
00116   if (!ok) return ok;
00117   vcl_vector<vcl_string> output_types;
00118   ok = pro.set_output_types(output_types);
00119   return ok;
00120 }
00121 
00122 bool bsvg_plot_write_process(bprb_func_process& pro)
00123 {
00124   if (pro.n_inputs() < 2) {
00125     vcl_cerr << "dbrec_image_parse_process - invalid inputs\n";
00126     return false;
00127   }
00128   unsigned i = 0;
00129   bxml_document_sptr doc = pro.get_input<bxml_document_sptr>(i++);
00130   vcl_string out_file = pro.get_input<vcl_string>(i++);
00131 
00132   bxml_write(out_file, *doc);
00133   return true;
00134 }
00135