Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "rt_nonfinite.h"
00012 #include "Optimal_affine_tracking_3d16_fast_realtime.h"
00013 #include "estimateRigidTransform.h"
00014 #include "quat2rot.h"
00015 #include "eye.h"
00016 #include "svd.h"
00017 #include "crossTimesMatrix.h"
00018 #include "sum.h"
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 void estimateRigidTransform(const real_T x[3888], const real_T y[3888], real_T
00032 T[16])
00033 {
00034 static real_T b_x[3888];
00035 static real_T b_y[3888];
00036 int32_T i12;
00037 int32_T i13;
00038 real_T x_centroid[3];
00039 real_T y_centroid[3];
00040 real_T x_centrized[3888];
00041 real_T y_centrized[3888];
00042 real_T b_y_centrized[3888];
00043 static real_T R22[11664];
00044 real_T B[16];
00045 static real_T A[20736];
00046 int32_T ii;
00047 real_T d2;
00048 int32_T i14;
00049 real_T b_B[16];
00050 real_T V[16];
00051 real_T unusedU1[16];
00052 real_T dv6[9];
00053 real_T dv7[9];
00054 real_T dv8[9];
00055 static const int8_T iv6[4] = { 0, 0, 0, 1 };
00056
00057 real_T dv9[16];
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 for (i12 = 0; i12 < 1296; i12++) {
00084 for (i13 = 0; i13 < 3; i13++) {
00085 b_x[i13 + 3 * i12] = x[i12 + 1296 * i13];
00086 b_y[i13 + 3 * i12] = y[i12 + 1296 * i13];
00087 }
00088 }
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 sum(b_x, x_centroid);
00107 sum(b_y, y_centroid);
00108 for (i12 = 0; i12 < 3; i12++) {
00109 y_centroid[i12] /= 1296.0;
00110 x_centroid[i12] /= 1296.0;
00111 }
00112
00113 for (i12 = 0; i12 < 1296; i12++) {
00114 x_centrized[3 * i12] = b_x[3 * i12] - x_centroid[0];
00115 x_centrized[1 + 3 * i12] = b_x[1 + 3 * i12] - x_centroid[1];
00116 x_centrized[2 + 3 * i12] = b_x[2 + 3 * i12] - x_centroid[2];
00117 y_centrized[3 * i12] = b_y[3 * i12] - y_centroid[0];
00118 y_centrized[1 + 3 * i12] = b_y[1 + 3 * i12] - y_centroid[1];
00119 y_centrized[2 + 3 * i12] = b_y[2 + 3 * i12] - y_centroid[2];
00120 }
00121
00122 for (i12 = 0; i12 < 3; i12++) {
00123 for (i13 = 0; i13 < 1296; i13++) {
00124 b_y[i13 + 1296 * i12] = y_centrized[i12 + 3 * i13] - x_centrized[i12 + 3 *
00125 i13];
00126 }
00127 }
00128
00129 for (i12 = 0; i12 < 3888; i12++) {
00130 b_x[i12] = x_centrized[i12] - y_centrized[i12];
00131 b_y_centrized[i12] = y_centrized[i12] + x_centrized[i12];
00132 }
00133
00134 crossTimesMatrix(b_y_centrized, R22);
00135 memset(&B[0], 0, sizeof(real_T) << 4);
00136 memset(&A[0], 0, 20736U * sizeof(real_T));
00137 for (ii = 0; ii < 1296; ii++) {
00138 A[ii << 4] = 0.0;
00139 for (i12 = 0; i12 < 3; i12++) {
00140 A[((i12 + 1) << 2) + (ii << 4)] = b_y[ii + 1296 * i12];
00141 }
00142
00143 for (i12 = 0; i12 < 3; i12++) {
00144 A[(i12 + (ii << 4)) + 1] = b_x[i12 + 3 * ii];
00145 }
00146
00147 for (i12 = 0; i12 < 3; i12++) {
00148 for (i13 = 0; i13 < 3; i13++) {
00149 A[((i13 + ((i12 + 1) << 2)) + (ii << 4)) + 1] = R22[(i13 + 3 * i12) + 9 *
00150 ii];
00151 }
00152 }
00153
00154 for (i12 = 0; i12 < 4; i12++) {
00155 for (i13 = 0; i13 < 4; i13++) {
00156 d2 = 0.0;
00157 for (i14 = 0; i14 < 4; i14++) {
00158 d2 += A[(i14 + (i12 << 2)) + (ii << 4)] * A[(i14 + (i13 << 2)) + (ii <<
00159 4)];
00160 }
00161
00162 B[i12 + (i13 << 2)] += d2;
00163 }
00164 }
00165 }
00166
00167 memcpy(&b_B[0], &B[0], sizeof(real_T) << 4);
00168 svd(b_B, B, unusedU1, V);
00169 b_eye(dv6);
00170 b_eye(dv7);
00171 quat2rot(*(real_T (*)[4])&V[12], dv8);
00172 for (i12 = 0; i12 < 3; i12++) {
00173 for (i13 = 0; i13 < 3; i13++) {
00174 unusedU1[i13 + (i12 << 2)] = dv7[i13 + 3 * i12];
00175 }
00176 }
00177
00178 for (i12 = 0; i12 < 3; i12++) {
00179 unusedU1[12 + i12] = x_centroid[i12];
00180 }
00181
00182 for (i12 = 0; i12 < 4; i12++) {
00183 unusedU1[3 + (i12 << 2)] = (real_T)iv6[i12];
00184 }
00185
00186 for (i12 = 0; i12 < 3; i12++) {
00187 for (i13 = 0; i13 < 3; i13++) {
00188 V[i13 + (i12 << 2)] = dv8[i13 + 3 * i12];
00189 }
00190 }
00191
00192 for (i12 = 0; i12 < 3; i12++) {
00193 V[12 + i12] = 0.0;
00194 }
00195
00196 for (i12 = 0; i12 < 4; i12++) {
00197 V[3 + (i12 << 2)] = (real_T)iv6[i12];
00198 }
00199
00200 for (i12 = 0; i12 < 4; i12++) {
00201 for (i13 = 0; i13 < 4; i13++) {
00202 dv9[i12 + (i13 << 2)] = 0.0;
00203 for (i14 = 0; i14 < 4; i14++) {
00204 dv9[i12 + (i13 << 2)] += unusedU1[i12 + (i14 << 2)] * V[i14 + (i13 << 2)];
00205 }
00206 }
00207 }
00208
00209 for (i12 = 0; i12 < 3; i12++) {
00210 for (i13 = 0; i13 < 3; i13++) {
00211 unusedU1[i13 + (i12 << 2)] = dv6[i13 + 3 * i12];
00212 }
00213 }
00214
00215 for (i12 = 0; i12 < 3; i12++) {
00216 unusedU1[12 + i12] = -y_centroid[i12];
00217 }
00218
00219 for (i12 = 0; i12 < 4; i12++) {
00220 unusedU1[3 + (i12 << 2)] = (real_T)iv6[i12];
00221 }
00222
00223 for (i12 = 0; i12 < 4; i12++) {
00224 for (i13 = 0; i13 < 4; i13++) {
00225 T[i12 + (i13 << 2)] = 0.0;
00226 for (i14 = 0; i14 < 4; i14++) {
00227 T[i12 + (i13 << 2)] += dv9[i12 + (i14 << 2)] * unusedU1[i14 + (i13 << 2)];
00228 }
00229 }
00230 }
00231
00232
00233 }
00234
00235