Point Cloud Library (PCL)
1.3.1
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2009, 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: crop_box.h 3080 2011-11-02 16:09:57Z rusu $ 00035 * 00036 */ 00037 00038 #ifndef PCL_FILTERS_CROP_BOX_H_ 00039 #define PCL_FILTERS_CROP_BOX_H_ 00040 00041 #include "pcl/point_types.h" 00042 #include "pcl/filters/filter_indices.h" 00043 #include "pcl/common/transforms.h" 00044 #include "pcl/common/eigen.h" 00045 //#include <Eigen/Geometry> 00046 00047 namespace pcl 00048 { 00053 template<typename PointT> 00054 class CropBox : public FilterIndices<PointT> 00055 { 00056 using Filter<PointT>::filter_name_; 00057 using Filter<PointT>::getClassName; 00058 using Filter<PointT>::indices_; 00059 using Filter<PointT>::input_; 00060 00061 typedef typename Filter<PointT>::PointCloud PointCloud; 00062 typedef typename PointCloud::Ptr PointCloudPtr; 00063 typedef typename PointCloud::ConstPtr PointCloudConstPtr; 00064 00065 public: 00067 CropBox () : 00068 min_pt_(Eigen::Vector4f (-1, -1, -1, 1)), 00069 max_pt_(Eigen::Vector4f (1, 1, 1, 1)), 00070 transform_(Eigen::Affine3f::Identity ()) 00071 { 00072 filter_name_ = "CropBox"; 00073 rotation_ = Eigen::Vector3f::Zero (); 00074 translation_ = Eigen::Vector3f::Zero (); 00075 } 00076 00080 inline void 00081 setMin (const Eigen::Vector4f &min_pt) 00082 { 00083 min_pt_ = min_pt; 00084 } 00085 00088 Eigen::Vector4f 00089 getMin () 00090 { 00091 return (min_pt_); 00092 } 00093 00097 inline void 00098 setMax (const Eigen::Vector4f &max_pt) 00099 { 00100 max_pt_ = max_pt; 00101 } 00102 00105 Eigen::Vector4f 00106 getMax () 00107 { 00108 return (max_pt_); 00109 } 00110 00114 inline void 00115 setTranslation (const Eigen::Vector3f &translation) 00116 { 00117 translation_ = translation; 00118 } 00119 00122 Eigen::Vector3f 00123 getTranslation () 00124 { 00125 return (translation_); 00126 } 00127 00131 inline void 00132 setRotation (const Eigen::Vector3f &rotation) 00133 { 00134 rotation_ = rotation; 00135 } 00136 00139 Eigen::Vector3f 00140 getRotation () 00141 { 00142 return (rotation_); 00143 } 00144 00148 inline void 00149 setTransform (const Eigen::Affine3f &transfrom) 00150 { 00151 transform_ = transfrom; 00152 } 00153 00156 Eigen::Affine3f 00157 getTransform () 00158 { 00159 return (transform_); 00160 } 00161 00162 protected: 00166 void 00167 applyFilter (PointCloud &output); 00168 00172 void 00173 applyFilter (std::vector<int> &indices); 00174 00175 private: 00177 Eigen::Vector4f min_pt_; 00178 Eigen::Vector4f max_pt_; 00179 Eigen::Vector3f translation_; 00180 Eigen::Vector3f rotation_; 00181 Eigen::Affine3f transform_; 00182 }; 00183 00185 00189 template<> 00190 class PCL_EXPORTS CropBox<sensor_msgs::PointCloud2> : public FilterIndices<sensor_msgs::PointCloud2> 00191 { 00192 using Filter<sensor_msgs::PointCloud2>::filter_name_; 00193 using Filter<sensor_msgs::PointCloud2>::getClassName; 00194 00195 typedef sensor_msgs::PointCloud2 PointCloud2; 00196 typedef PointCloud2::Ptr PointCloud2Ptr; 00197 typedef PointCloud2::ConstPtr PointCloud2ConstPtr; 00198 00199 public: 00201 CropBox () : 00202 min_pt_(Eigen::Vector4f (-1, -1, -1, 1)), 00203 max_pt_(Eigen::Vector4f (1, 1, 1, 1)), 00204 transform_(Eigen::Affine3f::Identity ()) 00205 { 00206 filter_name_ = "CropBox"; 00207 rotation_ = Eigen::Vector3f::Zero (); 00208 translation_ = Eigen::Vector3f::Zero (); 00209 } 00210 00214 inline void 00215 setMin (const Eigen::Vector4f& min_pt) 00216 { 00217 min_pt_ = min_pt; 00218 } 00219 00222 Eigen::Vector4f 00223 getMin () 00224 { 00225 return (min_pt_); 00226 } 00227 00231 inline void 00232 setMax (const Eigen::Vector4f &max_pt) 00233 { 00234 max_pt_ = max_pt; 00235 } 00236 00239 Eigen::Vector4f 00240 getMax () 00241 { 00242 return (max_pt_); 00243 } 00244 00248 inline void 00249 setTranslation (const Eigen::Vector3f &translation) 00250 { 00251 translation_ = translation; 00252 } 00253 00256 Eigen::Vector3f 00257 getTranslation () 00258 { 00259 return (translation_); 00260 } 00261 00265 inline void 00266 setRotation (const Eigen::Vector3f &rotation) 00267 { 00268 rotation_ = rotation; 00269 } 00270 00273 Eigen::Vector3f 00274 getRotation () 00275 { 00276 return (rotation_); 00277 } 00278 00282 inline void 00283 setTransform (const Eigen::Affine3f &transform) 00284 { 00285 transform_ = transform; 00286 } 00287 00290 Eigen::Affine3f 00291 getTransform () 00292 { 00293 return (transform_); 00294 } 00295 00296 protected: 00300 void 00301 applyFilter (PointCloud2 &output); 00302 00306 void 00307 applyFilter (std::vector<int> &indices); 00308 00310 Eigen::Vector4f min_pt_; 00311 Eigen::Vector4f max_pt_; 00312 Eigen::Vector3f translation_; 00313 Eigen::Vector3f rotation_; 00314 Eigen::Affine3f transform_; 00315 }; 00316 } 00317 00318 #endif // PCL_FILTERS_CROP_BOX_H_