Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleOperators.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 /**
26  @example ExampleOperators.cpp
27  @relates Vector, Matrix
28  @brief Example for Vector and Matrix operators
29  @ingroup g_examples
30  @author MIP
31 */
32 
33 #include <Base/Math/Vector.hh>
34 #include <Base/Math/Matrix.hh>
35 #include <Base/Math/Vector2.hh>
36 #include <Base/Math/Vector3.hh>
37 #include <Base/Math/Vector4.hh>
38 #include <Base/Math/Matrix2x2.hh>
39 #include <Base/Math/Matrix3x3.hh>
40 #include <Base/Math/Matrix3x4.hh>
41 #include <Base/Math/Matrix4x4.hh>
42 
43 using namespace std;
44 using namespace BIAS;
45 
46 int main()
47 {
48  Vector<double> rvec, vec(5, "1.0 2.0 3.0 4.0 5.0");
49  Vector2<double> rvec2, vec2(1.0, 2.0);
50  Vector3<double> rvec3, vec3(1.0, 2.0, 3.0);
51  Vector4<double> rvec4, vec4(1.0, 2.0, 3.0, 4.0);
52  Matrix<double> mat(5, 5), rmat;
53  Matrix<double> mat22(2, 2, "1 2 3 4"); // string ctor
54  mat.SetIdentity();
55  mat22.SetIdentity();
56  Matrix2x2<double> mat2x2("1.0, 2.0, 3.0, 4.0"); // string ctor
57  Matrix3x3<double> mat3x3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
58  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);
59 
60  Matrix4x4<double> mat4x4;
61  mat4x4.SetIdentity();
62  //double rd;
63 
64  // test the operators in Matrix.hh
65  rmat = mat + 6.0;
66  rmat = 6.0 + mat;
67  rmat = mat - 6.0;
68  rmat = 6.0 - mat;
69  rmat = mat * 2.0;
70  rmat = 2.0 * mat;
71  rmat = mat / 2.0;
72  mat += 3.0;
73  mat -= 3.0;
74  mat *= 3.0;
75  mat /= 1.4;
76  if (rmat==mat)
77  cout <<"rmat==mat" <<endl;
78  if (rmat!=mat)
79  cout <<"rmat!=mat" <<endl;
80 
81  rmat = mat;
82  if (rmat==mat)
83  cout <<"rmat==mat and that is ok" <<endl;
84 
85 
86  rvec = mat * vec;
87 
88  rvec2 = mat2x2 * vec2;
89  rvec2 = mat22 * vec2;
90  rvec = mat22 * vec2;
91 
92  rvec2 = vec2 + 2.0;
93  rvec2 = vec2 - 2.0;
94  rvec2 = vec2 * 2.0;
95  rvec2 = vec2 / 2.0;
96 
97  rvec2 += 2.0;
98  rvec2 -= 2.0;
99  rvec2 *= 2.0;
100  rvec2 /= 2.0;
101 
102  rvec2 = vec2 + vec2;
103  rvec2 = vec2 - vec2;
104  //rd = vec2 * vec2;
105 
106  rvec2 += vec2;
107  rvec2 -= vec2;
108 
109  return 0;
110 }
class Vector4 contains a Vector of dim.
Definition: Vector4.hh:65
void SetIdentity()
set the elements of this matrix to the identity matrix (posisbly overriding the inherited method) ...
Definition: Matrix4x4.hh:260