Skip to content

Commit 696ab0e

Browse files
committed
Avoid unnecessary iterations in FOV traversal by using a for loop
1 parent cb87cf7 commit 696ab0e

File tree

2 files changed

+21
-34
lines changed

2 files changed

+21
-34
lines changed

include/continuous_clustering/clustering/continuous_clustering.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ class RangeImageIndex
9797
return row_index == other.row_index && column_index == other.column_index;
9898
}
9999

100+
bool operator!=(const RangeImageIndex& other) const
101+
{
102+
return row_index != other.row_index || column_index != other.column_index;
103+
}
104+
105+
100106
bool operator<(const RangeImageIndex& other) const
101107
{
102108
return row_index < other.row_index || (row_index == other.row_index && column_index < other.column_index);

src/clustering/continuous_clustering.cpp

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -701,11 +701,11 @@ void ContinuousClustering::traverseFieldOfView(Point& point,
701701
{
702702
// go left each column until azimuth angle difference gets too large
703703
double min_possible_continuous_azimuth_angle = point.continuous_azimuth_angle - max_angle_diff;
704-
int num_steps_back = 0;
704+
int required_steps_back = static_cast<int>(std::ceil(max_angle_diff / srig_azimuth_width_per_column));
705+
required_steps_back = std::min(required_steps_back, config_.clustering.max_steps_in_row);
705706
int64_t other_column_index = point.local_column_index;
706-
while (num_steps_back <= config_.clustering.max_steps_in_row)
707+
for (int num_steps_back = 0; num_steps_back <= required_steps_back; num_steps_back++)
707708
{
708-
bool at_least_one_point_of_this_column_in_azimuth_range = false;
709709
for (int direction = -1; direction <= 1; direction += 2)
710710
{
711711
// do not go down in first column (these points are not associated to tree yet!)
@@ -728,33 +728,19 @@ void ContinuousClustering::traverseFieldOfView(Point& point,
728728
if (std::abs(point_other.inclination_angle - point.inclination_angle) > max_angle_diff)
729729
break;
730730

731-
// if this point is still in azimuth range then also search one column before
732-
if (point_other.continuous_azimuth_angle >= min_possible_continuous_azimuth_angle)
733-
at_least_one_point_of_this_column_in_azimuth_range = true;
734-
else
735-
{
736-
other_row_index += direction;
737-
num_steps_vertical++;
738-
continue;
739-
}
740-
741-
// if this point is ignored or has already the same tree root then do nothing (*1)
742-
if (point_other.is_ignored ||
743-
(point.tree_root_.column_index >= 0 && point_other.tree_root_ == point.tree_root_))
731+
// if other point is ignored or has already the same tree root then do nothing (*1)
732+
if (!point_other.is_ignored &&
733+
(point.tree_root_.column_index == 0 || point_other.tree_root_ != point.tree_root_))
744734
{
745-
other_row_index += direction;
746-
num_steps_vertical++;
747-
continue;
748-
}
749-
750-
// if distance is small enough then try to associate to tree
751-
if (checkClusteringCondition(point, point_other))
752-
{
753-
// check if point is already associated to any point tree
754-
if (point.tree_root_.column_index == -1)
755-
associatePointToPointTree(point, point_other, max_angle_diff);
756-
else
757-
associatePointTreeToPointTree(point, point_other);
735+
// if distance is small enough then try to associate to tree
736+
if (checkClusteringCondition(point, point_other))
737+
{
738+
// check if point is already associated to any point tree
739+
if (point.tree_root_.column_index == -1)
740+
associatePointToPointTree(point, point_other, max_angle_diff);
741+
else
742+
associatePointTreeToPointTree(point, point_other);
743+
}
758744
}
759745

760746
// stop searching if point was already associated and minimum number of columns were processed
@@ -772,16 +758,11 @@ void ContinuousClustering::traverseFieldOfView(Point& point,
772758
num_steps_back >= config_.clustering.stop_after_association_min_steps)
773759
break;
774760

775-
// stop searching in previous columns because in previous run all points were already out of angle range
776-
if (num_steps_back > 0 && !at_least_one_point_of_this_column_in_azimuth_range)
777-
break;
778-
779761
// stop searching if we are at the beginning of the ring buffer
780762
if (other_column_index == ring_buffer_first_local_column_index)
781763
break;
782764

783765
other_column_index--;
784-
num_steps_back++;
785766

786767
// jump to the end of the ring buffer
787768
if (other_column_index < 0)

0 commit comments

Comments
 (0)