Point Cloud Library (PCL)  1.5.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
brute_force.h
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-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  */
00037 
00038 #ifndef PCL_SEARCH_BRUTE_FORCE_H_
00039 #define PCL_SEARCH_BRUTE_FORCE_H_
00040 
00041 #include <pcl/search/search.h>
00042 
00043 namespace pcl
00044 {
00045   namespace search
00046   {
00051     template<typename PointT>
00052     class BruteForce: public Search<PointT>
00053     {
00054       typedef typename Search<PointT>::PointCloud PointCloud;
00055       typedef typename Search<PointT>::PointCloudConstPtr PointCloudConstPtr;
00056 
00057       typedef boost::shared_ptr<std::vector<int> > IndicesPtr;
00058       typedef boost::shared_ptr<const std::vector<int> > IndicesConstPtr;
00059 
00060       using pcl::search::Search<PointT>::input_;
00061       using pcl::search::Search<PointT>::indices_;
00062       using pcl::search::Search<PointT>::sorted_results_;
00063 
00064       struct Entry
00065       {
00066         Entry (int idx, float dist) : index (idx), distance (dist) {}
00067         Entry () {}
00068         unsigned index;
00069         float distance;
00070         bool operator < (const Entry& other) const
00071         {
00072           return distance < other.distance;
00073         }
00074         bool operator > (const Entry& other) const
00075         {
00076           return distance > other.distance;
00077         }
00078       };
00079 
00080       // replace by some metric functor
00081       float getDistSqr (const PointT& point1, const PointT& point2) const;
00082       public:
00083         BruteForce (bool sorted_results = false)
00084         : Search<PointT> ("BruteForce", sorted_results)
00085         {
00086         }
00087 
00089         virtual
00090         ~BruteForce ()
00091         {
00092         }
00093 
00102         int
00103         nearestKSearch (const PointT &point, int k, std::vector<int> &k_indices, std::vector<float> &k_distances) const;
00104 
00115         int
00116         radiusSearch (const PointT& point, double radius,
00117                       std::vector<int> &k_indices, std::vector<float> &k_sqr_distances,
00118                       unsigned int max_nn = 0) const;
00119 
00120       private:
00121         int
00122         denseKSearch (const PointT &point, int k, std::vector<int> &k_indices, std::vector<float> &k_distances) const;
00123 
00124         int
00125         sparseKSearch (const PointT &point, int k, std::vector<int> &k_indices, std::vector<float> &k_distances) const;
00126 
00127         int
00128         denseRadiusSearch (const PointT& point, double radius,
00129                            std::vector<int> &k_indices, std::vector<float> &k_sqr_distances,
00130                            unsigned int max_nn = 0) const;
00131 
00132         int
00133         sparseRadiusSearch (const PointT& point, double radius,
00134                             std::vector<int> &k_indices, std::vector<float> &k_sqr_distances,
00135                             unsigned int max_nn = 0) const;
00136     };
00137   }
00138 }
00139 
00140 #endif    // PCL_SEARCH_BRUTE_FORCE_H_