grid_map.h
Go to the documentation of this file.
1 // -*- mode: C++ -*-
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2014, JSK Lab
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of the JSK Lab nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
35 #ifndef JSK_RECOGNITION_UTILS_GRID_MAP_H_
36 #define JSK_RECOGNITION_UTILS_GRID_MAP_H_
37 #include <jsk_recognition_msgs/SparseOccupancyGrid.h>
38 
41 #include <pcl/point_types.h>
42 #include <pcl/point_cloud.h>
43 #include <map>
44 #include <set>
45 #include <Eigen/Geometry>
46 #include <boost/tuple/tuple.hpp>
47 
49 #include <opencv2/opencv.hpp>
50 
51 namespace jsk_recognition_utils
52 {
53 
54  // infinity range, might be slow...
55  class GridMap
56  {
57  public:
59  typedef std::set<int> RowIndices;
60  typedef std::map<int, RowIndices> Columns;
61  typedef Columns::iterator ColumnIterator;
62  typedef std::set<int>::iterator RowIterator;
63  GridMap(double resolution, const std::vector<float>& coefficients);
64  virtual ~GridMap();
65  virtual void registerPoint(const pcl::PointXYZRGB& point);
66  virtual std::vector<GridIndex::Ptr> registerLine(const pcl::PointXYZRGB& from, const pcl::PointXYZRGB& to);
67  virtual void removeIndex(const GridIndex::Ptr& index);
68  virtual void registerPointCloud(pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud);
69  virtual GridIndex::Ptr registerIndex(const GridIndex::Ptr& index);
70  virtual GridIndex::Ptr registerIndex(const int x, const int y);
71  virtual void pointToIndex(const pcl::PointXYZRGB& point, GridIndex::Ptr index);
72  virtual void pointToIndex(const Eigen::Vector3f& point, GridIndex::Ptr index);
73  virtual void indicesToPointCloud(const std::vector<GridIndex::Ptr>& indices,
74  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud);
75  virtual bool getValue(const GridIndex::Ptr& index);
76  virtual bool getValue(const GridIndex& index);
77  virtual bool getValue(const int x, const int y);
78  virtual void gridToPoint(GridIndex::Ptr index, Eigen::Vector3f& pos);
79  virtual void gridToPoint(const GridIndex& index, Eigen::Vector3f& pos);
80  virtual void gridToPoint2(const GridIndex& index, Eigen::Vector3f& pos);
81  virtual void fillRegion(const Eigen::Vector3f& start, std::vector<GridIndex::Ptr>& output);
82  virtual void fillRegion(const GridIndex::Ptr start, std::vector<GridIndex::Ptr>& output);
83  // toMsg does not fill header, be carefull
84  virtual void originPose(Eigen::Affine3f& output);
85  virtual void originPose(Eigen::Affine3d& output);
86  virtual void toMsg(jsk_recognition_msgs::SparseOccupancyGrid& grid);
87  virtual Plane toPlane();
88  virtual Plane::Ptr toPlanePtr();
89  virtual void vote();
90  virtual unsigned int getVoteNum();
91  virtual void setGeneration(unsigned int generation);
92  virtual unsigned int getGeneration();
93  virtual std::vector<float> getCoefficients();
94  virtual bool isBinsOccupied(const Eigen::Vector3f& p);
95  virtual int normalizedWidth();
96  virtual int normalizedHeight();
97  virtual boost::tuple<int, int> minMaxX();
98  virtual boost::tuple<int, int> minMaxY();
99  virtual int widthOffset();
100  virtual int heightOffset();
101  virtual int normalizedIndex(int width_offset, int height_offset,
102  int step,
103  int elem_size,
104  int original_x, int original_y);
105  virtual cv::Mat toImage();
106  virtual bool check4Neighbor(int x, int y);
108  virtual pcl::PointCloud<pcl::PointXYZ>::Ptr toPointCloud();
109  virtual void decrease(int i);
110  virtual void add(GridMap& other);
111  protected:
112  virtual void decreaseOne();
113 
114  double resolution_;
115  Eigen::Vector3f O_;
116 
117  // plane parameter
118  Eigen::Vector3f normal_;
119  double d_;
120 
121  Eigen::Vector3f ex_, ey_;
122 
123  std::vector<GridLine::Ptr> lines_;
125  unsigned int vote_;
126  unsigned int generation_;
127  private:
128  };
129 
130 }
131 
132 #endif
jsk_recognition_utils::GridMap::decreaseOne
virtual void decreaseOne()
Definition: grid_map.cpp:580
jsk_recognition_utils::GridMap::gridToPoint2
virtual void gridToPoint2(const GridIndex &index, Eigen::Vector3f &pos)
Definition: grid_map.cpp:240
jsk_recognition_utils::GridMap::registerPoint
virtual void registerPoint(const pcl::PointXYZRGB &point)
Definition: grid_map.cpp:95
jsk_recognition_utils::GridMap::getValue
virtual bool getValue(const GridIndex::Ptr &index)
Definition: grid_map.cpp:288
jsk_recognition_utils::GridMap::toPlanePtr
virtual Plane::Ptr toPlanePtr()
Definition: grid_map.cpp:410
jsk_recognition_utils::GridMap::removeIndex
virtual void removeIndex(const GridIndex::Ptr &index)
Definition: grid_map.cpp:446
jsk_recognition_utils::GridMap::normalizedWidth
virtual int normalizedWidth()
Definition: grid_map.cpp:507
jsk_recognition_utils::GridMap::resolution_
double resolution_
Definition: grid_map.h:178
jsk_recognition_utils::GridMap::generation_
unsigned int generation_
Definition: grid_map.h:190
jsk_recognition_utils::GridMap::setGeneration
virtual void setGeneration(unsigned int generation)
Definition: grid_map.cpp:437
boost::shared_ptr
jsk_recognition_utils::GridMap::Columns
std::map< int, RowIndices > Columns
Definition: grid_map.h:124
jsk_recognition_utils::GridMap::originPose
virtual void originPose(Eigen::Affine3f &output)
Definition: grid_map.cpp:359
jsk_recognition_utils::GridMap::vote_
unsigned int vote_
Definition: grid_map.h:189
jsk_recognition_utils::GridMap::fillRegion
virtual void fillRegion(const Eigen::Vector3f &start, std::vector< GridIndex::Ptr > &output)
Definition: grid_map.cpp:337
jsk_recognition_utils::GridMap::gridToPoint
virtual void gridToPoint(GridIndex::Ptr index, Eigen::Vector3f &pos)
Definition: grid_map.cpp:229
polygon_array_publisher.p
p
Definition: polygon_array_publisher.py:123
geo_util.h
jsk_recognition_utils
Definition: color_utils.h:41
jsk_recognition_utils::GridMap::~GridMap
virtual ~GridMap()
Definition: grid_map.cpp:70
jsk_recognition_utils::GridIndex::Ptr
boost::shared_ptr< GridIndex > Ptr
Definition: grid_index.h:111
jsk_recognition_utils::GridMap::d_
double d_
Definition: grid_map.h:183
jsk_recognition_utils::GridMap::ColumnIterator
Columns::iterator ColumnIterator
Definition: grid_map.h:125
jsk_recognition_utils::GridMap::RowIterator
std::set< int >::iterator RowIterator
Definition: grid_map.h:126
jsk_recognition_utils::GridMap::minMaxY
virtual boost::tuple< int, int > minMaxY()
Definition: grid_map.cpp:484
jsk_recognition_utils::GridMap::O_
Eigen::Vector3f O_
Definition: grid_map.h:179
jsk_recognition_utils::GridMap::RowIndices
std::set< int > RowIndices
Definition: grid_map.h:123
jsk_recognition_utils::GridMap::toPlane
virtual Plane toPlane()
Definition: grid_map.cpp:405
jsk_recognition_utils::GridMap::normal_
Eigen::Vector3f normal_
Definition: grid_map.h:182
jsk_recognition_utils::GridMap::registerIndex
virtual GridIndex::Ptr registerIndex(const GridIndex::Ptr &index)
Definition: grid_map.cpp:90
jsk_recognition_utils::GridMap::toConvexPolygon
virtual ConvexPolygon::Ptr toConvexPolygon()
Definition: grid_map.cpp:652
jsk_recognition_utils::GridMap::normalizedIndex
virtual int normalizedIndex(int width_offset, int height_offset, int step, int elem_size, int original_x, int original_y)
Definition: grid_map.cpp:533
jsk_recognition_utils::GridMap::pointToIndex
virtual void pointToIndex(const pcl::PointXYZRGB &point, GridIndex::Ptr index)
Definition: grid_map.cpp:218
jsk_recognition_utils::GridMap::getGeneration
virtual unsigned int getGeneration()
Definition: grid_map.cpp:441
jsk_recognition_utils::GridMap::registerPointCloud
virtual void registerPointCloud(pcl::PointCloud< pcl::PointXYZRGB >::Ptr cloud)
Definition: grid_map.cpp:210
jsk_recognition_utils::GridMap::check4Neighbor
virtual bool check4Neighbor(int x, int y)
Definition: grid_map.cpp:568
jsk_recognition_utils::GridMap::add
virtual void add(GridMap &other)
Definition: grid_map.cpp:608
jsk_recognition_utils::GridMap::getVoteNum
virtual unsigned int getVoteNum()
Definition: grid_map.cpp:432
jsk_recognition_utils::GridMap::normalizedHeight
virtual int normalizedHeight()
Definition: grid_map.cpp:513
jsk_recognition_utils::GridMap::isBinsOccupied
virtual bool isBinsOccupied(const Eigen::Vector3f &p)
Definition: grid_map.cpp:458
jsk_recognition_utils::GridMap::decrease
virtual void decrease(int i)
Definition: grid_map.cpp:601
jsk_recognition_utils::GridMap::indicesToPointCloud
virtual void indicesToPointCloud(const std::vector< GridIndex::Ptr > &indices, pcl::PointCloud< pcl::PointXYZRGB >::Ptr cloud)
Definition: grid_map.cpp:344
jsk_recognition_utils::GridMap::ex_
Eigen::Vector3f ex_
Definition: grid_map.h:185
jsk_recognition_utils::GridMap::getCoefficients
virtual std::vector< float > getCoefficients()
Definition: grid_map.cpp:417
jsk_recognition_utils::GridMap::widthOffset
virtual int widthOffset()
Definition: grid_map.cpp:519
grid_line.h
jsk_recognition_utils::GridMap::vote
virtual void vote()
Definition: grid_map.cpp:427
jsk_recognition_utils::GridMap::heightOffset
virtual int heightOffset()
Definition: grid_map.cpp:526
jsk_recognition_utils::GridMap::lines_
std::vector< GridLine::Ptr > lines_
Definition: grid_map.h:187
jsk_recognition_utils::Plane
Definition: plane.h:79
jsk_recognition_utils::GridMap::toPointCloud
virtual pcl::PointCloud< pcl::PointXYZ >::Ptr toPointCloud()
Definition: grid_map.cpp:629
jsk_recognition_utils::GridMap::registerLine
virtual std::vector< GridIndex::Ptr > registerLine(const pcl::PointXYZRGB &from, const pcl::PointXYZRGB &to)
Definition: grid_map.cpp:103
jsk_recognition_utils::GridMap::minMaxX
virtual boost::tuple< int, int > minMaxX()
Definition: grid_map.cpp:466
jsk_recognition_utils::GridMap::toMsg
virtual void toMsg(jsk_recognition_msgs::SparseOccupancyGrid &grid)
Definition: grid_map.cpp:379
jsk_recognition_utils::GridMap::GridMap
GridMap(double resolution, const std::vector< float > &coefficients)
Definition: grid_map.cpp:49
jsk_recognition_utils::GridMap::data_
Columns data_
Definition: grid_map.h:188
jsk_recognition_utils::GridMap::Ptr
boost::shared_ptr< GridMap > Ptr
Definition: grid_map.h:122
jsk_recognition_utils::GridMap::toImage
virtual cv::Mat toImage()
Definition: grid_map.cpp:544
grid_index.h
jsk_recognition_utils::GridMap
Definition: grid_map.h:87
jsk_recognition_utils::GridMap::ey_
Eigen::Vector3f ey_
Definition: grid_map.h:185


jsk_recognition_utils
Author(s):
autogenerated on Tue Jan 7 2025 04:04:52