ScanClustering.cpp
Go to the documentation of this file.
1 #include "ScanClustering.h"
2 
3 #include <RobotAPI/interface/units/LaserScannerUnit.h>
4 
6 {
7  ScanClustering::ScanClustering(const Params& params) : params(params)
8  {
9  }
10 
11  bool
12  ScanClustering::add(const LaserScanStep& scanStep)
13  {
14  if (scan.empty())
15  {
16  scan.push_back(scanStep);
17  return true;
18  }
19 
20  if (not supports(scanStep))
21  {
22  return false;
23  }
24 
25  scan.push_back(scanStep);
26  return true;
27  }
28 
29  std::vector<LaserScan>
30  ScanClustering::detectClusters(const LaserScan& scan)
31  {
32  const auto isInvalid = [&](const LaserScanStep& step) -> bool
33  { return step.distance > params.maxDistance; };
34 
35  std::vector<LaserScan> clusters;
36  for (const auto& laserScanStep : scan)
37  {
38  // cluster finished
39  if (isInvalid(laserScanStep) or (not add(laserScanStep)))
40  {
41  if (not cluster().empty())
42  {
43  clusters.push_back(cluster());
44  clear();
45 
46  // work on a new cluster
47  add(laserScanStep);
48  }
49  }
50  }
51 
52  return clusters;
53  }
54 
55  const LaserScan&
57  {
58  return scan;
59  }
60 
61  void
63  {
64  scan.clear();
65  }
66 
67  bool
68  ScanClustering::supports(const LaserScanStep& scanStep)
69  {
70  // OK to create a new cluster if it's empty
71  if (scan.empty())
72  {
73  return true;
74  }
75 
76  const float distanceDiff = std::fabs(scanStep.distance - scan.back().distance);
77  const bool isWithinDistanceRange = distanceDiff < params.distanceThreshold;
78 
79  const float angleDiff = std::fabs(scanStep.angle - scan.back().angle);
80  const bool isWithinAngleRange = angleDiff < params.angleThreshold;
81 
82  return (isWithinDistanceRange and isWithinAngleRange);
83  }
84 } // namespace armarx::navigation::components::laser_scanner_feature_extraction
armarx::navigation::components::laser_scanner_feature_extraction::detail::ScanClusteringParams
Definition: ScanClustering.h:30
armarx::navigation::components::laser_scanner_feature_extraction::ScanClustering::ScanClustering
ScanClustering(const Params &params)
Definition: ScanClustering.cpp:7
armarx::navigation::components::laser_scanner_feature_extraction::ScanClustering::detectClusters
Clusters detectClusters(const LaserScan &scan)
Performs cluster detection on a full laser scan.
Definition: ScanClustering.cpp:30
armarx::navigation::components::laser_scanner_feature_extraction::ScanClustering::cluster
const LaserScan & cluster() const
Definition: ScanClustering.cpp:56
armarx::navigation::components::laser_scanner_feature_extraction::ScanClustering::clear
void clear()
Definition: ScanClustering.cpp:62
armarx::navigation::components::laser_scanner_feature_extraction::ScanClustering::supports
bool supports(const LaserScanStep &scanStep)
Definition: ScanClustering.cpp:68
ScanClustering.h
armarx::navigation::components::laser_scanner_feature_extraction::detail::ScanClusteringParams::angleThreshold
float angleThreshold
Definition: ScanClustering.h:34
armarx::navigation::components::laser_scanner_feature_extraction::detail::ScanClusteringParams::distanceThreshold
float distanceThreshold
Definition: ScanClustering.h:33
armarx::navigation::components::laser_scanner_feature_extraction::ScanClustering::add
bool add(const LaserScanStep &scanStep)
Definition: ScanClustering.cpp:12
armarx::navigation::components::laser_scanner_feature_extraction
Definition: ArVizDrawer.cpp:28
armarx::navigation::components::laser_scanner_feature_extraction::detail::ScanClusteringParams::maxDistance
float maxDistance
Range filter: only consider points that are closer than maxDistance.
Definition: ScanClustering.h:37