44 : axis(axis), split(split), lesser(move(lesser)), greater(move(greater))
50 double val = point(this->
axis);
51 if (val < this->
split)
53 this->
lesser->nnInternal(point, neighbor, maxDist);
54 if (val + maxDist >= this->split)
56 this->
greater->nnInternal(point, neighbor, maxDist);
61 this->
greater->nnInternal(point, neighbor, maxDist);
62 if (val - maxDist <= this->split)
64 this->
lesser->nnInternal(point, neighbor, maxDist);
80 : points(points), count(count)
86 double maxDistSq = maxDist * maxDist;
88 for (
int i = 0; i < this->count; i++)
90 double dist = (point - this->
points[i]).squaredNorm();
93 neighbor = &this->
points[i];
100 maxDist = sqrt(maxDistSq);
111 if (n <= maxLeafSize)
119 double splitValue = boundingBox.
avg()(splitAxis);
130 int l =
splitPoints(points, n, splitAxis, splitValue);
134 if (n > 8 * maxLeafSize)
136 #pragma omp task shared(lesser) 139 #pragma omp task shared(greater) 157 size_t n = scan->numPoints();
158 auto points = boost::shared_array<Point>(
new Point[n]);
160 #pragma omp parallel for schedule(static) 161 for (
size_t i = 0; i < n; i++)
166 #pragma omp parallel // allows "pragma omp task" 167 #pragma omp single // only execute every task once 180 centroid_m = Vector3d::Zero();
181 centroid_d = Vector3d::Zero();
183 for (
size_t i = 0; i < scan->numPoints(); i++)
185 if (neighbors[i] !=
nullptr)
187 centroid_m += neighbors[i]->cast<
double>();
188 centroid_d += scan->point(i);
201 double distance = 0.0;
203 #pragma omp parallel for firstprivate(distance) reduction(+:found) schedule(dynamic,8) 204 for (
size_t i = 0; i < scan->numPoints(); i++)
206 if (tree->nearestNeighbor(scan->point(i), neighbors[i], distance, maxDistance))
int splitPoints(Vector3f *points, int n, int axis, double splitValue)
Sorts a Point array so that all Points smaller than splitValue are on the left.
T difference(int axis) const
Calculates the size of the Bounding Box along a certain axis.
virtual void nnInternal(const Point &point, Neighbor &neighbor, double &maxDist) const override
static size_t nearestNeighbors(KDTreePtr tree, SLAMScanPtr scan, Neighbor *neighbors, double maxDistance, Vector3d ¢roid_m, Vector3d ¢roid_d)
Finds the nearest neighbors of all points in a Scan using a pre-generated KDTree. ...
std::shared_ptr< KDTree > KDTreePtr
Representation of a point in 3D space.
Eigen::Vector3d Vector3d
Eigen 3D vector, double precision.
KDNode(int axis, double split, KDTreePtr &lesser, KDTreePtr &greater)
std::shared_ptr< KDTree > KDTreePtr
KDLeaf(Point *points, int count)
a kd-Tree Implementation for nearest Neighbor searches
static std::shared_ptr< KDTree > create(SLAMScanPtr scan, int maxLeafSize=20)
Creates a new KDTree from the given Scan.
Vector3< T > avg() const
Returns the average of all the Points in the Point Cloud.
virtual void nnInternal(const Point &point, Neighbor &neighbor, double &maxDist) const override
boost::shared_array< Point > points
int longestAxis() const
Calculates the axis that has the largest size of the Bounding Box.
std::shared_ptr< SLAMScanWrapper > SLAMScanPtr
A struct to calculate the Axis Aligned Bounding Box and Average Point of a Point Cloud.
KDTreePtr create_recursive(KDTree::Point *points, int n, int maxLeafSize)