Skip to content
Snippets Groups Projects
Commit 3c10408a authored by Dženan Zukić's avatar Dženan Zukić
Browse files

ENH: New return type of SpatialHashTableSeparateChaining::getPointsInAABB()...

ENH: New return type of SpatialHashTableSeparateChaining::getPointsInAABB() enables referencing vertices by their IDs. It also causes less constructor and allocation invocations.
parent 8ab08a06
No related branches found
No related tags found
No related merge requests found
......@@ -61,7 +61,7 @@ SpatialHashTableSeparateChaining::clear()
m_currentID = 0;
}
std::vector<Vec3d>
std::vector<size_t>
SpatialHashTableSeparateChaining::getPointsInAABB(const Vec3d& corner1, const Vec3d& corner2)
{
auto min_x = std::fmin(corner1.x(), corner2.x());
......@@ -94,9 +94,8 @@ SpatialHashTableSeparateChaining::getPointsInAABB(const Vec3d& corner1, const Ve
}
// Allocate beforehand
std::vector<Vec3d> points(tempPoints.size());
unsigned int numPoints = 0;
std::vector<size_t> points(0);
points.reserve(tempPoints.size());
// Fine iteration
for (auto p = tempPoints.begin(); p != tempPoints.end(); ++p)
......@@ -106,12 +105,13 @@ SpatialHashTableSeparateChaining::getPointsInAABB(const Vec3d& corner1, const Ve
point.y() >= min_y && point.y() <= max_y &&
point.z() >= min_z && point.z() <= max_z)
{
points[numPoints] = p->point;
numPoints++;
points.push_back(p->ID);
}
}
points.resize(numPoints);
//there is little need to waste time on this reallocation,
//as this is a temporary return array
//points.shrink_to_fit();
return points;
}
......
......@@ -110,11 +110,11 @@ public:
void setLoadFactorMax(float loadFactorMax);
///
/// \brief Finds all points in an AABB
/// \brief Finds IDs of all points in an AABB
/// \param corner1 One corner to the box
/// \param corner2 The other corner to the box
///
std::vector<Vec3d> getPointsInAABB(const Vec3d& corner1, const Vec3d& corner2);
std::vector<size_t> getPointsInAABB(const Vec3d& corner1, const Vec3d& corner2);
///
/// \brief Clears the table
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment