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
00011 typedef pcl::PointXYZRGB PRGB;
00012 typedef pcl::PointCloud<PRGB> PCRGB;
00013
00014 void pubLoop(PCRGB &pc, const std::string& topic)
00015 {
00016 ros::NodeHandle nh;
00017 ros::Publisher pub_pc = nh.advertise<sensor_msgs::PointCloud2>(topic, 1);
00018 ros::Rate r(1);
00019 sensor_msgs::PointCloud2 pc_msg;
00020 pcl::toROSMsg(pc, pc_msg);
00021 while(ros::ok()) {
00022 pc_msg.header.stamp = ros::Time::now();
00023 pub_pc.publish(pc_msg);
00024 r.sleep();
00025 }
00026 }
00027
00028 void sampleEllipse(Ellipsoid& e, double height)
00029 {
00030 PCRGB pc;
00031 double lat = 0, lon = 0;
00032 int numlat = 8, numlon = 14;
00033 for(int i=0;i<numlat;i++) {
00034 lat += PI / numlat;
00035 lon = 0;
00036 for(int j=0;j<600;j++) {
00037 lon += 2 * PI / 600;
00038 PRGB pt;
00039 ((uint32_t*) &pt.rgb)[0] = 0xffffffff;
00040 double x, y, z;
00041 e.ellipsoidalToCart(lat, lon, height, x, y, z);
00042 pt.x = x; pt.y = y; pt.z = z;
00043 pc.points.push_back(pt);
00044 }
00045 }
00046 lat = 0; lon = 0;
00047 for(int i=0;i<numlon;i++) {
00048 lat = 0;
00049 lon += 2 * PI / numlon;
00050 for(int j=0;j<600;j++) {
00051 lat += PI / 600;
00052 PRGB pt;
00053 ((uint32_t*) &pt.rgb)[0] = 0xffffffff;
00054 double x, y, z;
00055 e.ellipsoidalToCart(lat, lon, height, x, y, z);
00056 pt.x = x; pt.y = y; pt.z = z;
00057 pc.points.push_back(pt);
00058 }
00059 }
00060 pc.header.frame_id = "/base_link";
00061 pc.header.stamp = ros::Time::now();
00062 pubLoop(pc, "/sample_ellipsoid");
00063 }
00064
00065 int main(int argc, char **argv)
00066 {
00067 ros::init(argc, argv, "test");
00068 ros::NodeHandle nh;
00069 Ellipsoid e(1.0, 2.5);
00070 double lat, lon, height, x, y, z, newx, newy, newz, newlat, newlon, newheight;
00071 boost::mt19937 rand_gen;
00072 rand_gen.seed(static_cast<uint32_t>(std::time(0)));
00073 boost::uniform_real<> rand_lat_dist(0, PI);
00074 boost::uniform_real<> rand_lon_dist(0, 2 * PI);
00075 boost::uniform_real<> rand_height_dist(0, 4);
00076 boost::uniform_real<> rand_x_dist(-1, 1);
00077 boost::variate_generator<boost::mt19937&, boost::uniform_real<> > rand_x(rand_gen, rand_x_dist);
00078 boost::variate_generator<boost::mt19937&, boost::uniform_real<> > rand_lat(rand_gen, rand_lat_dist);
00079 boost::variate_generator<boost::mt19937&, boost::uniform_real<> > rand_lon(rand_gen, rand_lon_dist);
00080 boost::variate_generator<boost::mt19937&, boost::uniform_real<> > rand_height(rand_gen, rand_height_dist);
00081 double maxlon = -100, minlon = 100, maxlat = -100, minlat = 100;
00082 height = 1.0;
00083 for(int i=0;i<100;i++) {
00084 x = rand_x(); y = rand_x(); z = rand_x();
00085 lat = rand_lat(); lon = rand_lon(); height = rand_height();
00086 e.ellipsoidalToCart(lat, lon, height, x, y, z);
00087 e.cartToEllipsoidal(x, y, z, newlat, newlon, newheight);
00088 if(x > 0 && y > 0)
00089 printf("1:");
00090 if(x < 0 && y > 0)
00091 printf("2:");
00092 if(x < 0 && y < 0)
00093 printf("3:");
00094 if(x > 0 && y < 0)
00095 printf("4:");
00096
00097 printf("%f %f %f\n", lat-newlat, lon-newlon, height-newheight);
00098
00099 e.mollweideProjection(lat, lon, x, y);
00100 maxlon = max(lon, maxlon);
00101 minlon = min(lon, minlon);
00102 maxlat = max(lat, maxlat);
00103 minlat = min(lat, minlat);
00104 }
00105 printf("lon %f, %f; lat %f, %f\n", minlon, maxlon, minlat, maxlat);
00106 sampleEllipse(e, 0.2);
00107 return 0;
00108 }