contrib/brl/bseg/sdet/sdet_denoise_mrf_bp_params.cxx
Go to the documentation of this file.
00001 // This is brl/bseg/sdet/sdet_denoise_mrf_bp_params.cxx
00002 #include "sdet_denoise_mrf_bp_params.h"
00003 //:
00004 // \file
00005 // See sdet_denoise_mrf_bp_params.h
00006 //
00007 //-----------------------------------------------------------------------------
00008 #include <vcl_sstream.h>
00009 #include <vcl_iostream.h>
00010 
00011 //------------------------------------------------------------------------
00012 // Constructors
00013 //
00014 
00015 sdet_denoise_mrf_bp_params::
00016 sdet_denoise_mrf_bp_params(const sdet_denoise_mrf_bp_params& dmp)
00017   : gevd_param_mixin(), vbl_ref_count()
00018 {
00019   InitParams(dmp.n_labels_, dmp.n_iter_, dmp.pyramid_levels_, dmp.discontinuity_cost_,
00020              dmp.truncation_cost_, dmp.kappa_, dmp.lambda_);
00021 
00022 }
00023 
00024 sdet_denoise_mrf_bp_params::
00025 sdet_denoise_mrf_bp_params(unsigned n_labels,
00026                            unsigned n_iter, unsigned pyramid_levels,
00027                            float discontinuity_cost,
00028                            float truncation_cost,
00029                            float kappa,
00030                            float lambda )
00031 {
00032   InitParams(n_labels, n_iter, pyramid_levels, discontinuity_cost,
00033              truncation_cost, kappa, lambda);
00034 }
00035 
00036 void sdet_denoise_mrf_bp_params::
00037 InitParams(unsigned n_labels, unsigned n_iter, unsigned pyramid_levels,
00038            float discontinuity_cost, float truncation_cost,
00039            float kappa, float lambda)
00040 {
00041   n_labels_ = n_labels;
00042   n_iter_ = n_iter;
00043   pyramid_levels_ = pyramid_levels;
00044   discontinuity_cost_ = discontinuity_cost;
00045   truncation_cost_ = truncation_cost;
00046   kappa_ = kappa; 
00047   lambda_ = lambda;
00048 }
00049 
00050 //-----------------------------------------------------------------------------
00051 //
00052 //:   Checks that parameters are within acceptable bounds
00053 bool sdet_denoise_mrf_bp_params::SanityCheck()
00054 {
00055   //  Note that msg << ends seems to restart the string and erase the
00056   //  previous string. We should only use it as the last call, use
00057   //  vcl_endl otherwise.
00058   vcl_stringstream msg;
00059   bool valid = true;
00060 
00061   if (n_labels_ < 2)
00062     {
00063       msg << "ERROR: at least 2 labels are needed!\n";
00064       valid = false;
00065     }
00066 
00067   if (n_iter_ < 1)
00068     {
00069       msg << "ERROR: at least 1 iteration is needed!\n";
00070       valid = false;
00071     }
00072   if ( pyramid_levels_ < 1)
00073     {
00074       msg << "ERROR: need at least one pyramid level\n";
00075       valid = false;
00076     }
00077   if (discontinuity_cost_ < 0.0f)
00078     {
00079       msg << "ERROR: discontinuity cost can't be negative\n";
00080       valid = false;
00081     }
00082   if (truncation_cost_ < 0.0f)
00083     {
00084       msg << "ERROR: discontinuity cost can't be negative\n";
00085       valid = false;
00086     }
00087   if (kappa_ < 0.0f)
00088     {
00089       msg << "ERROR: kappa can't be negative\n";
00090       valid = false;
00091     }
00092 
00093   if (lambda_ < 0.0f)
00094     {
00095       msg << "ERROR: lambda can't be negative\n";
00096       valid = false;
00097     }
00098 
00099   msg << vcl_ends;
00100 
00101   SetErrorMsg(msg.str().c_str());
00102   return valid;
00103 }
00104 
00105 vcl_ostream& operator << (vcl_ostream& os, const sdet_denoise_mrf_bp_params& dmp)
00106 {
00107   return
00108   os << "sdet_denoise_mrf_bp_params:\n[---\n"
00109      << "n labels " << dmp.n_labels_ << vcl_endl
00110      << "n iterations " << dmp.n_iter_ << vcl_endl
00111      << "pyramid levels " << dmp.pyramid_levels_ << vcl_endl
00112      << "discontinuity cost " << dmp.discontinuity_cost_ << vcl_endl
00113      << "truncation cost " << dmp.truncation_cost_ << vcl_endl
00114      << "kappa  " << dmp.kappa_ << vcl_endl
00115      << "lambda  " << dmp.lambda_ << vcl_endl
00116      << "---]\n";
00117 }