forked from PointCloudLibrary/pcl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ExtractPolygonalPrismData and ConcaveHull bugfix (PointCloudLibrary#5168
) * ExtractPolygonalPrismData and ConcaveHull bugfix PointCloudLibrary#5163 (comment) * ExtractPolygonalPrismData and ConcaveHull bugfix PointCloudLibrary#5163 (comment) * test by generating the concave hull manually * sin and cos for floats * azure test compilation errors * minor changes per code review * minor changes per review * Update CMakeLists.txt * Update test_concave_prism.cpp * Update extract_polygonal_prism_data.hpp * Rename * Rename * Rename * Update extract_polygonal_prism_data.hpp --------- Co-authored-by: Yoav Miller <yoavm@magnusmetal.com> Co-authored-by: Markus Vieth <39675748+mvieth@users.noreply.github.com>
- Loading branch information
1 parent
8f2f865
commit f63fcf4
Showing
4 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include <pcl/test/gtest.h> | ||
#include <pcl/point_types.h> | ||
#include <pcl/point_cloud.h> | ||
|
||
#include <pcl/segmentation/extract_polygonal_prism_data.h> | ||
|
||
#include <random> | ||
|
||
using namespace pcl; | ||
using std::vector; | ||
|
||
TEST(ExtractPolygonalPrism, two_rings) | ||
{ | ||
float rMin = 0.1, rMax = 0.25f; | ||
float dx = 0.5f; // shift the rings from [0,0,0] to [+/-dx, 0, 0] | ||
|
||
// prepare 2 rings | ||
PointCloud<PointXYZ>::Ptr ring(new PointCloud<PointXYZ>); | ||
{ // use random | ||
std::random_device rd; | ||
std::mt19937 gen(rd()); | ||
std::uniform_real_distribution<float> radiusDist(rMin, rMax); | ||
std::uniform_real_distribution<float> radianDist(-M_PI, M_PI); | ||
std::uniform_real_distribution<float> zDist(-0.01f, 0.01f); | ||
for (size_t i = 0; i < 1000; i++) { | ||
float radius = radiusDist(gen); | ||
float angle = radianDist(gen); | ||
float z = zDist(gen); | ||
PointXYZ point(cosf(angle) * radius, sinf(angle) * radius, z); | ||
ring->push_back(point); | ||
} | ||
} | ||
|
||
PointCloud<PointXYZ>::Ptr cloud(new PointCloud<PointXYZ>); | ||
cloud->reserve(ring->size() * 2); | ||
for (auto& point : ring->points) { | ||
auto left = point; | ||
auto right = point; | ||
left.x -= dx; | ||
right.x += dx; | ||
cloud->push_back(left); | ||
cloud->push_back(right); | ||
} | ||
|
||
// create hull | ||
PointCloud<PointXYZ>::Ptr hullCloud(new PointCloud<PointXYZ>); | ||
vector<Vertices> rings(4); | ||
float radiuses[] = {rMin - 0.01f, rMax + 0.01f, rMin - 0.01f, rMax + 0.01f}; | ||
float centers[] = {-dx, -dx, +dx, +dx}; | ||
for (size_t i = 0; i < rings.size(); i++) { | ||
auto r = radiuses[i]; | ||
auto xCenter = centers[i]; | ||
for (float a = -M_PI; a < M_PI; a += 0.05f) { | ||
rings[i].vertices.push_back(hullCloud->size()); | ||
PointXYZ point(xCenter + r * cosf(a), r * sinf(a), 0); | ||
hullCloud->push_back(point); | ||
} | ||
} | ||
|
||
// add more points before using prism | ||
size_t ringsPointCount = cloud->size(); | ||
cloud->push_back(PointXYZ(0, 0, 0)); | ||
for (float a = -M_PI; a < M_PI; a += 0.05f) { | ||
float r = 4 * rMax; | ||
PointXYZ point(r * cosf(a), r * sinf(a), 0); | ||
cloud->push_back(point); | ||
} | ||
|
||
// do prism | ||
PointIndices::Ptr inliers(new PointIndices); | ||
ExtractPolygonalPrismData<PointXYZ> ex; | ||
{ | ||
ex.setInputCloud(cloud); | ||
ex.setInputPlanarHull(hullCloud); | ||
ex.setHeightLimits(-1, 1); | ||
ex.setPolygons(rings); | ||
ex.segment(*inliers); | ||
} | ||
|
||
// check that all of the rings are in the prism. | ||
EXPECT_EQ(inliers->indices.size(), ringsPointCount); | ||
for(std::size_t i=0; i<inliers->indices.size(); ++i) { | ||
EXPECT_EQ(inliers->indices[i], i); | ||
} | ||
} | ||
|
||
int | ||
main(int argc, char** argv) | ||
{ | ||
testing::InitGoogleTest(&argc, argv); | ||
return (RUN_ALL_TESTS()); | ||
} |