-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloud_show.cpp
executable file
·265 lines (216 loc) · 7.03 KB
/
cloud_show.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#include "ag_driver/api/lidar_driver.hpp"
#include "ag_driver/msg/pcl_point_cloud_msg.hpp"
#include <pcl/point_types.h>
#include <pcl/visualization/pcl_visualizer.h>
using namespace asensing::lidar;
using namespace pcl::visualization;
typedef PointCloudT<PointXYZIRT> PointCloudMsg;
typedef PointXYZIRT PCLMsg;
//typedef pcl::PointXYZI PCLMsg
std::shared_ptr<PCLVisualizer> pcl_viewer;
std::mutex mtx_viewer;
SyncQueue<std::shared_ptr<PointCloudMsg>> free_cloud_queue;
SyncQueue<std::shared_ptr<PointCloudMsg>> stuffed_cloud_queue;
bool ViewerStopFlag =false;
bool checkKeywordExist(int argc, const char* const* argv, const char* str)
{
for (int i = 1; i < argc; i++)
{
if (strcmp(argv[i], str) == 0)
{
return true;
}
}
return false;
}
bool parseArgument(int argc, const char* const* argv, const char* str, std::string& val)
{
int index = -1;
for (int i = 1; i < argc; i++)
{
if (strcmp(argv[i], str) == 0)
{
index = i + 1;
}
}
if (index > 0 && index < argc)
{
val = argv[index];
return true;
}
return false;
}
void parseParam(int argc, char* argv[], AGDriverParam& param)
{
std::string result_str;
//
// input param
//
parseArgument(argc, argv, "-pcap", param.input_param.pcap_path);
if (param.input_param.pcap_path.empty())
{
param.input_type = InputType::ONLINE_LIDAR;
}
else
{
param.input_type = InputType::PCAP_FILE;
// param.input_param.pcap_repeat = false;
}
if (parseArgument(argc, argv, "-msop", result_str))
{
param.input_param.msop_port = std::stoi(result_str);
}
if (parseArgument(argc, argv, "-difop", result_str))
{
param.input_param.difop_port = std::stoi(result_str);
}
parseArgument(argc, argv, "-group", param.input_param.group_address);
parseArgument(argc, argv, "-host", param.input_param.host_address);
//
// decoder param
//
if (parseArgument(argc, argv, "-type", result_str))
{
param.lidar_type = strToLidarType(result_str);
}
if (parseArgument(argc, argv, "-x", result_str))
{
param.decoder_param.transform_param.x = std::stof(result_str);
}
if (parseArgument(argc, argv, "-y", result_str))
{
param.decoder_param.transform_param.y = std::stof(result_str);
}
if (parseArgument(argc, argv, "-z", result_str))
{
param.decoder_param.transform_param.z = std::stof(result_str);
}
if (parseArgument(argc, argv, "-roll", result_str))
{
param.decoder_param.transform_param.roll = std::stof(result_str);
}
if (parseArgument(argc, argv, "-elevation", result_str))
{
param.decoder_param.transform_param.elevation = std::stof(result_str);
}
if (parseArgument(argc, argv, "-azimuth", result_str))
{
param.decoder_param.transform_param.azimuth = std::stof(result_str);
}
}
void printHelpMenu()
{
AG_MSG << "Arguments: " << AG_REND;
AG_MSG << " -type = LiDAR type(A0)" << AG_REND;
AG_MSG << " -pcap = The path of the pcap file, off-line mode if it is true, else online mode." << AG_REND;
AG_MSG << " -msop = LiDAR msop port number, the default value is 3355." << AG_REND;
AG_MSG << " -difop = LiDAR difop port number, the default value is 4466." << AG_REND;
AG_MSG << " -group = LiDAR destination group address if multi-cast mode." << AG_REND;
AG_MSG << " -host = Host address." << AG_REND;
AG_MSG << " -x = Transformation parameter, unit: m " << AG_REND;
AG_MSG << " -y = Transformation parameter, unit: m " << AG_REND;
AG_MSG << " -z = Transformation parameter, unit: m " << AG_REND;
AG_MSG << " -roll = Transformation parameter, unit: radian " << AG_REND;
AG_MSG << " -elevation = Transformation parameter, unit: radian " << AG_REND;
AG_MSG << " -azimuth = Transformation parameter, unit: radian " << AG_REND;
AG_MSG << "" << AG_REND;
AG_MSG << "Example: cloudshow -type A0 -pcap /opt/data/A0-test.pcap" << AG_REND;
}
void exceptionCallback(const Error& code)
{
AG_WARNING << code.toString() << AG_REND;
}
std::shared_ptr<PointCloudMsg> pointCloudGetCallback(void)
{
std::shared_ptr<PointCloudMsg> msg = free_cloud_queue.pop();
if (msg.get() != NULL)
{
return msg;
}
return std::make_shared<PointCloudMsg>();
}
void pointCloudPutCallback(std::shared_ptr<PointCloudMsg> msg)
{
stuffed_cloud_queue.push(msg);
}
bool to_exit_process = false;
void processCloud(void)
{
while (!to_exit_process)
{
std::shared_ptr<PointCloudMsg> msg = stuffed_cloud_queue.popWait();
if (msg.get() == NULL)
{
continue;
}
// AG_DEBUG << "[" << msg->frame_id << "] Width = " << msg->width << ", Height = " << msg->height << ", Size = " << msg->points.size() << AG_REND;
//
// show the point cloud
//
pcl::PointCloud<PCLMsg>::Ptr pcl_pointcloud(new pcl::PointCloud<PCLMsg>);
pcl_pointcloud->points.swap(msg->points);
pcl_pointcloud->height = msg->height;
pcl_pointcloud->width = msg->width;
pcl_pointcloud->is_dense = msg->is_dense;
PointCloudColorHandlerGenericField<PCLMsg> point_color_handle(pcl_pointcloud, "range");
{
const std::lock_guard<std::mutex> lock(mtx_viewer);
pcl_viewer->updatePointCloud<PCLMsg>(pcl_pointcloud, point_color_handle, "aglidar");
}
free_cloud_queue.push(msg);
}
}
int main(int argc, char* argv[])
{
AG_TITLE << "------------------------------------------------------" << AG_REND;
AG_TITLE << " CloudShow Version: v" << getDriverVersion() << AG_REND;
AG_TITLE << "------------------------------------------------------" << AG_REND;
if (argc < 2)
{
printHelpMenu();
return 0;
}
if (checkKeywordExist(argc, argv, "-h") || checkKeywordExist(argc, argv, "--help"))
{
printHelpMenu();
return 0;
}
std::thread cloud_handle_thread = std::thread(processCloud);
#ifndef WIN32
pthread_setname_np(cloud_handle_thread.native_handle(), "process_cloud");
#endif
AGDriverParam param;
// param.decoder_param.dense_points = true;
parseParam(argc, argv, param);
param.print();
pcl_viewer = std::make_shared<PCLVisualizer>("Cloud Show");
pcl_viewer->setBackgroundColor(0.0, 0.0, 0.0);
pcl_viewer->setCameraPosition(0, 0, 20, 0, 0, -1, 1, 0, 0);
pcl_viewer->addCoordinateSystem(1.0);
pcl::PointCloud<PCLMsg>::Ptr pcl_pointcloud(new pcl::PointCloud<PCLMsg>);
pcl_viewer->addPointCloud<PCLMsg>(pcl_pointcloud, "aglidar");
pcl_viewer->setPointCloudRenderingProperties(PCL_VISUALIZER_POINT_SIZE, 2, "aglidar");
LidarDriver<PointCloudMsg> driver;
driver.regExceptionCallback(exceptionCallback);
driver.regPointCloudCallback(pointCloudGetCallback, pointCloudPutCallback);
if (!driver.init(param))
{
AG_ERROR << "Driver Initialize Error..." << AG_REND;
return -1;
}
AG_INFO << "Asensing Lidar-Driver Viewer start......" << AG_REND;
driver.setDefaultSelectionParam();
driver.start();
while (!pcl_viewer->wasStopped())
{
{
const std::lock_guard<std::mutex> lock(mtx_viewer);
pcl_viewer->spinOnce();
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
driver.stop();
to_exit_process = true;
cloud_handle_thread.join();
return 0;
}