Apollo  6.0
Open source self driving car software
bitmap2d.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
17 #pragma once
18 
19 #include <vector>
20 
21 #include <boost/format.hpp>
22 #include "Eigen/Core"
23 
24 namespace apollo {
25 namespace perception {
26 namespace lidar {
27 
28 class Bitmap2D {
29  public:
30  enum class DirectionMajor { XMAJOR = 0, YMAJOR = 1 };
31  typedef Eigen::Matrix<size_t, 2, 1> Vec2ui;
32  typedef Eigen::Matrix<size_t, 3, 1> Vec3ui;
33 
34  Bitmap2D() = default;
35  virtual ~Bitmap2D() = default;
36 
38 
39  // getter and setter
40  const Eigen::Vector2d& min_range() const { return min_range_; }
41  const Eigen::Vector2d& max_range() const { return max_range_; }
42  const Eigen::Vector2d& cell_size() const { return cell_size_; }
43  const Vec2ui& map_size() const { return map_size_; }
44  const Vec2ui& dims() const { return dims_; }
45  const std::vector<uint64_t>& bitmap() const { return bitmap_; }
46  int dir_major() const { return static_cast<int>(dir_major_); }
47  int op_dir_major() const { return static_cast<int>(op_dir_major_); }
48 
50  const Eigen::Vector2d& cell_size);
51 
52  void SetUp(const DirectionMajor dir_major);
53 
54  // the only function for range check
55  bool Empty() const { return bitmap_.empty(); }
56  bool IsExists(const Eigen::Vector2d& p) const;
57 
58  bool Check(const Eigen::Vector2d& p) const;
59  void Set(const Eigen::Vector2d& p);
60  void Reset(const Eigen::Vector2d& p);
61 
62  // x for major x, min_y <= valid_y <= max_y
63  void Set(const double x, const double min_y, const double max_y);
64  void Reset(const double x, const double min_y, const double max_y);
65 
66  // output some meta data
67  friend std::ostream& operator<<(std::ostream& out, const Bitmap2D& bitmap) {
68  out << boost::format(
69  "min_range: %lf %lf; max_range: %lf %lf;"
70  "cell_size: %lf %lf; dims: %d %d; dir_major: %s") %
71  bitmap.min_range_.x() % bitmap.min_range_.y() %
72  bitmap.max_range_.x() % bitmap.max_range_.y() %
73  bitmap.cell_size_.x() % bitmap.cell_size_.y() %
74  bitmap.dims_.x() % bitmap.dims_.y() %
75  (bitmap.dir_major_ == DirectionMajor::XMAJOR ? "x" : "y");
76  return out;
77  }
78 
79  private:
80  // closed range
81  inline bool CheckBit(const size_t loc, const uint64_t block) const;
82  inline void SetBit(const size_t loc, uint64_t* block);
83  inline void ResetBit(const size_t loc, uint64_t* block);
84 
85  inline void SetTailBits(const size_t tail_num, uint64_t* block);
86  inline void ResetTailBits(const size_t tail_num, uint64_t* block);
87 
88  inline void SetHeadBits(const size_t tail_num, uint64_t* block);
89  inline void ResetHeadBits(const size_t tail_num, uint64_t* block);
90 
91  inline void SetRangeBits(const size_t head, const size_t tail,
92  uint64_t* block);
93 
94  inline void ResetRangeBits(const size_t head, const size_t tail,
95  uint64_t* block);
96 
97  inline Vec3ui RealToBitmap(const Eigen::Vector2d& p) const;
98  inline int Index(const Vec3ui& p) const;
99 
100  Eigen::Vector2d min_range_;
101  Eigen::Vector2d max_range_;
102  Eigen::Vector2d cell_size_;
103  Vec2ui dims_;
105  DirectionMajor op_dir_major_ = DirectionMajor::YMAJOR;
106 
107  std::vector<uint64_t> bitmap_;
108  Vec2ui map_size_;
109 };
110 
111 } // namespace lidar
112 } // namespace perception
113 } // namespace apollo
int op_dir_major() const
Definition: bitmap2d.h:47
Eigen::Matrix< size_t, 3, 1 > Vec3ui
Definition: bitmap2d.h:32
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
const Eigen::Vector2d & cell_size() const
Definition: bitmap2d.h:42
Definition: bitmap2d.h:28
const Vec2ui & map_size() const
Definition: bitmap2d.h:43
void SetUp(const DirectionMajor dir_major)
Eigen::Vector2d Vector2d
Definition: base_map_fwd.h:36
Eigen::Matrix< size_t, 2, 1 > Vec2ui
Definition: bitmap2d.h:31
DirectionMajor
Definition: bitmap2d.h:30
DirectionMajor OppositeDirection(const DirectionMajor dir_major)
friend std::ostream & operator<<(std::ostream &out, const Bitmap2D &bitmap)
Definition: bitmap2d.h:67
bool IsExists(const Eigen::Vector2d &p) const
bool Empty() const
Definition: bitmap2d.h:55
const std::vector< uint64_t > & bitmap() const
Definition: bitmap2d.h:45
void Set(const Eigen::Vector2d &p)
int dir_major() const
Definition: bitmap2d.h:46
void Reset(const Eigen::Vector2d &p)
const Eigen::Vector2d & max_range() const
Definition: bitmap2d.h:41
void Init(const Eigen::Vector2d &min_range, const Eigen::Vector2d &max_range, const Eigen::Vector2d &cell_size)
const Eigen::Vector2d & min_range() const
Definition: bitmap2d.h:40
const Vec2ui & dims() const
Definition: bitmap2d.h:44
bool Check(const Eigen::Vector2d &p) const