Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleSymmetricMatrix3x3.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  @example ExampleSymmetricMatrix3x3.cpp
25  @relates SymmetricMatrix3x3
26  @brief Example for a symmetric matric
27  @ingroup g_examples
28  @author woelk 11/2007 (c) www.vision-n.de
29 */
30 
31 #include <Base/Math/SymmetricMatrix3x3.hh>
32 #include <Base/Math/Matrix3x3.hh>
33 
34 #include <fstream>
35 
36 using namespace BIAS;
37 using namespace std;
38 
39 int main(int argc, char *argv[])
40 {
42  Matrix3x3<float> src, dst;
43  // cout << "sizeof(float) = "<<sizeof(float)<<endl
44  // << "sizeof(double) = "<<sizeof(double)<<endl
45  // << "sizeof(SymmetricMatrix3x3<float>) = "
46  // << sizeof(SymmetricMatrix3x3<float>)<<endl
47  // << "sizeof(SymmetricMatrix3x3<double>) = "
48  // << sizeof(SymmetricMatrix3x3<double>)<<endl;
49 
50  for (int r=0; r<3; r++){
51  for (int c=r; c<3; c++){
52  src[r][c] = src[c][r] = (float)(r*3+c);
53  }
54  }
55  cout << "src: "<<src<<endl;
56 
57 
58  sm = src;
59  cout << "symmetric matrix: \n"<< sm << endl;
60 
61  sm.GetMatrix(dst);
62  cout << "dst: "<<dst<<endl;
63 
64  for (int r=0; r<3; r++){
65  for (int c=0; c<3; c++){
66  cout << sm(r,c) << "\t";
67  }
68  cout << endl;
69  }
70 
71  sm(2,1) = 7.0f;
72 
73  cout << "\nafter changing one element: \n" << sm << endl;
74 
75  cout << endl << "writing: \n";
76  for (int r=0; r<3; r++){
77  for (int c=0; c<3; c++){
78  cout << sm(r,c) << "\t";
79  }
80  cout << endl;
81  }
82 
83  string fname = "foo.mat";
84  ofstream of(fname.c_str());
85  if (sm.Write(of)!=0){
86  BIASERR("error writing symmetric matrix");
87  return -1;
88  }
89  of.close();
90 
91  ifstream is(fname.c_str());
92  if (sm2.Read(is)!=0){
93  BIASERR("error reading Symmetric matrix");
94  return -1;
95  }
96  is.close();
97 
98  cout << "read: \n"<<sm2<<endl;
99 
100  return 0;
101 }
int Read(std::istream &is)
int Write(std::ostream &os) const
binary io
is a &#39;fixed size&#39; quadratic matrix of dim.
Definition: Matrix.hh:54
void GetMatrix(Matrix3x3< T > &dst) const
conversion to full matrix
is a &#39;fixed size&#39; symmetric quadratic matrix of dim.