Point Cloud Library (PCL)
1.7.0
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010-2012, Willow Garage, Inc. 00006 * 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * * Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * * Redistributions in binary form must reproduce the above 00016 * copyright notice, this list of conditions and the following 00017 * disclaimer in the documentation and/or other materials provided 00018 * with the distribution. 00019 * * Neither the name of the copyright holder(s) nor the names of its 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 * $Id: filter_indices.h 4707 2012-02-23 10:34:17Z florentinus $ 00037 * 00038 */ 00039 00040 #ifndef PCL_FILTERS_FILTER_INDICES_H_ 00041 #define PCL_FILTERS_FILTER_INDICES_H_ 00042 00043 #include <pcl/filters/filter.h> 00044 00045 namespace pcl 00046 { 00047 /** \brief Removes points with x, y, or z equal to NaN 00048 * \param cloud_in the input point cloud 00049 * \param index the mapping (ordered): cloud_out.points[i] = cloud_in.points[index[i]] 00050 * \note The density of the point cloud is lost. 00051 * \note Can be called with cloud_in == cloud_out 00052 * \ingroup filters 00053 */ 00054 template<typename PointT> void 00055 removeNaNFromPointCloud (const pcl::PointCloud<PointT> &cloud_in, std::vector<int> &index); 00056 00057 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00058 /** \brief @b FilterIndices represents the base class for filters that are about binary point removal. 00059 * <br> 00060 * All derived classes have to implement the \a filter (PointCloud &output) and the \a filter (std::vector<int> &indices) methods. 00061 * Ideally they also make use of the \a negative_, \a keep_organized_ and \a extract_removed_indices_ systems. 00062 * The distinguishment between the \a negative_ and \a extract_removed_indices_ systems only makes sense if the class automatically 00063 * filters non-finite entries in the filtering methods (recommended). 00064 * \author Justin Rosen 00065 * \ingroup filters 00066 */ 00067 template<typename PointT> 00068 class FilterIndices : public Filter<PointT> 00069 { 00070 public: 00071 using Filter<PointT>::extract_removed_indices_; 00072 typedef pcl::PointCloud<PointT> PointCloud; 00073 00074 typedef boost::shared_ptr< FilterIndices<PointT> > Ptr; 00075 typedef boost::shared_ptr< const FilterIndices<PointT> > ConstPtr; 00076 00077 00078 /** \brief Constructor. 00079 * \param[in] extract_removed_indices Set to true if you want to be able to extract the indices of points being removed (default = false). 00080 */ 00081 FilterIndices (bool extract_removed_indices = false) : 00082 negative_ (false), 00083 keep_organized_ (false), 00084 user_filter_value_ (std::numeric_limits<float>::quiet_NaN ()) 00085 { 00086 extract_removed_indices_ = extract_removed_indices; 00087 } 00088 00089 /** \brief Empty virtual destructor. */ 00090 virtual 00091 ~FilterIndices () 00092 { 00093 } 00094 00095 inline void 00096 filter (PointCloud &output) 00097 { 00098 pcl::Filter<PointT>::filter (output); 00099 } 00100 00101 /** \brief Calls the filtering method and returns the filtered point cloud indices. 00102 * \param[out] indices the resultant filtered point cloud indices 00103 */ 00104 inline void 00105 filter (std::vector<int> &indices) 00106 { 00107 if (!initCompute ()) 00108 return; 00109 00110 // Apply the actual filter 00111 applyFilter (indices); 00112 00113 deinitCompute (); 00114 } 00115 00116 /** \brief Set whether the regular conditions for points filtering should apply, or the inverted conditions. 00117 * \param[in] negative false = normal filter behavior (default), true = inverted behavior. 00118 */ 00119 inline void 00120 setNegative (bool negative) 00121 { 00122 negative_ = negative; 00123 } 00124 00125 /** \brief Get whether the regular conditions for points filtering should apply, or the inverted conditions. 00126 * \return The value of the internal \a negative_ parameter; false = normal filter behavior (default), true = inverted behavior. 00127 */ 00128 inline bool 00129 getNegative () 00130 { 00131 return (negative_); 00132 } 00133 00134 /** \brief Set whether the filtered points should be kept and set to the value given through \a setUserFilterValue (default: NaN), 00135 * or removed from the PointCloud, thus potentially breaking its organized structure. 00136 * \param[in] keep_organized false = remove points (default), true = redefine points, keep structure. 00137 */ 00138 inline void 00139 setKeepOrganized (bool keep_organized) 00140 { 00141 keep_organized_ = keep_organized; 00142 } 00143 00144 /** \brief Get whether the filtered points should be kept and set to the value given through \a setUserFilterValue (default = NaN), 00145 * or removed from the PointCloud, thus potentially breaking its organized structure. 00146 * \return The value of the internal \a keep_organized_ parameter; false = remove points (default), true = redefine points, keep structure. 00147 */ 00148 inline bool 00149 getKeepOrganized () 00150 { 00151 return (keep_organized_); 00152 } 00153 00154 /** \brief Provide a value that the filtered points should be set to instead of removing them. 00155 * Used in conjunction with \a setKeepOrganized (). 00156 * \param[in] value the user given value that the filtered point dimensions should be set to (default = NaN). 00157 */ 00158 inline void 00159 setUserFilterValue (float value) 00160 { 00161 user_filter_value_ = value; 00162 } 00163 00164 protected: 00165 using Filter<PointT>::initCompute; 00166 using Filter<PointT>::deinitCompute; 00167 00168 /** \brief False = normal filter behavior (default), true = inverted behavior. */ 00169 bool negative_; 00170 00171 /** \brief False = remove points (default), true = redefine points, keep structure. */ 00172 bool keep_organized_; 00173 00174 /** \brief The user given value that the filtered point dimensions should be set to (default = NaN). */ 00175 float user_filter_value_; 00176 00177 /** \brief Abstract filter method for point cloud indices. */ 00178 virtual void 00179 applyFilter (std::vector<int> &indices) = 0; 00180 }; 00181 00182 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00183 /** \brief @b FilterIndices represents the base class for filters that are about binary point removal. 00184 * <br> 00185 * All derived classes have to implement the \a filter (PointCloud &output) and the \a filter (std::vector<int> &indices) methods. 00186 * Ideally they also make use of the \a negative_, \a keep_organized_ and \a extract_removed_indices_ systems. 00187 * The distinguishment between the \a negative_ and \a extract_removed_indices_ systems only makes sense if the class automatically 00188 * filters non-finite entries in the filtering methods (recommended). 00189 * \author Justin Rosen 00190 * \ingroup filters 00191 */ 00192 template<> 00193 class PCL_EXPORTS FilterIndices<pcl::PCLPointCloud2> : public Filter<pcl::PCLPointCloud2> 00194 { 00195 public: 00196 typedef pcl::PCLPointCloud2 PCLPointCloud2; 00197 00198 /** \brief Constructor. 00199 * \param[in] extract_removed_indices Set to true if you want to extract the indices of points being removed (default = false). 00200 */ 00201 FilterIndices (bool extract_removed_indices = false) : 00202 negative_ (false), 00203 keep_organized_ (false), 00204 user_filter_value_ (std::numeric_limits<float>::quiet_NaN ()) 00205 { 00206 extract_removed_indices_ = extract_removed_indices; 00207 } 00208 00209 /** \brief Empty virtual destructor. */ 00210 virtual 00211 ~FilterIndices () 00212 { 00213 } 00214 00215 virtual void 00216 filter (PCLPointCloud2 &output) 00217 { 00218 pcl::Filter<PCLPointCloud2>::filter (output); 00219 } 00220 00221 /** \brief Calls the filtering method and returns the filtered point cloud indices. 00222 * \param[out] indices the resultant filtered point cloud indices 00223 */ 00224 void 00225 filter (std::vector<int> &indices); 00226 00227 /** \brief Set whether the regular conditions for points filtering should apply, or the inverted conditions. 00228 * \param[in] negative false = normal filter behavior (default), true = inverted behavior. 00229 */ 00230 inline void 00231 setNegative (bool negative) 00232 { 00233 negative_ = negative; 00234 } 00235 00236 /** \brief Get whether the regular conditions for points filtering should apply, or the inverted conditions. 00237 * \return The value of the internal \a negative_ parameter; false = normal filter behavior (default), true = inverted behavior. 00238 */ 00239 inline bool 00240 getNegative () 00241 { 00242 return (negative_); 00243 } 00244 00245 /** \brief Set whether the filtered points should be kept and set to the value given through \a setUserFilterValue (default: NaN), 00246 * or removed from the PointCloud, thus potentially breaking its organized structure. 00247 * \param[in] keep_organized false = remove points (default), true = redefine points, keep structure. 00248 */ 00249 inline void 00250 setKeepOrganized (bool keep_organized) 00251 { 00252 keep_organized_ = keep_organized; 00253 } 00254 00255 /** \brief Get whether the filtered points should be kept and set to the value given through \a setUserFilterValue (default = NaN), 00256 * or removed from the PointCloud, thus potentially breaking its organized structure. 00257 * \return The value of the internal \a keep_organized_ parameter; false = remove points (default), true = redefine points, keep structure. 00258 */ 00259 inline bool 00260 getKeepOrganized () 00261 { 00262 return (keep_organized_); 00263 } 00264 00265 /** \brief Provide a value that the filtered points should be set to instead of removing them. 00266 * Used in conjunction with \a setKeepOrganized (). 00267 * \param[in] value the user given value that the filtered point dimensions should be set to (default = NaN). 00268 */ 00269 inline void 00270 setUserFilterValue (float value) 00271 { 00272 user_filter_value_ = value; 00273 } 00274 00275 protected: 00276 /** \brief False = normal filter behavior (default), true = inverted behavior. */ 00277 bool negative_; 00278 00279 /** \brief False = remove points (default), true = redefine points, keep structure. */ 00280 bool keep_organized_; 00281 00282 /** \brief The user given value that the filtered point dimensions should be set to (default = NaN). */ 00283 float user_filter_value_; 00284 00285 /** \brief Abstract filter method for point cloud indices. */ 00286 virtual void 00287 applyFilter (std::vector<int> &indices) = 0; 00288 }; 00289 } 00290 00291 #ifdef PCL_NO_PRECOMPILE 00292 #include <pcl/filters/impl/filter_indices.hpp> 00293 #endif 00294 00295 #endif //#ifndef PCL_FILTERS_FILTER_INDICES_H_ 00296