polygon_primitive_planefitting.cpp
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
36 #ifndef _polygon_primitive_planefitting_CPP_
37 #define _polygon_primitive_planefitting_CPP_
38 
39 
40 #include "polygon_primitive.h"
41 
42 #include <CGAL/Cartesian.h>
43 #include <CGAL/linear_least_squares_fitting_3.h>
44 #include <list>
45 
54 double c_polygon_primitive::fit_plane_to_pc(pcl::PointCloud<pcl::PointXYZ>::Ptr pcin, pcl::ModelCoefficients::Ptr plane)
55 {
56 
57  //STEP1. Create a list of pts xyz
58  std::list<CGAL::Cartesian<double>::Point_3> points;
59 
60  for (int i=0; i<(int)pcin->points.size(); i++)
61  {
62  points.push_back(CGAL::Cartesian<double>::Point_3(pcin->points[i].x, pcin->points[i].y, pcin->points[i].z));
63  }
64 
65  //STEP2. Fit the plane to the list of points
66  CGAL::Cartesian<double>::Plane_3 pl;
67  double fit_quality = CGAL::linear_least_squares_fitting_3(points.begin(),points.end(),pl,CGAL::Dimension_tag<0>());
68 
69  //STEP3. Copy to the model coefficients
70  plane->values[0] = pl.a();
71  plane->values[1] = pl.b();
72  plane->values[2] = pl.c();
73  plane->values[3] = pl.d();
74 
75 return fit_quality;}
76 
87 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)
88 {
89 
90  //STEP1. Create a list of pts xyz
91  std::list<CGAL::Cartesian<double>::Point_3> points;
92 
93  //find out many insertions of points according to ratio
94  double weight_pcin1 = (1-ratio)/(double)pcin1->points.size();
95  double weight_pcin2 = ratio/(double)pcin2->points.size();
96 
97  //int count_pcin1 = (int)(weight_pcin1*((int)pcin1->points.size() + (int)pcin2->points.size()));
98  //int count_pcin2 = (int)(weight_pcin2*((int)pcin1->points.size() + (int)pcin2->points.size()));
99 
100  //ROS_INFO("weight_pcin1 %f count_pcin1 %d", weight_pcin1, count_pcin1);
101  //ROS_INFO("weight_pcin2 %f count_pcin2 %d", weight_pcin2, count_pcin2);
102 
103  for (int i=0; i<(int)pcin1->points.size(); i++)
104  {
105  for (double j=0; j<weight_pcin1; j+=0.00001)
106  points.push_back(CGAL::Cartesian<double>::Point_3(pcin1->points[i].x, pcin1->points[i].y, pcin1->points[i].z));
107  }
108 
109  for (int i=0; i<(int)pcin2->points.size(); i++)
110  {
111  for (double j=0; j<weight_pcin2; j+=0.00001)
112  points.push_back(CGAL::Cartesian<double>::Point_3(pcin2->points[i].x, pcin2->points[i].y, pcin2->points[i].z));
113  }
114 
115  //STEP2. Fit the plane to the list of points
116  CGAL::Cartesian<double>::Plane_3 pl;
117  double fit_quality = CGAL::linear_least_squares_fitting_3(points.begin(),points.end(),pl,CGAL::Dimension_tag<0>());
118 
119  //STEP3. Copy to the model coefficients
120  plane->values[0] = pl.a();
121  plane->values[1] = pl.b();
122  plane->values[2] = pl.c();
123  plane->values[3] = pl.d();
124 
125 return fit_quality;}
126 
127 
128 
129 
130 #endif
131 
134 /*Previous 3 lines appended automatically on Sun Feb 5 19:40:16 WET 2012 */
double 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)
fits a plane to two weighted point clouds, given a ratio
int ratio
Definition: ddt.cpp:58
A class c_polygon_primitive that contains information about a detected polygon primitive as well as t...
double fit_plane_to_pc(pcl::PointCloud< pcl::PointXYZ >::Ptr pcin, pcl::ModelCoefficients::Ptr plane)
Fits a plane to a point cloud.


polygon_primitives_extraction
Author(s): Miguel Oliveira
autogenerated on Mon Mar 2 2015 01:32:42