| Bsoft 2.0.5 Bernard's software package

Transform.cpp
Go to the documentation of this file.
1
9 #include "Transform.h"
10 #include "Matrix.h"
11 #include "matrix_linear.h"
12 #include "utilities.h"
13
14 // Declaration of global variables
15 extern int verbose; // Level of output to the screen
16
17
30 Transform transform_matrix_solve(Matrix a, vector<double>& bx,
31 vector<double>& by, vector<double>& bz, int flag)
32 {
33 long n(a.rows());
34 int i, j, c;
35 int ft = (n>3)? 1: 0;
36 Matrix3 mat;
37
38 for ( i=0; i<n-1; i++ )
39 for ( j=i+1; j<n; j++ ) a[i][j] = a[j][i];
40
41 c = a.check_for_singularity();
42
43 if ( verbose & VERB_FULL )
44 cout << "Singularity check: " << c << endl;
45
46 if ( verbose & VERB_FULL )
47 cout << a;
48
49 if ( c ) {
50 n--;
51 i = 0;
52 j = c;
53 while ( ( j = j >> 1 ) ) i++; // I'm not sure this works correctly!
54 if ( verbose & VERB_FULL )
55 cout << "Deleting row " << i << endl;
56 a = a.delete_row_column(i);
57 }
58
59 if ( verbose & VERB_FULL )
60 cout << a;
61
62 if ( flag ) a.singular_value_decomposition();
63 else a.LU_decomposition();
64 a.multiply_in_place(bx);
65 a.multiply_in_place(by);
66 a.multiply_in_place(bz);
67
68 if ( verbose & VERB_FULL )
69 cout << a;
70
71 switch ( c ) {
72 case 0:
73 mat = Matrix3(bx[0],bx[1],bx[2],by[0],by[1],by[2],bz[0],bz[1],bz[2]);
74 break;
75 case 1:
76 mat = Matrix3(0,0,1,0,by[1],by[2],0,bz[1],bz[2]);
77 break;
78 case 2:
79 mat = Matrix3(bx[0],0,bx[2],0,1,0,bz[0],0,bz[2]);
80 break;
81 case 4:
82 mat = Matrix3(bx[0],bx[1],0,by[0],by[1],0,0,0,1);
83 break;
84 default: break;
85 }
86
87 // cout << mat << endl;
88 mat.normalize();
89 // cout << mat << endl;
90
91 Transform t(mat);
92
93 if ( ft ) t.trans = Vector3<double>(bx[3], by[3], bz[3]);
94
95 return t;
96 }
97
109 Transform transform_find(int n, Vector3<double>* vector1, Vector3<double>* vector2, int shift)
110 {
111 long m = 3 + shift;
112 long h, i, j;
113 // double bx[4], by[4], bz[4], v[4] = {0,0,0,1};
114 vector<double> bx(4), by(4), bz(4), v(4,0);
115 Matrix a(m,m);
116
117 v[3] = 1;
118
119 for ( i=0; i<4; i++ ) bx[i] = by[i] = bz[i] = 0;
120
121 for ( h=0; h<n; h++ ) {
122 v[0] = vector1[h][0];
123 v[1] = vector1[h][1];
124 v[2] = vector1[h][2];
125 for ( i=0; i<m; i++ ) {
126 bx[i] += v[i]*vector2[h][0];
127 by[i] += v[i]*vector2[h][1];
128 bz[i] += v[i]*vector2[h][2];
129 for ( j=0; j<=i; j++ ) a[i][j] += v[i]*v[j];
130 }
131 }
132
133 return transform_matrix_solve(a, bx, by, bz, 0);
134 }
135
Matrix::rows
long rows()
Definition: Matrix.h:153
Matrix::delete_row_column
Matrix delete_row_column(long rc)
Definition: Matrix.h:173
utilities.h
Header file for general utilities.
Matrix::check_for_singularity
int check_for_singularity()
Definition: Matrix.h:188
Matrix3
Definition: Matrix3.h:17
Transform.h
Class for a generalized transform object.
Matrix.h
Generalized matrix class.
Matrix::singular_value_decomposition
double singular_value_decomposition()
Singular value decomposition of a matrix .
Definition: matrix.cpp:177
verbose
int verbose
Transform
Definition: Transform.h:24
transform_matrix_solve
Transform transform_matrix_solve(Matrix a, vector< double > &bx, vector< double > &by, vector< double > &bz, int flag)
Solves a 3D geometry fit matrix.
Definition: Transform.cpp:30
Transform::trans
Vector3< double > trans
Definition: Transform.h:30
Matrix
Definition: Matrix.h:21
transform_find
Transform transform_find(int n, Vector3< double > *vector1, Vector3< double > *vector2, int shift)
Determines the transformation between two sets of vectors.
Definition: Transform.cpp:109
Matrix3::normalize
void normalize()
Definition: Matrix3.h:294
matrix_linear.h
Header file for matrix functions.
Vector3< double >
VERB_FULL
#define VERB_FULL
Definition: utilities.h:109