$search
00001 #include "ros/ros.h" 00002 #include <ros/message_traits.h> 00003 #include <ros/serialization.h> 00004 #include "sensor_msgs/PointCloud2.h" 00005 #include "geometry_msgs/Pose.h" 00006 #include "vfh_recognizer_db/normals_vfh_db_estimator.h" 00007 #include <pcl/common/common.h> 00008 #include "household_objects_database/database_view.h" 00009 #include "household_objects_database/database_vfh.h" 00010 #include "household_objects_database/database_vfh_orientation.h" 00011 #include "household_objects_database/objects_database.h" 00012 #include "household_objects_database/database_helper_classes.h" 00013 #include <fstream> 00014 #include <iostream> 00015 #include <pcl_ros/point_cloud.h> 00016 #include <vfh_recognizer_db/vfh_recognition.h> 00017 00018 using namespace std; 00019 namespace ser = ros::serialization; 00020 00021 typedef pcl::PointCloud<pcl::PointXYZ> PointCloud; 00022 household_objects_database::ObjectsDatabase * database; 00023 00024 void 00025 getPointCloudFromView (pcl::PointCloud<pcl::PointNormal> & cloud, boost::shared_ptr< 00026 household_objects_database::DatabaseView> & view) 00027 { 00028 //database->getViewFromVFHId (vfh_id, view); 00029 database->loadFromDatabase (&view->view_point_cloud_data_); 00030 boost::shared_array<uint8_t> bufferRead (new uint8_t[view->view_point_cloud_data_.data ().size ()]); 00031 memcpy (&bufferRead[0], &(view->view_point_cloud_data_.data ()[0]), view->view_point_cloud_data_.data ().size ()); 00032 ser::IStream streamIn (bufferRead.get (), view->view_point_cloud_data_.data ().size ()); 00033 ser::deserialize (streamIn, cloud); 00034 } 00035 00036 int 00037 main (int argc, char **argv) 00038 { 00039 ros::init (argc, argv, "create_descriptors"); 00040 database = new household_objects_database::ObjectsDatabase ("wgs36.willowgarage.com", "5432", "willow", "willow", 00041 "household_objects"); 00042 if (!database->isConnected ()) 00043 { 00044 std::cerr << "Database failed to connect \n"; 00045 return -1; 00046 } 00047 std::cerr << "Database connected successfully \n"; 00048 00049 //read point cloud from database 00050 std::vector<boost::shared_ptr<household_objects_database::DatabaseView> > views; 00051 std::stringstream where; 00052 where << "iteration = " << atoi (argv[1]); 00053 std::string where_clause (where.str ()); 00054 if (!database->getList (views, where_clause)) 00055 { 00056 std::cout << "No views returned" << std::endl; 00057 return false; 00058 } 00059 00060 int new_iteration = atoi (argv[2]); 00061 std::cout << "NUMBER OF VIEWS:" << views.size () << std::endl; 00062 00063 //we can call the service with the views... 00064 for (size_t i = 0; i < views.size (); i++) 00065 { 00066 //read from raw views 00067 //pcl::PointCloud < pcl::PointXYZ >::Ptr cloud (new pcl::PointCloud < pcl::PointXYZ > ()); 00068 00069 boost::shared_ptr< household_objects_database::DatabaseView> view; 00070 view = views.at(i); 00071 sensor_msgs::PointCloud2Ptr cloud(new sensor_msgs::PointCloud2()); 00072 std::stringstream raw_path; 00073 raw_path << "/u/aaldoma/data/raw_views_iteration_17/view_" << view->view_id_.data () << ".pcd"; 00074 std::cout << raw_path.str() << std::endl; 00075 pcl::io::loadPCDFile (raw_path.str(), *cloud); 00076 00077 ros::NodeHandle n; 00078 ros::ServiceClient client = n.serviceClient<vfh_recognizer_db::normals_vfh_db_estimator>("normals_vfh_db_estimator"); 00079 vfh_recognizer_db::normals_vfh_db_estimator srv; 00080 srv.request.view = *cloud; 00081 srv.request.transform = view->view_transform_.data ().pose_; 00082 srv.request.model_id.data = view->scaled_model_id_.data (); 00083 srv.request.iteration.data = new_iteration; 00084 00085 if (client.call(srv)) 00086 { 00087 ROS_INFO("Call succeeded"); 00088 } 00089 else 00090 { 00091 ROS_ERROR("Failed to call service normals_vfh_db_estimator"); 00092 return 1; 00093 } 00094 00095 } 00096 00097 return 0; 00098 } 00099