Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
BogIO.hh
1 #ifndef __BogIO_hh__
2 #define __BogIO_hh__
3 
4 #include <Base/Math/Matrix3x3.hh>
5 
6 #include <fstream>
7 #include <sstream>
8 #include <vector>
9 #include <string>
10 
11 namespace BIAS {
12 
13 
14 
15  // JW 03/2005
16  template <class T>
17  int LoadBogRC(const std::string & filename, Matrix3x3<T>& mat)
18  {
19  mat.SetZero();// reset this
20  std::ifstream fs( filename.c_str() );
21  if (!fs) {
22  BIASERR("could not open file "<<filename);
23  return -1; // error, could not open file.
24  };
25  // parse and read in
26  const unsigned int nMax=1024;
27  char caLine[nMax];
28  // std string for find
29  std::string strLine;
30  // helper for string to number /atof)
31  std::istringstream iss;
32  unsigned int pos=0, line=0;
33  std::vector<std::string> pattern;
34  pattern.clear();
35  pattern.push_back("RC11 ="); // 0
36  pattern.push_back("RC12 ="); // 1
37  pattern.push_back("RC13 ="); // 2
38 
39  pattern.push_back("RC21 ="); // 3
40  pattern.push_back("RC22 ="); // 4
41  pattern.push_back("RC23 ="); // 5
42 
43  pattern.push_back("RC31 ="); // 6
44  pattern.push_back("RC32 ="); // 7
45  pattern.push_back("RC33 ="); // 8
46 
47  std::vector< bool > found;
48  found.resize( pattern.size(), false);
49  BIASASSERT(found.size()>8);
50  while (!fs.eof() && (fs)
51  && (
52  !found[0]
53  || !found[1]
54  || !found[2]
55  || !found[3]
56  || !found[4]
57  || !found[5]
58  || !found[6]
59  || !found[7]
60  || !found[8])
61  )
62  {
63  line++;
64  fs.getline(&caLine[0], nMax);
65  strLine = caLine;
66  for (unsigned int i=0; i<pattern.size(); i++){
67  pos = (unsigned int)strLine.find(pattern[i]);
68  if (pos != std::string::npos){
69  found[i]=true;
70  iss.clear();
71  iss.str( // after pattern: start, length
72  strLine.substr(pos+pattern[i].size(), strLine.size()-pos-pattern[i].size())
73  );
74  BIASASSERT(i<9); // dim
75  iss >> mat.GetData()[i];
76  };
77  };
78  };
79  // check if we found all patterns
80  BIASASSERT(found.size()==pattern.size());
81  bool foundAll=true;
82  for (unsigned int j=0; j<found.size(); j++) foundAll=foundAll&&found[j];
83  if (!foundAll) return -99; // missed something
84  return 0; // OK.
85  }
86 
87 
88 
89  // JW 03/2005
90  template <class T>
91  int LoadBogK(const std::string & filename, Matrix3x3<T>& mat)
92  {
93  mat.SetIdentity();// reset this
94  std::ifstream fs( filename.c_str() );
95  if (!fs) {
96  BIASERR("could not open file "<<filename);
97  return -1; // error, could not open file.
98  };
99  // parse and read in
100  const unsigned int nMax=1024;
101  char caLine[nMax];
102  // std string for find
103  std::string strLine;
104  // helper for string to number /atof)
105  std::istringstream iss;
106  unsigned int pos=0, line=0;
107  std::vector<std::string> pattern;
108  pattern.clear();
109 
110  pattern.push_back("FC_U ="); // 0
111  pattern.push_back("SKEW ="); // 1
112  pattern.push_back("CC_U ="); // 2
113  // unused place holder:
114  pattern.push_back("UNUSED_UNUSED-x82S6jd_UNUSED "); // 3
115  pattern.push_back("FC_V ="); // 4
116  pattern.push_back("CC_V ="); // 5
117 
118  std::vector< bool > found;
119  found.resize( pattern.size(), false);
120  BIASASSERT(found.size()>5);
121  while (!fs.eof() && (fs)
122  && (
123  !found[0]
124  || !found[1]
125  || !found[2]
126  //|| !found[3] //unused
127  || !found[4]
128  || !found[5] )
129  )
130  {
131  line++;
132  fs.getline(&caLine[0], nMax);
133  strLine = caLine;
134  for (unsigned int i=0; i<pattern.size(); i++){
135  if (i!=3){
136  pos = (unsigned int)strLine.find(pattern[i]);
137  if (pos != std::string::npos){
138  found[i]=true;
139  iss.clear();
140  iss.str( // after pattern: start, length
141  strLine.substr(pos+pattern[i].size(), strLine.size()-pos-pattern[i].size())
142  );
143  BIASASSERT(i<9); // dim
144  iss>> mat.GetData()[i];
145  }
146  }
147  };
148  };
149  // check if we found all patterns
150  BIASASSERT(found.size()==pattern.size());
151  bool foundAll=true;
152  for (unsigned int j=0; j<found.size(); j++) {
153  if (j!=3) foundAll=foundAll&&found[j];
154  }
155  if (!foundAll) return -99; // missed something
156  return 0; // OK.
157  }
158 
159 }
160 
161 #endif // __BogIO_hh__
int LoadBogK(const std::string &filename, Matrix3x3< T > &mat)
Definition: BogIO.hh:91
is a &#39;fixed size&#39; quadratic matrix of dim.
Definition: Matrix.hh:54
int LoadBogRC(const std::string &filename, Matrix3x3< T > &mat)
Definition: BogIO.hh:17
void SetIdentity()
set the elements of this matrix to the identity matrix (possibly overriding the inherited method) ...
Definition: Matrix3x3.hh:429