contrib/brl/bseg/sdet/sdet_grid_finder_params.cxx
Go to the documentation of this file.
00001 // This is brl/bseg/sdet/sdet_grid_finder_params.cxx
00002 #include "sdet_grid_finder_params.h"
00003 //:
00004 // \file
00005 // See sdet_grid_finder_params.h
00006 //
00007 //-----------------------------------------------------------------------------
00008 #include <vcl_sstream.h>
00009 #include <vcl_iostream.h>
00010 
00011 //------------------------------------------------------------------------
00012 // Constructors
00013 //
00014 
00015 sdet_grid_finder_params::
00016 sdet_grid_finder_params(const sdet_grid_finder_params& gfp)
00017   : gevd_param_mixin()
00018 {
00019   InitParams(gfp.n_lines_x_,
00020              gfp.n_lines_y_,
00021              gfp.spacing_,
00022              gfp.thresh_,
00023              gfp.angle_tol_,
00024              gfp.verbose_,
00025              gfp.debug_state_);
00026 }
00027 
00028 sdet_grid_finder_params::
00029 sdet_grid_finder_params(const int n_lines_x, const int n_lines_y,
00030                         const double spacing, const int thresh,
00031                         const float angle_tol, bool verbose,
00032                         int debug_state)
00033 {
00034   InitParams(n_lines_x, n_lines_y, spacing, thresh, angle_tol, verbose,
00035              debug_state);
00036 }
00037 
00038 void
00039 sdet_grid_finder_params::get_debug_choices(vcl_vector<vcl_string>& choices)
00040 {
00041   choices.clear();
00042   choices.push_back("NO_DEBUG");
00043   choices.push_back("VANISHING_POINT");
00044   choices.push_back("AFFINE_GROUP_BEFORE_SKEW_SCALE");
00045   choices.push_back("AFFINE_GROUP_AFTER_SKEW_SCALE");
00046   choices.push_back("TRANS_PERIM_LINES");
00047   choices.push_back("AFFINE_GROUP_AFTER_TRANS");
00048 }
00049 
00050 void sdet_grid_finder_params::InitParams(const int n_lines_x,
00051                                          const int n_lines_y,
00052                                          const double spacing,
00053                                          const int thresh,
00054                                          const float angle_tol,
00055                                          bool verbose,
00056                                          int debug_state)
00057 {
00058   n_lines_x_=n_lines_x;
00059   n_lines_y_=n_lines_y;
00060   spacing_=spacing;
00061   thresh_ = thresh;
00062   angle_tol_ = angle_tol;
00063   verbose_ = verbose;
00064   debug_state_ = debug_state;
00065 }
00066 
00067 //-----------------------------------------------------------------------------
00068 //
00069 //:   Checks that parameters are within acceptable bounds
00070 //    Note that msg << ends seems to restart the string and erase the
00071 //    previous string. We should only use it as the last call, use
00072 //    vcl_endl otherwise.
00073 bool sdet_grid_finder_params::SanityCheck()
00074 {
00075   vcl_stringstream msg;
00076   bool valid = true;
00077 
00078   if (n_lines_x_<2)
00079   {
00080     msg << "ERROR: need at least 2 lines in the x direction";
00081     valid = false;
00082   }
00083   if (n_lines_x_<2)
00084   {
00085     msg << "ERROR: need at least 2 lines in the y direction";
00086     valid = false;
00087   }
00088   if (spacing_<=0)
00089   {
00090     msg << "ERROR: need finite spacing";
00091     valid = false;
00092   }
00093   if (thresh_<1)
00094   {
00095     msg << "ERROR: need at least 1 line in a bin ";
00096     valid = false;
00097   }
00098   if (angle_tol_<5)
00099   {
00100     msg << "ERROR: need at least 5 degrees tolerance ";
00101     valid = false;
00102   }
00103   msg << vcl_ends;
00104 
00105   SetErrorMsg(msg.str().c_str());
00106   return valid;
00107 }
00108 
00109 vcl_ostream& operator << (vcl_ostream& os, const sdet_grid_finder_params& gfp)
00110 {
00111   return
00112   os << "sdet_grid_finder_params:\n[---\n"
00113      << "number of lines in x direction (y lines) " << gfp.n_lines_x_ << '\n'
00114      << "number of lines in y direction (x lines) " << gfp.n_lines_y_ << '\n'
00115      << "spacing between lines " << gfp.spacing_ << '\n'
00116      << "hough index bin count threshold " << gfp.thresh_ << '\n'
00117      << "hough angle tolerance " << gfp.thresh_ << '\n'
00118      << "---]" << vcl_endl;
00119 }