Point Cloud Library (PCL)  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
crop_box.hpp
Go to the documentation of this file.
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.hpp 3746 2011-12-31 22:19:47Z rusu $
00035  *
00036  */
00037 
00038 #ifndef PCL_FILTERS_IMPL_CROP_BOX_H_
00039 #define PCL_FILTERS_IMPL_CROP_BOX_H_
00040 
00041 #include "pcl/filters/crop_box.h"
00042 
00043 
00045 template<typename PointT>
00046 void
00047 pcl::CropBox<PointT>::applyFilter (PointCloud &output)
00048 {
00049   output.resize (input_->points.size ());
00050   int indice_count = 0;
00051 
00052   // We filter out invalid points
00053   output.is_dense = true;
00054 
00055   Eigen::Affine3f transform = Eigen::Affine3f::Identity();
00056   Eigen::Affine3f inverse_transform = Eigen::Affine3f::Identity();
00057 
00058   if (rotation_ != Eigen::Vector3f::Zero ())
00059   {
00060     pcl::getTransformation (0, 0, 0,
00061                             rotation_ (0), rotation_ (1), rotation_ (2),
00062                             transform);
00063     inverse_transform = transform.inverse();
00064   }
00065 
00066   for (size_t index = 0; index < indices_->size (); ++index)
00067   {
00068     if (!input_->is_dense)
00069       // Check if the point is invalid
00070       if (!pcl_isfinite (input_->points[index].x) ||
00071           !pcl_isfinite (input_->points[index].y) ||
00072           !pcl_isfinite (input_->points[index].z))
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     // Get local point
00126     PointT local_pt = input_->points[(*indices_)[index]];
00127 
00128     // Transform point to world space
00129     if (!(transform_.matrix().isIdentity()))
00130       local_pt = pcl::transformPoint<PointT> (local_pt, transform_);
00131 
00132     if (translation_ != Eigen::Vector3f::Zero ())
00133     {
00134       local_pt.x -= translation_ (0);
00135       local_pt.y -= translation_ (1);
00136       local_pt.z -= translation_ (2);
00137     }
00138 
00139     // Transform point to local space of crop box
00140     if (!(inverse_transform.matrix().isIdentity()))
00141       local_pt = pcl::transformPoint<PointT> (local_pt, inverse_transform);
00142 
00143     if (local_pt.x < min_pt_[0] || local_pt.y < min_pt_[1] || local_pt.z < min_pt_[2])
00144       continue;
00145     if (local_pt.x > max_pt_[0] || local_pt.y > max_pt_[1] || local_pt.z > max_pt_[2])
00146       continue;
00147 
00148     indices[indice_count++] = (*indices_)[index];
00149   }
00150   indices.resize (indice_count);
00151 }
00152 
00153 #define PCL_INSTANTIATE_CropBox(T) template class PCL_EXPORTS pcl::CropBox<T>;
00154 
00155 #endif    // PCL_FILTERS_IMPL_CROP_BOX_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines