Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleLoadBan.cpp
1 /* This file is part of the BIAS library (Basic ImageAlgorithmS).
2 
3  Copyright (C) 2003-2009 (see file CONTACT for details)
4  Multimediale Systeme der Informationsverarbeitung
5  Institut fuer Informatik
6  Christian-Albrechts-Universitaet Kiel
7 
8 
9  BIAS is free software; you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation; either version 2.1 of the License, or
12  (at your option) any later version.
13 
14  BIAS is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with BIAS; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
22 
23 
24 /**
25  @example ExampleLoadBan.cpp
26  @relates Matrix3x4,Vector
27  @brief load 3x4 matrix from Boujou .ban file.
28  And this example demonstrates Dart usage: how to generate a runtime test by comparing against reference values and submit results to Dart server dashboard.
29  @ingroup g_examples
30  @author Jan Woetzel
31 */
32 
33 //#include <Base/Common/LeakChecking.h>
34 
35 #include <Base/Common/BIASpragma.hh>
36 // STD
37 #include <iostream>
38 #include <fstream>
39 #include <sstream>
40 #include <string>
41 
42 // BIAS
43 #include <bias_config.h>
44 #include <Base/Math/Matrix3x4.hh>
45 #include <Base/Math/Vector.hh>
46 
47 using namespace std;
48 using namespace BIAS;
49 
50 int main(int argc, char* argv[] )
51 {
52  int result=0;
53  BIASASSERT(argc>0);
54  cout<<"Starting "<<argv[0]<<endl;
55 #ifdef BIAS_TESTS_DATA
56  //string filename="calib01.ban";
57  //string filename(BIAS_TESTS_DATA "calib01.ban");
58  string filename;
59  filename = string(BIAS_TESTS_DATA);
60  filename += "calib01.ban";
61 #else
62  string filename;
63  cout<<"BIAS_TESTS_DATA not defined."<<endl;
64  return -1;
65 #endif
66 
68 
69  //
70  // first test: load Time=2 Matrix from ban file:
71  //
72  // load one 3x4 matrix from .ban file containing multiple P's
73  cout<<"trying to load "<<filename<<endl;
74  result = A .LoadBan(filename, 2);
75  if (result==0){
76  cout<<"successfully loaded "<<filename<<endl
77  <<"A: "<<A<<endl;
78  } else {
79  cout<<"Error. couls not load "<<filename<<endl;
80  result = -2000;
81  return result;
82  };
83 
84  //
85  // second test: are the values correct?
86  //
87  const double v[12] = {
88  405.1, -0.0678595, -96.8174, 3800.26,
89  -2.10686, -202.721, -68.4048, 3483.67,
90  -0.00379941, 0.00217521, -0.171449, 7.94237 };
91 
92  cout<<"DBG reference v is: "<<endl;
93  for (unsigned int i=0; i<12;i++) cout<<v[i]<<" ";
94  cout<<endl;
95  const double eps=1E-10; // desired precision
96  for (unsigned int i=0; i<12; i++) {
97  if (fabs(v[i] - A.GetData()[i]) >eps){
98  cout<<"Error: mismatch for element "<<i<<" : "<<endl
99  <<"should be: "<<v[i]
100  <<"but read : "<<A.GetData()[i]
101  <<endl;
102  result += -1*i;
103  }
104  }
105 
106  //
107  // third test: this should fail because only 0,1,2 are inside the file
108  //
109  int errCode = A.LoadBan(filename, 3);
110  if (errCode == 0){
111  cout<<"Error: acces to Time 3 should return error but didn't."<<endl;
112  result += -100;
113  };
114 
115  cout<<"done with result = "<<result<<endl;
116  return result;
117 }
118 
int LoadBan(const std::string &filename, const unsigned int &Time=0)
Loads a PMatrix from .ban file given by AddCameraKey and Time index.
Definition: Matrix3x4.cpp:102
T * GetData()
get the pointer to the data array of the matrix (for faster direct memeory access) ...
Definition: Matrix.hh:185