CGR Localization
 All Classes Namespaces Files Functions Variables Macros Pages
plane_polygon.h
Go to the documentation of this file.
1 //========================================================================
2 // This software is free: you can redistribute it and/or modify
3 // it under the terms of the GNU Lesser General Public License Version 3,
4 // as published by the Free Software Foundation.
5 //
6 // This software is distributed in the hope that it will be useful,
7 // but WITHOUT ANY WARRANTY; without even the implied warranty of
8 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 // GNU Lesser General Public License for more details.
10 //
11 // You should have received a copy of the GNU Lesser General Public License
12 // Version 3 in the file COPYING that came with this distribution.
13 // If not, see <http://www.gnu.org/licenses/>.
14 //========================================================================
20 //========================================================================
21 
22 #include <vector>
23 #include <fstream>
24 #include <string>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <xmmintrin.h>
28 #include <smmintrin.h>
29 #include "geometry.h"
30 #include "quaternion_helper.h"
31 #include "terminal_utils.h"
32 #include "timer.h"
33 #include "grahams_scan.h"
34 #include <eigen3/Eigen/Dense>
35 #include <eigen3/Eigen/Eigenvalues>
36 #include <eigen3/Eigen/Geometry>
37 
38 #ifndef PLANE_POLYGON_H
39 #define PLANE_POLYGON_H
40 
41 using namespace std;
42 using namespace Eigen;
43 
44 
49 protected:
51  vector<vector2d> normals2D;
53  vector<vector2d> edgeDir2D;
55  vector<double> edgeLengths;
57  vector<double> offsets2D;
58 
62  Matrix3d m, eigenVectors;
64  Vector3d eigenValues;
66  SelfAdjointEigenSolver<Matrix3d> solver;
67 
68 public:
70  double numPoints;
72  vector<vector2i> pixelLocs;
74  vector<vector3f> vertices;
76  vector<vector2f> vertices2D;
77  // Plane equation: for points p on the plane, (p-p0).dot(normal) = 0 or p.dot(normal) + offset = 0
83  double offset;
85  vector3f b1, b2;
86 
87 
89  double sum_xx, sum_yy, sum_zz, sum_xy, sum_xz, sum_yz;
91  float width, height;
93  vector2f min2D, max2D;
95  vector3f corners[4];
96 
99 
102 
103 protected:
105  bool constructConvexPoly(vector<vector3f>& points);
107  bool computePlaneParameters(vector<vector3f>& points);
108 
109 public:
111  PlanePolygon();
113  PlanePolygon(vector< vector3f > points);
115  PlanePolygon(vector<vector3f> points, vector<vector2i> _pixelLocs);
117  ~PlanePolygon();
118 
120  double distFromPlane(vector3f p);
122  vector3f rayFromPlane(vector3f p);
124  vector2f projectOnto (const vector3f& p) const {return vector2f(b1.dot(p-p0), b2.dot(p-p0));}
126  bool liesAlongside(const vector3f& p) const;
128  void merge(PlanePolygon& poly2);
130  void merge(vector< PlanePolygon >& polygons);
132  void transform(vector3f translation, Quaternionf rotation);
134  void transform(const GVector::matrix3d< float >& M);
136  vector3f intersect(vector3f l0, vector3f l);
137 };
138 
139 #endif //PLANE_POLYGON_H
Subroutines to spice up stdout.
bool validPolygon
Indicates whether a valid convex plane polygon fit was copmuted or not.
Definition: plane_polygon.h:98
float width
Rectangular dimensions of the polygon.
Definition: plane_polygon.h:91
vector2f min2D
Rectangular extents of the polygon in 2D.
Definition: plane_polygon.h:93
vector< double > offsets2D
Offsets to the edges such that for an interior point p, normals2D[i].dot(p)+offsets2D[i]> 0 for all i...
Definition: plane_polygon.h:57
SelfAdjointEigenSolver< Matrix3d > solver
Solver to solve for optimal plane parameters.
Definition: plane_polygon.h:66
Helpers for integrating Eigen Quaternions with GVector classes.
Matrix3d m
Matrices for computing optimal plane parameters.
Definition: plane_polygon.h:62
Vector3d eigenValues
Eigenvectors of the plane scatter matrix.
Definition: plane_polygon.h:64
vector3f p0
Point on the plane corresponding to the centroid of the sampled points.
Definition: plane_polygon.h:81
double offset
Perpendicular offset of the plane from the origin.
Definition: plane_polygon.h:83
vector< double > edgeLengths
Length of the edge (vertices2D[i], vertices2D[i+1])
Definition: plane_polygon.h:55
vector2f projectOnto(const vector3f &p) const
Project 3D point onto the plane polygon and return corresponding 2D coordinates.
double conditionNumber
Ratio of the eigenvalues corresponding to the planar basis vectors.
vector< vector3f > vertices
Vertices of the polygon.
Definition: plane_polygon.h:74
vector< vector2f > vertices2D
Vertices projected onto the 2D basis vectors.
Definition: plane_polygon.h:76
vector3f b1
Basis vectors on the plane. b1 corresponds to the major axis and b2 to the minor axis.
Definition: plane_polygon.h:85
GrahamsScan grahamsScan
Graham Scan class used to generate convex hull of the polygon.
Definition: plane_polygon.h:60
vector< vector2i > pixelLocs
Pixel locations of the points sampled from the depth image used to construct the polygon.
Definition: plane_polygon.h:72
vector< vector2d > normals2D
Normals to the edges. normals2D[i] is normal to the edge (vertices2D[i], vertices2D[i+1]) ...
Definition: plane_polygon.h:51
double numPoints
Number of points used to build the polygon.
Definition: plane_polygon.h:70
vector< vector2d > edgeDir2D
Unit vectors parallel to the edges. edgeDir2D[i] is parallel to the edge (vertices2D[i], vertices2D[i+1])
Definition: plane_polygon.h:53
double sum_xx
Coefficients of the moments of the points.
Definition: plane_polygon.h:89
vector3f normal
Normal to the plane.
Definition: plane_polygon.h:79