icp_utils.cpp
Go to the documentation of this file.
00001 /*
00002  * icp_utils.cpp
00003  *
00004  *  Created on: Feb 15, 2010
00005  *      Author: sturm
00006  */
00007 
00008 #include "icp/icp_utils.h"
00009 
00010 namespace icp {
00011 
00012 inline void multiply(double TR[9], double TT[3], geometry_msgs::Pose &track) {
00013         double x = track.position.x;
00014         double y = track.position.y;
00015         double z = track.position.z;
00016         track.position.x = TR[0] * x + TR[3] * y + TR[6] * z + TT[0];
00017         track.position.y = TR[1] * x + TR[4] * y + TR[7] * z + TT[1];
00018         track.position.z = TR[2] * x + TR[5] * y + TR[8] * z + TT[2];
00019 }
00020 
00021 TrajData::TrajData(const articulation_msgs::TrackMsg &track) {
00022         n = track.pose.size();
00023         points = new double[3 * n];
00024         pointsT = new double[3 * n];
00025         weights = new double[3 * n];
00026         index = new int[n];
00027         randvec = new unsigned int[n];
00028         std::vector<int> list;
00029         list.resize(n);
00030         for (size_t i = 0; i < n; i++) {
00031                 list[i] = i;
00032         }
00033         random_shuffle(list.begin(), list.end());
00034         for (size_t i = 0; i < n; i++) {
00035                 points[i + 0 * n] = track.pose[i].position.x;
00036                 points[i + 1 * n] = track.pose[i].position.y;
00037                 points[i + 2 * n] = track.pose[i].position.z;
00038                 pointsT[i * 3 + 0] = track.pose[i].position.x;
00039                 pointsT[i * 3 + 1] = track.pose[i].position.y;
00040                 pointsT[i * 3 + 2] = track.pose[i].position.z;
00041                 weights[i] = 1;
00042                 index[i] = i;
00043                 randvec[i] = list[i];
00044                 //printf("%d ",randvec[i]);
00045         }
00046 }
00047 
00048 TrajData::~TrajData() {
00049         delete points;
00050         delete weights;
00051         delete index;
00052 }
00053 
00054 IcpAlign::IcpAlign(const articulation_msgs::TrackMsg &track_model,
00055                 const articulation_msgs::TrackMsg &track_data, int iter) :
00056         model(track_model), data(track_data), iter(iter), tree(NULL) {
00057         tree = icp::build_kdtree(model.points, model.n, 3, model.index, model.n, 0);
00058         icp::icp(TR, TT, model.pointsT, model.n, data.pointsT, data.weights,
00059                         data.n, data.randvec, data.n, data.n * 1.45, iter, tree);
00060 }
00061 
00062 IcpAlign::~IcpAlign() {
00063         icp::free_tree(tree->rootptr);
00064 }
00065 
00066 void IcpAlign::TransformData(articulation_msgs::TrackMsg &track_data_aligned) {
00067         for (size_t i = 0; i < track_data_aligned.pose.size(); i++) {
00068                 multiply(TR, TT, track_data_aligned.pose[i]);
00069         }
00070 }
00071 
00072 void IcpAlign::TransformModel(articulation_msgs::TrackMsg &track_model_aligned) {
00073         double TR2[9];
00074         double TT2[3];
00075         for (int r = 0; r < 3; r++) {
00076                 TT2[r] = 0;
00077                 for (int c = 0; c < 3; c++) {
00078                         TR2[r * 3 + c] = TR[c * 3 + r];
00079                 }
00080         }
00081         for (int r = 0; r < 3; r++) {
00082                 for (int c = 0; c < 3; c++) {
00083                         TT2[r] += TR[r * 3 + c] * (-TT[c]);
00084                 }
00085         }
00086         for (size_t i = 0; i < track_model_aligned.pose.size(); i++) {
00087                 multiply(TR2, TT2, track_model_aligned.pose[i]);
00088         }
00089 }
00090 
00091 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


icp
Author(s): Maintained by Juergen Sturm
autogenerated on Wed Dec 26 2012 15:34:47