|
37 | 37 | * |
38 | 38 | */ |
39 | 39 |
|
40 | | -#include <pcl/test/gtest.h> |
41 | | -#include <pcl/point_cloud.h> |
42 | | -#include <pcl/features/normal_3d.h> |
43 | 40 | #include <pcl/features/boundary.h> |
| 41 | +#include <pcl/features/normal_3d.h> |
44 | 42 | #include <pcl/io/pcd_io.h> |
45 | 43 | #include <pcl/search/kdtree.h> // for KdTree |
| 44 | +#include <pcl/test/gtest.h> |
| 45 | +#include <pcl/point_cloud.h> |
46 | 46 |
|
47 | 47 | using namespace pcl; |
48 | 48 | using namespace pcl::io; |
49 | 49 |
|
50 | 50 | using KdTreePtr = search::KdTree<PointXYZ>::Ptr; |
51 | 51 |
|
52 | 52 | PointCloud<PointXYZ> cloud; |
53 | | -pcl::Indices indices; |
| 53 | +PointCloud<Normal>::Ptr normals(new PointCloud<Normal>()); |
| 54 | +pcl::IndicesPtr indicesptr(new pcl::Indices()); |
54 | 55 | KdTreePtr tree; |
55 | 56 |
|
56 | | -////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
57 | | -TEST (PCL, BoundaryEstimation) |
| 57 | +TEST(PCL, BoundaryEstimationOMP) |
58 | 58 | { |
59 | | - Eigen::Vector4f u = Eigen::Vector4f::Zero (); |
60 | | - Eigen::Vector4f v = Eigen::Vector4f::Zero (); |
61 | | - |
62 | | - // Estimate normals first |
63 | | - NormalEstimation<PointXYZ, Normal> n; |
64 | | - PointCloud<Normal>::Ptr normals (new PointCloud<Normal> ()); |
| 59 | + BoundaryEstimation<PointXYZ, Normal, Boundary> b; |
| 60 | + b.setNumberOfThreads(0); |
| 61 | + b.setInputNormals(normals); |
| 62 | + // Object |
| 63 | + PointCloud<Boundary>::Ptr bps(new PointCloud<Boundary>()); |
65 | 64 | // set parameters |
66 | | - n.setInputCloud (cloud.makeShared ()); |
67 | | - pcl::IndicesPtr indicesptr (new pcl::Indices (indices)); |
68 | | - n.setIndices (indicesptr); |
69 | | - n.setSearchMethod (tree); |
70 | | - n.setKSearch (static_cast<int> (indices.size ())); |
| 65 | + b.setInputCloud(cloud.makeShared()); |
| 66 | + b.setIndices(indicesptr); |
| 67 | + b.setSearchMethod(tree); |
| 68 | + b.setKSearch(static_cast<int>(indicesptr->size())); |
71 | 69 | // estimate |
72 | | - n.compute (*normals); |
| 70 | + b.compute(*bps); |
| 71 | + EXPECT_EQ(bps->size(), indicesptr->size()); |
| 72 | + |
| 73 | + bool pt = false; |
| 74 | + |
| 75 | + pt = (*bps)[0].boundary_point; |
| 76 | + EXPECT_FALSE(pt); |
| 77 | + pt = (*bps)[indicesptr->size() / 3].boundary_point; |
| 78 | + EXPECT_FALSE(pt); |
| 79 | + pt = (*bps)[indicesptr->size() / 2].boundary_point; |
| 80 | + EXPECT_FALSE(pt); |
| 81 | + pt = (*bps)[indicesptr->size() - 1].boundary_point; |
| 82 | + EXPECT_TRUE(pt); |
| 83 | +} |
| 84 | + |
| 85 | +////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 86 | +TEST(PCL, BoundaryEstimation) |
| 87 | +{ |
| 88 | + Eigen::Vector4f u = Eigen::Vector4f::Zero(); |
| 89 | + Eigen::Vector4f v = Eigen::Vector4f::Zero(); |
73 | 90 |
|
74 | 91 | BoundaryEstimation<PointXYZ, Normal, Boundary> b; |
75 | | - b.setInputNormals (normals); |
76 | | - EXPECT_EQ (b.getInputNormals (), normals); |
| 92 | + b.setInputNormals(normals); |
| 93 | + EXPECT_EQ(b.getInputNormals(), normals); |
77 | 94 |
|
78 | 95 | // getCoordinateSystemOnPlane |
79 | | - for (const auto &point : normals->points) |
80 | | - { |
81 | | - b.getCoordinateSystemOnPlane (point, u, v); |
82 | | - Vector4fMapConst n4uv = point.getNormalVector4fMap (); |
83 | | - EXPECT_NEAR (n4uv.dot(u), 0, 1e-4); |
84 | | - EXPECT_NEAR (n4uv.dot(v), 0, 1e-4); |
85 | | - EXPECT_NEAR (u.dot(v), 0, 1e-4); |
| 96 | + for (const auto& point : *normals) { |
| 97 | + b.getCoordinateSystemOnPlane(point, u, v); |
| 98 | + Vector4fMapConst n4uv = point.getNormalVector4fMap(); |
| 99 | + EXPECT_NEAR(n4uv.dot(u), 0, 1e-4); |
| 100 | + EXPECT_NEAR(n4uv.dot(v), 0, 1e-4); |
| 101 | + EXPECT_NEAR(u.dot(v), 0, 1e-4); |
86 | 102 | } |
87 | 103 |
|
88 | 104 | // isBoundaryPoint (indices) |
89 | 105 | bool pt = false; |
90 | | - pt = b.isBoundaryPoint (cloud, 0, indices, u, v, static_cast<float>(M_PI) / 2.0); |
91 | | - EXPECT_FALSE (pt); |
92 | | - pt = b.isBoundaryPoint (cloud, static_cast<int> (indices.size ()) / 3, indices, u, v, static_cast<float>(M_PI) / 2.0); |
93 | | - EXPECT_FALSE (pt); |
94 | | - pt = b.isBoundaryPoint (cloud, static_cast<int> (indices.size ()) / 2, indices, u, v, static_cast<float>(M_PI) / 2.0); |
95 | | - EXPECT_FALSE (pt); |
96 | | - pt = b.isBoundaryPoint (cloud, static_cast<int> (indices.size ()) - 1, indices, u, v, static_cast<float>(M_PI) / 2.0); |
97 | | - EXPECT_TRUE (pt); |
| 106 | + pt = b.isBoundaryPoint(cloud, 0, *indicesptr, u, v, static_cast<float>(M_PI) / 2.0); |
| 107 | + EXPECT_FALSE(pt); |
| 108 | + pt = b.isBoundaryPoint(cloud, |
| 109 | + static_cast<int>(indicesptr->size()) / 3, |
| 110 | + *indicesptr, |
| 111 | + u, |
| 112 | + v, |
| 113 | + static_cast<float>(M_PI) / 2.0); |
| 114 | + EXPECT_FALSE(pt); |
| 115 | + pt = b.isBoundaryPoint(cloud, |
| 116 | + static_cast<int>(indicesptr->size()) / 2, |
| 117 | + *indicesptr, |
| 118 | + u, |
| 119 | + v, |
| 120 | + static_cast<float>(M_PI) / 2.0); |
| 121 | + EXPECT_FALSE(pt); |
| 122 | + pt = b.isBoundaryPoint(cloud, |
| 123 | + static_cast<int>(indicesptr->size()) - 1, |
| 124 | + *indicesptr, |
| 125 | + u, |
| 126 | + v, |
| 127 | + static_cast<float>(M_PI) / 2.0); |
| 128 | + EXPECT_TRUE(pt); |
98 | 129 |
|
99 | 130 | // isBoundaryPoint (points) |
100 | | - pt = b.isBoundaryPoint (cloud, cloud[0], indices, u, v, static_cast<float>(M_PI) / 2.0); |
101 | | - EXPECT_FALSE (pt); |
102 | | - pt = b.isBoundaryPoint (cloud, cloud[indices.size () / 3], indices, u, v, static_cast<float>(M_PI) / 2.0); |
103 | | - EXPECT_FALSE (pt); |
104 | | - pt = b.isBoundaryPoint (cloud, cloud[indices.size () / 2], indices, u, v, static_cast<float>(M_PI) / 2.0); |
105 | | - EXPECT_FALSE (pt); |
106 | | - pt = b.isBoundaryPoint (cloud, cloud[indices.size () - 1], indices, u, v, static_cast<float>(M_PI) / 2.0); |
107 | | - EXPECT_TRUE (pt); |
| 131 | + pt = b.isBoundaryPoint( |
| 132 | + cloud, cloud[0], *indicesptr, u, v, static_cast<float>(M_PI) / 2.0); |
| 133 | + EXPECT_FALSE(pt); |
| 134 | + pt = b.isBoundaryPoint(cloud, |
| 135 | + cloud[indicesptr->size() / 3], |
| 136 | + *indicesptr, |
| 137 | + u, |
| 138 | + v, |
| 139 | + static_cast<float>(M_PI) / 2.0); |
| 140 | + EXPECT_FALSE(pt); |
| 141 | + pt = b.isBoundaryPoint(cloud, |
| 142 | + cloud[indicesptr->size() / 2], |
| 143 | + *indicesptr, |
| 144 | + u, |
| 145 | + v, |
| 146 | + static_cast<float>(M_PI) / 2.0); |
| 147 | + EXPECT_FALSE(pt); |
| 148 | + pt = b.isBoundaryPoint(cloud, |
| 149 | + cloud[indicesptr->size() - 1], |
| 150 | + *indicesptr, |
| 151 | + u, |
| 152 | + v, |
| 153 | + static_cast<float>(M_PI) / 2.0); |
| 154 | + EXPECT_TRUE(pt); |
108 | 155 |
|
109 | 156 | // Object |
110 | | - PointCloud<Boundary>::Ptr bps (new PointCloud<Boundary> ()); |
| 157 | + PointCloud<Boundary>::Ptr bps(new PointCloud<Boundary>()); |
111 | 158 |
|
112 | 159 | // set parameters |
113 | | - b.setInputCloud (cloud.makeShared ()); |
114 | | - b.setIndices (indicesptr); |
115 | | - b.setSearchMethod (tree); |
116 | | - b.setKSearch (static_cast<int> (indices.size ())); |
| 160 | + b.setInputCloud(cloud.makeShared()); |
| 161 | + b.setIndices(indicesptr); |
| 162 | + b.setSearchMethod(tree); |
| 163 | + b.setKSearch(static_cast<int>(indicesptr->size())); |
117 | 164 |
|
118 | 165 | // estimate |
119 | | - b.compute (*bps); |
120 | | - EXPECT_EQ (bps->size (), indices.size ()); |
| 166 | + b.compute(*bps); |
| 167 | + EXPECT_EQ(bps->size(), indicesptr->size()); |
121 | 168 |
|
122 | 169 | pt = (*bps)[0].boundary_point; |
123 | | - EXPECT_FALSE (pt); |
124 | | - pt = (*bps)[indices.size () / 3].boundary_point; |
125 | | - EXPECT_FALSE (pt); |
126 | | - pt = (*bps)[indices.size () / 2].boundary_point; |
127 | | - EXPECT_FALSE (pt); |
128 | | - pt = (*bps)[indices.size () - 1].boundary_point; |
129 | | - EXPECT_TRUE (pt); |
| 170 | + EXPECT_FALSE(pt); |
| 171 | + pt = (*bps)[indicesptr->size() / 3].boundary_point; |
| 172 | + EXPECT_FALSE(pt); |
| 173 | + pt = (*bps)[indicesptr->size() / 2].boundary_point; |
| 174 | + EXPECT_FALSE(pt); |
| 175 | + pt = (*bps)[indicesptr->size() - 1].boundary_point; |
| 176 | + EXPECT_TRUE(pt); |
130 | 177 | } |
131 | 178 |
|
132 | 179 | /* ---[ */ |
133 | 180 | int |
134 | | -main (int argc, char** argv) |
| 181 | +main(int argc, char** argv) |
135 | 182 | { |
136 | | - if (argc < 2) |
137 | | - { |
138 | | - std::cerr << "No test file given. Please download `bun0.pcd` and pass its path to the test." << std::endl; |
| 183 | + if (argc < 2) { |
| 184 | + std::cerr << "No test file given. Please download `bun0.pcd` and pass its path to " |
| 185 | + "the test." |
| 186 | + << std::endl; |
139 | 187 | return (-1); |
140 | 188 | } |
141 | 189 |
|
142 | | - if (loadPCDFile<PointXYZ> (argv[1], cloud) < 0) |
143 | | - { |
144 | | - std::cerr << "Failed to read test file. Please download `bun0.pcd` and pass its path to the test." << std::endl; |
| 190 | + if (loadPCDFile<PointXYZ>(argv[1], cloud) < 0) { |
| 191 | + std::cerr << "Failed to read test file. Please download `bun0.pcd` and pass its " |
| 192 | + "path to the test." |
| 193 | + << std::endl; |
145 | 194 | return (-1); |
146 | 195 | } |
147 | 196 |
|
148 | | - indices.resize (cloud.size ()); |
149 | | - for (std::size_t i = 0; i < indices.size (); ++i) |
150 | | - indices[i] = static_cast<int> (i); |
| 197 | + indicesptr->resize(cloud.size()); |
| 198 | + for (std::size_t i = 0; i < indicesptr->size(); ++i) |
| 199 | + (*indicesptr)[i] = static_cast<int>(i); |
| 200 | + |
| 201 | + tree.reset(new search::KdTree<PointXYZ>(false)); |
| 202 | + tree->setInputCloud(cloud.makeShared()); |
151 | 203 |
|
152 | | - tree.reset (new search::KdTree<PointXYZ> (false)); |
153 | | - tree->setInputCloud (cloud.makeShared ()); |
| 204 | + // Estimate normals first |
| 205 | + NormalEstimation<PointXYZ, Normal> n; |
| 206 | + // set parameters |
| 207 | + n.setInputCloud(cloud.makeShared()); |
| 208 | + n.setIndices(indicesptr); |
| 209 | + n.setSearchMethod(tree); |
| 210 | + n.setKSearch(static_cast<int>(indicesptr->size())); |
| 211 | + // estimate |
| 212 | + n.compute(*normals); |
154 | 213 |
|
155 | | - testing::InitGoogleTest (&argc, argv); |
156 | | - return (RUN_ALL_TESTS ()); |
| 214 | + testing::InitGoogleTest(&argc, argv); |
| 215 | + return (RUN_ALL_TESTS()); |
157 | 216 | } |
158 | 217 | /* ]--- */ |
0 commit comments