00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00036 #ifndef _polygon_primitive_planefitting_CPP_
00037 #define _polygon_primitive_planefitting_CPP_
00038
00039
00040 #include "polygon_primitive.h"
00041
00042 #include <CGAL/Cartesian.h>
00043 #include <CGAL/linear_least_squares_fitting_3.h>
00044 #include <list>
00045
00054 double c_polygon_primitive::fit_plane_to_pc(pcl::PointCloud<pcl::PointXYZ>::Ptr pcin, pcl::ModelCoefficients::Ptr plane)
00055 {
00056
00057
00058 std::list<CGAL::Cartesian<double>::Point_3> points;
00059
00060 for (int i=0; i<(int)pcin->points.size(); i++)
00061 {
00062 points.push_back(CGAL::Cartesian<double>::Point_3(pcin->points[i].x, pcin->points[i].y, pcin->points[i].z));
00063 }
00064
00065
00066 CGAL::Cartesian<double>::Plane_3 pl;
00067 double fit_quality = CGAL::linear_least_squares_fitting_3(points.begin(),points.end(),pl,CGAL::Dimension_tag<0>());
00068
00069
00070 plane->values[0] = pl.a();
00071 plane->values[1] = pl.b();
00072 plane->values[2] = pl.c();
00073 plane->values[3] = pl.d();
00074
00075 return fit_quality;}
00076
00087 double c_polygon_primitive::fit_plane_to_two_pc_and_ratio(pcl::PointCloud<pcl::PointXYZ>::Ptr pcin1, pcl::PointCloud<pcl::PointXYZ>::Ptr pcin2, double ratio, pcl::ModelCoefficients::Ptr plane)
00088 {
00089
00090
00091 std::list<CGAL::Cartesian<double>::Point_3> points;
00092
00093
00094 double weight_pcin1 = (1-ratio)/(double)pcin1->points.size();
00095 double weight_pcin2 = ratio/(double)pcin2->points.size();
00096
00097
00098
00099
00100
00101
00102
00103 for (int i=0; i<(int)pcin1->points.size(); i++)
00104 {
00105 for (double j=0; j<weight_pcin1; j+=0.00001)
00106 points.push_back(CGAL::Cartesian<double>::Point_3(pcin1->points[i].x, pcin1->points[i].y, pcin1->points[i].z));
00107 }
00108
00109 for (int i=0; i<(int)pcin2->points.size(); i++)
00110 {
00111 for (double j=0; j<weight_pcin2; j+=0.00001)
00112 points.push_back(CGAL::Cartesian<double>::Point_3(pcin2->points[i].x, pcin2->points[i].y, pcin2->points[i].z));
00113 }
00114
00115
00116 CGAL::Cartesian<double>::Plane_3 pl;
00117 double fit_quality = CGAL::linear_least_squares_fitting_3(points.begin(),points.end(),pl,CGAL::Dimension_tag<0>());
00118
00119
00120 plane->values[0] = pl.a();
00121 plane->values[1] = pl.b();
00122 plane->values[2] = pl.c();
00123 plane->values[3] = pl.d();
00124
00125 return fit_quality;}
00126
00127
00128
00129
00130 #endif
00131
00134