contrib/brl/bseg/sdet/sdet_image_mesh_params.cxx
Go to the documentation of this file.
00001 // This is brl/bseg/sdet/sdet_image_mesh_params.cxx
00002 #include "sdet_image_mesh_params.h"
00003 //:
00004 // \file
00005 // See sdet_image_mesh_params.h
00006 //
00007 //-----------------------------------------------------------------------------
00008 #include <vcl_sstream.h>
00009 #include <vcl_iostream.h>
00010 
00011 //------------------------------------------------------------------------
00012 // Constructors
00013 //
00014 
00015 sdet_image_mesh_params::
00016 sdet_image_mesh_params(const sdet_image_mesh_params& imp)
00017   : gevd_param_mixin(), vbl_ref_count()
00018 {
00019   InitParams(imp.smooth_, imp.thresh_,
00020              imp.min_fit_length_,
00021              imp.rms_distance_,
00022              imp.step_half_width_);
00023 }
00024 
00025 sdet_image_mesh_params::
00026 sdet_image_mesh_params(float smooth, float thresh,
00027                        int min_fit_length,
00028                        double rms_distance,
00029                        double step_half_width)
00030 {
00031   InitParams(smooth, thresh, min_fit_length, rms_distance, step_half_width);
00032 }
00033 
00034 void sdet_image_mesh_params::InitParams(float smooth, float thresh,
00035                                         int min_fit_length,
00036                                         double rms_distance,
00037                                         double step_half_width)
00038 {
00039   smooth_ = smooth;
00040   thresh_ = thresh;
00041   min_fit_length_ = min_fit_length;
00042   rms_distance_ = rms_distance;
00043   step_half_width_ = step_half_width;
00044 }
00045 
00046 //-----------------------------------------------------------------------------
00047 //
00048 //:   Checks that parameters are within acceptable bounds
00049 bool sdet_image_mesh_params::SanityCheck()
00050 {
00051   //  Note that msg << ends seems to restart the string and erase the
00052   //  previous string. We should only use it as the last call, use
00053   //  vcl_endl otherwise.
00054   vcl_stringstream msg;
00055   bool valid = true;
00056 
00057   if (smooth_ < 0.5f)
00058   {
00059     msg << "ERROR: smoothing has no effect!\n";
00060     valid = false;
00061   }
00062   if (thresh_ < 0.0f)
00063   {
00064     msg << "ERROR: threshold cannot be negative\n";
00065     valid = false;
00066   }
00067   if (min_fit_length_<3)
00068   {
00069     msg << "ERROR: need at least 3 points for a fit\n";
00070     valid = false;
00071   }
00072   if (rms_distance_>1)
00073   {
00074     msg << "ERROR: a line fit should be better than one pixel rms\n";
00075     valid = false;
00076   }
00077   if (step_half_width_<=0)
00078   {
00079     msg << "ERROR: infeasible step transition width\n";
00080     valid = false;
00081   }
00082   msg << vcl_ends;
00083 
00084   SetErrorMsg(msg.str().c_str());
00085   return valid;
00086 }
00087 
00088 vcl_ostream& operator << (vcl_ostream& os, const sdet_image_mesh_params& imp)
00089 {
00090   return
00091   os << "sdet_image_mesh_params:\n[---\n"
00092      << "smooth sigma" << imp.smooth_ << vcl_endl
00093      << "thresh " << imp.thresh_ << vcl_endl
00094      << "min fit length " << imp.min_fit_length_ << vcl_endl
00095      << "rms distance tolerance" << imp.rms_distance_ << vcl_endl
00096      << "step half width" << imp.step_half_width_ << vcl_endl
00097      << "---]\n";
00098 }