affordances.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2014, Andreas ten Pas
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *
00018  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00021  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00022  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00023  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00024  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00026  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00027  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00028  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029  *  POSSIBILITY OF SUCH DAMAGE.
00030  */
00031 
00032 #ifndef AFFORDANCES_H
00033 #define AFFORDANCES_H
00034 
00035 #include <fstream>
00036 #include <iostream>
00037 #include <omp.h>
00038 #include <pcl/features/feature.h>
00039 #include <pcl/features/normal_3d.h>
00040 #include <pcl/features/normal_3d_omp.h>
00041 #include <pcl/kdtree/kdtree_flann.h>
00042 #include <pcl_ros/point_cloud.h>
00043 #include <pcl/point_types.h>
00044 #include <stdlib.h>
00045 #include <string>
00046 #include <tf/transform_datatypes.h>
00047 #include "curvature_estimation_taubin.h"
00048 #include "curvature_estimation_taubin.hpp"
00049 #include "cylindrical_shell.h"
00050 
00051 typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;
00052 typedef pcl::PointCloud<pcl::PointXYZRGB> PointCloudRGB;
00053 
00054 // workspace limits of the robot
00055 struct WorkspaceLimits
00056 {
00057         double min_x;
00058         double max_x;
00059         double min_y;
00060         double max_y;
00061         double min_z;
00062         double max_z;
00063 };
00064 
00070 class Affordances
00071 {
00072         public:
00073 
00077                 void 
00078     initParams(ros::NodeHandle node);
00079     
00084                 PointCloud::Ptr 
00085     maxRangeFilter(const PointCloud::Ptr &cloud_in);
00086     
00091                 PointCloud::Ptr 
00092     workspaceFilter(const PointCloud::Ptr &cloud_in, tf::StampedTransform *transform = NULL);
00093     
00098     PointCloudRGB::Ptr 
00099     workspaceFilter(const PointCloudRGB::Ptr &cloud_in, tf::StampedTransform *transform = NULL);
00100         
00104     std::vector<CylindricalShell> 
00105     searchAffordances(const PointCloud::Ptr &cloud, tf::StampedTransform *transform = NULL);
00106     
00111     std::vector<CylindricalShell> 
00112     searchAffordances(const PointCloud::Ptr &cloud, const std::vector<int> &indices);
00113     
00119     std::vector<CylindricalShell> 
00120     searchAffordancesTaubin(const PointCloud::Ptr &cloud, const Eigen::MatrixXd &samples, 
00121       bool is_logging = true);
00122         
00129     std::vector< std::vector<CylindricalShell> > 
00130     searchHandles(const PointCloud::Ptr &cloud, std::vector<CylindricalShell> shells);
00131     
00132     std::vector<int> 
00133     createRandomIndices(const PointCloud::Ptr &cloud, int size);
00134     
00141                 bool 
00142     isPointInWorkspace(double x, double y, double z, tf::StampedTransform *transform = NULL);
00143     
00146     std::string getPCDFile() { return this->file; }
00147     
00150     int getNumSamples() { return this->num_samples; }
00151     
00154     double getTargetRadius() { return this->target_radius; }
00155       
00156   
00157         private:    
00158   
00163     void 
00164     estimateNormals(const PointCloud::Ptr &cloud, 
00165                     const pcl::PointCloud<pcl::Normal>::Ptr &cloud_normals);
00166     
00175                 void 
00176     estimateCurvatureAxisPCA(const PointCloud::Ptr &cloud, int nn_center_idx, 
00177                             std::vector<int> nn_indices, Eigen::Vector3d &axis, 
00178                             Eigen::Vector3d &normal);
00179 
00186     void 
00187     estimateCurvatureAxisNormals(const pcl::PointCloud<pcl::Normal>::Ptr &cloud_normals, 
00188                                 const std::vector<int> &nn_indices, 
00189                                 Eigen::Vector3d &axis, Eigen::Vector3d &normal);
00190   
00195     std::vector<CylindricalShell> 
00196     searchAffordancesNormalsOrPCA(const PointCloud::Ptr &cloud, 
00197       tf::StampedTransform *transform = NULL);
00198                                 
00203     std::vector<CylindricalShell> 
00204     searchAffordancesTaubin(const PointCloud::Ptr &cloud, tf::StampedTransform *transform = NULL);
00205     
00213     void findBestColinearSet(const std::vector<CylindricalShell> &list, 
00214                             std::vector<int> &inliersMaxSet, 
00215                             std::vector<int> &outliersMaxSet);
00216                             
00224                 int numInFront(const PointCloud::Ptr &cloud, int center_index, double radius);
00225 
00226     // parameters (read-in from ROS launch file)
00227                 double target_radius;
00228                 double radius_error;
00229                 double handle_gap;
00230                 int num_samples;
00231                 double max_range;
00232                 bool use_clearance_filter;
00233                 bool use_occlusion_filter;
00234                 int curvature_estimator;
00235                 int alignment_runs;
00236                 int alignment_min_inliers;
00237                 double alignment_dist_radius;
00238                 double alignment_orient_radius;
00239                 double alignment_radius_radius;
00240                 WorkspaceLimits workspace_limits;
00241                 int num_threads;
00242     std::string file;
00243                 
00244                 // standard parameters
00245                 static const int CURVATURE_ESTIMATOR; // curvature axis estimation method
00246                 static const int NUM_SAMPLES; // number of neighborhoods
00247                 static const int NUM_NEAREST_NEIGHBORS; // number of nearest neighbors to be found
00248                 static const double NEIGHBOR_RADIUS;
00249                 static const int MAX_NUM_IN_FRONT; // max. threshold of allowed points in front of a neighborhood center point (occlusion filtering)
00250                 static const double TARGET_RADIUS; // approx. radius of the target handle
00251                 static const double RADIUS_ERROR; // allowed deviation from target radius
00252                 static const double HANDLE_GAP; // min. gap around affordances
00253                 static const double MAX_RANGE; // max. range of robot arms
00254                 static const bool USE_CLEARANCE_FILTER; // whether the clearance filter is used
00255                 static const bool USE_OCCLUSION_FILTER; // whether the occlusion filter is used
00256                 static const int ALIGNMENT_RUNS; // number of RANSAC runs
00257                 static const int ALIGNMENT_MIN_INLIERS; // min. number of inliers for colinear cylinder set
00258                 static const double ALIGNMENT_DIST_RADIUS; // distance threshold
00259                 static const double ALIGNMENT_ORIENT_RADIUS; // orientation threshold
00260                 static const double ALIGNMENT_RADIUS_RADIUS; // radius threshold
00261                 static const double WORKSPACE_MIN;
00262                 static const double WORKSPACE_MAX;
00263 };
00264 
00265 #endif


handle_detector
Author(s):
autogenerated on Fri Aug 28 2015 10:59:15