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

Example for Vector and Matrix operators

, Matrix

Author
MIP
/*
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 ExampleOperators.cpp
@relates Vector, Matrix
@brief Example for Vector and Matrix operators
@ingroup g_examples
@author MIP
*/
#include <Base/Math/Vector.hh>
#include <Base/Math/Matrix.hh>
#include <Base/Math/Vector2.hh>
#include <Base/Math/Vector3.hh>
#include <Base/Math/Vector4.hh>
#include <Base/Math/Matrix2x2.hh>
#include <Base/Math/Matrix3x3.hh>
#include <Base/Math/Matrix3x4.hh>
#include <Base/Math/Matrix4x4.hh>
using namespace std;
using namespace BIAS;
int main()
{
Vector<double> rvec, vec(5, "1.0 2.0 3.0 4.0 5.0");
Vector2<double> rvec2, vec2(1.0, 2.0);
Vector3<double> rvec3, vec3(1.0, 2.0, 3.0);
Vector4<double> rvec4, vec4(1.0, 2.0, 3.0, 4.0);
Matrix<double> mat(5, 5), rmat;
Matrix<double> mat22(2, 2, "1 2 3 4"); // string ctor
mat.SetIdentity();
mat22.SetIdentity();
Matrix2x2<double> mat2x2("1.0, 2.0, 3.0, 4.0"); // string ctor
Matrix3x3<double> mat3x3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
Matrix3x4<double> mat3x4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0);
mat4x4.SetIdentity();
//double rd;
// test the operators in Matrix.hh
rmat = mat + 6.0;
rmat = 6.0 + mat;
rmat = mat - 6.0;
rmat = 6.0 - mat;
rmat = mat * 2.0;
rmat = 2.0 * mat;
rmat = mat / 2.0;
mat += 3.0;
mat -= 3.0;
mat *= 3.0;
mat /= 1.4;
if (rmat==mat)
cout <<"rmat==mat" <<endl;
if (rmat!=mat)
cout <<"rmat!=mat" <<endl;
rmat = mat;
if (rmat==mat)
cout <<"rmat==mat and that is ok" <<endl;
rvec = mat * vec;
rvec2 = mat2x2 * vec2;
rvec2 = mat22 * vec2;
rvec = mat22 * vec2;
rvec2 = vec2 + 2.0;
rvec2 = vec2 - 2.0;
rvec2 = vec2 * 2.0;
rvec2 = vec2 / 2.0;
rvec2 += 2.0;
rvec2 -= 2.0;
rvec2 *= 2.0;
rvec2 /= 2.0;
rvec2 = vec2 + vec2;
rvec2 = vec2 - vec2;
//rd = vec2 * vec2;
rvec2 += vec2;
rvec2 -= vec2;
return 0;
}