Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Test/VectorTest.cpp

Go to the documentation of this file.
00001 ///////////////////////////////////////////////////////////////////////////
00002 //
00003 // vectst.cpp - Test vector functions
00004 //   Tests the following functions:
00005 //    Add vectors c = a + b
00006 //    Subtract vectors c = a - b
00007 //    Multiply vectors c = a * b
00008 //    Dot product c = sum( a * b )
00009 //    Sum of vector s = sum( a )
00010 //    Scale and copy a vector
00011 //    Comparison ( a == b ) and ( a != b )
00012 //
00013 //   Inputs:
00014 //    None
00015 //
00016 //   Outputs:
00017 //    Print of test vectors and results
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   // Initialize vector with data
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   // Sum of two float vectors
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   // Difference of two float vectors
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   // Product of two float vectors
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   // New vector v4 from subrange of vector v2
00055   Vector<float> v4 = v2( 2, 5 );
00056 
00057   // Offset product of two float vectors
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   // Dot product of two float vectors
00065   float fDot = mult( v1, v2 );
00066   cout << "\nDot product of v1 and v2 = " << fDot << endl;
00067 
00068   // Sum of all elements of a float vector
00069   float fSum = sum( v1 );
00070   cout << "\nSum of v1 = " << fSum << endl;
00071 
00072   // Format floating point numbers
00073   cout.precision( 1 );
00074   cout.setf( ios::fixed, ios::floatfield );
00075 
00076   // Convert a vector to a different type
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   // Scale and convert a vector to a different type
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   // Set elements of a vector to a constant
00092   cout << "\nAll elements of a vector set to 5.0\n";
00093   v2 = 5.0f;
00094   cout << v2;
00095 
00096   // Compare two vectors
00097   v3 = v2;
00098   cout << v3;
00099   cout << ( ( v2 == v3 ) ? "Vectors equal\n" : "Vectors not equal\n" );
00100 
00101   // Change vector slightly
00102   v3[2] = -v3[2];
00103   cout << v3;
00104   cout << ( ( v2 == v3 ) ? "Vectors equal\n" : "Vectors not equal\n" );
00105 
00106   return 0;
00107 }

Generated on Sun Oct 14 18:46:45 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001