estimateRigidTransform.cpp
Go to the documentation of this file.
00001 /*
00002  * estimateRigidTransform.cpp
00003  *
00004  * Code generation for function 'estimateRigidTransform'
00005  *
00006  * C source code generated on: Wed Jul 24 16:11:35 2013
00007  *
00008  */
00009 
00010 /* Include files */
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 /* Type Definitions */
00021 
00022 /* Named Constants */
00023 
00024 /* Variable Declarations */
00025 
00026 /* Variable Definitions */
00027 
00028 /* Function Declarations */
00029 
00030 /* Function Definitions */
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   /*  ESTIMATERIGIDTRANSFORM */
00060   /*    [T, EPS] = ESTIMATERIGIDTRANSFORM(X, Y) estimates the rigid transformation */
00061   /*    that best aligns x with y (in the least-squares sense). */
00062   /*    */
00063   /*    Reference: "Estimating Rigid Transformations" in  */
00064   /*    "Computer Vision, a modern approach" by Forsyth and Ponce (1993), page 480 */
00065   /*    (page 717(?) of the newer edition) */
00066   /*  */
00067   /*    Input: */
00068   /*        X: 3xN, N 3-D points (N>=3) */
00069   /*        Y: 3xN, N 3-D points (N>=3) */
00070   /*  */
00071   /*    Output */
00072   /*        T: the rigid transformation that aligns x and y as:  xh = T * yh */
00073   /*           (h denotes homogenous coordinates)   */
00074   /*           (corrspondence between points x(:,i) and y(:,i) is assumed) */
00075   /*         */
00076   /*        EPS: the smallest singular value. The closer this value it is  */
00077   /*           to 0, the better the estimate is. (large values mean that the  */
00078   /*           transform between the two data sets cannot be approximated */
00079   /*           well with a rigid transform. */
00080   /*  */
00081   /*    Babak Taati, 2003 */
00082   /*    (revised 2009) */
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   /*  if nargin ~= 2 */
00091   /*      error('Requires two input arguments.') */
00092   /*  end */
00093   /*   */
00094   /*  if size(x,1)~=3 || size(y,1)~=3 */
00095   /*      error('Input point clouds must be a 3xN matrix.'); */
00096   /*  end */
00097   /*   */
00098   /*  if size(x, 2) ~= size(y,2) */
00099   /*      error('Input point clouds must be of the same size'); */
00100   /*  end                             */
00101   /*   */
00102   /*  if size(x,2)<3 || size(y,2)<3 */
00103   /*      error('At least 3 point matches are needed'); */
00104   /*  end                             */
00105   /*  since x has N=3+ points, length shows the number of points */
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   /*  Eps = S(4,4); */
00233 }
00234 
00235 /* End of code generation (estimateRigidTransform.cpp) */


depth_tracker_ros_vr8
Author(s): shusain
autogenerated on Fri Dec 6 2013 20:45:46