pcod-common v1.0.0
Shared preprocessing and postprocessing for point-cloud object detection
Loading...
Searching...
No Matches
point_preprocess.cpp
Go to the documentation of this file.
1// Copyright Institute for Automotive Engineering (ika), RWTH Aachen University
2// SPDX-License-Identifier: Apache-2.0
3
5
6#include <stdexcept>
7
8namespace pcod_common {
9
11 if (value == "none") {
13 }
14 if (value == "value_threshold") {
16 }
17 if (value == "min_max") {
19 }
20 if (value == "z_score") {
22 }
23 throw std::runtime_error("Unsupported point feature normalization type: " + value);
24}
25
26bool PointPreprocessor::IsPointValid(float x, float y, float z) const {
27 const bool in_range = (x >= config_.x_min && x < config_.x_max && !std::isnan(x) && y >= config_.y_min && y < config_.y_max &&
28 !std::isnan(y) && z >= config_.z_min && z < config_.z_max && !std::isnan(z));
29 if (!in_range) {
30 return false;
31 }
32
33 if (config_.det_area_remove_outside) {
34 const float delta_x = x - config_.da_cx;
35 const float delta_y = y - config_.da_cy;
36 const float squared_distance_to_center = delta_x * delta_x + delta_y * delta_y;
37 if (squared_distance_to_center > config_.da_radius * config_.da_radius) {
38 return false;
39 }
40 float angle_to_center = std::atan2(delta_y, delta_x);
41 float angle_offset = angle_to_center - config_.da_bearing_rad;
42 while (angle_offset > static_cast<float>(M_PI)) {
43 angle_offset -= static_cast<float>(2.0 * M_PI);
44 }
45 while (angle_offset < static_cast<float>(-M_PI)) {
46 angle_offset += static_cast<float>(2.0 * M_PI);
47 }
48 if (std::abs(angle_offset) > config_.da_fov_rad * 0.5F + 1e-6F) {
49 return false;
50 }
51 }
52
53 if (config_.remove_points_in_zone) {
54 const bool in_nd_zone = (x >= config_.nd_x_min && x <= config_.nd_x_max && y >= config_.nd_y_min && y <= config_.nd_y_max);
55 if (in_nd_zone) {
56 return false;
57 }
58 }
59
60 return true;
61}
62
63void PointPreprocessor::SetZScoreStats(float mean, float stddev) {
64 z_score_mean_ = mean;
65 z_score_std_ = std::abs(stddev) > config_.epsilon ? stddev : config_.epsilon;
66}
67
68float PointPreprocessor::NormalizePointFeature(float intensity) const {
70 return intensity;
71 }
73 if (config_.value_threshold <= 0.0F) {
74 return intensity;
75 }
76 const float clipped = std::min(std::max(intensity, 0.0F), config_.value_threshold);
77 return clipped / std::max(config_.value_threshold, config_.epsilon);
78 }
80 const float denom = std::max(config_.max_value - config_.min_value, config_.epsilon);
81 const float scaled = (intensity - config_.min_value) / denom;
82 return std::min(std::max(scaled, 0.0F), 1.0F);
83 }
85 return (intensity - z_score_mean_) / std::max(z_score_std_, config_.epsilon);
86 }
87 return intensity;
88}
89
90} // namespace pcod_common
float NormalizePointFeature(float intensity) const
bool IsPointValid(float x, float y, float z) const
void SetZScoreStats(float mean, float stddev)
PointFeatureNormalizationType ParsePointFeatureNormalizationType(const std::string &value)
bool remove_points_in_zone
Enable rectangular no-detection-zone filtering.
float min_value
Minimum for min-max normalization.
float da_cy
Detection-area center Y.
float x_max
Maximum accepted X coordinate.
float value_threshold
Divisor for value-threshold normalization.
bool det_area_remove_outside
Enable radial field-of-view filtering.
float y_min
Minimum accepted Y coordinate.
float epsilon
Lower bound for unsafe normalization divisors.
float z_min
Minimum accepted Z coordinate.
float nd_x_min
No-detection-zone minimum X.
float x_min
Minimum accepted X coordinate.
float da_radius
Detection-area radius.
float z_max
Maximum accepted Z coordinate.
float da_fov_rad
Detection-area angular width in radians.
float nd_y_max
No-detection-zone maximum Y.
float da_bearing_rad
Detection-area center bearing in radians.
float y_max
Maximum accepted Y coordinate.
float da_cx
Detection-area center X.
float max_value
Maximum for min-max normalization.
PointFeatureNormalizationType normalization_type
Feature transform.
float nd_x_max
No-detection-zone maximum X.
float nd_y_min
No-detection-zone minimum Y.