contrib/mul/mipa/mipa_vector_normaliser.cxx
Go to the documentation of this file.
00001 //:
00002 // \file
00003 // \author Martin Roberts
00004 // \brief Base class for normalisation algorithms for image texture vectors
00005 
00006 #include "mipa_vector_normaliser.h"
00007 #include <vsl/vsl_indent.h>
00008 #include <vsl/vsl_binary_loader.h>
00009 #include <mbl/mbl_cloneables_factory.h>
00010 #include <mbl/mbl_read_props.h>
00011 #include <mbl/mbl_parse_block.h>
00012 #include <mbl/mbl_exception.h>
00013 
00014 //=======================================================================
00015 
00016 void vsl_add_to_binary_loader(const mipa_vector_normaliser& b)
00017 {
00018   vsl_binary_loader<mipa_vector_normaliser>::instance().add(b);
00019 }
00020 
00021 //=======================================================================
00022 
00023 void vsl_b_write(vsl_b_ostream& bfs, const mipa_vector_normaliser& b)
00024 {
00025   b.b_write(bfs);
00026 }
00027 
00028 //=======================================================================
00029 //: Initialise from a text stream.
00030 // The default implementation is for attribute-less normalisers,
00031 // and throws if it finds any data in the stream.
00032 void mipa_vector_normaliser::config_from_stream(
00033   vcl_istream &is, const mbl_read_props_type &extra_props)
00034 {
00035   vcl_string s = mbl_parse_block(is);
00036   if (s.empty() || s=="{}") return;
00037 
00038   mbl_exception_parse_error x(
00039     this->is_a() + " expects no properties in initialisation,\n"
00040     "But the following properties were given:\n" + s);
00041   mbl_exception_error(x);
00042 }
00043 
00044 
00045 //=======================================================================
00046 //: Create a concrete mipa_vector_normaliser-derived object, from a text specification.
00047 vcl_auto_ptr<mipa_vector_normaliser>
00048   mipa_vector_normaliser::new_normaliser_from_stream(
00049     vcl_istream &is, const mbl_read_props_type &extra_props)
00050 {
00051   vcl_string name;
00052   is >> name;
00053 
00054   vcl_auto_ptr<mipa_vector_normaliser> ps =
00055     mbl_cloneables_factory<mipa_vector_normaliser>::get_clone(name);
00056 
00057   ps -> config_from_stream(is, extra_props);
00058   return ps;
00059 }
00060 
00061 //=======================================================================
00062 
00063 void vsl_b_read(vsl_b_istream& bfs, mipa_vector_normaliser& b)
00064 {
00065   b.b_read(bfs);
00066 }
00067 
00068 //=======================================================================
00069 
00070 vcl_ostream& operator<<(vcl_ostream& os,const mipa_vector_normaliser& b)
00071 {
00072   os << b.is_a() << ": ";
00073   vsl_indent_inc(os);
00074   b.print_summary(os);
00075   vsl_indent_dec(os);
00076   return os;
00077 }
00078 
00079 //=======================================================================
00080 
00081 vcl_ostream& operator<<(vcl_ostream& os,const mipa_vector_normaliser* b)
00082 {
00083   if (b)
00084     return os << *b;
00085   else
00086     return os << "No mipa_vector_normaliser defined.";
00087 }
00088 
00089 //=======================================================================
00090 //: Stream output operator for class reference
00091 void vsl_print_summary(vcl_ostream& os,const mipa_vector_normaliser& b)
00092 {
00093   os << b;
00094 }
00095 
00096 //=======================================================================
00097 //: Stream output operator for class reference
00098 void vsl_print_summary(vcl_ostream& os,const mipa_vector_normaliser* b)
00099 {
00100   if (b)
00101     os << *b;
00102   else
00103     os << vsl_indent() << "No mipa_vector_normaliser defined.";
00104 }