passthrough.hpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2010-2012, 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 the copyright holder(s) 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$
00037  *
00038  */
00039 
00040 #ifndef PCL_FILTERS_IMPL_PASSTHROUGH_HPP_
00041 #define PCL_FILTERS_IMPL_PASSTHROUGH_HPP_
00042 
00043 #include <pcl/filters/passthrough.h>
00044 #include <pcl/common/io.h>
00045 
00047 template <typename PointT> void
00048 pcl::PassThrough<PointT>::applyFilter (PointCloud &output)
00049 {
00050   std::vector<int> indices;
00051   if (keep_organized_)
00052   {
00053     bool temp = extract_removed_indices_;
00054     extract_removed_indices_ = true;
00055     applyFilterIndices (indices);
00056     extract_removed_indices_ = temp;
00057 
00058     output = *input_;
00059     for (int rii = 0; rii < static_cast<int> (removed_indices_->size ()); ++rii)  // rii = removed indices iterator
00060       output.points[(*removed_indices_)[rii]].x = output.points[(*removed_indices_)[rii]].y = output.points[(*removed_indices_)[rii]].z = user_filter_value_;
00061     if (!pcl_isfinite (user_filter_value_))
00062       output.is_dense = false;
00063   }
00064   else
00065   {
00066     output.is_dense = true;
00067     applyFilterIndices (indices);
00068     copyPointCloud (*input_, indices, output);
00069   }
00070 }
00071 
00073 template <typename PointT> void
00074 pcl::PassThrough<PointT>::applyFilterIndices (std::vector<int> &indices)
00075 {
00076   // The arrays to be used
00077   indices.resize (indices_->size ());
00078   removed_indices_->resize (indices_->size ());
00079   int oii = 0, rii = 0;  // oii = output indices iterator, rii = removed indices iterator
00080 
00081   // Has a field name been specified?
00082   if (filter_field_name_.empty ())
00083   {
00084     // Only filter for non-finite entries then
00085     for (int iii = 0; iii < static_cast<int> (indices_->size ()); ++iii)  // iii = input indices iterator
00086     {
00087       // Non-finite entries are always passed to removed indices
00088       if (!pcl_isfinite (input_->points[(*indices_)[iii]].x) ||
00089           !pcl_isfinite (input_->points[(*indices_)[iii]].y) ||
00090           !pcl_isfinite (input_->points[(*indices_)[iii]].z))
00091       {
00092         if (extract_removed_indices_)
00093           (*removed_indices_)[rii++] = (*indices_)[iii];
00094         continue;
00095       }
00096       indices[oii++] = (*indices_)[iii];
00097     }
00098   }
00099   else
00100   {
00101     // Attempt to get the field name's index
00102     std::vector<pcl::PCLPointField> fields;
00103     int distance_idx = pcl::getFieldIndex (*input_, filter_field_name_, fields);
00104     if (distance_idx == -1)
00105     {
00106       PCL_WARN ("[pcl::%s::applyFilter] Unable to find field name in point type.\n", getClassName ().c_str ());
00107       indices.clear ();
00108       removed_indices_->clear ();
00109       return;
00110     }
00111 
00112     // Filter for non-finite entries and the specified field limits
00113     for (int iii = 0; iii < static_cast<int> (indices_->size ()); ++iii)  // iii = input indices iterator
00114     {
00115       // Non-finite entries are always passed to removed indices
00116       if (!pcl_isfinite (input_->points[(*indices_)[iii]].x) ||
00117           !pcl_isfinite (input_->points[(*indices_)[iii]].y) ||
00118           !pcl_isfinite (input_->points[(*indices_)[iii]].z))
00119       {
00120         if (extract_removed_indices_)
00121           (*removed_indices_)[rii++] = (*indices_)[iii];
00122         continue;
00123       }
00124 
00125       // Get the field's value
00126       const uint8_t* pt_data = reinterpret_cast<const uint8_t*> (&input_->points[(*indices_)[iii]]);
00127       float field_value = 0;
00128       memcpy (&field_value, pt_data + fields[distance_idx].offset, sizeof (float));
00129 
00130       // Remove NAN/INF/-INF values. We expect passthrough to output clean valid data.
00131       if (!pcl_isfinite (field_value))
00132       {
00133         if (extract_removed_indices_)
00134           (*removed_indices_)[rii++] = (*indices_)[iii];
00135         continue;
00136       }
00137 
00138       // Outside of the field limits are passed to removed indices
00139       if (!negative_ && (field_value < filter_limit_min_ || field_value > filter_limit_max_))
00140       {
00141         if (extract_removed_indices_)
00142           (*removed_indices_)[rii++] = (*indices_)[iii];
00143         continue;
00144       }
00145 
00146       // Inside of the field limits are passed to removed indices if negative was set
00147       if (negative_ && field_value > filter_limit_min_ && field_value < filter_limit_max_)
00148       {
00149         if (extract_removed_indices_)
00150           (*removed_indices_)[rii++] = (*indices_)[iii];
00151         continue;
00152       }
00153 
00154       // Otherwise it was a normal point for output (inlier)
00155       indices[oii++] = (*indices_)[iii];
00156     }
00157   }
00158 
00159   // Resize the output arrays
00160   indices.resize (oii);
00161   removed_indices_->resize (rii);
00162 }
00163 
00164 #define PCL_INSTANTIATE_PassThrough(T) template class PCL_EXPORTS pcl::PassThrough<T>;
00165 
00166 #endif  // PCL_FILTERS_IMPL_PASSTHROUGH_HPP_
00167 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:27:52