MCPcopy Create free account
hub / github.com/TJU-Aerial-Robotics/YOPO / expand_cloud

Method expand_cloud

Simulator/src/src/sensor_simulator.cpp:100–133  ·  view source on GitHub ↗

TODO: 不能像python那样用一个向量一次性全算吗?

Source from the content-addressed store, hash-verified

98
99// TODO: 不能像python那样用一个向量一次性全算吗?
100void SensorSimulator::expand_cloud(pcl::PointCloud<pcl::PointXYZ>::Ptr expanded_cloud, int direction) {
101 auto start = std::chrono::high_resolution_clock::now();
102 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_temp(new pcl::PointCloud<pcl::PointXYZ>());
103 *cloud_temp = *expanded_cloud;
104 pcl::PointXYZ min_point, max_point;
105 pcl::getMinMax3D(*expanded_cloud, min_point, max_point);
106
107 float min_value = (direction == 0) ? min_point.x : min_point.y;
108 float max_value = (direction == 0) ? max_point.x : max_point.y;
109
110 // 镜像原始点云并添加到扩展点云中
111 for (const auto& point : cloud_temp->points) {
112 pcl::PointXYZ mirrored_point = point;
113 if (direction == 0) {
114 mirrored_point.x = 2 * min_value - point.x; // 以 x 轴最小值为轴进行镜像
115 } else {
116 mirrored_point.y = 2 * min_value - point.y; // 以 y 轴最小值为轴进行镜像
117 }
118 expanded_cloud->push_back(mirrored_point);
119 }
120
121 // 计算偏移量,保证方向上的最小值为0
122 float offset = max_value - min_value;
123 for (auto& point : expanded_cloud->points) {
124 if (direction == 0) {
125 point.x += offset;
126 } else {
127 point.y += offset;
128 }
129 }
130 auto end = std::chrono::high_resolution_clock::now();
131 std::chrono::duration<double> elapsed = end - start;
132 // std::cout << "点云扩张一次耗时: " << elapsed.count() << " 秒" << std::endl; // 输出耗时
133}
134
135
136void SensorSimulator::timerDepthCallback(const ros::TimerEvent&) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected