PCLGraspModel.cpp
Go to the documentation of this file.
00001 
00013 // RAIL Recognition
00014 #include "rail_recognition/PCLGraspModel.h"
00015 #include "rail_recognition/PointCloudMetrics.h"
00016 
00017 using namespace std;
00018 using namespace rail::pick_and_place;
00019 
00020 PCLGraspModel::PCLGraspModel(const graspdb::GraspModel &grasp_model)
00021     : graspdb::GraspModel(grasp_model),
00022       pc_(new pcl::PointCloud<pcl::PointXYZRGB>)
00023 {
00024   // default to false
00025   original_ = false;
00026 
00027   // copy the point cloud if it exists
00028   if (grasp_model.getPointCloud().data.size() > 0)
00029   {
00030     this->setPointCloud(grasp_model.getPointCloud());
00031   } else
00032   {
00033     // simply store the header information
00034     pc_->header.frame_id = grasp_model.getPointCloud().header.frame_id;
00035     avg_r_ = 0;
00036     avg_g_ = 0;
00037     avg_b_ = 0;
00038   }
00039 }
00040 
00041 bool PCLGraspModel::isOriginal() const
00042 {
00043   return original_;
00044 }
00045 
00046 void PCLGraspModel::setOriginal(const bool original)
00047 {
00048   original_ = original;
00049 }
00050 
00051 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr &PCLGraspModel::getPCLPointCloud() const
00052 {
00053   return pc_;
00054 }
00055 
00056 sensor_msgs::PointCloud2 &PCLGraspModel::getPointCloud()
00057 {
00058   throw std::runtime_error("PCLGraspModel::getPointCloud() is unsupported.");
00059 }
00060 
00061 const sensor_msgs::PointCloud2 &PCLGraspModel::getPointCloud() const
00062 {
00063   throw std::runtime_error("PCLGraspModel::getPointCloud() is unsupported.");
00064 }
00065 
00066 void PCLGraspModel::setPointCloud(const sensor_msgs::PointCloud2 &point_cloud)
00067 {
00068   // copy the point cloud
00069   point_cloud_metrics::rosPointCloud2ToPCLPointCloud(point_cloud, pc_);
00070   // compute RGB information
00071   point_cloud_metrics::calculateAvgColors(pc_, avg_r_, avg_g_, avg_b_);
00072 }
00073 
00074 double PCLGraspModel::getAverageRed() const
00075 {
00076   return avg_r_;
00077 }
00078 
00079 double PCLGraspModel::getAverageGreen() const
00080 {
00081   return avg_g_;
00082 }
00083 
00084 double PCLGraspModel::getAverageBlue() const
00085 {
00086   return avg_b_;
00087 }
00088 
00089 graspdb::GraspModel PCLGraspModel::toGraspModel() const
00090 {
00091   // convert the point cloud to a ROS message
00092   sensor_msgs::PointCloud2 msg;
00093   point_cloud_metrics::pclPointCloudToROSPointCloud2(this->getPCLPointCloud(), msg);
00094 
00095   // convert the basic values
00096   graspdb::GraspModel grasp_model(this->getID(), this->getObjectName(), this->getGrasps(), msg, this->getCreated());
00097   return grasp_model;
00098 }


rail_recognition
Author(s): David Kent , Russell Toris , bhetherman
autogenerated on Thu Jun 6 2019 19:44:08