Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00039 #include <ar_track_alvar/kinect_filtering.h>
00040 #include <fstream>
00041
00042 namespace a=ar_track_alvar;
00043 namespace gm=geometry_msgs;
00044
00045 using std::cerr;
00046 using std::ifstream;
00047
00048
00049 float randFloat (float a, float b)
00050 {
00051 const float u = static_cast<float>(rand())/RAND_MAX;
00052 return a + u*(b-a);
00053 }
00054
00055
00056
00057 a::ARCloud::Ptr generateCloud(const double px, const double py, const double pz,
00058 const double vx, const double vy, const double vz,
00059 const double wx, const double wy, const double wz)
00060 {
00061 const double INC=0.1;
00062 const double NOISE=0.01;
00063
00064 a::ARCloud::Ptr cloud(boost::make_shared<a::ARCloud>());
00065 for (double u=0; u<1+INC/2; u+=INC)
00066 {
00067 for (double v=0; v<1+INC/2; v+=INC)
00068 {
00069 a::ARPoint p;
00070 p.x = px+u*vx+v*wx+randFloat(-NOISE, NOISE);
00071 p.y = py+u*vy+v*wy+randFloat(-NOISE, NOISE);
00072 p.z = pz+u*vz+v*wz+randFloat(-NOISE, NOISE);
00073 cloud->points.push_back(p);
00074 }
00075 }
00076 return cloud;
00077 }
00078
00079 int main (int argc, char** argv)
00080 {
00081 ros::init(argc, argv, "test_points");
00082 ifstream f("points");
00083 a::ARCloud::Ptr cloud(new a::ARCloud());
00084 while (!f.eof())
00085 {
00086 a::ARPoint pt;
00087 f >> pt.x >> pt.y >> pt.z;
00088 cloud->points.push_back(pt);
00089 }
00090 ROS_INFO("Cloud has %zu points such as (%.2f, %.2f, %.2f)",
00091 cloud->points.size(), cloud->points[0].x, cloud->points[0].y,
00092 cloud->points[0].z);
00093 a::ARPoint p1, p2, p3;
00094 p1.x = 0.1888;
00095 p1.y = 0.1240;
00096 p1.z = 0.8620;
00097 p2.x = 0.0372;
00098 p2.y = 0.1181;
00099 p2.z = 0.8670;
00100 p3.x = 42;
00101 p3.y = 24;
00102 p3.z = 88;
00103
00104 a::PlaneFitResult res = a::fitPlane(cloud);
00105 ROS_INFO("Plane equation is %.3fx + %.3fy + %.3fz + %.3f = 0",
00106 res.coeffs.values[0], res.coeffs.values[1], res.coeffs.values[2],
00107 res.coeffs.values[3]);
00108
00109 gm::Quaternion q = a::extractOrientation(res.coeffs, p1, p2, p3, p1);
00110 ROS_INFO_STREAM("Orientation is " << q);
00111 return 0;
00112 }