$search
00001 /* 00002 * test.cpp 00003 * 00004 * Created on: 16.03.2012 00005 * Author: josh 00006 */ 00007 00008 #include "ros/ros.h" 00009 #include <pcl/point_types.h> 00010 #include <pcl/point_cloud.h> 00011 #include <pcl/ros/conversions.h> 00012 #ifdef PCL_VERSION_COMPARE 00013 #include <pcl/common/transforms.h> 00014 #else 00015 #include <pcl/common/transform.h> 00016 #endif 00017 #include <sensor_msgs/PointCloud2.h> 00018 00019 #include <cob_3d_mapping_msgs/ShapeArray.h> 00020 #include <cob_3d_mapping_msgs/Shape.h> 00021 00022 #include <ros/time.h> 00023 00024 #include <boost/shared_ptr.hpp> 00025 00026 00027 int main(int argc, char **argv) { 00028 00029 00030 00031 00032 00033 ros::init(argc, argv, "talker"); 00034 ros::NodeHandle n; 00035 ros::Publisher pub = n.advertise<cob_3d_mapping_msgs::ShapeArray>("/segmentation/shape_array",1); 00036 00037 ros::Rate loop_rate(1); 00038 00039 int number_shapes=10; 00040 if(argc==2) 00041 { 00042 number_shapes = atoi(argv[1]); 00043 std::cout<<"Publishing map with "<<number_shapes<<" shapes.\n"; 00044 } 00045 else 00046 { 00047 std::cout<<"WARNING: Use number of shapes in map as input argument.(Using default value 10) \n"; 00048 } 00049 00050 00051 float x_shift,y_shift,z_shift; 00052 00053 x_shift=-0.5; 00054 y_shift=-0.5; 00055 z_shift=-0.5; 00056 00057 00058 int runner = 1; 00059 //while(ros::ok()) { 00060 for(int k=0;k<2;++k){ 00061 00062 cob_3d_mapping_msgs::ShapeArray sa; 00063 sa.header.frame_id="/map"; 00064 00065 for(int i =0 ;i<number_shapes;i++) 00066 { 00067 00068 // Transform shape with pcl:: transformation 00069 Eigen::Affine3f transform ; 00070 Eigen::Vector3f u1,u2,o; 00071 00072 u1<<0,1,0; 00073 u2<<0,0,1; 00074 o<<i*x_shift,i*y_shift,i*z_shift; 00075 pcl::getTransformationFromTwoUnitVectorsAndOrigin(u1,u2,o,transform); 00076 00077 00078 cob_3d_mapping_msgs::Shape s; 00079 //transform parameters 00080 Eigen::Vector3f normal,centroid; 00081 double d; 00082 00083 normal << 0, 0, 1; 00084 normal= transform.rotation() * normal; 00085 00086 centroid << 1, 1, 1; 00087 centroid =transform * centroid; 00088 00089 d= 0; 00090 d=fabs(centroid.dot(normal)); 00091 00092 00093 // put params to shape msg 00094 s.params.push_back(normal[0]); 00095 s.params.push_back(normal[1]); 00096 s.params.push_back(normal[2]); 00097 s.params.push_back(d); 00098 s.centroid.x = centroid[0]; 00099 s.centroid.y = centroid[1]; 00100 s.centroid.z = centroid[2]; 00101 s.header.frame_id="/map"; 00102 00103 s.color.r = 0; 00104 s.color.g = 1; 00105 s.color.b = 0; 00106 s.color.a = 1; 00107 00108 pcl::PointCloud<pcl::PointXYZ> pc; 00109 pcl::PointXYZ pt; 00110 00111 pt.x=0; 00112 pt.y=0; 00113 pt.z=0; 00114 pc.push_back(pt); 00115 00116 pt.x=1; 00117 pt.y=0; 00118 pt.z=0; 00119 pc.push_back(pt); 00120 00121 pt.x=1; 00122 pt.y=2; 00123 pt.z=0; 00124 pc.push_back(pt); 00125 00126 pt.x=0; 00127 pt.y=2; 00128 pt.z=0; 00129 pc.push_back(pt); 00130 00131 pt.x=0.5; 00132 pt.y=1; 00133 pt.z=0; 00134 pc.push_back(pt); 00135 00136 00137 00138 //transform poincloud 00139 pcl::getTransformedPointCloud(pc,transform,pc); 00140 00141 sensor_msgs::PointCloud2 pc2; 00142 pcl::toROSMsg(pc,pc2); 00143 s.points.push_back(pc2); 00144 s.holes.push_back(false); 00145 sa.shapes.push_back(s); 00146 } 00147 00148 pub.publish(sa); 00149 00150 ros::spinOnce(); 00151 loop_rate.sleep(); 00152 runner++; 00153 } 00154 00155 return 0; 00156 } 00157