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
27#include "Math/Math3d.h"
28
30{
31
32 struct Polygon
33 {
34 int nCorners; // corners which form the convex hull of the polygon. ordered by y (desc).
35 Vec3d hull
36 [2 *
37 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
41 1]; // contains the points of the hull in the order they have
42 // on a path going around the edge of the polygon, starting and ending
43 // at the highest point, in a clockwise sense
44 // +1 reserves space to copy the first entry for hull lines
45
46 // in left and right hull, the entry 0 is the lowest point, 1 the highest, then in descending y-order
47 // the other points, and the last entry is the lowest point again.
48 int nCornersLeft; // left part of the hull
50
51 int nCornersRight; // right part of the hull
53
54 Vec3d center3d; // center of the fingertip (3D)
55
56 float minX, maxX, minY, maxY; // extremest coordinate values in x- and y-direction
57 };
58
59 // Sorts the points in the array inout by their X-coordinate (descending)
60 void SortByX(Vec3d* inout, int arraylength);
61 void SortByY(Vec3d* inout, int arraylength);
62
63 // Returns true if the two consecutive line segments described by the three points
64 // make a turn to the left
65 bool LeftTurn(Vec3d p1, Vec3d p2, Vec3d p3);
66 bool RightTurn(Vec3d p1, Vec3d p2, Vec3d p3);
67
68 // Returns true if Point lies on the right side of the line defined by linePoint1 and linePoint2 (2D)
69 bool PointIsOnTheRightSideOfTheLine(Vec3d Point, Vec3d linePoint1, Vec3d linePoint2);
70
71
72 // Analog zu Sanders-VL Algorithmentechnik, Folien 16 vom 12.02.2008, S.28-32.
73 // Calculates the convex hull of the points in "in", the left part of the hull is stored in hull_left,
74 // the right part in hull_right. Both start with the lowest point, then the highest point, then the
75 // points of the respective hull descending by Y until the lowest point (again).
76 // hull_left, hull_right, temp1 and temp2 have to be of size (max number of corners of a polygon) + 1
77 void CalcConvexHull(Vec3d* in,
78 int num_all_points,
79 Vec3d* hull_left,
80 int* num_hull_points_left,
81 Vec3d* hull_right,
82 int* num_hull_points_right,
83 Vec3d* temp1,
84 Vec3d* temp2);
85 void CalcConvexHull(Vec3d* in,
86 int num_all_points,
87 Vec3d* hull_left,
88 int* num_hull_points_left,
89 Vec3d* hull_right,
90 int* num_hull_points_right);
91
92 // Interface to create the convex polygon pol from the points in the array in
93 void CalcConvexHull(Vec3d* in, int num_all_points, Polygon* pol, Vec3d* temp1, Vec3d* temp2);
94 void CalcConvexHull(Vec3d* in, int num_all_points, Polygon* pol);
95
96 // Interface to create the convex polygon pol from the points already in pol->hull
97 void CalcConvexHull(Polygon* pol, Vec3d* temp1, Vec3d* temp2);
98 void CalcConvexHull(Polygon* pol);
99
100 // Creates a convex polygon from the points in hullpoints, assuming that they all belong to the
101 // convex hull
102 void CreateConvexPolygonFromHullPoints(Vec3d* hullpoints, int nPoints, Polygon* pol);
103
104
105 // Returns the convex polygon that is the intersection polygon of p1 and p2. pointAccu and boolTable have to
106 // be of size 2*(maximal number of points in a normal polygon), clockwiseHullPoly1/2 of size (maximal number
107 // of points in a normal polygon)+1
109 Polygon* p2,
110 Polygon* pInter,
111 Vec3d* pointAccu,
112 bool* boolTable,
113 Vec3d* clockwiseHullPoly1,
114 Vec3d* clockwiseHullPoly2);
115 void GetPolygonIntersection(Polygon* p1, Polygon* p2, Polygon* pInter);
116
117
118 // Returns true if it is possible that the two polygons intersect
119 bool PolygonsMightIntersect(Polygon* pol1, Polygon* pol2);
120
121} // namespace visionx::ConvexPolygonCalculations
#define DSHT_MAX_POLYGON_CORNERS
void SortByY(Vec3d *inout, int arraylength)
Definition Polygon.cpp:61
bool LeftTurn(Vec3d p1, Vec3d p2, Vec3d p3)
Definition Polygon.cpp:83
bool PointIsOnTheRightSideOfTheLine(Vec3d Point, Vec3d linePoint1, Vec3d linePoint2)
Definition Polygon.cpp:97
bool RightTurn(Vec3d p1, Vec3d p2, Vec3d p3)
Definition Polygon.cpp:90
void CreateConvexPolygonFromHullPoints(Vec3d *hullpoints, int nPoints, Polygon *pol)
Definition Polygon.cpp:340
void SortByX(Vec3d *inout, int arraylength)
Definition Polygon.cpp:37
bool PolygonsMightIntersect(Polygon *pol1, Polygon *pol2)
Definition Polygon.cpp:106
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:122
void GetPolygonIntersection(Polygon *p1, Polygon *p2, Polygon *pInter, Vec3d *pointAccu, bool *boolTable, Vec3d *clockwiseHullPoly1, Vec3d *clockwiseHullPoly2)
Definition Polygon.cpp:428
Eigen::Vector3f Point
Vec3d hullCircle[2 *DSHT_MAX_POLYGON_CORNERS+1]
Definition Polygon.h:41
Vec3d hull[2 *DSHT_MAX_POLYGON_CORNERS]
Definition Polygon.h:37
Vec3d hullLeft[2 *DSHT_MAX_POLYGON_CORNERS+1]
Definition Polygon.h:49
Vec3d hullRight[2 *DSHT_MAX_POLYGON_CORNERS+1]
Definition Polygon.h:52