00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <j2k/Fred/Math/Vector.hpp>
00021
00022 #error "Not Working Yet! Test to be modified"
00023
00024 int main()
00025 {
00026
00027 static float x[] = { 9.0f, 8.0f, 7.0f, 6.0f, 5.0f };
00028 static float y[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f };
00029 Vector<float> v1( ELEMENTS(x), x );
00030 Vector<float> v2( ELEMENTS(y), y );
00031 Vector<float> v3;
00032
00033
00034 v3 = add( v1, v2 );
00035 cout << "Vector sum: v3 = v1 + v2\n";
00036 cout << "v1 v2 v3\n";
00037 for( int i = 0 ; i < v3.length(); i++ )
00038 cout << v1[i] << " " << v2[i] << " " << v3[i] << endl;
00039
00040
00041 v3 = sub( v1, v2 );
00042 cout << "\nVector subtract: v3 = v1 - v2\n";
00043 cout << "v1 v2 v3\n";
00044 for( i = 0 ; i < v3.length(); i++ )
00045 cout << v1[i] << " " << v2[i] << " " << v3[i] << endl;
00046
00047
00048 v3 = pwisemult( v1, v2 );
00049 cout << "\nVector product: v3 = v1 * v2\n";
00050 cout << "v1 v2 v3\n";
00051 for( i = 0 ; i < v3.length(); i++ )
00052 cout << v1[i] << " " << v2[i] << " " << v3[i] << endl;
00053
00054
00055 Vector<float> v4 = v2( 2, 5 );
00056
00057
00058 v3 = pwisemult( v1, v4 );
00059 cout << "\nVector product: v3 = v1 * v4\n";
00060 cout << "v1 v4 v3\n";
00061 for( i = 0 ; i < v3.length(); i++ )
00062 cout << v1[i] << " " << v4[i] << " " << v3[i] << endl;
00063
00064
00065 float fDot = mult( v1, v2 );
00066 cout << "\nDot product of v1 and v2 = " << fDot << endl;
00067
00068
00069 float fSum = sum( v1 );
00070 cout << "\nSum of v1 = " << fSum << endl;
00071
00072
00073 cout.precision( 1 );
00074 cout.setf( ios::fixed, ios::floatfield );
00075
00076
00077 Vector<int> vInt( v1.length() );
00078 conv( vInt, v1 );
00079 cout << "\nConvert float to int: vInt = v1\n";
00080 cout << "v1 vInt\n";
00081 for( i = 0 ; i < vInt.length(); i++ )
00082 cout << v1[i] << " " << vInt[i] << endl;
00083
00084
00085 conv( vInt, scale( 0.5, v1 ) );
00086 cout << "\nScale and convert float to int: vInt = 0.5 * v1\n";
00087 cout << "v1 vInt\n";
00088 for( i = 0 ; i < vInt.length(); i++ )
00089 cout << v1[i] << " " << vInt[i] << endl;
00090
00091
00092 cout << "\nAll elements of a vector set to 5.0\n";
00093 v2 = 5.0f;
00094 cout << v2;
00095
00096
00097 v3 = v2;
00098 cout << v3;
00099 cout << ( ( v2 == v3 ) ? "Vectors equal\n" : "Vectors not equal\n" );
00100
00101
00102 v3[2] = -v3[2];
00103 cout << v3;
00104 cout << ( ( v2 == v3 ) ? "Vectors equal\n" : "Vectors not equal\n" );
00105
00106 return 0;
00107 }