Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleSymmetricMatrix3x3.cpp

Example for a symmetric matric

Author
woelk 11/2007 (c) www.vision-n.de
/* This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2003-2009 (see file CONTACT for details)
Multimediale Systeme der Informationsverarbeitung
Institut fuer Informatik
Christian-Albrechts-Universitaet Kiel
BIAS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
BIAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BIAS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
/**
@example ExampleSymmetricMatrix3x3.cpp
@relates SymmetricMatrix3x3
@brief Example for a symmetric matric
@ingroup g_examples
@author woelk 11/2007 (c) www.vision-n.de
*/
#include <Base/Math/SymmetricMatrix3x3.hh>
#include <Base/Math/Matrix3x3.hh>
#include <fstream>
using namespace BIAS;
using namespace std;
int main(int argc, char *argv[])
{
Matrix3x3<float> src, dst;
// cout << "sizeof(float) = "<<sizeof(float)<<endl
// << "sizeof(double) = "<<sizeof(double)<<endl
// << "sizeof(SymmetricMatrix3x3<float>) = "
// << sizeof(SymmetricMatrix3x3<float>)<<endl
// << "sizeof(SymmetricMatrix3x3<double>) = "
// << sizeof(SymmetricMatrix3x3<double>)<<endl;
for (int r=0; r<3; r++){
for (int c=r; c<3; c++){
src[r][c] = src[c][r] = (float)(r*3+c);
}
}
cout << "src: "<<src<<endl;
sm = src;
cout << "symmetric matrix: \n"<< sm << endl;
sm.GetMatrix(dst);
cout << "dst: "<<dst<<endl;
for (int r=0; r<3; r++){
for (int c=0; c<3; c++){
cout << sm(r,c) << "\t";
}
cout << endl;
}
sm(2,1) = 7.0f;
cout << "\nafter changing one element: \n" << sm << endl;
cout << endl << "writing: \n";
for (int r=0; r<3; r++){
for (int c=0; c<3; c++){
cout << sm(r,c) << "\t";
}
cout << endl;
}
string fname = "foo.mat";
ofstream of(fname.c_str());
if (sm.Write(of)!=0){
BIASERR("error writing symmetric matrix");
return -1;
}
of.close();
ifstream is(fname.c_str());
if (sm2.Read(is)!=0){
BIASERR("error reading Symmetric matrix");
return -1;
}
is.close();
cout << "read: \n"<<sm2<<endl;
return 0;
}