Apollo 10.0
自动驾驶开放平台
visualization_manager.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 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
21#pragma once
22
23#include <atomic>
24#include <list>
25#include <map>
26#include <string>
27#include <thread>
28#include <utility>
29#include <vector>
30
33
34namespace apollo {
35namespace localization {
36namespace msf {
37
46
48 double timestamp = 0.0;
49 double x = 0;
50 double y = 0;
51 double z = 0;
52
53 double qx = 0.0;
54 double qy = 0.0;
55 double qz = 0.0;
56 double qw = 0.0;
57
58 double std_x = 0;
59 double std_y = 0;
60 double std_z = 0;
61
62 LocalizationMsg interpolate(const double scale,
63 const LocalizationMsg &loc_msg) {
65 res.x = this->x * (1 - scale) + loc_msg.x * scale;
66 res.y = this->y * (1 - scale) + loc_msg.y * scale;
67 res.z = this->z * (1 - scale) + loc_msg.z * scale;
68
69 Eigen::Quaterniond quatd1(this->qw, this->qx, this->qy, this->qz);
70 Eigen::Quaterniond quatd2(loc_msg.qw, loc_msg.qx, loc_msg.qy, loc_msg.qz);
71 Eigen::Quaterniond res_quatd = quatd1.slerp(scale, quatd2);
72 res.qx = res_quatd.x();
73 res.qy = res_quatd.y();
74 res.qz = res_quatd.z();
75 res.qw = res_quatd.w();
76
77 res.std_x = this->std_x * (1 - scale) + loc_msg.std_x * scale;
78 res.std_y = this->std_y * (1 - scale) + loc_msg.std_y * scale;
79 res.std_z = this->std_z * (1 - scale) + loc_msg.std_z * scale;
80
81 return res;
82 }
83};
84
85template <class MessageType>
87 public:
88 typedef
89 typename std::list<std::pair<double, MessageType>>::iterator ListIterator;
90
91 public:
92 explicit MessageBuffer(int capacity);
94
95 bool PushNewMessage(const double timestamp, const MessageType &msg);
96 bool PopOldestMessage(MessageType *msg);
97 bool GetMessageBefore(const double timestamp, MessageType *msg);
98 bool GetMessage(const double timestamp, MessageType *msg);
99
100 void Clear();
101
102 void SetCapacity(const unsigned int capacity);
103 void GetAllMessages(std::list<std::pair<double, MessageType>> *msg_list);
104
105 bool IsEmpty();
106 unsigned int BufferSize();
107
108 protected:
109 std::map<double, ListIterator> msg_map_;
110 std::list<std::pair<double, MessageType>> msg_list_;
111
112 protected:
113 pthread_mutex_t buffer_mutex_;
114 unsigned int capacity_;
115};
116
117template <class MessageType>
118class IntepolationMessageBuffer : public MessageBuffer<MessageType> {
119 public:
120 typedef
121 typename std::list<std::pair<double, MessageType>>::iterator ListIterator;
122
123 public:
124 explicit IntepolationMessageBuffer(int capacity);
126
127 bool QueryMessage(const double timestamp, MessageType *msg,
128 double timeout_s = 0.01);
129
130 private:
131 bool WaitMessageBufferOk(const double timestamp,
132 std::map<double, ListIterator> *msg_map,
133 std::list<std::pair<double, MessageType>> *msg_list,
134 double timeout_ms);
135};
136
148
150#define LOC_INFO_NUM 3
151
152 public:
155
157 static VisualizationManager visual_manage;
158 return visual_manage;
159 }
160
161 bool Init(const std::string &map_folder, const std::string &map_visual_folder,
162 const Eigen::Affine3d &velodyne_extrinsic,
163 const VisualMapParam &map_param);
164 bool Init(const VisualizationManagerParams &params);
165
166 void AddLidarFrame(const LidarVisFrame &lidar_frame);
167 void AddGNSSLocMessage(const LocalizationMsg &gnss_loc_msg);
168 void AddLidarLocMessage(const LocalizationMsg &lidar_loc_msg);
169 void AddFusionLocMessage(const LocalizationMsg &fusion_loc_msg);
170 void StartVisualization();
171 void StopVisualization();
172
173 private:
174 void DoVisualize();
175 bool GetZoneIdFromMapFolder(const std::string &map_folder,
176 const unsigned int resolution_id, int *zone_id);
177
178 private:
179 VisualizationEngine visual_engine_;
180 // Visualization Thread
181 std::thread visual_thread_;
182 std::atomic<bool> stop_visualization_;
183
184 MessageBuffer<LidarVisFrame> lidar_frame_buffer_;
185 IntepolationMessageBuffer<LocalizationMsg> gnss_loc_info_buffer_;
186 IntepolationMessageBuffer<LocalizationMsg> lidar_loc_info_buffer_;
187 IntepolationMessageBuffer<LocalizationMsg> fusion_loc_info_buffer_;
188};
189
190} // namespace msf
191} // namespace localization
192} // namespace apollo
bool QueryMessage(const double timestamp, MessageType *msg, double timeout_s=0.01)
std::list< std::pair< double, MessageType > >::iterator ListIterator
bool GetMessageBefore(const double timestamp, MessageType *msg)
std::list< std::pair< double, MessageType > >::iterator ListIterator
bool GetMessage(const double timestamp, MessageType *msg)
void SetCapacity(const unsigned int capacity)
std::list< std::pair< double, MessageType > > msg_list_
void GetAllMessages(std::list< std::pair< double, MessageType > > *msg_list)
bool PushNewMessage(const double timestamp, const MessageType &msg)
std::map< double, ListIterator > msg_map_
The engine to draw all elements for visualization.
void AddLidarLocMessage(const LocalizationMsg &lidar_loc_msg)
void AddFusionLocMessage(const LocalizationMsg &fusion_loc_msg)
void AddLidarFrame(const LidarVisFrame &lidar_frame)
bool Init(const std::string &map_folder, const std::string &map_visual_folder, const Eigen::Affine3d &velodyne_extrinsic, const VisualMapParam &map_param)
void AddGNSSLocMessage(const LocalizationMsg &gnss_loc_msg)
EigenVector< Eigen::Vector3d > EigenVector3dVec
Definition eigen_defs.h:46
class register implement
Definition arena_queue.h:37
::apollo::common::EigenVector3dVec pt3ds
The 3D point cloud in this frame.
LocalizationMsg interpolate(const double scale, const LocalizationMsg &loc_msg)
The data structure to store parameters of a map
EIGEN_MAKE_ALIGNED_OPERATOR_NEW std::string map_folder
The engine for localization visualization.