|
Point Cloud Library (PCL)
1.5.1
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Willow Garage, Inc. 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 * * Neither the name of Willow Garage, Inc. nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 * $Id: conditional_removal.h 4702 2012-02-23 09:39:33Z gedikli $ 00035 * 00036 */ 00037 00038 #ifndef PCL_FILTER_FIELD_VAL_CONDITION_H_ 00039 #define PCL_FILTER_FIELD_VAL_CONDITION_H_ 00040 00041 #include <pcl/filters/filter.h> 00042 00043 namespace pcl 00044 { 00046 namespace ComparisonOps 00047 { 00051 typedef enum 00052 { 00053 GT, GE, LT, LE, EQ 00054 } CompareOp; 00055 } 00056 00058 00059 template<typename PointT> 00060 class PointDataAtOffset 00061 { 00062 public: 00064 PointDataAtOffset (uint8_t datatype, uint32_t offset) : 00065 datatype_ (datatype), offset_ (offset) 00066 { 00067 } 00068 00073 int 00074 compare (const PointT& p, const double& val); 00075 protected: 00077 uint8_t datatype_; 00078 00080 uint32_t offset_; 00081 private: 00082 PointDataAtOffset () 00083 { 00084 } 00085 }; 00086 00088 00089 template<typename PointT> 00090 class ComparisonBase 00091 { 00092 public: 00093 typedef boost::shared_ptr<ComparisonBase<PointT> > Ptr; 00094 typedef boost::shared_ptr<const ComparisonBase<PointT> > ConstPtr; 00095 00097 inline bool 00098 isCapable () const 00099 { 00100 return (capable_); 00101 } 00102 00104 virtual bool 00105 evaluate (const PointT &point) const = 0; 00106 00107 protected: 00109 bool capable_; 00110 00112 std::string field_name_; 00113 00115 uint32_t offset_; 00116 00118 ComparisonOps::CompareOp op_; 00119 }; 00120 00122 00123 template<typename PointT> 00124 class FieldComparison : public ComparisonBase<PointT> 00125 { 00126 using ComparisonBase<PointT>::field_name_; 00127 using ComparisonBase<PointT>::op_; 00128 using ComparisonBase<PointT>::capable_; 00129 00130 public: 00131 typedef boost::shared_ptr<FieldComparison<PointT> > Ptr; 00132 typedef boost::shared_ptr<const FieldComparison<PointT> > ConstPtr; 00133 00139 FieldComparison (std::string field_name, ComparisonOps::CompareOp op, double compare_val); 00140 00142 virtual ~FieldComparison (); 00143 00148 virtual bool 00149 evaluate (const PointT &point) const; 00150 00151 protected: 00153 double compare_val_; 00154 00156 PointDataAtOffset<PointT>* point_data_; 00157 00158 private: 00159 FieldComparison () 00160 { 00161 } // not allowed 00162 }; 00163 00165 00166 template<typename PointT> 00167 class PackedRGBComparison : public ComparisonBase<PointT> 00168 { 00169 using ComparisonBase<PointT>::capable_; 00170 using ComparisonBase<PointT>::op_; 00171 00172 public: 00178 PackedRGBComparison (std::string component_name, ComparisonOps::CompareOp op, double compare_val); 00179 00184 virtual bool 00185 evaluate (const PointT &point) const; 00186 00187 protected: 00189 std::string component_name_; 00190 00192 uint32_t component_offset_; 00193 00195 double compare_val_; 00196 00197 private: 00198 PackedRGBComparison () 00199 { 00200 } // not allowed 00201 00202 }; 00203 00205 00206 template<typename PointT> 00207 class PackedHSIComparison : public ComparisonBase<PointT> 00208 { 00209 using ComparisonBase<PointT>::capable_; 00210 using ComparisonBase<PointT>::op_; 00211 00212 public: 00218 PackedHSIComparison (std::string component_name, ComparisonOps::CompareOp op, double compare_val); 00219 00224 virtual bool 00225 evaluate (const PointT &point) const; 00226 00227 typedef enum 00228 { 00229 H, // -128 to 127 corresponds to -pi to pi 00230 S, // 0 to 255 00231 I // 0 to 255 00232 } ComponentId; 00233 00234 protected: 00236 std::string component_name_; 00237 00239 ComponentId component_id_; 00240 00242 double compare_val_; 00243 00245 uint32_t rgb_offset_; 00246 00247 private: 00248 PackedHSIComparison () 00249 { 00250 } // not allowed 00251 }; 00252 00254 00255 template<typename PointT> 00256 class ConditionBase 00257 { 00258 public: 00259 typedef typename pcl::ComparisonBase<PointT> ComparisonBase; 00260 typedef typename ComparisonBase::Ptr ComparisonBasePtr; 00261 typedef typename ComparisonBase::ConstPtr ComparisonBaseConstPtr; 00262 00263 typedef boost::shared_ptr<ConditionBase<PointT> > Ptr; 00264 typedef boost::shared_ptr<const ConditionBase<PointT> > ConstPtr; 00265 00267 ConditionBase () : capable_ (true) 00268 { 00269 } 00270 00272 virtual ~ConditionBase () 00273 { 00274 // comparisons are boost::shared_ptr.will take care of themselves 00275 comparisons_.clear (); 00276 00277 // conditions are boost::shared_ptr. will take care of themselves 00278 conditions_.clear (); 00279 } 00280 00284 void 00285 addComparison (ComparisonBaseConstPtr comparison); 00286 00290 void 00291 addCondition (Ptr condition); 00292 00294 inline bool 00295 isCapable () const 00296 { 00297 return (capable_); 00298 } 00299 00303 virtual bool 00304 evaluate (const PointT &point) const = 0; 00305 00306 protected: 00308 bool capable_; 00309 00311 std::vector<ComparisonBaseConstPtr> comparisons_; 00312 00314 std::vector<Ptr> conditions_; 00315 }; 00316 00318 00319 template<typename PointT> 00320 class ConditionAnd : public ConditionBase<PointT> 00321 { 00322 using ConditionBase<PointT>::conditions_; 00323 using ConditionBase<PointT>::comparisons_; 00324 00325 public: 00326 typedef boost::shared_ptr<ConditionAnd<PointT> > Ptr; 00327 typedef boost::shared_ptr<const ConditionAnd<PointT> > ConstPtr; 00328 00330 ConditionAnd () : 00331 ConditionBase<PointT> () 00332 { 00333 } 00334 00341 virtual bool 00342 evaluate (const PointT &point) const; 00343 }; 00344 00346 00347 template<typename PointT> 00348 class ConditionOr : public ConditionBase<PointT> 00349 { 00350 using ConditionBase<PointT>::conditions_; 00351 using ConditionBase<PointT>::comparisons_; 00352 00353 public: 00354 typedef boost::shared_ptr<ConditionOr<PointT> > Ptr; 00355 typedef boost::shared_ptr<const ConditionOr<PointT> > ConstPtr; 00356 00358 ConditionOr () : 00359 ConditionBase<PointT> () 00360 { 00361 } 00362 00369 virtual bool 00370 evaluate (const PointT &point) const; 00371 }; 00372 00374 00404 template<typename PointT> 00405 class ConditionalRemoval : public Filter<PointT> 00406 { 00407 using Filter<PointT>::input_; 00408 using Filter<PointT>::filter_name_; 00409 using Filter<PointT>::getClassName; 00410 00411 using Filter<PointT>::removed_indices_; 00412 using Filter<PointT>::extract_removed_indices_; 00413 00414 typedef typename Filter<PointT>::PointCloud PointCloud; 00415 typedef typename PointCloud::Ptr PointCloudPtr; 00416 typedef typename PointCloud::ConstPtr PointCloudConstPtr; 00417 00418 public: 00419 typedef typename pcl::ConditionBase<PointT> ConditionBase; 00420 typedef typename ConditionBase::Ptr ConditionBasePtr; 00421 typedef typename ConditionBase::ConstPtr ConditionBaseConstPtr; 00422 00429 ConditionalRemoval (int extract_removed_indices = false) : 00430 Filter<PointT>::Filter (extract_removed_indices), keep_organized_ (false), condition_ (), 00431 user_filter_value_ (std::numeric_limits<float>::quiet_NaN ()) 00432 { 00433 filter_name_ = "ConditionalRemoval"; 00434 } 00435 00441 ConditionalRemoval (ConditionBasePtr condition, bool extract_removed_indices = false) : 00442 Filter<PointT>::Filter (extract_removed_indices), keep_organized_ (false), condition_ (), 00443 user_filter_value_ (std::numeric_limits<float>::quiet_NaN ()) 00444 { 00445 filter_name_ = "ConditionalRemoval"; 00446 setCondition (condition); 00447 } 00448 00457 inline void 00458 setKeepOrganized (bool val) 00459 { 00460 keep_organized_ = val; 00461 } 00462 00463 inline bool 00464 getKeepOrganized () 00465 { 00466 return (keep_organized_); 00467 } 00468 00474 inline void 00475 setUserFilterValue (float val) 00476 { 00477 user_filter_value_ = val; 00478 } 00479 00486 void 00487 setCondition (ConditionBasePtr condition); 00488 00489 protected: 00493 void 00494 applyFilter (PointCloud &output); 00495 00496 typedef typename pcl::traits::fieldList<PointT>::type FieldList; 00497 00499 bool capable_; 00500 00504 bool keep_organized_; 00505 00507 ConditionBasePtr condition_; 00508 00512 float user_filter_value_; 00513 }; 00514 } 00515 00516 #endif
1.8.0