00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
#ifndef __UFTR_H__
00011
#define __UFTR_H__
00012
00013
#include <fstream>
00014 void write_matrix(
char *filename, cWtransf &xf )
00015 {
00016 ofstream str(filename);
00017
for(
int i=0;i<16;i++) {
00018
char buf[256];
00019
double val = xf.matrix()[i];
00020 sprintf(buf,
"%10.4lf", val);
00021 str << buf <<
" ";
00022 }
00023 }
00024
00025 int read_matrix(
char *filename, cWtransf &xf )
00026 {
00027 ifstream str(filename);
00028
if (str.bad() || str.fail())
00029
return 0;
00030
00031
for(
int i=0;i<16;i++) {
00032
double val;
00033 str >> val;
00034 *((
double *)xf.matrix()+i) = val;
00035 }
00036
return 1;
00037 }
00038
00039
00040 class UserFriendlyTrackerRegistration
00041 {
00042
protected:
00043 int _done_basic_reg;
00044 int _done_head_reg;
00045
00046 Wtransf
_K;
00047 Wtransf
_sample_basic_C;
00048 Wtransf
_sample_head_D;
00049
00050 Wtransf
_raw_basic;
00051 Wtransf
_raw_head;
00052
00053 Wtransf
_reg_basic;
00054 Wtransf
_reg_head;
00055
00056 Wtransf
_mid_eye;
00057
00058
public:
00059 UserFriendlyTrackerRegistration()
00060 {
00061
_done_basic_reg =
_done_head_reg = 0;
00062
00063
00064
00065
00066
_K = Wtransf::translation(Wvec(0, 0, 1.0 + 1.0/12.0/4.0));
00067 }
00068
00069 int done_basic_registration()
const {
return _done_basic_reg; }
00070 int done_head_registration ()
const {
return _done_head_reg; }
00071
00072
00073 cWtransf &
reg_basic()
const {
return _reg_basic; }
00074 cWtransf &
reg_head()
const {
return _mid_eye; }
00075 cWtransf &
raw_basic()
const {
return _raw_basic; }
00076 cWtransf &
raw_head()
const {
return _raw_head; }
00077
00078 cWtransf &
sample_basic_C()
const {
return _sample_basic_C; }
00079 cWtransf &
sample_head_D() const {
return _sample_head_D; }
00080 cWtransf &
K() const {
return _K; }
00081
00082
00083
00084 void set_K(cWtransf &K) {
_K = K; }
00085
00086
00087 void grab_basic_sample_C()
00088 {
00089
_done_basic_reg = 1;
00090
_sample_basic_C =
_raw_basic;
00091
write_matrix(
".LAST-RUN-basic",
_sample_basic_C);
00092 }
00093
00094
00095 void grab_head_sample_D()
00096 {
00097
_done_head_reg = 1;
00098
_sample_head_D =
_reg_head;
00099
write_matrix(
".LAST-RUN-head",
_sample_head_D);
00100 }
00101
00102 void use_last_runs_registration() {
00103
00104
read_matrix(
".LAST-RUN-basic",
_sample_basic_C);
00105
_done_basic_reg = 1;
00106
read_matrix(
".LAST-RUN-head",
_sample_head_D);
00107
_done_head_reg = 1;
00108 }
00109
00110
00111 void set_raw_basic_tracker_xf(cWtransf &xf)
00112 {
00113
_raw_basic = xf;
00114
00115
if (
_done_basic_reg)
00116
_reg_basic =
register_basic_sample(
_raw_basic);
00117 }
00118
00119
00120 void set_raw_head_tracker_xf(cWtransf &xf)
00121 {
00122
_raw_head = xf;
00123
00124
if (
_done_basic_reg) {
00125
_reg_head =
register_basic_sample(
_raw_head);
00126
00127
if (
_done_head_reg)
00128
_mid_eye =
register_head_sample(
_reg_head);
00129 }
00130 }
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 Wtransf
register_basic_sample(cWtransf &xf)
00142 {
00143
return (
_K *
_sample_basic_C.invert() * xf);
00144 }
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 Wtransf
register_head_sample(cWtransf &xf)
00156 {
00157
00158 Wtransf R =
_sample_head_D;
00159 R(0, 3) = R(1, 3) = R(2, 3) = 0;
00160
00161
00162 Wtransf T = Wtransf::translation(Wvec(
_sample_head_D(0, 3),
00163
_sample_head_D(1, 3),
_sample_head_D(2, 3)));
00164
00165
return (xf * (R.invert() * (
_K * T.invert())));
00166 }
00167 };
00168
00169
#endif // __UFTR_H__