00001 #include <hrl_phri_2011/ellipsoid_space.h>
00002 #include <ros/ros.h>
00003 #include <boost/random/uniform_real.hpp>
00004 #include <boost/random/mersenne_twister.hpp>
00005 #include <boost/random/variate_generator.hpp>
00006 #include <sensor_msgs/PointCloud2.h>
00007 #include <pcl_ros/point_cloud.h>
00008 #include <pcl/point_cloud.h>
00009 #include <pcl/point_types.h>
00010 #include <hrl_phri_2011/EllipsoidParams.h>
00011 #include <hrl_phri_2011/utils.h>
00012
00013 typedef pcl::PointXYZRGB PRGB;
00014 typedef pcl::PointCloud<PRGB> PCRGB;
00015
00016 void pubLoop(PCRGB &pc, const std::string& topic)
00017 {
00018 ros::NodeHandle nh;
00019 ros::Publisher pub_pc = nh.advertise<sensor_msgs::PointCloud2>(topic, 1);
00020 ros::Rate r(1);
00021 sensor_msgs::PointCloud2 pc_msg;
00022 pcl::toROSMsg(pc, pc_msg);
00023 while(ros::ok()) {
00024 pc_msg.header.stamp = ros::Time::now();
00025 pub_pc.publish(pc_msg);
00026 r.sleep();
00027 }
00028 }
00029
00030 class EllispoidVisualizer
00031 {
00032 private:
00033 ros::Publisher pub_pc;
00034 ros::Subscriber sub_e_params;
00035 PCRGB head_pc;
00036 bool is_head;
00037
00038 public:
00039 EllispoidVisualizer(const PCRGB& pc_head, const std::string& topic, bool use_head=true) :
00040 head_pc(pc_head), is_head(use_head)
00041 {
00042 ros::NodeHandle nh;
00043 pub_pc = nh.advertise<sensor_msgs::PointCloud2>(topic, 1);
00044 sub_e_params = nh.subscribe("/ellipsoid_params", 1, &EllispoidVisualizer::publishEllipoid, this);
00045 }
00046 void sampleEllipse(double A, double B, double height, PCRGB& pc);
00047 void projectEllipsoid(double A, double B, double height, const PCRGB& pc, PCRGB& pc_ell);
00048 void publishEllipoid(hrl_phri_2011::EllipsoidParams::ConstPtr e_params);
00049 };
00050
00051 void EllispoidVisualizer::sampleEllipse(double A, double B, double height, PCRGB& pc)
00052 {
00053 Ellipsoid e(A, B);
00054 double lat = 0, lon = 0;
00055 int numlat = 8, numlon = 16;
00056 for(int i=0;i<numlat;i++) {
00057 lat += PI / numlat;
00058 lon = 0;
00059 for(int j=0;j<600;j++) {
00060 lon += 2 * PI / 600;
00061 PRGB pt;
00062 ((uint32_t*) &pt.rgb)[0] = 0xffffffff;
00063 double x, y, z;
00064 e.ellipsoidalToCart(lat, lon, height, x, y, z);
00065 pt.x = x; pt.y = y; pt.z = z;
00066 pc.points.push_back(pt);
00067 }
00068 }
00069 lat = 0; lon = 0;
00070 for(int i=0;i<numlon;i++) {
00071 lat = 0;
00072 lon += 2 * PI / numlon;
00073 for(int j=0;j<600;j++) {
00074 lat += PI / 600;
00075 PRGB pt;
00076 ((uint32_t*) &pt.rgb)[0] = 0xffffffff;
00077 double x, y, z;
00078 e.ellipsoidalToCart(lat, lon, height, x, y, z);
00079 pt.x = x; pt.y = y; pt.z = z;
00080 pc.points.push_back(pt);
00081 }
00082 }
00083 }
00084
00085 void EllispoidVisualizer::projectEllipsoid(double A, double B, double height, const PCRGB& pc, PCRGB& pc_ell)
00086 {
00087 Ellipsoid e(A, B);
00088 double lat, lon, hei, x, y, z;
00089 BOOST_FOREACH(PRGB const pt, pc.points) {
00090 PRGB npt;
00091
00092 e.cartToEllipsoidal(pt.x, pt.y, pt.z, lat, lon, hei);
00093 e.ellipsoidalToCart(lat, lon, height, x, y, z);
00094 npt.x = x; npt.y = y; npt.z = z;
00095 npt.rgb = pt.rgb;
00096
00097 pc_ell.points.push_back(npt);
00098 }
00099 pc_ell.header.frame_id = "base_link";
00100
00101 }
00102
00103 void EllispoidVisualizer::publishEllipoid(hrl_phri_2011::EllipsoidParams::ConstPtr e_params)
00104 {
00105 PCRGB pc, proj_head;
00106 double A = 1;
00107 double E = e_params->E;
00108 double B = sqrt(1 - SQ(E));
00109 pc.header.frame_id = "/ellipse_frame";
00110 sampleEllipse(A, B, e_params->height, pc);
00111 if(is_head) {
00112 projectEllipsoid(A, B, e_params->height, head_pc, proj_head);
00113 proj_head.header.frame_id = "/ellipse_frame";
00114 pc += proj_head;
00115 }
00116 pc.header.stamp = ros::Time::now();
00117 pub_pc.publish(pc);
00118 }
00119
00120 int main(int argc, char **argv)
00121 {
00122 ros::init(argc, argv, "ellipsoid_visualizer");
00123 PCRGB pc_head;
00124 Ellipsoid ell;
00125 loadRegisteredHead(argv[1], argv[2], pc_head, ell);
00126 EllispoidVisualizer ev(pc_head, "/ellipsoid", false);
00127 ros::spin();
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 return 0;
00160 }