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

Function randPSurface

tools/mesh_sampling.cpp:80–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80inline void
81randPSurface (vtkPolyData * polydata, std::vector<double> * cumulativeAreas, double totalArea, Eigen::Vector3f& p, bool calcNormal, Eigen::Vector3f& n, bool calcColor, Eigen::Vector3f& c)
82{
83 float r = static_cast<float> (uniform_deviate (rand ()) * totalArea);
84
85 auto low = std::lower_bound (cumulativeAreas->begin (), cumulativeAreas->end (), r);
86 vtkIdType el = static_cast<vtkIdType>(low - cumulativeAreas->begin ());
87
88 double A[3], B[3], C[3];
89 vtkIdType npts = 0;
90 vtkCellPtsPtr ptIds = nullptr;
91
92 polydata->GetCellPoints (el, npts, ptIds);
93 polydata->GetPoint (ptIds[0], A);
94 polydata->GetPoint (ptIds[1], B);
95 polydata->GetPoint (ptIds[2], C);
96 if (calcNormal)
97 {
98 // OBJ: Vertices are stored in a counter-clockwise order by default
99 Eigen::Vector3f v1 = Eigen::Vector3f (A[0], A[1], A[2]) - Eigen::Vector3f (C[0], C[1], C[2]);
100 Eigen::Vector3f v2 = Eigen::Vector3f (B[0], B[1], B[2]) - Eigen::Vector3f (C[0], C[1], C[2]);
101 n = v1.cross (v2);
102 n.normalize ();
103 }
104 float r1 = static_cast<float> (uniform_deviate (rand ()));
105 float r2 = static_cast<float> (uniform_deviate (rand ()));
106 randomPointTriangle (static_cast<float>(A[0]), static_cast<float>(A[1]), static_cast<float>(A[2]),
107 static_cast<float>(B[0]), static_cast<float>(B[1]), static_cast<float>(B[2]),
108 static_cast<float>(C[0]), static_cast<float>(C[1]), static_cast<float>(C[2]), r1, r2, p);
109
110 if (calcColor)
111 {
112 vtkUnsignedCharArray *const colors = vtkUnsignedCharArray::SafeDownCast (polydata->GetPointData ()->GetScalars ());
113 if (colors && colors->GetNumberOfComponents () == 3)
114 {
115 double cA[3], cB[3], cC[3];
116 colors->GetTuple (ptIds[0], cA);
117 colors->GetTuple (ptIds[1], cB);
118 colors->GetTuple (ptIds[2], cC);
119
120 randomPointTriangle (static_cast<float>(cA[0]), static_cast<float>(cA[1]), static_cast<float>(cA[2]),
121 static_cast<float>(cB[0]), static_cast<float>(cB[1]), static_cast<float>(cB[2]),
122 static_cast<float>(cC[0]), static_cast<float>(cC[1]), static_cast<float>(cC[2]), r1, r2, c);
123 }
124 else
125 {
126 static bool printed_once = false;
127 if (!printed_once)
128 PCL_WARN ("Mesh has no vertex colors, or vertex colors are not RGB!\n");
129 printed_once = true;
130 }
131 }
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)

Callers 1

uniform_samplingFunction · 0.70

Calls 6

lower_boundFunction · 0.85
uniform_deviateFunction · 0.70
randomPointTriangleFunction · 0.70
beginMethod · 0.45
endMethod · 0.45
GetPointMethod · 0.45

Tested by

no test coverage detected