99 if (frame ==
nullptr) {
100 AERROR <<
"Input null frame ptr.";
104 AERROR <<
"Input null frame cloud.";
108 AERROR <<
"Input none points.";
112 unsigned int data_id = 0;
113 unsigned int valid_point_num = 0;
114 unsigned int valid_point_num_cur = 0;
116 size_t num_points = 0;
117 size_t num_points_all = 0;
119 unsigned int nr_points_element = 3;
140 num_points_all = num_points;
142 if (num_points_all > default_point_size_) {
143 default_point_size_ = num_points * 2;
144 point_attribute_.resize(default_point_size_);
145 point_indices_temp_.resize(default_point_size_);
146 data_.resize(default_point_size_ * 3);
147 ground_height_signed_.resize(default_point_size_);
153 for (i = 0; i < num_points; ++i) {
156 frame->
cloud->points_semantic_label(index) & 15) !=
158 point_attribute_[i] = std::make_pair(index, -1);
161 point_attribute_[i] = std::make_pair(index, valid_point_num);
162 point_indices_temp_[valid_point_num++] = index;
163 if (single_ground_detect_) {
164 const auto& pt = frame->
cloud->at(index);
165 data_[data_id++] =
static_cast<float>(pt.x);
166 data_[data_id++] =
static_cast<float>(pt.y);
167 data_[data_id++] =
static_cast<float>(pt.z);
170 data_[data_id++] =
static_cast<float>(pt.x - cloud_center_(0));
171 data_[data_id++] =
static_cast<float>(pt.y - cloud_center_(1));
172 data_[data_id++] =
static_cast<float>(pt.z - cloud_center_(2));
176 for (i = 0; i < num_points; ++i) {
178 frame->
cloud->points_semantic_label(i) & 15) !=
180 point_attribute_[i] = std::make_pair(i, -1);
183 point_attribute_[i] = std::make_pair(i, valid_point_num);
184 point_indices_temp_[valid_point_num++] =
static_cast<int>(i);
185 if (single_ground_detect_) {
186 const auto& pt = frame->
cloud->at(i);
187 data_[data_id++] =
static_cast<float>(pt.x);
188 data_[data_id++] =
static_cast<float>(pt.y);
189 data_[data_id++] =
static_cast<float>(pt.z);
192 data_[data_id++] =
static_cast<float>(pt.x - cloud_center_(0));
193 data_[data_id++] =
static_cast<float>(pt.y - cloud_center_(1));
194 data_[data_id++] =
static_cast<float>(pt.z - cloud_center_(2));
199 CHECK_GE(num_points, valid_point_num);
200 CHECK_EQ(data_id, valid_point_num * 3);
203 AINFO <<
"spatial temporal seg: use roi " << use_roi_ <<
" roi points "
204 << num_points <<
" and input of ground detector: " << valid_point_num;
206 pfdetector_->
ResetParams(ori_sample_z_lower_, ori_sample_z_upper_);
207 if (use_semantic_ground_) {
209 parsing_height_buffer_, frame->
timestamp);
211 if (!pfdetector_->
Detect(data_.data(), ground_height_signed_.data(),
212 valid_point_num, nr_points_element)) {
213 ADEBUG <<
"failed to call ground detector!";
214 non_ground_indices.
indices.insert(
215 non_ground_indices.
indices.end(), point_indices_temp_.begin(),
216 point_indices_temp_.begin() + valid_point_num);
236 size_t ground_z_value_count = 0;
237 float ground_z_value = 0.0;
238 if (origin_ground_z_array_.size() >= ground_z_average_frame) {
239 origin_ground_z_array_.pop_front();
241 auto valid_index = [&](
int row,
int col) {
242 if (row >= 0 && row < grid_size_ && col >= 0 && col < grid_size_) {
247 for (i = 0; i < num_points; ++i) {
250 size_t pc_index = point_attribute_[i].first;
251 size_t count = point_attribute_[i].second;
254 if (single_ground_detect_) {
255 const auto& pt = frame->
cloud->at(pc_index);
261 pc[0] = pt.x - cloud_center_(0);
262 pc[1] = pt.y - cloud_center_(1);
263 pc[2] = pt.z - cloud_center_(2);
266 int cur_row, cur_col = 0;
267 std::vector<std::pair<int, int>> neighbors;
268 pfdetector_->
Pc2Voxel(pc[0], pc[1], pc[2], &cur_row, &cur_col);
269 neighbors.push_back(std::make_pair(cur_row, cur_col));
270 neighbors.push_back(std::make_pair(cur_row - 1, cur_col));
271 neighbors.push_back(std::make_pair(cur_row + 1, cur_col));
272 neighbors.push_back(std::make_pair(cur_row, cur_col - 1));
273 neighbors.push_back(std::make_pair(cur_row, cur_col + 1));
274 float min_z = std::numeric_limits<float>::max();
275 for (
size_t k = 0; k < neighbors.size(); k++) {
276 int row = neighbors[k].first;
277 int col = neighbors[k].second;
278 if (!valid_index(row, col)) {
286 min_z = std::fabs(z_dis) < min_z ? std::fabs(z_dis) : min_z;
291 z_dis = ground_height_signed_.data()[count];
293 frame->
cloud->mutable_points_height()->at(pc_index) = z_dis;
294 frame->
world_cloud->mutable_points_height()->at(pc_index) = z_dis;
296 const auto& ppp = frame->
cloud->at(pc_index);
297 Eigen::Vector3d pc_novatel =
299 float threshold = ground_thres_;
300 if (pc_novatel(1) > 0 && pc_novatel(1) < near_range_dist_ &&
301 pc_novatel(0) > FLAGS_x_back - 0.1 &&
302 pc_novatel(0) < FLAGS_x_front + 0.1) {
303 threshold = near_range_ground_thres_;
305 if (pc_novatel(1) >= near_range_dist_ &&
306 pc_novatel(1) < middle_range_dist_ &&
307 pc_novatel(0) > FLAGS_x_back - 0.1 &&
308 pc_novatel(0) < FLAGS_x_front + 0.1) {
309 threshold = middle_range_ground_thres_;
313 if (z_dis > threshold) {
314 non_ground_indices.
indices.push_back(i);
316 frame->
cloud->mutable_points_label()->at(pc_index) =
318 frame->
world_cloud->mutable_points_label()->at(pc_index) =
320 if (sqrt(ppp.x * ppp.x + ppp.y * ppp.y) < 8 && fabs(z_dis) < 0.1) {
321 ++ground_z_value_count;
322 ground_z_value += ppp.z;
326 AINFO <<
"succeed to call ground detector with non ground points "
327 << non_ground_indices.
indices.size();
329 float oriHeight = ground_z_value /
330 (
static_cast<float>(ground_z_value_count) * 1.0f);
331 origin_ground_z_array_.push_back(oriHeight);
332 float ori_height = 0.0;
333 for (
auto value : origin_ground_z_array_) {
337 (
static_cast<float>(origin_ground_z_array_.size()) * 1.0f);
343 out1.open(
"semantic/" + std::to_string(frame->
timestamp) +
".txt");
344 if (out1.is_open()) {
345 for (
size_t i = 0; i < frame->
cloud->size(); i++) {
347 frame->
cloud->points_semantic_label(i) & 15));
348 int label_index =
static_cast<uint8_t
>(
349 frame->
cloud->points_label(i));
350 if (single_ground_detect_) {
351 const auto& pt = frame->
cloud->at(i);
352 out1 << pt.x <<
", " << pt.y <<
", " << pt.z <<
", "
353 << pt.intensity <<
", " << index <<
", " << label_index
357 out1 << pt.x - cloud_center_(0) <<
", "
358 << pt.y - cloud_center_(1) <<
", "
359 << pt.z - cloud_center_(2) <<
", " << pt.intensity
360 <<
", " << index <<
", " << label_index << std::endl;
367 if (use_ground_service_) {
369 if (ground_service !=
nullptr) {
375 unsigned int index = 0;
376 for (
unsigned int r = 0; r < rows; ++r) {
377 for (
unsigned int c = 0; c < cols; ++c) {
381 index = r * cols + c;
391 ground_service->UpdateServiceContent(ground_service_content_);
393 AINFO <<
"Failed to find ground service and cannot update.";