Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "ros/ros.h"
00032 #include "ros/package.h"
00033 #include "sensor_msgs/PointCloud2.h"
00034
00035
00036 #include "pcl/io/pcd_io.h"
00037 #include "pcl/point_types.h"
00038 #include "pcl/filters/voxel_grid.h"
00039
00040
00041 #include "boost/filesystem.hpp"
00042 #include "boost/filesystem/path.hpp"
00043 #include "boost/filesystem/operations.hpp"
00044 #include "boost/filesystem/fstream.hpp"
00045 #include "boost/tokenizer.hpp"
00046 #include "boost/algorithm/string.hpp"
00047
00048 class WifiView
00049 {
00050 public:
00051 WifiView();
00052 ~WifiView();
00053 void load();
00054 void run();
00055
00056 private:
00057 ros::NodeHandle nh_;
00058
00059
00060 float box_x_,box_y_,box_z_;
00061
00062
00063 std::map<std::string,sensor_msgs::PointCloud2> ap_map_;
00064
00065 std::vector<ros::Publisher> wifi_map_pub_;
00066
00067 };
00068
00069
00070
00071 WifiView::WifiView()
00072 {
00073
00074 box_x_ = 1.0;
00075 box_y_ = 1.0;
00076 box_z_ = 256.0;
00077
00078
00079 load();
00080
00081
00082 std::map<std::string,sensor_msgs::PointCloud2>::iterator it;
00083
00084 it = ap_map_.begin();
00085
00086 while(it != ap_map_.end())
00087 {
00088 std::ostringstream topic;
00089 topic << "wifimap" << (*it).first;
00090 std::string t = boost::algorithm::replace_all_copy(topic.str(),":","");
00091 ros::Publisher each_map_pub = nh_.advertise<sensor_msgs::PointCloud2>(t.c_str(), 1);
00092 wifi_map_pub_.push_back(each_map_pub);
00093 ++it;
00094 }
00095 }
00096
00097
00098
00099 WifiView::~WifiView()
00100 {
00101
00102 }
00103
00104
00105
00106 void WifiView::load()
00107 {
00108 int ap_count = 0;
00109 namespace f = boost::filesystem;
00110 f::path map_dir = ros::package::getPath("wifi_tools") + "/map";
00111 f::directory_iterator end;
00112 for( f::directory_iterator it(map_dir); it!=end; ++it )
00113 {
00114 if( !(f::is_directory(*it)) )
00115 {
00116
00117 std::string leaf = (*it).path().leaf().c_str();
00118 boost::char_separator< char > sep(".");
00119 boost::tokenizer< boost::char_separator< char > > tokens(leaf, sep);
00120 boost::tokenizer< boost::char_separator< char > >::iterator file_it;
00121 file_it = tokens.begin();
00122 std::string mac_address = (std::string)(*file_it);
00123
00124
00125 std::ifstream ap_ifs((*it).path().c_str());
00126 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>),cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);
00127 pcl::io::loadPCDFile<pcl::PointXYZ> ((*it).path().c_str(), *cloud);
00128
00129
00130 pcl::VoxelGrid<pcl::PointXYZ> box;
00131 box.setInputCloud (cloud);
00132 box.setLeafSize (box_x_,box_y_,box_z_);
00133 box.filter (*cloud_filtered);
00134
00135
00136 sensor_msgs::PointCloud2::Ptr cloud_msg(new sensor_msgs::PointCloud2());
00137 pcl::toROSMsg(*cloud_filtered, *cloud_msg);
00138 (*cloud_msg).header.frame_id = "/map";
00139 (*cloud_msg).header.stamp = ros::Time::now();
00140 ap_map_.insert(std::map<std::string,sensor_msgs::PointCloud2 >::value_type(mac_address,*cloud_msg));
00141 ap_count++;
00142 }
00143 }
00144 ROS_INFO("%d access points data have loaded.",ap_count);
00145 }
00146
00147
00148
00149 void WifiView::run()
00150 {
00151 std::map<std::string,sensor_msgs::PointCloud2>::iterator it;
00152 std::vector<ros::Publisher>::iterator pub_it;
00153 it = ap_map_.begin();
00154 pub_it = wifi_map_pub_.begin();
00155 while(it != ap_map_.end())
00156 {
00157 (*pub_it).publish((*it).second);
00158 ++pub_it;
00159 ++it;
00160 }
00161 }
00162
00163
00164
00165 int main(int argc, char** argv)
00166 {
00167 ros::init(argc, argv, "wifi_viewer");
00168 ros::NodeHandle nh;
00169 WifiView wifi_map;
00170
00171 ros::Rate rate_Hz(1);
00172 while (ros::ok())
00173 {
00174 wifi_map.run();
00175 rate_Hz.sleep();
00176 }
00177 return (0);
00178 }