$search
00001 /**************************************************************** 00002 * 00003 * Copyright (c) 2011 00004 * 00005 * Fraunhofer Institute for Manufacturing Engineering 00006 * and Automation (IPA) 00007 * 00008 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00009 * 00010 * Project name: care-o-bot 00011 * ROS stack name: cob_environment_perception_intern 00012 * ROS package name: cob_3d_mapping_semantics 00013 * Description: 00014 * 00015 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00016 * 00017 * Author: Waqas Tanveer email:Waqas.Tanveer@ipa.fraunhofer.de 00018 * Supervised by: Georg Arbeiter, email:georg.arbeiter@ipa.fhg.de 00019 * 00020 * Date of creation: 11/2011 00021 * ToDo: 00022 * 00023 * 00024 * 00025 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00026 * 00027 * Redistribution and use in source and binary forms, with or without 00028 * modification, are permitted provided that the following conditions are met: 00029 * 00030 * * Redistributions of source code must retain the above copyright 00031 * notice, this list of conditions and the following disclaimer. 00032 * * Redistributions in binary form must reproduce the above copyright 00033 * notice, this list of conditions and the following disclaimer in the 00034 * documentation and/or other materials provided with the distribution. 00035 * * Neither the name of the Fraunhofer Institute for Manufacturing 00036 * Engineering and Automation (IPA) nor the names of its 00037 * contributors may be used to endorse or promote products derived from 00038 * this software without specific prior written permission. 00039 * 00040 * This program is free software: you can redistribute it and/or modify 00041 * it under the terms of the GNU Lesser General Public License LGPL as 00042 * published by the Free Software Foundation, either version 3 of the 00043 * License, or (at your option) any later version. 00044 * 00045 * This program is distributed in the hope that it will be useful, 00046 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00047 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00048 * GNU Lesser General Public License LGPL for more details. 00049 * 00050 * You should have received a copy of the GNU Lesser General Public 00051 * License LGPL along with this program. 00052 * If not, see <http://www.gnu.org/licenses/>. 00053 * 00054 ****************************************************************/ 00055 //internal include 00056 #include "cob_3d_mapping_semantics/table_extraction.h" 00057 #include <ros/console.h> 00058 00059 using namespace cob_3d_mapping; 00060 00061 bool 00062 TableExtraction::isTable() 00063 { 00064 if(!poly_ptr_) 00065 { 00066 ROS_ERROR("Input polygon not set, aborting..."); 00067 return false; 00068 } 00069 //Check if the plane spanned by the polygon is horizontal or not 00070 if (isHorizontal() && isHeightOk() && isSizeOk()) 00071 return true; 00072 else 00073 return false; 00074 } 00075 00076 bool 00077 TableExtraction::isHorizontal () 00078 { 00079 //check components of normal vector with threshold values 00080 if ((poly_ptr_->normal (2) >= norm_z_max_ || poly_ptr_->normal (2) <= norm_z_min_) && (poly_ptr_->normal (0) < norm_x_max_ 00081 && poly_ptr_->normal (0) > norm_x_min_) && (poly_ptr_->normal (1) < norm_y_max_ && poly_ptr_->normal (1) > norm_y_min_)) 00082 { 00083 return true; 00084 } 00085 else 00086 { 00087 return false; 00088 } 00089 } 00090 00091 bool 00092 TableExtraction::isHeightOk () 00093 { 00094 if(poly_ptr_->centroid(2) > height_min_ && poly_ptr_->centroid(2) < height_max_) 00095 return true; 00096 else return false; 00097 } 00098 00099 00100 bool 00101 TableExtraction::isSizeOk () 00102 { 00103 double area = poly_ptr_->computeArea(); 00104 if (area >= area_min_ && area <= area_max_) 00105 return true; 00106 return false; 00107 } 00108 00109 00110 00111 /*void 00112 TableExtraction::calcPolyCentroid (Polygon::Ptr poly_ptr_) 00113 { 00114 //static int ctr = 0; 00115 double x0, y0, z0, xi, yi, zi, xi_1, yi_1, zi_1; 00116 00117 double sum1, sum2, sum3, area; 00118 00119 pcl::PointXYZ c_tri; 00120 pcl::PointXYZ cross_p; 00121 double tri_area; 00122 double mag_cross_p; 00123 00124 centroid_.resize (poly_ptr_->poly_points.size ()); 00125 for (unsigned int i = 0; i < poly_ptr_->poly_points.size (); i++) 00126 { 00127 //initialize variables 00128 sum1 = 0; 00129 sum2 = 0; 00130 sum3 = 0; 00131 area = 0; 00132 00133 pcl::PointXYZ v1, v2; 00134 x0 = poly_ptr_->poly_points[i][0][0]; 00135 y0 = poly_ptr_->poly_points[i][0][1]; 00136 z0 = poly_ptr_->poly_points[i][0][2]; 00137 for (unsigned int j = 1; j < (poly_ptr_->poly_points[i].size () - 1); j++) 00138 { 00139 v1.x = 0; 00140 v1.y = 0; 00141 v1.z = 0; 00142 v2.x = 0; 00143 v2.y = 0; 00144 v2.z = 0; 00145 00146 mag_cross_p = 0; 00147 tri_area = 0; 00148 xi = poly_ptr_->poly_points[i][j][0]; 00149 yi = poly_ptr_->poly_points[i][j][1]; 00150 zi = poly_ptr_->poly_points[i][j][2]; 00151 00152 xi_1 = poly_ptr_->poly_points[i][j + 1][0]; 00153 yi_1 = poly_ptr_->poly_points[i][j + 1][1]; 00154 zi_1 = poly_ptr_->poly_points[i][j + 1][2]; 00155 00156 v1.x = xi - x0; 00157 v1.y = yi - y0; 00158 v1.z = zi - z0; 00159 00160 v2.x = xi_1 - x0; 00161 v2.y = yi_1 - y0; 00162 v2.z = zi_1 - z0; 00163 00164 cross_p.x = ((v1.y * v2.z) - (v2.y * v1.z)); 00165 cross_p.y = -((v1.x * v2.z) - (v1.z * v2.x)); 00166 cross_p.z = ((v1.x * v2.y) - (v1.y * v2.x)); 00167 00168 mag_cross_p = sqrt (pow (cross_p.x, 2) + pow (cross_p.y, 2) + pow (cross_p.z, 2)); 00169 tri_area = mag_cross_p / 2; 00170 00171 c_tri.x = (x0 + xi + xi_1) / 3; 00172 c_tri.y = (y0 + yi + yi_1) / 3; 00173 c_tri.z = (z0 + zi + zi_1) / 3; 00174 00175 sum1 = sum1 + (c_tri.x * tri_area); 00176 sum2 = sum2 + (c_tri.y * tri_area); 00177 sum3 = sum3 + (c_tri.z * tri_area); 00178 area = area + tri_area; 00179 00180 } 00181 centroid_[i].x = (sum1 / area); 00182 centroid_[i].y = (sum2 / area); 00183 centroid_[i].z = (sum3 / area); 00184 poly_ptr_->centroid = centroid_; 00185 00186 std::cout << "\n\t*** Centroid of polygon ( " << i << " ) " << std::endl; 00187 std::cout << "\tCx:" << centroid_[i].x; 00188 std::cout << "\tCy:" << centroid_[i].y; 00189 std::cout << "\tCz:" << centroid_[i].z << std::endl; 00190 std::cout << "\n\t*** Area of polygon ( " << i << " ) = "<< area << std::endl; 00191 00192 } 00193 00194 }*/ 00195 00196