00001 // This is mul/clsfy/clsfy_builder_1d.cxx 00002 #include "clsfy_builder_1d.h" 00003 //: 00004 // \file 00005 // \brief Describe an abstract classifier builder for scalar data 00006 // \author Tim Cootes 00007 00008 //======================================================================= 00009 00010 #include <vsl/vsl_indent.h> 00011 #include <vsl/vsl_binary_loader.h> 00012 #include <mbl/mbl_read_props.h> 00013 #include <mbl/mbl_cloneables_factory.h> 00014 00015 //======================================================================= 00016 00017 void vsl_add_to_binary_loader(const clsfy_builder_1d& b) 00018 { 00019 vsl_binary_loader<clsfy_builder_1d>::instance().add(b); 00020 } 00021 00022 //======================================================================= 00023 00024 vcl_string clsfy_builder_1d::is_a() const 00025 { 00026 return vcl_string("clsfy_builder_1d"); 00027 } 00028 00029 bool clsfy_builder_1d::is_class(vcl_string const& s) const 00030 { 00031 return s == clsfy_builder_1d::is_a(); 00032 } 00033 00034 //======================================================================= 00035 //: Initialise the parameters from a text stream. 00036 // Default case accepts no parameters. 00037 void clsfy_builder_1d::config(vcl_istream &as) 00038 { 00039 mbl_read_props_type props = mbl_read_props_ws(as); 00040 00041 // Check there are no unused properties 00042 mbl_read_props_look_for_unused_props("clsfy_builder_1d::config", 00043 props, mbl_read_props_type()); 00044 } 00045 00046 //======================================================================= 00047 //: Load description from a text stream 00048 // The stream should contain the name of the feature extractor 00049 // class that will be used, followed by a brace-enclosed list of 00050 // parameters for the builder. This function will construct 00051 // the appropriate clsfy_builder_1d derivative and return that. 00052 // \throws if the parse fails. 00053 vcl_auto_ptr<clsfy_builder_1d> clsfy_builder_1d::new_builder( 00054 vcl_istream &as) 00055 { 00056 vcl_string name; 00057 as >> name; 00058 00059 vcl_auto_ptr<clsfy_builder_1d> ps; 00060 try 00061 { 00062 ps = mbl_cloneables_factory<clsfy_builder_1d>::get_clone(name); 00063 } 00064 catch (const mbl_exception_no_name_in_factory & e) 00065 { 00066 throw (mbl_exception_parse_error( e.what() )); 00067 } 00068 00069 ps->config(as); 00070 00071 return ps; 00072 } 00073 00074 //======================================================================= 00075 00076 void vsl_b_write(vsl_b_ostream& os, const clsfy_builder_1d& b) 00077 { 00078 b.b_write(os); 00079 } 00080 00081 //======================================================================= 00082 00083 void vsl_b_read(vsl_b_istream& bfs, clsfy_builder_1d& b) 00084 { 00085 b.b_read(bfs); 00086 } 00087 00088 //======================================================================= 00089 00090 vcl_ostream& operator<<(vcl_ostream& os,const clsfy_builder_1d& b) 00091 { 00092 os << b.is_a() << ": "; 00093 vsl_indent_inc(os); 00094 b.print_summary(os); 00095 vsl_indent_dec(os); 00096 return os; 00097 } 00098 00099 //======================================================================= 00100 00101 vcl_ostream& operator<<(vcl_ostream& os,const clsfy_builder_1d* b) 00102 { 00103 if (b) 00104 return os << *b; 00105 else 00106 return os << "No clsfy_builder_1d defined."; 00107 } 00108