Utility functions.


Defines

#define fatal(E, S,...)   vfatal((E), (S), (tag::Fmt,## __VA_ARGS__))

Functions

vector< string > split (const string &s)
template<class C>
ato (const string &s)
double sq (double d)
vector< int > range (int num)
template<class C>
void vfatal (int err, const string &s, const C &list)
istream & operator>> (istream &i, array< float, 2 > &f)
array< float, 2 > Arr (const Vector< 2 > &vec)
Matrix< 3 > invert (const Matrix< 3 > &m)
void draw_offset_list (const vector< ImageRef > &offsets)
void draw_offsets ()
CVD::ImageRef ir_rounded (const tag::array< float, 2 > &v)


Define Documentation

#define fatal ( E,
S,
...   )     vfatal((E), (S), (tag::Fmt,## __VA_ARGS__))

Print an error message and the exit.

Parameters:
E Error code
S Format string

Definition at line 125 of file learn_fast_tree.cc.

Referenced by find_best_split(), load_features(), main(), and datapoint< FEATURE_SIZE >::pack_trits().


Function Documentation

vector<string> split ( const string &  s  ) 

Tokenise a string.

Parameters:
s String to be split
Returns:
Tokens

Definition at line 249 of file faster_tree.cc.

Referenced by load_a_tree().

00250 {
00251     istringstream i(s);
00252 
00253     vector<string> v;
00254 
00255     while(!i.eof())
00256     {
00257         string s;
00258         i >> s;
00259         if(s != "")
00260             v.push_back(s);
00261     }
00262     return v;
00263 }

template<class C>
C ato ( const string &  s  )  [inline]

String to some class.

Name modelled on atoi.

Parameters:
s String to parse
Returns:
class the string was parsed in to.

Definition at line 269 of file faster_tree.cc.

00270 {
00271     istringstream i(s);
00272     C c;
00273     i >> c;
00274 
00275     if(i.bad())
00276         throw   ParseError();
00277     
00278     return c;
00279 }

double sq ( double  d  ) 

Square a number.

Parameters:
d Number to square
Returns:
$d^2$

Definition at line 100 of file learn_detector.cc.

Referenced by learn_detector().

00101 {
00102     return d*d;
00103 }

vector<int> range ( int  num  ) 

Populate a std::vector with the numbers 0,1,.

..,num

Parameters:
num Size if the range
Returns:
the populated vector.

Definition at line 110 of file learn_detector.cc.

00111 {
00112     vector<int> r;
00113 
00114     for(int i=0; i < num; i++)
00115         r.push_back(i);
00116     return r;
00117 }

template<class C>
void vfatal ( int  err,
const string &  s,
const C &  list 
) [inline]

Print an error message and the exit, using Tuple stype VARARGS.

Parameters:
err Error code
s Format string
list Argument list

Definition at line 131 of file learn_fast_tree.cc.

00132 {
00133     vfPrintf(cerr, s + "\n", list);
00134     exit(err);
00135 }

istream& operator>> ( istream &  i,
array< float, 2 > &  f 
)

Load an array from an istream.

Parameters:
i Stream to load from
f array to load in to

Definition at line 88 of file load_data.cc.

00089 {
00090     i >> f[0] >> f[1];
00091     return i;
00092 }

array<float, 2> Arr ( const Vector< 2 > &  vec  ) 

Convert a vector in to an array.

Parameters:
vec Vector to convert

Definition at line 97 of file load_data.cc.

Referenced by load_warps_vgg().

00098 {
00099     return array<float, 2>((TupleHead, vec[0], vec[1]));
00100 }

Matrix<3> invert ( const Matrix< 3 > &  m  ) 

Invert a matrix.

Parameters:
m Matrix to invert

Definition at line 223 of file load_data.cc.

Referenced by tree_element::detect_corner(), load_warps_vgg(), and tree_element::make_fast_detector().

00224 {
00225     LU<3> i(m);
00226     return i.get_inverse();
00227 }

void draw_offset_list ( const vector< ImageRef > &  offsets  ) 

Pretty print some offsets to stdout.

Parameters:
offsets List of offsets to pretty-print.

Definition at line 91 of file offsets.cc.

Referenced by draw_offsets().

00092 {
00093 
00094     cout << "Allowed offsets: " << offsets.size() << endl;
00095 
00096     ImageRef min, max;
00097     min.x = *min_element(member_iterator(offsets.begin(), &ImageRef::x), member_iterator(offsets.end(), &ImageRef::x));
00098     max.x = *max_element(member_iterator(offsets.begin(), &ImageRef::x), member_iterator(offsets.end(), &ImageRef::x));
00099     min.y = *min_element(member_iterator(offsets.begin(), &ImageRef::y), member_iterator(offsets.end(), &ImageRef::y));
00100     max.y = *max_element(member_iterator(offsets.begin(), &ImageRef::y), member_iterator(offsets.end(), &ImageRef::y));
00101 
00102     cout << print << min <<max << endl;
00103 
00104     Image<int> o(max-min+ImageRef(1,1), -1);
00105     for(unsigned int i=0; i <offsets.size(); i++)
00106         o[offsets[i] -min] = i;
00107 
00108     for(int y=0; y < o.size().y; y++)
00109     {
00110         for(int x=0; x < o.size().x; x++)
00111             cout << "+------";
00112         cout << "+"<< endl;
00113 
00114         for(int x=0; x < o.size().x; x++)
00115             cout << "|      ";
00116         cout << "|"<< endl;
00117 
00118 
00119         for(int x=0; x < o.size().x; x++)
00120         {
00121             if(o[y][x] >= 0)
00122                 cout << "|  " << setw(2) << o[y][x] << "  ";
00123             else if(ImageRef(x, y) == o.size() / 2)
00124                 cout << "|   " << "#" << "  ";
00125             else 
00126                 cout << "|      ";
00127         }
00128         cout <<  "|" << endl;
00129 
00130         for(int x=0; x < o.size().x; x++)
00131             cout << "|      ";
00132         cout << "|"<< endl;
00133     }
00134 
00135     for(int x=0; x < o.size().x; x++)
00136         cout << "+------";
00137     cout << "+"<< endl;
00138 
00139     cout << endl;
00140 
00141 }

void draw_offsets (  ) 

Prettyprints the contents of offsets.

Definition at line 201 of file offsets.cc.

Referenced by run_learn_detector().

00202 {
00203     //Print the offsets out.    
00204     for(unsigned int i=0; i < 8; i++)
00205     {
00206         cout << "Offsets " << i << endl;
00207         draw_offset_list(offsets[i]);   
00208         cout << endl;
00209     }
00210 }

CVD::ImageRef ir_rounded ( const tag::array< float, 2 > &  v  )  [inline]

Convert a float array into an image co-ordinate.

Numbers are rounded

Parameters:
v The array to convert

Definition at line 30 of file utility.h.

Referenced by compute_repeatability(), prune_warps(), and transform_offsets().

00031 {
00032     return CVD::ImageRef(
00033   static_cast<int>(v[0] > 0.0 ? v[0] + 0.5 : v[0] - 0.5),
00034   static_cast<int>(v[1] > 0.0 ? v[1] + 0.5 : v[1] - 0.5));
00035 }


Generated on Mon Mar 2 12:47:12 2009 for FAST-ER by  doxygen 1.5.3