00001 #include "ros/ros.h"
00002 #include <pcl/point_types.h>
00003 #include <pcl/point_cloud.h>
00004 #include <pcl/ros/conversions.h>
00005 #include <pcl/features/normal_3d.h>
00006 #include <pcl/point_representation.h>
00007 #include <pcl/kdtree/kdtree_flann.h>
00008 #include <pcl/io/pcd_io.h>
00009 #include <pcl/conversions.h>
00010 #include <pcl_conversions/pcl_conversions.h>
00011
00012 #include <sensor_msgs/PointCloud2.h>
00013
00014 #include <cob_3d_mapping_msgs/ShapeArray.h>
00015 #include <cob_3d_mapping_msgs/Shape.h>
00016 #include <cob_3d_mapping_common/polygon.h>
00017
00018 #include <ros/time.h>
00019 #include <math.h>
00020 #include <Eigen/Core>
00021 #include <boost/shared_ptr.hpp>
00022 #include <pcl/common/eigen.h>
00023 #include <eigen_conversions/eigen_msg.h>
00024
00025 #define PI 3.14159265
00026 using namespace std;
00027
00028 void
00029 firstShape (cob_3d_mapping_msgs::Shape& s, Eigen::Vector3f origin, Eigen::Vector3f normal, Eigen::Vector3f x_axis, Eigen::Vector3f color)
00030 {
00031 pcl::PointXYZ pt;
00032 pcl::PointCloud<pcl::PointXYZ> pc;
00033 sensor_msgs::PointCloud2 pc_msg;
00034
00035 s.id = 0;
00036
00037 Eigen::Affine3f t;
00038 pcl::getTransformationFromTwoUnitVectorsAndOrigin(normal.cross(x_axis), normal, origin, t);
00039 tf::poseEigenToMsg(t.inverse().cast<double>(), s.pose);
00040
00041
00042 s.params[0] = normal[0];
00043 s.params[1] = normal[1];
00044 s.params[2] = normal[2];
00045 s.params[3] = origin.dot(normal);
00046
00047 s.color.r = color[0];
00048 s.color.g = color[1];
00049 s.color.b = color[2];
00050 s.color.a = 1;
00051
00052 float z = 0;
00053
00054 pt.x = 0.0;
00055 pt.y = 0.0;
00056 pt.z = z;
00057 pc.push_back (pt);
00058
00059 pt.x = 1.0;
00060 pt.y = 0.0;
00061 pt.z = z;
00062 pc.push_back (pt);
00063
00064 pt.x = 1.0;
00065 pt.y = 1.0;
00066 pt.z = z;
00067 pc.push_back (pt);
00068
00069 pt.x = 0.0;
00070 pt.y = 1.0;
00071 pt.z = z;
00072 pc.push_back (pt);
00073
00074 pt.x = 0.7;
00075 pt.y = 0.7;
00076 pt.z = z;
00077 pc.push_back (pt);
00078
00079 pcl::PCLPointCloud2 pc2;
00080 pcl::toPCLPointCloud2(pc, pc2);
00081 pcl_conversions::fromPCL(pc2, pc_msg);
00082
00083 s.points.push_back (pc_msg);
00084
00085 s.holes.push_back(false);
00086 }
00087
00088 void
00089 secondShape (cob_3d_mapping_msgs::Shape& s, Eigen::Vector3f origin, Eigen::Vector3f normal, Eigen::Vector3f x_axis, Eigen::Vector3f color)
00090 {
00091 pcl::PointXYZ pt;
00092 pcl::PointCloud<pcl::PointXYZ> pc, pc_h;
00093 sensor_msgs::PointCloud2 pc_msg, pc_msg_h;
00094
00095 s.id = 1;
00096
00097 s.params[0] = normal[0];
00098 s.params[1] = normal[1];
00099 s.params[2] = normal[2];
00100 s.params[3] = origin.dot(normal);
00101
00102 Eigen::Affine3f t;
00103 pcl::getTransformationFromTwoUnitVectorsAndOrigin(normal.cross(x_axis), normal, origin, t);
00104 tf::poseEigenToMsg(t.inverse().cast<double>(), s.pose);
00105
00106 s.color.r = color[0];
00107 s.color.g = color[1];
00108 s.color.b = color[2];
00109 s.color.a = 1;
00110
00111 pt.x = 0;
00112 pt.y = 0;
00113 pt.z = 0;
00114 pc.push_back (pt);
00115
00116 pt.x = 2;
00117 pt.y = 0;
00118 pc.push_back (pt);
00119
00120 pt.x = 2;
00121 pt.y = 2;
00122 pc.push_back (pt);
00123
00124 pt.x = 0;
00125 pt.y = 2;
00126 pc.push_back (pt);
00127
00128 pt.x = 0.5;
00129 pt.y = 0.5;
00130 pc_h.push_back(pt);
00131
00132 pt.x = 0.5;
00133 pt.y = 1;
00134 pc_h.push_back(pt);
00135
00136 pt.x = 1;
00137 pt.y = 0.5;
00138 pc_h.push_back(pt);
00139
00140 pcl::PCLPointCloud2 pc2;
00141 pcl::toPCLPointCloud2(pc, pc2);
00142 pcl_conversions::fromPCL(pc2, pc_msg);
00143
00144 s.points.push_back (pc_msg);
00145
00146 pcl::PCLPointCloud2 pc2_h;
00147 pcl::toPCLPointCloud2(pc_h, pc2_h);
00148 pcl_conversions::fromPCL(pc2_h, pc_msg_h);
00149
00150 s.points.push_back (pc_msg_h);
00151
00152 s.holes.push_back(false);
00153 s.holes.push_back(true);
00154 }
00155
00156 void
00157 thirdShape (cob_3d_mapping_msgs::Shape& s, Eigen::Vector3f origin, Eigen::Vector3f normal, Eigen::Vector3f x_axis, Eigen::Vector3f color)
00158 {
00159 pcl::PointXYZ pt;
00160 pcl::PointCloud<pcl::PointXYZ> pc;
00161 sensor_msgs::PointCloud2 pc_msg;
00162
00163 s.id = 2;
00164
00165 s.params[0] = normal[0];
00166 s.params[1] = normal[1];
00167 s.params[2] = normal[2];
00168 s.params[3] = origin.dot(normal);
00169
00170 Eigen::Affine3f t;
00171 pcl::getTransformationFromTwoUnitVectorsAndOrigin(normal.cross(x_axis), normal, origin, t);
00172 tf::poseEigenToMsg(t.inverse().cast<double>(), s.pose);
00173
00174 s.color.r = color[0];
00175 s.color.g = color[1];
00176 s.color.b = color[2];
00177 s.color.a = 1;
00178
00179 pt.x = -5;
00180 pt.y = -5;
00181 pt.z = 0;
00182 pc.push_back (pt);
00183
00184 pt.x = -5;
00185 pt.y = -1;
00186 pt.z = 0;
00187 pc.push_back (pt);
00188
00189 pt.x = -6;
00190 pt.y = -5;
00191 pt.z = 0;
00192 pc.push_back (pt);
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 pcl::PCLPointCloud2 pc2;
00203 pcl::toPCLPointCloud2(pc, pc2);
00204 pcl_conversions::fromPCL(pc2, pc_msg);
00205
00206 s.points.push_back (pc_msg);
00207
00208 s.holes.push_back(false);
00209 }
00210
00211 void
00212 fourthShape (cob_3d_mapping_msgs::Shape& s, Eigen::Vector3f origin, Eigen::Vector3f normal, Eigen::Vector3f x_axis, Eigen::Vector3f color)
00213 {
00214 pcl::PointXYZ pt;
00215 pcl::PointCloud<pcl::PointXYZ> pc;
00216 sensor_msgs::PointCloud2 pc_msg;
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 s.id = 3;
00235 s.params[0] = normal[0];
00236 s.params[1] = normal[1];
00237 s.params[2] = normal[2];
00238 s.params[3] = origin.dot(normal);
00239
00240 Eigen::Affine3f t;
00241 pcl::getTransformationFromTwoUnitVectorsAndOrigin(normal.cross(x_axis), normal, origin, t);
00242 tf::poseEigenToMsg(t.inverse().cast<double>(), s.pose);
00243
00244 s.color.r = color[0];
00245 s.color.g = color[1];
00246 s.color.b = color[2];
00247 s.color.a = 1;
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 int x = 1, y = 0, z = 0;
00272 pt.x = x;
00273 pt.y = y;
00274 pt.z = z;
00275 pc.push_back (pt);
00276
00277
00278 x = 0, y = 1, z = 0;
00279 pt.x = x;
00280 pt.y = y;
00281 pt.z = z;
00282 pc.push_back (pt);
00283
00284
00285 x = 0, y = 0, z = 0;
00286 pt.x = x;
00287 pt.y = y;
00288 pt.z = z;
00289 pc.push_back (pt);
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311 pcl::PCLPointCloud2 pc2;
00312 pcl::toPCLPointCloud2(pc, pc2);
00313 pcl_conversions::fromPCL(pc2, pc_msg);
00314
00315 s.points.push_back (pc_msg);
00316
00317 s.holes.push_back(false);
00318 }
00319
00320 void
00321 fifthShape (cob_3d_mapping_msgs::Shape& s, Eigen::Vector3f origin, Eigen::Vector3f normal, Eigen::Vector3f x_axis, Eigen::Vector3f color)
00322 {
00323 pcl::PointXYZ pt;
00324 pcl::PointCloud<pcl::PointXYZ> pc;
00325 sensor_msgs::PointCloud2 pc_msg;
00326
00327 s.id = 4;
00328
00329 s.params[0] = normal[0];
00330 s.params[1] = normal[1];
00331 s.params[2] = normal[2];
00332 s.params[3] = origin.dot(normal);
00333
00334 Eigen::Affine3f t;
00335 pcl::getTransformationFromTwoUnitVectorsAndOrigin(normal.cross(x_axis), normal, origin, t);
00336 tf::poseEigenToMsg(t.inverse().cast<double>(), s.pose);
00337
00338 s.color.r = color[0];
00339 s.color.g = color[1];
00340 s.color.b = color[2];
00341 s.color.a = 1;
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364 float x = 0 , y = -1, z = 0;
00365
00366 pt.x = x;
00367 pt.y = y;
00368 pt.z = z;
00369 pc.push_back (pt);
00370
00371 x = 1 , y = -1, z = 0;
00372
00373 pt.x = x;
00374 pt.y = y;
00375 pt.z = z;
00376 pc.push_back (pt);
00377
00378 x = 1.5 , y = -1, z = 0;
00379
00380 pt.x = x;
00381 pt.y = y;
00382 pt.z = z;
00383 pc.push_back (pt);
00384
00385
00386 x = 0.8 , y = -1, z = 0;
00387
00388 pt.x = x;
00389 pt.y = y;
00390 pt.z = z;
00391 pc.push_back (pt);
00392
00393 x = 0.5 , y = -1, z = 0;
00394 pt.x = x;
00395 pt.y = y;
00396 pt.z = z;
00397 pc.push_back (pt);
00398
00399 x = 0 , y = -1, z = 0;
00400 pt.x = x;
00401 pt.y = y;
00402 pt.z = z;
00403 pc.push_back (pt);
00404
00405 x = -1 , y = -1, z = 0;
00406 pt.x = x;
00407 pt.y = y;
00408 pt.z = z;
00409 pc.push_back (pt);
00410
00411 x = 0 , y = -1, z = 0;
00412 pt.x = x;
00413 pt.y = y;
00414 pt.z = z;
00415 pc.push_back (pt);
00416
00417 x = -0.5 , y = -1, z = 0;
00418 pt.x = x;
00419 pt.y = y;
00420 pt.z = z;
00421 pc.push_back (pt);
00422
00423
00424
00425
00426
00427
00428
00429 pcl::PCLPointCloud2 pc2;
00430 pcl::toPCLPointCloud2(pc, pc2);
00431 pcl_conversions::fromPCL(pc2, pc_msg);
00432
00433 s.points.push_back (pc_msg);
00434
00435 s.holes.push_back(false);
00436 }
00437
00438 void
00439 sixthShape (cob_3d_mapping_msgs::Shape& s, Eigen::Vector3f origin, Eigen::Vector3f normal, Eigen::Vector3f x_axis, Eigen::Vector3f color)
00440 {
00441
00442 pcl::PointXYZ pt;
00443 pcl::PointCloud<pcl::PointXYZ> pc;
00444 sensor_msgs::PointCloud2 pc2;
00445
00446 s.id = 5;
00447
00448 s.params[0] = normal[0];
00449 s.params[1] = normal[1];
00450 s.params[2] = normal[2];
00451 s.params[3] = origin.dot(normal);
00452
00453 Eigen::Affine3f t;
00454 pcl::getTransformationFromTwoUnitVectorsAndOrigin(normal.cross(x_axis), normal, origin, t);
00455 tf::poseEigenToMsg(t.inverse().cast<double>(), s.pose);
00456
00457 s.color.r = color[0];
00458 s.color.g = color[1];
00459 s.color.b = color[2];
00460 s.color.a = 1;
00461
00462 int x = 2, y = 0, z = 0;
00463 pt.x = x;
00464 pt.y = y;
00465 pt.z = z;
00466 pc.push_back (pt);
00467
00468 x = 2, y = 1, z = 0;
00469 pt.x = x;
00470 pt.y = y;
00471 pt.z = z;
00472 pc.push_back (pt);
00473
00474 x = 2, y = 1, z = 0;
00475 pt.x = x;
00476 pt.y = y;
00477 pt.z = z;
00478 pc.push_back (pt);
00479
00480 x = 2, y = 0, z = 0;
00481 pt.x = x;
00482 pt.y = y;
00483 pt.z = z;
00484 pc.push_back (pt);
00485
00486 s.holes.push_back(false);
00487 }
00488
00489 int
00490 main (int argc, char **argv)
00491 {
00492
00493 ros::init (argc, argv, "test_shape_array");
00494 ros::NodeHandle n;
00495 ros::Publisher pub = n.advertise<cob_3d_mapping_msgs::ShapeArray> ("/geometry_map/map_array", 1);
00496
00497 ROS_INFO("\nPublishing shape_array...........");
00498 ros::Rate loop_rate (1);
00499 loop_rate.sleep ();
00500 uint32_t seq = 0;
00501
00502
00503 {
00504 cob_3d_mapping_msgs::ShapeArray sa;
00505 sa.header.frame_id = "/map";
00506 sa.header.stamp = ros::Time::now ();
00507 sa.header.seq = seq++;
00508
00509 cob_3d_mapping_msgs::Shape s;
00510 s.params.resize (4);
00511
00512 s.header.frame_id = "/map";
00513 s.header.stamp = sa.header.stamp;
00514
00515 s.type = cob_3d_mapping_msgs::Shape::POLYGON;
00516
00517
00518 Eigen::Vector3f normal (0, 0, 1);
00519 Eigen::Vector3f origin (0, 0, 0);
00520 Eigen::Vector3f x_axis (1, 0, 0);
00521 Eigen::Vector3f color (1, 0, 0);
00522
00523 firstShape (s, origin, normal, x_axis, color);
00524 sa.shapes.push_back (s);
00525 s.points.clear ();
00526 s.holes.clear();
00527
00528 color[0] = 0;
00529 color[1] = 1;
00530 color[2] = 0;
00531 origin(2) = 1;
00532
00533 secondShape (s, origin, normal, x_axis, color);
00534 sa.shapes.push_back (s);
00535 s.points.clear ();
00536 s.holes.clear();
00537
00538 color[0] = 1;
00539 color[1] = 1;
00540 color[2] = 0;
00541 origin(1) = 1;
00542 normal = Eigen::Vector3f(0,1,1);
00543 normal.normalize();
00544
00545 thirdShape (s, origin, normal, x_axis, color);
00546 sa.shapes.push_back (s);
00547 s.points.clear ();
00548 s.holes.clear();
00549
00550 normal[0] = 0.707;
00551 normal[1] = 0.707;
00552 normal[2] = 0.707;
00553 origin = Eigen::Vector3f(-1,-1,-1);
00554
00555 color[0] = 0;
00556 color[1] = 0;
00557 color[2] = 1;
00558
00559 fourthShape (s, origin, normal, x_axis, color);
00560 sa.shapes.push_back (s);
00561 s.points.clear ();
00562 s.holes.clear();
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586 pub.publish (sa);
00587 loop_rate.sleep ();
00588 ros::spin ();
00589
00590 }
00591
00592 return 0;
00593 }
00594