Point Cloud Library (PCL)  1.3.1
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 3277 2011-11-30 17:15:41Z mdixon $
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   Eigen::Affine3f transform = Eigen::Affine3f::Identity();
00053   Eigen::Affine3f inverse_transform = Eigen::Affine3f::Identity();
00054 
00055   if (rotation_ != Eigen::Vector3f::Zero ())
00056   {
00057     pcl::getTransformation (0, 0, 0,
00058                             rotation_ (0), rotation_ (1), rotation_ (2),
00059                             transform);
00060     inverse_transform = transform.inverse();
00061   }
00062 
00063   for (size_t index = 0; index < indices_->size (); ++index)
00064   {
00065     // Get local point
00066     PointT local_pt = input_->points[(*indices_)[index]];
00067 
00068     // Transform point to world space
00069     if (!(transform_.matrix().isIdentity()))
00070       local_pt = pcl::transformPoint<PointT> (local_pt, transform_);
00071 
00072     if (translation_ != Eigen::Vector3f::Zero ())
00073     {
00074       local_pt.x -= translation_ (0);
00075       local_pt.y -= translation_ (1);
00076       local_pt.z -= translation_ (2);
00077     }
00078 
00079     // Transform point to local space of crop box
00080     if (!(inverse_transform.matrix().isIdentity()))
00081       local_pt = pcl::transformPoint<PointT> (local_pt, inverse_transform);
00082 
00083     if (local_pt.x < min_pt_[0] || local_pt.y < min_pt_[1] || local_pt.z < min_pt_[2])
00084       continue;
00085     if (local_pt.x > max_pt_[0] || local_pt.y > max_pt_[1] || local_pt.z > max_pt_[2])
00086       continue;
00087 
00088     output.points[indice_count++] = input_->points[(*indices_)[index]];
00089   }
00090   output.width = indice_count;
00091   output.height = 1;
00092   output.resize (output.width * output.height);
00093 }
00094 
00096 template<typename PointT> void
00097 pcl::CropBox<PointT>::applyFilter (std::vector<int> &indices)
00098 {
00099   indices.resize (input_->points.size ());
00100   int indice_count = 0;
00101 
00102   Eigen::Affine3f transform = Eigen::Affine3f::Identity();
00103   Eigen::Affine3f inverse_transform = Eigen::Affine3f::Identity();
00104 
00105   if (rotation_ != Eigen::Vector3f::Zero ())
00106   {
00107     pcl::getTransformation (0, 0, 0,
00108                             rotation_ (0), rotation_ (1), rotation_ (2),
00109                             transform);
00110     inverse_transform = transform.inverse();
00111   }
00112 
00113   for (size_t index = 0; index < indices_->size (); ++index)
00114   {
00115     // Get local point
00116     PointT local_pt = input_->points[(*indices_)[index]];
00117 
00118     // Transform point to world space
00119     if (!(transform_.matrix().isIdentity()))
00120       local_pt = pcl::transformPoint<PointT> (local_pt, transform_);
00121 
00122     if (translation_ != Eigen::Vector3f::Zero ())
00123     {
00124       local_pt.x -= translation_ (0);
00125       local_pt.y -= translation_ (1);
00126       local_pt.z -= translation_ (2);
00127     }
00128 
00129     // Transform point to local space of crop box
00130     if (!(inverse_transform.matrix().isIdentity()))
00131       local_pt = pcl::transformPoint<PointT> (local_pt, inverse_transform);
00132 
00133     if (local_pt.x < min_pt_[0] || local_pt.y < min_pt_[1] || local_pt.z < min_pt_[2])
00134       continue;
00135     if (local_pt.x > max_pt_[0] || local_pt.y > max_pt_[1] || local_pt.z > max_pt_[2])
00136       continue;
00137 
00138     indices[indice_count++] = (*indices_)[index];
00139   }
00140   indices.resize (indice_count);
00141 }
00142 
00143 #define PCL_INSTANTIATE_CropBox(T) template class PCL_EXPORTS pcl::CropBox<T>;
00144 
00145 #endif    // PCL_FILTERS_IMPL_CROP_BOX_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines