Apollo 10.0
自动驾驶开放平台
bitmap2d.h
浏览该文件的文档.
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
23#include "Eigen/Core"
24
25namespace apollo {
26namespace perception {
27namespace lidar {
28
29class Bitmap2D {
30 public:
31 enum class DirectionMajor { XMAJOR = 0, YMAJOR = 1 };
32 typedef Eigen::Matrix<size_t, 2, 1> Vec2ui;
33 typedef Eigen::Matrix<size_t, 3, 1> Vec3ui;
34
39 Bitmap2D() = default;
40
45 virtual ~Bitmap2D() = default;
46
54
55 // getter and setter
61 const Eigen::Vector2d& min_range() const { return min_range_; }
62
68 const Eigen::Vector2d& max_range() const { return max_range_; }
69
75 const Eigen::Vector2d& cell_size() const { return cell_size_; }
76
82 const Vec2ui& map_size() const { return map_size_; }
83
89 const Vec2ui& dims() const { return dims_; }
90
96 const std::vector<uint64_t>& bitmap() const { return bitmap_; }
97
103 int dir_major() const { return static_cast<int>(dir_major_); }
104
110 int op_dir_major() const { return static_cast<int>(op_dir_major_); }
111
119 void Init(const Eigen::Vector2d& min_range, const Eigen::Vector2d& max_range,
120 const Eigen::Vector2d& cell_size);
121
127 void SetUp(const DirectionMajor dir_major);
128
129 // the only function for range check
136 bool Empty() const { return bitmap_.empty(); }
137
145 bool IsExists(const Eigen::Vector2d& p) const;
146
154 bool Check(const Eigen::Vector2d& p) const;
155
161 void Set(const Eigen::Vector2d& p);
162
168 void Reset(const Eigen::Vector2d& p);
169
170 // x for major x, min_y <= valid_y <= max_y
178 void Set(const double x, const double min_y, const double max_y);
179
187 void Reset(const double x, const double min_y, const double max_y);
188
196 friend std::ostream& operator<<(std::ostream& out, const Bitmap2D& bitmap) {
197 out << boost::format(
198 "min_range: %lf %lf; max_range: %lf %lf;"
199 "cell_size: %lf %lf; dims: %d %d; dir_major: %s") %
200 bitmap.min_range_.x() % bitmap.min_range_.y() %
201 bitmap.max_range_.x() % bitmap.max_range_.y() %
202 bitmap.cell_size_.x() % bitmap.cell_size_.y() %
203 bitmap.dims_.x() % bitmap.dims_.y() %
204 (bitmap.dir_major_ == DirectionMajor::XMAJOR ? "x" : "y");
205 return out;
206 }
207
208 private:
209 // closed range
210 inline bool CheckBit(const size_t loc, const uint64_t block) const;
211 inline void SetBit(const size_t loc, uint64_t* block);
212 inline void ResetBit(const size_t loc, uint64_t* block);
213
214 inline void SetTailBits(const size_t tail_num, uint64_t* block);
215 inline void ResetTailBits(const size_t tail_num, uint64_t* block);
216
217 inline void SetHeadBits(const size_t tail_num, uint64_t* block);
218 inline void ResetHeadBits(const size_t tail_num, uint64_t* block);
219
220 inline void SetRangeBits(const size_t head, const size_t tail,
221 uint64_t* block);
222
223 inline void ResetRangeBits(const size_t head, const size_t tail,
224 uint64_t* block);
225
226 inline Vec3ui RealToBitmap(const Eigen::Vector2d& p) const;
227 inline int Index(const Vec3ui& p) const;
228
229 Eigen::Vector2d min_range_;
230 Eigen::Vector2d max_range_;
231 Eigen::Vector2d cell_size_;
232 Vec2ui dims_;
233 DirectionMajor dir_major_ = DirectionMajor::XMAJOR;
234 DirectionMajor op_dir_major_ = DirectionMajor::YMAJOR;
235
236 std::vector<uint64_t> bitmap_;
237 Vec2ui map_size_;
238};
239
240} // namespace lidar
241} // namespace perception
242} // namespace apollo
virtual ~Bitmap2D()=default
Destroy the Bitmap 2D object
const Eigen::Vector2d & max_range() const
Return the max_range_
Definition bitmap2d.h:68
void Set(const Eigen::Vector2d &p)
Set the vector p
Definition bitmap2d.cc:128
int dir_major() const
Return the dir_major_
Definition bitmap2d.h:103
void SetUp(const DirectionMajor dir_major)
Set the dir_major_ and op_dir_major_
Definition bitmap2d.cc:92
DirectionMajor OppositeDirection(const DirectionMajor dir_major)
Opposite direction of direction_major
Definition bitmap2d.cc:28
bool IsExists(const Eigen::Vector2d &p) const
check the vector p is in bitmap_
Definition bitmap2d.cc:115
const Vec2ui & dims() const
Retrun the dims_
Definition bitmap2d.h:89
void Reset(const Eigen::Vector2d &p)
Reset the vector p
Definition bitmap2d.cc:134
Bitmap2D()=default
Construct a new Bitmap 2D object
const Eigen::Vector2d & min_range() const
Return the min_range_
Definition bitmap2d.h:61
const std::vector< uint64_t > & bitmap() const
Return the bitmap_
Definition bitmap2d.h:96
friend std::ostream & operator<<(std::ostream &out, const Bitmap2D &bitmap)
print some meta data
Definition bitmap2d.h:196
int op_dir_major() const
Return the op_dir_major
Definition bitmap2d.h:110
Eigen::Matrix< size_t, 3, 1 > Vec3ui
Definition bitmap2d.h:33
void Init(const Eigen::Vector2d &min_range, const Eigen::Vector2d &max_range, const Eigen::Vector2d &cell_size)
Init of Bitmap 2D object
Definition bitmap2d.cc:72
bool Empty() const
cehck the bitmap_ is emtpy
Definition bitmap2d.h:136
const Vec2ui & map_size() const
Return the map_size_
Definition bitmap2d.h:82
bool Check(const Eigen::Vector2d &p) const
Check the vector p
Definition bitmap2d.cc:121
Eigen::Matrix< size_t, 2, 1 > Vec2ui
Definition bitmap2d.h:32
const Eigen::Vector2d & cell_size() const
Return the cell_size_
Definition bitmap2d.h:75
class register implement
Definition arena_queue.h:37