Polygon.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 #include "Math/Math3d.h"
27 
28 #include "../HandLocalisationConstants.h"
29 
30 
32 {
33 
34  struct Polygon
35  {
36  int nCorners; // corners which form the convex hull of the polygon. ordered by y (desc).
37  Vec3d hull[2 * DSHT_MAX_POLYGON_CORNERS]; // z-value is 1 if the corner belongs to the left part, 2 for the
38  // right part, 3 if it belongs to both (highest and lowest point).
39 
40  Vec3d hullCircle[2 * DSHT_MAX_POLYGON_CORNERS + 1]; // contains the points of the hull in the order they have
41  // on a path going around the edge of the polygon, starting and ending
42  // at the highest point, in a clockwise sense
43  // +1 reserves space to copy the first entry for hull lines
44 
45  // in left and right hull, the entry 0 is the lowest point, 1 the highest, then in descending y-order
46  // the other points, and the last entry is the lowest point again.
47  int nCornersLeft; // left part of the hull
49 
50  int nCornersRight; // right part of the hull
52 
53  Vec3d center3d; // center of the fingertip (3D)
54 
55  float minX, maxX, minY, maxY; // extremest coordinate values in x- and y-direction
56  };
57 
58 
59 
60  // Sorts the points in the array inout by their X-coordinate (descending)
61  void SortByX(Vec3d* inout, int arraylength);
62  void SortByY(Vec3d* inout, int arraylength);
63 
64  // Returns true if the two consecutive line segments described by the three points
65  // make a turn to the left
66  bool LeftTurn(Vec3d p1, Vec3d p2, Vec3d p3);
67  bool RightTurn(Vec3d p1, Vec3d p2, Vec3d p3);
68 
69  // Returns true if Point lies on the right side of the line defined by linePoint1 and linePoint2 (2D)
70  bool PointIsOnTheRightSideOfTheLine(Vec3d Point, Vec3d linePoint1, Vec3d linePoint2);
71 
72 
73 
74  // Analog zu Sanders-VL Algorithmentechnik, Folien 16 vom 12.02.2008, S.28-32.
75  // Calculates the convex hull of the points in "in", the left part of the hull is stored in hull_left,
76  // the right part in hull_right. Both start with the lowest point, then the highest point, then the
77  // points of the respective hull descending by Y until the lowest point (again).
78  // hull_left, hull_right, temp1 and temp2 have to be of size (max number of corners of a polygon) + 1
79  void CalcConvexHull(Vec3d* in, int num_all_points, Vec3d* hull_left, int* num_hull_points_left, Vec3d* hull_right, int* num_hull_points_right, Vec3d* temp1, Vec3d* temp2);
80  void CalcConvexHull(Vec3d* in, int num_all_points, Vec3d* hull_left, int* num_hull_points_left, Vec3d* hull_right, int* num_hull_points_right);
81 
82  // Interface to create the convex polygon pol from the points in the array in
83  void CalcConvexHull(Vec3d* in, int num_all_points, Polygon* pol, Vec3d* temp1, Vec3d* temp2);
84  void CalcConvexHull(Vec3d* in, int num_all_points, Polygon* pol);
85 
86  // Interface to create the convex polygon pol from the points already in pol->hull
87  void CalcConvexHull(Polygon* pol, Vec3d* temp1, Vec3d* temp2);
88  void CalcConvexHull(Polygon* pol);
89 
90  // Creates a convex polygon from the points in hullpoints, assuming that they all belong to the
91  // convex hull
92  void CreateConvexPolygonFromHullPoints(Vec3d* hullpoints, int nPoints, Polygon* pol);
93 
94 
95 
96  // Returns the convex polygon that is the intersection polygon of p1 and p2. pointAccu and boolTable have to
97  // be of size 2*(maximal number of points in a normal polygon), clockwiseHullPoly1/2 of size (maximal number
98  // of points in a normal polygon)+1
99  void GetPolygonIntersection(Polygon* p1, Polygon* p2, Polygon* pInter, Vec3d* pointAccu, bool* boolTable, Vec3d* clockwiseHullPoly1, Vec3d* clockwiseHullPoly2);
100  void GetPolygonIntersection(Polygon* p1, Polygon* p2, Polygon* pInter);
101 
102 
103 
104  // Returns true if it is possible that the two polygons intersect
105  bool PolygonsMightIntersect(Polygon* pol1, Polygon* pol2);
106 
107 }
108 
109 
DSHT_MAX_POLYGON_CORNERS
#define DSHT_MAX_POLYGON_CORNERS
Definition: HandLocalisationConstants.h:46
visionx::ConvexPolygonCalculations::Polygon::hullCircle
Vec3d hullCircle[2 *DSHT_MAX_POLYGON_CORNERS+1]
Definition: Polygon.h:40
visionx::ConvexPolygonCalculations::Polygon::hullLeft
Vec3d hullLeft[2 *DSHT_MAX_POLYGON_CORNERS+1]
Definition: Polygon.h:48
visionx::ConvexPolygonCalculations::LeftTurn
bool LeftTurn(Vec3d p1, Vec3d p2, Vec3d p3)
Definition: Polygon.cpp:88
visionx::ConvexPolygonCalculations::RightTurn
bool RightTurn(Vec3d p1, Vec3d p2, Vec3d p3)
Definition: Polygon.cpp:97
visionx::ConvexPolygonCalculations::GetPolygonIntersection
void GetPolygonIntersection(Polygon *p1, Polygon *p2, Polygon *pInter, Vec3d *pointAccu, bool *boolTable, Vec3d *clockwiseHullPoly1, Vec3d *clockwiseHullPoly2)
Definition: Polygon.cpp:423
visionx::ConvexPolygonCalculations::Polygon::maxY
float maxY
Definition: Polygon.h:55
visionx::ConvexPolygonCalculations::Polygon::nCorners
int nCorners
Definition: Polygon.h:36
visionx::ConvexPolygonCalculations::SortByY
void SortByY(Vec3d *inout, int arraylength)
Definition: Polygon.cpp:63
visionx::ConvexPolygonCalculations::Polygon
Definition: Polygon.h:34
visionx::ConvexPolygonCalculations::CreateConvexPolygonFromHullPoints
void CreateConvexPolygonFromHullPoints(Vec3d *hullpoints, int nPoints, Polygon *pol)
Definition: Polygon.cpp:336
visionx::ConvexPolygonCalculations::Polygon::hullRight
Vec3d hullRight[2 *DSHT_MAX_POLYGON_CORNERS+1]
Definition: Polygon.h:51
visionx::ConvexPolygonCalculations::Polygon::center3d
Vec3d center3d
Definition: Polygon.h:53
visionx::ConvexPolygonCalculations
Definition: Polygon.cpp:29
visionx::ConvexPolygonCalculations::PolygonsMightIntersect
bool PolygonsMightIntersect(Polygon *pol1, Polygon *pol2)
Definition: Polygon.cpp:115
visionx::ConvexPolygonCalculations::Polygon::nCornersLeft
int nCornersLeft
Definition: Polygon.h:47
visionx::ConvexPolygonCalculations::Polygon::maxX
float maxX
Definition: Polygon.h:55
GfxTL::Vec3d
VectorXD< 3, double > Vec3d
Definition: VectorXD.h:695
Point
Definition: PointCloud.h:21
visionx::ConvexPolygonCalculations::SortByX
void SortByX(Vec3d *inout, int arraylength)
Definition: Polygon.cpp:37
visionx::ConvexPolygonCalculations::Polygon::minY
float minY
Definition: Polygon.h:55
visionx::ConvexPolygonCalculations::Polygon::hull
Vec3d hull[2 *DSHT_MAX_POLYGON_CORNERS]
Definition: Polygon.h:37
visionx::ConvexPolygonCalculations::Polygon::nCornersRight
int nCornersRight
Definition: Polygon.h:50
visionx::ConvexPolygonCalculations::Polygon::minX
float minX
Definition: Polygon.h:55
visionx::ConvexPolygonCalculations::CalcConvexHull
void CalcConvexHull(Vec3d *in, int num_all_points, Vec3d *hull_left, int *num_hull_points_left, Vec3d *hull_right, int *num_hull_points_right, Vec3d *temp1, Vec3d *temp2)
Definition: Polygon.cpp:134
visionx::ConvexPolygonCalculations::PointIsOnTheRightSideOfTheLine
bool PointIsOnTheRightSideOfTheLine(Vec3d Point, Vec3d linePoint1, Vec3d linePoint2)
Definition: Polygon.cpp:106