pcdfilter_pa.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 *                                                                             *
00003 * pcdfilter_pa.cpp                                                            *
00004 * ================                                                            *
00005 *                                                                             *
00006 *******************************************************************************
00007 *                                                                             *
00008 * github repository                                                           *
00009 *   https://github.com/peterweissig/ros_pcdfilter                             *
00010 *                                                                             *
00011 * Chair of Automation Technology, Technische Universität Chemnitz             *
00012 *   https://www.tu-chemnitz.de/etit/proaut                                    *
00013 *                                                                             *
00014 *******************************************************************************
00015 *                                                                             *
00016 * New BSD License                                                             *
00017 *                                                                             *
00018 * Copyright (c) 2015-2017, Peter Weissig, Technische Universität Chemnitz     *
00019 * All rights reserved.                                                        *
00020 *                                                                             *
00021 * Redistribution and use in source and binary forms, with or without          *
00022 * modification, are permitted provided that the following conditions are met: *
00023 *     * Redistributions of source code must retain the above copyright        *
00024 *       notice, this list of conditions and the following disclaimer.         *
00025 *     * Redistributions in binary form must reproduce the above copyright     *
00026 *       notice, this list of conditions and the following disclaimer in the   *
00027 *       documentation and/or other materials provided with the distribution.  *
00028 *     * Neither the name of the Technische Universität Chemnitz nor the       *
00029 *       names of its contributors may be used to endorse or promote products  *
00030 *       derived from this software without specific prior written permission. *
00031 *                                                                             *
00032 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" *
00033 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE   *
00034 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE  *
00035 * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY      *
00036 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES  *
00037 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR          *
00038 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER  *
00039 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT          *
00040 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY   *
00041 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
00042 * DAMAGE.                                                                     *
00043 *                                                                             *
00044 ******************************************************************************/
00045 
00046 // local headers
00047 #include "pcdfilter_pa/pcdfilter_pa.h"
00048 
00049 // additional libraries
00050 #include "opencv2/calib3d/calib3d.hpp"
00051 #include "opencv2/photo/photo.hpp"
00052 
00053 // standard headers
00054 #include <string>
00055 #include <math.h>
00056 
00057 //**************************[cPcdFilterPa]*************************************
00058 cPcdFilterPa::cPcdFilterPa() {
00059 }
00060 
00061 //**************************[~cPcdFilterPa]************************************
00062 cPcdFilterPa::~cPcdFilterPa() {
00063 }
00064 
00065 //**************************[pointcloudFilter]*********************************
00066 std::vector<int> cPcdFilterPa::pointcloudFilter(const cv::Mat &pointcloud,
00067     std::vector<bool> &mask) const {
00068 
00069     std::vector <int> count(params_.filters_.size(), 0);
00070     mask.resize(pointcloud.rows, true);
00071 
00072     for (int i_point = pointcloud.rows - 1; i_point >= 0; i_point--) {
00073         for (int i_filter = params_.filters_.size() - 1; i_filter >= 0;
00074           i_filter--) {
00075             if (params_.filters_[i_filter].type_ ==
00076               cPcdFilterPaFilter::ftNONE) {
00077                 continue;
00078             }
00079             cv::Vec3f v((float*) pointcloud.ptr(i_point));
00080             v = params_.filters_[i_filter].rotation_ * v +
00081               params_.filters_[i_filter].translation_;
00082 
00083             bool check = false;
00084             switch (params_.filters_[i_filter].type_) {
00085                 case cPcdFilterPaFilter::ftCUBE :
00086                     if (std::fabs(v[0]) >
00087                       params_.filters_[i_filter].parameter_[0]) {
00088                         check = true; break;
00089                     }
00090                     if (std::fabs(v[1]) >
00091                       params_.filters_[i_filter].parameter_[0]) {
00092                         check = true; break;
00093                     }
00094                     if (std::fabs(v[2]) >
00095                       params_.filters_[i_filter].parameter_[0]) {
00096                         check = true; break;
00097                     }
00098                     break;
00099 
00100                 case cPcdFilterPaFilter::ftBLOCK :
00101                     if (std::fabs(v[0]) >
00102                       params_.filters_[i_filter].parameter_[0]) {
00103                         check = true; break;
00104                     }
00105                     if (std::fabs(v[1]) >
00106                       params_.filters_[i_filter].parameter_[1]) {
00107                         check = true; break;
00108                     }
00109                     if (std::fabs(v[2]) >
00110                       params_.filters_[i_filter].parameter_[2]) {
00111                         check = true; break;
00112                     }
00113                     break;
00114 
00115                 case cPcdFilterPaFilter::ftSPHERE :
00116                     if (v[0] * v[0] + v[1] * v[1] + v[2] * v[2] >
00117                       params_.filters_[i_filter].parameter_[0]) {
00118                         check = true; break;
00119                     }
00120                     break;
00121 
00122                 case cPcdFilterPaFilter::ftCYLINDER :
00123                     if (v[1] * v[1] + v[2] * v[2] >
00124                       params_.filters_[i_filter].parameter_[0]) {
00125                         check = true; break;
00126                     }
00127                     if (std::fabs(v[0]) >
00128                       params_.filters_[i_filter].parameter_[1]) {
00129                         check = true; break;
00130                     }
00131                     break;
00132 
00133                 case cPcdFilterPaFilter::ftCONE :
00134                         if (v[0] <= 0) {
00135                         check = true; break;
00136                         }
00137 
00138                         if (v[0] > params_.filters_[i_filter].parameter_[0]) {
00139                         check = true; break;
00140                         }
00141 
00142                         if ((v[1] * v[1] + v[2] * v[2]) > (v[0] * v[0]) *
00143                           params_.filters_[i_filter].parameter_[1]) {
00144                         check = true; break;
00145                     }
00146                     break;
00147             }
00148             if (params_.filters_[i_filter].inverse_) {
00149                 check = ! check;
00150             }
00151             if (check == false) {
00152                 count[i_filter]++;
00153                 mask[i_point] = false;
00154                 break;
00155             }
00156         }
00157     }
00158 
00159     return count;
00160 }


pcdfilter_pa
Author(s):
autogenerated on Thu Aug 3 2017 03:00:01