test_points.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  */
30 
39 #include <ar_track_alvar/kinect_filtering.h>
40 #include <fstream>
41 
42 namespace a=ar_track_alvar;
43 namespace gm=geometry_msgs;
44 
45 using std::cerr;
46 using std::ifstream;
47 
48 // Random float between a and b
49 float randFloat (float a, float b)
50 {
51  const float u = static_cast<float>(rand())/RAND_MAX;
52  return a + u*(b-a);
53 }
54 
55 // Generate points in a square in space of form p+av+bw where
56 // a and b range from 0 to 1
57 a::ARCloud::Ptr generateCloud(const double px, const double py, const double pz,
58  const double vx, const double vy, const double vz,
59  const double wx, const double wy, const double wz)
60 {
61  const double INC=0.1;
62  const double NOISE=0.01;
63 
64  a::ARCloud::Ptr cloud(boost::make_shared<a::ARCloud>());
65  for (double u=0; u<1+INC/2; u+=INC)
66  {
67  for (double v=0; v<1+INC/2; v+=INC)
68  {
69  a::ARPoint p;
70  p.x = px+u*vx+v*wx+randFloat(-NOISE, NOISE);
71  p.y = py+u*vy+v*wy+randFloat(-NOISE, NOISE);
72  p.z = pz+u*vz+v*wz+randFloat(-NOISE, NOISE);
73  cloud->points.push_back(p);
74  }
75  }
76  return cloud;
77 }
78 
79 int main (int argc, char** argv)
80 {
81  ros::init(argc, argv, "test_points");
82  ifstream f("points");
83  a::ARCloud::Ptr cloud(new a::ARCloud());
84  while (!f.eof())
85  {
86  a::ARPoint pt;
87  f >> pt.x >> pt.y >> pt.z;
88  cloud->points.push_back(pt);
89  }
90  ROS_INFO("Cloud has %zu points such as (%.2f, %.2f, %.2f)",
91  cloud->points.size(), cloud->points[0].x, cloud->points[0].y,
92  cloud->points[0].z);
93  a::ARPoint p1, p2, p3;
94  p1.x = 0.1888;
95  p1.y = 0.1240;
96  p1.z = 0.8620;
97  p2.x = 0.0372;
98  p2.y = 0.1181;
99  p2.z = 0.8670;
100  p3.x = 42;
101  p3.y = 24;
102  p3.z = 88;
103 
105  ROS_INFO("Plane equation is %.3fx + %.3fy + %.3fz + %.3f = 0",
106  res.coeffs.values[0], res.coeffs.values[1], res.coeffs.values[2],
107  res.coeffs.values[3]);
108 
109  gm::Quaternion q = a::extractOrientation(res.coeffs, p1, p2, p3, p1);
110  ROS_INFO_STREAM("Orientation is " << q);
111  return 0;
112 }
pcl::PointXYZRGB ARPoint
pcl::PointCloud< ARPoint > ARCloud
int main(int argc, char **argv)
Definition: test_points.cpp:79
f
int extractOrientation(const pcl::ModelCoefficients &coeffs, const ARPoint &p1, const ARPoint &p2, const ARPoint &p3, const ARPoint &p4, geometry_msgs::Quaternion &retQ)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
float randFloat(float a, float b)
Definition: test_points.cpp:49
#define ROS_INFO(...)
#define ROS_INFO_STREAM(args)
pcl::ModelCoefficients coeffs
const int res
a::ARCloud::Ptr generateCloud(const double px, const double py, const double pz, const double vx, const double vy, const double vz, const double wx, const double wy, const double wz)
Definition: test_points.cpp:57
PlaneFitResult fitPlane(ARCloud::ConstPtr cloud)


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Mon Jun 10 2019 12:47:04