Skip to content

Commit

Permalink
improve readability
Browse files Browse the repository at this point in the history
Signed-off-by: kyoichi-sugahara <kyoichi.sugahara@tier4.jp>
  • Loading branch information
kyoichi-sugahara committed Aug 25, 2023
1 parent eeba145 commit 917d37d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,37 @@ PredictedObjects filterObjects(
const std::shared_ptr<ObjectsFilteringParams> & params);

/**
* @brief Filter objects based on their velocity.
* @brief Filters objects based on their velocity.
*
* @param objects The predicted objects to filter.
* @param lim_v Velocity limit for filtering.
* @return PredictedObjects The filtered objects.
* Depending on the remove_above_threshold parameter, this function either removes objects with
* velocities above the given threshold or only keeps those objects. It uses the helper function
* filterObjectsByVelocity() to do the actual filtering.
*
* @param objects The objects to be filtered.
* @param velocity_threshold The velocity threshold for the filtering.
* @param remove_above_threshold If true, objects with velocities above the threshold are removed.
* If false, only objects with velocities above the threshold are
* kept.
* @return A new collection of objects that have been filtered according to the rules.
*/
PredictedObjects filterObjectsByVelocity(
const PredictedObjects & objects, const double lim_v, const bool filter_dynamic_objects = true);
const PredictedObjects & objects, const double velocity_threshold,
const bool remove_above_threshold == true);

/**
* @brief Filter objects based on a velocity range.
* @brief Helper function to filter objects based on their velocity.
*
* @param objects The predicted objects to filter.
* @param min_v Minimum velocity for filtering.
* @param max_v Maximum velocity for filtering.
* @return PredictedObjects The filtered objects.
* This function iterates over all objects and calculates their velocity norm. If the velocity norm
* is within the velocity_threshold and max_velocity range, the object is added to a new collection.
* This new collection is then returned.
*
* @param objects The objects to be filtered.
* @param velocity_threshold The minimum velocity for an object to be included in the output.
* @param max_velocity The maximum velocity for an object to be included in the output.
* @return A new collection of objects that have been filtered according to the rules.
*/
PredictedObjects filterObjectsByVelocity(
const PredictedObjects & objects, double min_v, double max_v);
const PredictedObjects & objects, double velocity_threshold, double max_velocity);

/**
* @brief Filter objects based on their position relative to a current_pose.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,26 @@ PredictedObjects filterObjects(
}

PredictedObjects filterObjectsByVelocity(
const PredictedObjects & objects, double lim_v, const bool filter_dynamic_objects)
const PredictedObjects & objects, const double velocity_threshold,
const bool remove_above_threshold)
{
if (filter_dynamic_objects) {
return filterObjectsByVelocity(objects, -lim_v, lim_v);
return filterObjectsByVelocity(objects, -velocity_threshold, velocity_threshold);
} else {
return filterObjectsByVelocity(objects, lim_v, std::numeric_limits<double>::max());
return filterObjectsByVelocity(objects, velocity_threshold, std::numeric_limits<double>::max());
}
}

PredictedObjects filterObjectsByVelocity(
const PredictedObjects & objects, double min_v, double max_v)
const PredictedObjects & objects, double velocity_threshold, double max_velocity)
{
PredictedObjects filtered;
filtered.header = objects.header;
for (const auto & obj : objects.objects) {
const auto v_norm = std::hypot(
obj.kinematics.initial_twist_with_covariance.twist.linear.x,
obj.kinematics.initial_twist_with_covariance.twist.linear.y);
if (min_v < v_norm && v_norm < max_v) {
if (velocity_threshold < v_norm && v_norm < max_velocity) {
filtered.objects.push_back(obj);
}
}
Expand Down

0 comments on commit 917d37d

Please sign in to comment.