|
Point Cloud Library (PCL)
1.6.0
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2009-2011, 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 Willow Garage, Inc. 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: crop_box.hpp 5026 2012-03-12 02:51:44Z rusu $ 00037 * 00038 */ 00039 00040 #ifndef PCL_FILTERS_IMPL_CROP_BOX_H_ 00041 #define PCL_FILTERS_IMPL_CROP_BOX_H_ 00042 00043 #include <pcl/filters/crop_box.h> 00044 00045 00047 template<typename PointT> 00048 void 00049 pcl::CropBox<PointT>::applyFilter (PointCloud &output) 00050 { 00051 output.resize (input_->points.size ()); 00052 int indice_count = 0; 00053 00054 // We filter out invalid points 00055 output.is_dense = true; 00056 00057 Eigen::Affine3f transform = Eigen::Affine3f::Identity(); 00058 Eigen::Affine3f inverse_transform = Eigen::Affine3f::Identity(); 00059 00060 if (rotation_ != Eigen::Vector3f::Zero ()) 00061 { 00062 pcl::getTransformation (0, 0, 0, 00063 rotation_ (0), rotation_ (1), rotation_ (2), 00064 transform); 00065 inverse_transform = transform.inverse (); 00066 } 00067 00068 for (size_t index = 0; index < indices_->size (); ++index) 00069 { 00070 if (!input_->is_dense) 00071 // Check if the point is invalid 00072 if (!isFinite (input_->points[index])) 00073 continue; 00074 00075 // Get local point 00076 PointT local_pt = input_->points[(*indices_)[index]]; 00077 00078 // Transform point to world space 00079 if (!(transform_.matrix ().isIdentity ())) 00080 local_pt = pcl::transformPoint<PointT> (local_pt, transform_); 00081 00082 if (translation_ != Eigen::Vector3f::Zero ()) 00083 { 00084 local_pt.x -= translation_ (0); 00085 local_pt.y -= translation_ (1); 00086 local_pt.z -= translation_ (2); 00087 } 00088 00089 // Transform point to local space of crop box 00090 if (!(inverse_transform.matrix ().isIdentity ())) 00091 local_pt = pcl::transformPoint<PointT> (local_pt, inverse_transform); 00092 00093 if (local_pt.x < min_pt_[0] || local_pt.y < min_pt_[1] || local_pt.z < min_pt_[2]) 00094 continue; 00095 if (local_pt.x > max_pt_[0] || local_pt.y > max_pt_[1] || local_pt.z > max_pt_[2]) 00096 continue; 00097 00098 output.points[indice_count++] = input_->points[(*indices_)[index]]; 00099 } 00100 output.width = indice_count; 00101 output.height = 1; 00102 output.resize (output.width * output.height); 00103 } 00104 00106 template<typename PointT> void 00107 pcl::CropBox<PointT>::applyFilter (std::vector<int> &indices) 00108 { 00109 indices.resize (input_->points.size ()); 00110 int indice_count = 0; 00111 00112 Eigen::Affine3f transform = Eigen::Affine3f::Identity (); 00113 Eigen::Affine3f inverse_transform = Eigen::Affine3f::Identity (); 00114 00115 if (rotation_ != Eigen::Vector3f::Zero ()) 00116 { 00117 pcl::getTransformation (0, 0, 0, 00118 rotation_ (0), rotation_ (1), rotation_ (2), 00119 transform); 00120 inverse_transform = transform.inverse (); 00121 } 00122 00123 for (size_t index = 0; index < indices_->size (); ++index) 00124 { 00125 if (!input_->is_dense) 00126 // Check if the point is invalid 00127 if (!isFinite (input_->points[index])) 00128 continue; 00129 00130 // Get local point 00131 PointT local_pt = input_->points[(*indices_)[index]]; 00132 00133 // Transform point to world space 00134 if (!(transform_.matrix ().isIdentity ())) 00135 local_pt = pcl::transformPoint<PointT> (local_pt, transform_); 00136 00137 if (translation_ != Eigen::Vector3f::Zero ()) 00138 { 00139 local_pt.x -= translation_ (0); 00140 local_pt.y -= translation_ (1); 00141 local_pt.z -= translation_ (2); 00142 } 00143 00144 // Transform point to local space of crop box 00145 if (!(inverse_transform.matrix ().isIdentity ())) 00146 local_pt = pcl::transformPoint<PointT> (local_pt, inverse_transform); 00147 00148 if (local_pt.x < min_pt_[0] || local_pt.y < min_pt_[1] || local_pt.z < min_pt_[2]) 00149 continue; 00150 if (local_pt.x > max_pt_[0] || local_pt.y > max_pt_[1] || local_pt.z > max_pt_[2]) 00151 continue; 00152 00153 indices[indice_count++] = (*indices_)[index]; 00154 } 00155 indices.resize (indice_count); 00156 } 00157 00158 #define PCL_INSTANTIATE_CropBox(T) template class PCL_EXPORTS pcl::CropBox<T>; 00159 00160 #endif // PCL_FILTERS_IMPL_CROP_BOX_H_
1.7.6.1