contrib/mul/clsfy/clsfy_binary_1d_wrapper.cxx
Go to the documentation of this file.
00001 // Copyright: (C) 2009 Imorphics PLC
00002 #include "clsfy_binary_1d_wrapper.h"
00003 //:
00004 // \file
00005 // \brief Wrap a classifier_1d in general classifier_base derivative.
00006 // \author Ian Scott
00007 // \date 2 Sep 2009
00008 
00009 //=======================================================================
00010 
00011 #include <vcl_string.h>
00012 #include <vcl_iostream.h>
00013 #include <vcl_vector.h>
00014 #include <vcl_cmath.h>
00015 #include <vsl/vsl_binary_io.h>
00016 #include <clsfy/clsfy_binary_threshold_1d.h>
00017 
00018 
00019 //=======================================================================
00020 
00021 
00022 clsfy_binary_1d_wrapper::clsfy_binary_1d_wrapper():
00023   classifier_1d_(new clsfy_binary_threshold_1d())
00024 {}
00025 
00026 vcl_string clsfy_binary_1d_wrapper::is_a() const
00027 {
00028   return vcl_string("clsfy_binary_1d_wrapper");
00029 }
00030 
00031 //=======================================================================
00032 
00033 bool clsfy_binary_1d_wrapper::is_class(vcl_string const& s) const
00034 {
00035   return s == clsfy_binary_1d_wrapper::is_a() || clsfy_classifier_base::is_class(s);
00036 }
00037 
00038 //=======================================================================
00039 
00040 //:
00041 // required if data is present in this class
00042 void clsfy_binary_1d_wrapper::print_summary(vcl_ostream& os) const
00043 {
00044   os << "underlying classifier: ";
00045   vsl_print_summary(os, classifier_1d_);
00046 }
00047 
00048 //=======================================================================
00049 
00050 void clsfy_binary_1d_wrapper::b_write(vsl_b_ostream& bfs) const
00051 {
00052   short version_no=1;
00053   vsl_b_write(bfs,version_no);
00054   vsl_b_write(bfs,classifier_1d_);
00055 }
00056 
00057 //=======================================================================
00058 
00059 void clsfy_binary_1d_wrapper::b_read(vsl_b_istream& bfs)
00060 {
00061   if (!bfs) return;
00062 
00063   short version;
00064   vsl_b_read(bfs,version);
00065   switch (version)
00066   {
00067     case 1:
00068       vsl_b_read(bfs,classifier_1d_);
00069       break;
00070     default:
00071       vcl_cerr << "I/O ERROR: clsfy_binary_1d_wrapper::b_read(vsl_b_istream&)\n"
00072                << "           Unknown version number "<< version << '\n';
00073       bfs.is().clear(vcl_ios::badbit); // Set an unrecoverable IO error on stream
00074   }
00075 }
00076