grid_map.h
Go to the documentation of this file.
00001 // -*- mode: C++ -*-
00002 /*********************************************************************
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2014, JSK Lab
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/o2r other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of the JSK Lab nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
00034  *********************************************************************/
00035 #ifndef JSK_RECOGNITION_UTILS_GRID_MAP_H_
00036 #define JSK_RECOGNITION_UTILS_GRID_MAP_H_
00037 #include <jsk_recognition_msgs/SparseOccupancyGrid.h>
00038 
00039 #include "jsk_recognition_utils/grid_index.h"
00040 #include "jsk_recognition_utils/grid_line.h"
00041 #include <pcl/point_types.h>
00042 #include <pcl/point_cloud.h>
00043 #include <map>
00044 #include <set>
00045 #include <Eigen/Geometry>
00046 #include <boost/tuple/tuple.hpp>
00047 
00048 #include "jsk_recognition_utils/geo_util.h"
00049 #include <opencv2/opencv.hpp>
00050 
00051 namespace jsk_recognition_utils
00052 {
00053 
00054    // infinity range, might be slow...
00055   class GridMap
00056   {
00057   public:
00058     typedef boost::shared_ptr<GridMap> Ptr;
00059     typedef std::set<int> RowIndices;
00060     typedef std::map<int, RowIndices> Columns;
00061     typedef Columns::iterator ColumnIterator;
00062     typedef std::set<int>::iterator RowIterator;
00063     GridMap(double resolution, const std::vector<float>& coefficients);
00064     virtual ~GridMap();
00065     virtual void registerPoint(const pcl::PointXYZRGB& point);
00066     virtual std::vector<GridIndex::Ptr> registerLine(const pcl::PointXYZRGB& from, const pcl::PointXYZRGB& to);
00067     virtual void removeIndex(const GridIndex::Ptr& index);
00068     virtual void registerPointCloud(pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud);
00069     virtual GridIndex::Ptr registerIndex(const GridIndex::Ptr& index);
00070     virtual GridIndex::Ptr registerIndex(const int x, const int y);
00071     virtual void pointToIndex(const pcl::PointXYZRGB& point, GridIndex::Ptr index);
00072     virtual void pointToIndex(const Eigen::Vector3f& point, GridIndex::Ptr index);
00073     virtual void indicesToPointCloud(const std::vector<GridIndex::Ptr>& indices,
00074                                      pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud);
00075     virtual bool getValue(const GridIndex::Ptr& index);
00076     virtual bool getValue(const GridIndex& index);
00077     virtual bool getValue(const int x, const int y);
00078     virtual void gridToPoint(GridIndex::Ptr index, Eigen::Vector3f& pos);
00079     virtual void gridToPoint(const GridIndex& index, Eigen::Vector3f& pos);
00080     virtual void gridToPoint2(const GridIndex& index, Eigen::Vector3f& pos);
00081     virtual void fillRegion(const Eigen::Vector3f& start, std::vector<GridIndex::Ptr>& output);
00082     virtual void fillRegion(const GridIndex::Ptr start, std::vector<GridIndex::Ptr>& output);
00083     // toMsg does not fill header, be carefull
00084     virtual void originPose(Eigen::Affine3f& output);
00085     virtual void originPose(Eigen::Affine3d& output);
00086     virtual void toMsg(jsk_recognition_msgs::SparseOccupancyGrid& grid);
00087     virtual Plane toPlane();
00088     virtual Plane::Ptr toPlanePtr();
00089     virtual void vote();
00090     virtual unsigned int getVoteNum();
00091     virtual void setGeneration(unsigned int generation);
00092     virtual unsigned int getGeneration();
00093     virtual std::vector<float> getCoefficients();
00094     virtual bool isBinsOccupied(const Eigen::Vector3f& p);
00095     virtual int normalizedWidth();
00096     virtual int normalizedHeight();
00097     virtual boost::tuple<int, int> minMaxX();
00098     virtual boost::tuple<int, int> minMaxY();
00099     virtual int widthOffset();
00100     virtual int heightOffset();
00101     virtual int normalizedIndex(int width_offset, int height_offset,
00102                                 int step,
00103                                 int elem_size,
00104                                 int original_x, int original_y);
00105     virtual cv::Mat toImage();
00106     virtual bool check4Neighbor(int x, int y);
00107     virtual ConvexPolygon::Ptr toConvexPolygon();
00108     virtual pcl::PointCloud<pcl::PointXYZ>::Ptr toPointCloud();
00109     virtual void decrease(int i);
00110     virtual void add(GridMap& other);
00111   protected:
00112     virtual void decreaseOne();
00113     
00114     double resolution_;
00115     Eigen::Vector3f O_;
00116     
00117     // plane parameter
00118     Eigen::Vector3f normal_;
00119     double d_;
00120     
00121     Eigen::Vector3f ex_, ey_;
00122     
00123     std::vector<GridLine::Ptr> lines_;
00124     Columns data_;
00125     unsigned int vote_;
00126     unsigned int generation_;
00127   private:
00128   };
00129   
00130 }
00131 
00132 #endif


jsk_recognition_utils
Author(s):
autogenerated on Tue Jul 2 2019 19:40:37