Subversion Repositories gelsvn

Rev

Rev 417 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 417 Rev 596
1
#include <iostream>
1
#include <iostream>
2
 
2
 
3
#include "CGLA/Vec3f.h"
3
#include "CGLA/Vec3f.h"
4
#include "CGLA/Mat3x3f.h"
4
#include "CGLA/Mat3x3f.h"
5
#include "CGLA/statistics.h"
5
#include "CGLA/statistics.h"
6
#include "CGLA/eigensolution.h"
6
#include "CGLA/eigensolution.h"
7
 
7
 
8
using namespace std;
8
using namespace std;
9
using namespace CGLA;
9
using namespace CGLA;
10
 
10
 
11
 
11
 
12
float frand() { return static_cast<float>(gel_rand())/GEL_RAND_MAX - 0.5f;}
12
float frand() { return static_cast<float>(gel_rand())/GEL_RAND_MAX - 0.5f;}
13
 
13
 
14
/* This is a non-exhaustive test program for CGLA */
14
/* This is a non-exhaustive test program for CGLA */
15
int main()
15
int main()
16
{
16
{
17
    Vec3f norm(1,0,0);
17
    Vec3f norm(1,0,0);
18
    norm.normalize();
18
    norm.normalize();
19
    
19
    
20
    Vec3f a,b;
20
    Vec3f a,b;
21
    orthogonal(norm,a,b);
21
    orthogonal(norm,a,b);
22
    
22
    
23
    cout << "The frame " << endl;
23
    cout << "The frame " << endl;
24
    cout << norm << a << b << endl;
24
    cout << norm << a << b << endl;
25
    
25
    
26
    vector<Vec3f> vec;
26
    vector<Vec3f> vec;
27
    gel_srand(0);
27
    gel_srand(0);
28
    for(int i=0;i<100000;++i)
28
    for(int i=0;i<100000;++i)
29
    {
29
    {
30
	Vec3f p = 1.0f*frand()*norm + 2.02f*frand()*a + 3.05f*frand()*b;
30
	Vec3f p = 1.0f*frand()*norm + 2.02f*frand()*a + 3.05f*frand()*b;
31
	vec.push_back(p);
31
	vec.push_back(p);
32
    }
32
    }
33
    
33
    
34
    Mat3x3f A(0);
34
    Mat3x3f A(0);
35
    Vec3f m = covariance(vec, A);
35
    Vec3f m = covariance(vec, A);
36
    
36
    
37
    cout << "Mean and covariance " << endl;
37
    cout << "Mean and covariance " << endl;
38
    cout << m << "\n" << A << endl;
38
    cout << m << "\n" << A << endl;
39
    
39
    
40
    
40
    
41
    Mat3x3f Q,L;
41
    Mat3x3f Q,L;
42
    int n = power_eigensolution(A, Q, L);
42
    int n = power_eigensolution(A, Q, L);
43
    
43
    
44
    cout << "The " << n << " eigensolutions are ";
44
    cout << "The " << n << " eigensolutions are ";
45
    cout << Q << L << endl;
45
    cout << Q << L << endl;
46
    
46
    
47
    cout << "Dot products " 
47
    cout << "Dot products " 
48
	<< dot(Q[0], Q[1]) << " "
48
	<< dot(Q[0], Q[1]) << " "
49
	<< dot(Q[0], Q[2]) << " " 
49
	<< dot(Q[0], Q[2]) << " " 
50
	<< dot(Q[1], Q[2]) << endl;
50
	<< dot(Q[1], Q[2]) << endl;
-
 
51
    
-
 
52
    cout << "Now with identity" << endl;
-
 
53
    A = identity_Mat3x3f();
-
 
54
    n = power_eigensolution(A, Q, L);
-
 
55
    cout << "The " << n << " eigensolutions are ";
-
 
56
    cout << Q << L << endl;
-
 
57
    
-
 
58
    cout << "Dot products " 
-
 
59
	<< dot(Q[0], Q[1]) << " "
-
 
60
	<< dot(Q[0], Q[2]) << " " 
-
 
61
	<< dot(Q[1], Q[2]) << endl;
51
 
62
 
52
	return 0;
63
	return 0;
53
}
64
}
54
 
65