17 #ifdef NUKLEI_USE_CGAL
18 using namespace cgal_pca_types;
19 std::list<Point_3> points;
22 Vector3 loc = i->getLoc();
23 points.push_back(Point_3(loc[0], loc[1], loc[2]));
28 #if CGAL_VERSION_NR >= 1030400000
29 CGAL::linear_least_squares_fitting_3(points.begin(),points.end(), plane, centroid, CGAL::Dimension_tag<0>());
31 CGAL::linear_least_squares_fitting_3(points.begin(),points.end(), plane, centroid);
34 m.SetColumn(0, Vector3(plane.base1()[0], plane.base1()[1], plane.base1()[2]));
35 m.SetColumn(1, Vector3(plane.base2()[0], plane.base2()[1], plane.base2()[2]));
36 m.SetColumn(2, Vector3(plane.orthogonal_vector()[0], plane.orthogonal_vector()[1], plane.orthogonal_vector()[2]));
40 k.
loc_ = Vector3(centroid[0], centroid[1], centroid[2]);
41 k.
ori_ = la::quaternionCopy(m);
54 NUKLEI_THROW(
"This function requires CGAL. See http://renaud-detry.net/nuklei/group__install.html");
63 #ifdef NUKLEI_USE_CGAL
64 using namespace cgal_pca_types;
68 "Need at least 3 for plane fitting.");
70 Plane_3 bestPlane(Point_3(1,0,0), Point_3(0,1,0), Point_3(0,0,0));
72 int bestPlaneInliners = 0;
73 for (
unsigned r = 0; r < nSeeds; ++r)
75 std::vector<Point_3> randomPoints;
76 for (
int i = 0; i < 3; ++i)
79 randomPoints.push_back(Point_3(loc[0], loc[1], loc[2]));
81 Plane_3 plane(randomPoints.at(0),
84 if (plane.is_degenerate())
continue;
89 Vector3 loc = i->getLoc();
90 Point_3 proj = plane.projection(Point_3(loc[0], loc[1], loc[2]));
93 if (d < inlinerThreshold) inliners++;
96 if (inliners > bestPlaneInliners)
98 bestPlaneInliners = inliners;
108 Vector3 loc = i->getLoc();
109 Point_3 proj = bestPlane.projection(Point_3(loc[0], loc[1], loc[2]));
112 if (d < inlinerThreshold) kc.
add(*i);
117 NUKLEI_THROW(
"This function requires CGAL. See http://renaud-detry.net/nuklei/group__install.html");