MCPcopy Create free account
hub / github.com/PointCloudLibrary/pcl / uniform_sampling

Function uniform_sampling

tools/mesh_sampling.cpp:134–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132}
133
134void
135uniform_sampling (vtkSmartPointer<vtkPolyData> polydata, std::size_t n_samples, bool calc_normal, bool calc_color, pcl::PointCloud<pcl::PointXYZRGBNormal> & cloud_out)
136{
137 polydata->BuildCells ();
138 vtkSmartPointer<vtkCellArray> cells = polydata->GetPolys ();
139
140 double p1[3], p2[3], p3[3], totalArea = 0;
141 std::vector<double> cumulativeAreas (cells->GetNumberOfCells (), 0);
142 vtkIdType npts = 0;
143 vtkCellPtsPtr ptIds = nullptr;
144 std::size_t cellId = 0;
145 for (cells->InitTraversal (); cells->GetNextCell (npts, ptIds); cellId++)
146 {
147 polydata->GetPoint (ptIds[0], p1);
148 polydata->GetPoint (ptIds[1], p2);
149 polydata->GetPoint (ptIds[2], p3);
150 totalArea += vtkTriangle::TriangleArea (p1, p2, p3);
151 cumulativeAreas[cellId] = totalArea;
152 }
153
154 cloud_out.resize (n_samples);
155 cloud_out.width = static_cast<std::uint32_t> (n_samples);
156 cloud_out.height = 1;
157
158 for (std::size_t i = 0; i < n_samples; i++)
159 {
160 Eigen::Vector3f p;
161 Eigen::Vector3f n (0, 0, 0);
162 Eigen::Vector3f c (0, 0, 0);
163 randPSurface (polydata, &cumulativeAreas, totalArea, p, calc_normal, n, calc_color, c);
164 cloud_out[i].x = p[0];
165 cloud_out[i].y = p[1];
166 cloud_out[i].z = p[2];
167 if (calc_normal)
168 {
169 cloud_out[i].normal_x = n[0];
170 cloud_out[i].normal_y = n[1];
171 cloud_out[i].normal_z = n[2];
172 }
173 if (calc_color)
174 {
175 cloud_out[i].r = static_cast<std::uint8_t>(c[0]);
176 cloud_out[i].g = static_cast<std::uint8_t>(c[1]);
177 cloud_out[i].b = static_cast<std::uint8_t>(c[2]);
178 }
179 }
180}
181
182using namespace pcl;
183using namespace pcl::io;

Callers 1

mainFunction · 0.70

Calls 3

randPSurfaceFunction · 0.70
GetPointMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected