tools.cpp
Go to the documentation of this file.
00001 #include "tools.h"
00002 #include <iostream>
00003 #include <pcl/filters/passthrough.h>
00004 #include <Eigen/SVD>
00005 
00006 #include <cmath>
00007 
00008 geometry_msgs::PoseStamped getPoseStamped(const Eigen::Vector3f& pos, const tf::Quaternion& rotation){
00009   geometry_msgs::PoseStamped posestamped;
00010   posestamped.header.stamp = ros::Time::now();
00011   posestamped.header.frame_id = "/torso_lift_link" ;
00012   posestamped.pose.position.x = pos(0);
00013   posestamped.pose.position.y = pos(1);
00014   posestamped.pose.position.z = pos(2);
00015   posestamped.pose.orientation.w = rotation.getW();
00016   posestamped.pose.orientation.x = rotation.getX();
00017   posestamped.pose.orientation.y = rotation.getY();
00018   posestamped.pose.orientation.y = rotation.getY();
00019   return posestamped;
00020 }
00021 
00022 visualization_msgs::Marker visualize_filter_box(float xmin,float xmax,float ymin,float ymax,float zmin,float zmax, std_msgs::Header header){
00023   visualization_msgs::Marker marker;
00024   marker.header = header;
00025   //marker.header.stamp = ros::Time::now();
00026   marker.ns = "door_manipulation";
00027   marker.id = 0;
00028   marker.type = visualization_msgs::Marker::CUBE;
00029   marker.action = visualization_msgs::Marker::MODIFY;
00030   marker.pose.position.x = xmin+(fabs(xmin-xmax)/2.0);
00031   marker.pose.position.y = ymin+(fabs(ymin-ymax)/2.0);
00032   marker.pose.position.z = zmin+(fabs(zmin-zmax)/2.0);
00033   marker.pose.orientation.x = 0.0;
00034   marker.pose.orientation.y = 0.0;
00035   marker.pose.orientation.z = 0.0;
00036   marker.pose.orientation.w = 1.0;
00037   marker.scale.x = fabs((xmin-xmax));
00038   marker.scale.y = fabs((ymin-ymax));
00039   marker.scale.z = fabs((zmin-zmax));
00040   marker.color.a = 0.3;
00041   marker.color.r = 0.0;
00042   marker.color.g = 1.0;
00043   marker.color.b = 1.0;
00044   return marker;
00045 }
00046 
00047 bool computeMainAxis(const myCloudType& pc, Eigen::Vector3f& mean, Eigen::Vector3f& main_axis, float eval_ratio_threshold){
00048   using namespace Eigen;
00049 
00050   mean = Vector3f::Zero();
00051   for(unsigned int i = 0; i < pc.size(); i++){
00052     const myPointType& p = pc.points.at(i);
00053     mean += p.getVector3fMap ();
00054   }
00055   mean /= static_cast<float>(pc.size());
00056 
00057   Matrix3f cov = Matrix3f::Zero();
00058   for(unsigned int i = 0; i < pc.size(); i++){
00059     const myPointType& p = pc.points.at(i);
00060     Vector3f v = p.getVector3fMap() - mean;
00061     cov += v * v.adjoint();
00062   }
00063   cov /= static_cast<float>(pc.size());
00064 
00065   JacobiSVD<Matrix3f> svd(cov, ComputeFullU);
00066   Matrix3f eigenvectors = svd.matrixU();
00067   //use first col as main eigenvector
00068   main_axis = eigenvectors.col(0); 
00069 
00070   //std::cout << "EigenVectors:" << std::endl << eigenvectors << std::endl;
00071   //std::cout << "EigenValues:\n" << svd.singularValues() << std::endl;
00072   Vector3f evals = svd.singularValues();
00073   if(evals(0) / evals(1) < eval_ratio_threshold){
00074       ROS_WARN_THROTTLE(5, "Low Eigenvalue Ratio: %f", (evals(0) / evals(1)));
00075       return false;
00076   }else 
00077       return true;
00078 }
00079     
00080 void box_filter(myCloudType::Ptr pc, float xmin,float xmax,float ymin,float ymax,float zmin,float zmax){
00081   // Create the filtering object
00082   pcl::PassThrough<myPointType> pass;
00083   pass.setInputCloud (pc);
00084 
00085   pass.setFilterFieldName ("z");
00086   pass.setFilterLimits (zmin, zmax);
00087   pass.filter (*pc);
00088 
00089   pass.setFilterFieldName ("y");
00090   pass.setFilterLimits (ymin, ymax);
00091   pass.filter (*pc);
00092 
00093   pass.setFilterFieldName ("x");
00094   pass.setFilterLimits (xmin, xmax);
00095   pass.filter (*pc);
00096 
00097 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


door_manipulation_tools
Author(s): Felix Endres
autogenerated on Wed Dec 26 2012 16:02:19