LIBRCSC Docs
Documentation for HELIOS's BASE LIBRCSC library for RoboCup 2D Simulation League.
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
convex_hull.h
Go to the documentation of this file.
1// -*-c++-*-
2
8/*
9 *Copyright:
10
11 Copyright (C) Hidehisa Akiyama
12
13 This code is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 3 of the License, or (at your option) any later version.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
27 *EndCopyright:
28 */
29
30#ifndef RCSC_GEOM_CONVEX_HULL_H
31#define RCSC_GEOM_CONVEX_HULL_H
32
33#include <rcsc/geom/vector_2d.h>
36
37#include <vector>
38#include <set>
39
40namespace rcsc {
41
43public:
44 typedef std::vector< Vector2D > PointCont;
45 typedef std::vector< Vector2D > VertexCont;
46 typedef std::vector< Segment2D > EdgeCont;
47
53 DirectMethod,
54 WrappingMethod,
55 GrahamScan,
56 // IncrementalMethod,
57 // DivideConquer,
58 // QuickMethod,
59 // InnerPointsElimination,
60 };
61
62private:
63
64 PointCont M_input_points;
65
66 VertexCont M_vertices;
67 EdgeCont M_edges;
68
69
70 // not used
71 ConvexHull( const ConvexHull & ) = delete;
72 ConvexHull & operator=( const ConvexHull & ) = delete;
73
74public:
75
80
85 ConvexHull( const PointCont & v );
86
90 void clear();
91
96
101 void addPoint( const Vector2D & p )
102 {
103 M_input_points.push_back( p );
104 }
105
110 void addPoints( const PointCont & v )
111 {
112 M_input_points.insert( M_input_points.end(), v.begin(), v.end() );
113 }
114
118 // void compute();
119
124 void compute( const MethodType type = WrappingMethod );
125
130 const PointCont & inputPoints() const
131 {
132 return M_input_points;
133 }
134
139 const VertexCont & vertices() const
140 {
141 return M_vertices;
142 }
143
148 const EdgeCont & edges() const
149 {
150 return M_edges;
151 }
152
153private:
154
158 void computeDirectMethod();
159
163 void computeWrappingMethod();
164
168 void computeGrahamScan();
169
173 // void computeIncrementalMethod();
174
178 // void computeDivideAndConquer();
179
183 // void computeQuickMethod();
184
188 // void computeInnerPointsElimination();
189
190private:
191
195 size_t getMinPointIndex() const;
196
197 void sortPointsByAngleFrom( const size_t index );
198
199public:
200
206
212 std::ostream & printInputPoints( std::ostream & os ) const;
213
219 std::ostream & printVertices( std::ostream & os ) const;
220
226 std::ostream & printEdges( std::ostream & os ) const;
227
228};
229
230}
231
232#endif
Definition: convex_hull.h:42
std::ostream & printInputPoints(std::ostream &os) const
output input points to the stream in gnuplot format.
ConvexHull()
create empty convex hull
void clearResults()
clear result variables.
MethodType
algoritym type
Definition: convex_hull.h:52
ConvexHull(const PointCont &v)
create convex hull with given points
std::ostream & printEdges(std::ostream &os) const
output edges to the stream in gnuplot format.
std::vector< Vector2D > PointCont
input point container
Definition: convex_hull.h:44
Polygon2D toPolygon() const
get the convex hull polygon
void addPoint(const Vector2D &p)
add a new point to the set of input point
Definition: convex_hull.h:101
const PointCont & inputPoints() const
get the reference to the input point container
Definition: convex_hull.h:130
const VertexCont & vertices() const
get the reference to the vertex container ordered by counter clockwise
Definition: convex_hull.h:139
void clear()
clear all data.
std::vector< Vector2D > VertexCont
result vertex container
Definition: convex_hull.h:45
std::ostream & printVertices(std::ostream &os) const
output vertices to the stream in gnuplot format.
void addPoints(const PointCont &v)
add new points to the set of input pointc
Definition: convex_hull.h:110
void compute(const MethodType type=WrappingMethod)
generate convex hull by default method.
std::vector< Segment2D > EdgeCont
result edge container
Definition: convex_hull.h:46
const EdgeCont & edges() const
get the reference to the result edge container
Definition: convex_hull.h:148
2D polygon region class
Definition: polygon_2d.h:47
2D point vector class
Definition: vector_2d.h:46
2D polygon region Header File.
2D segment line Header File.
2d vector class Header File.