shape_mask.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2008, 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 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 
00035 /* Author: Ioan Sucan */
00036 
00037 #ifndef MOVEIT_POINT_CONTAINMENT_FILTER_SELF_MASK_
00038 #define MOVEIT_POINT_CONTAINMENT_FILTER_SELF_MASK_
00039 
00040 #include <sensor_msgs/PointCloud2.h>
00041 #include <geometric_shapes/bodies.h>
00042 #include <boost/function.hpp>
00043 #include <string>
00044 #include <vector>
00045 #include <set>
00046 #include <map>
00047 
00048 #include <boost/thread/mutex.hpp>
00049 
00050 namespace point_containment_filter
00051 {
00052 typedef unsigned int ShapeHandle;
00053 
00055 class ShapeMask
00056 {
00057 public:
00059   enum
00060   {
00061     INSIDE = 0,
00062     OUTSIDE = 1,
00063     CLIP = 2
00064   };
00065 
00066   typedef boost::function<bool(ShapeHandle, Eigen::Affine3d&)> TransformCallback;
00067 
00069   ShapeMask(const TransformCallback& transform_callback = TransformCallback());
00070 
00072   ~ShapeMask();
00073 
00074   ShapeHandle addShape(const shapes::ShapeConstPtr& shape, double scale = 1.0, double padding = 0.0);
00075   void removeShape(ShapeHandle handle);
00076 
00077   void setTransformCallback(const TransformCallback& transform_callback);
00078 
00083   void maskContainment(const sensor_msgs::PointCloud2& data_in, const Eigen::Vector3d& sensor_pos,
00084                        const double min_sensor_dist, const double max_sensor_dist, std::vector<int>& mask);
00085 
00088   int getMaskContainment(double x, double y, double z) const;
00089 
00092   int getMaskContainment(const Eigen::Vector3d& pt) const;
00093 
00094 private:
00095   struct SeeShape
00096   {
00097     SeeShape()
00098     {
00099       body = NULL;
00100     }
00101 
00102     bodies::Body* body;
00103     ShapeHandle handle;
00104     double volume;
00105   };
00106 
00107   struct SortBodies
00108   {
00109     bool operator()(const SeeShape& b1, const SeeShape& b2)
00110     {
00111       if (b1.volume > b2.volume)
00112         return true;
00113       if (b1.volume < b2.volume)
00114         return false;
00115       return b1.handle < b2.handle;
00116     }
00117   };
00118 
00120   void freeMemory();
00121 
00122   TransformCallback transform_callback_;
00123   ShapeHandle next_handle_;
00124   ShapeHandle min_handle_;
00125 
00126   mutable boost::mutex shapes_lock_;
00127   std::set<SeeShape, SortBodies> bodies_;
00128   std::map<ShapeHandle, std::set<SeeShape, SortBodies>::iterator> used_handles_;
00129   std::vector<bodies::BoundingSphere> bspheres_;
00130 };
00131 }
00132 
00133 #endif


perception
Author(s): Ioan Sucan , Jon Binney , Suat Gedikli
autogenerated on Wed Jun 19 2019 19:24:12