CUGL 1.3
Cornell University Game Library
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
CUPathOutliner.h
1 //
2 // CUPathOutliner.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module is a factory for outlining the boundary of a polygon. While
6 // this code is very straight-forward, previous semesters have shown that it
7 // is best to factor this functionality out of Poly2.
8 //
9 // Because math objects are intended to be on the stack, we do not provide
10 // any shared pointer support in this class.
11 //
12 // CUGL MIT License:
13 // This software is provided 'as-is', without any express or implied
14 // warranty. In no event will the authors be held liable for any damages
15 // arising from the use of this software.
16 //
17 // Permission is granted to anyone to use this software for any purpose,
18 // including commercial applications, and to alter it and redistribute it
19 // freely, subject to the following restrictions:
20 //
21 // 1. The origin of this software must not be misrepresented; you must not
22 // claim that you wrote the original software. If you use this software
23 // in a product, an acknowledgment in the product documentation would be
24 // appreciated but is not required.
25 //
26 // 2. Altered source versions must be plainly marked as such, and must not
27 // be misrepresented as being the original software.
28 //
29 // 3. This notice may not be removed or altered from any source distribution.
30 //
31 // Author: Walker White
32 // Version: 6/22/16
33 
34 #ifndef __CU_PATH_OUTLINER_H__
35 #define __CU_PATH_OUTLINER_H__
36 
37 #include <cugl/math/CUPoly2.h>
38 #include <cugl/math/CUVec2.h>
39 #include <cugl/math/polygon/CUSimpleTriangulator.h>
40 #include <cugl/math/polygon/CUDelaunayTriangulator.h>
41 #include <vector>
42 
43 namespace cugl {
44 
50 enum class PathTraversal : int {
52  NONE = 0,
54  OPEN = 1,
56  CLOSED = 2,
58  INTERIOR = 3
59 };
60 
79 class PathOutliner {
80 #pragma mark Values
81 private:
83  std::vector<Vec2> _input;
85  std::vector<unsigned short> _output;
87  bool _calculated;
88 
90  DelaunayTriangulator _triangulator;
91 
92 #pragma mark -
93 #pragma mark Constructors
94 public:
99 
108  PathOutliner(const std::vector<Vec2>& points) : _calculated(false) { _input = points; }
109 
121  PathOutliner(const Poly2& poly) : _calculated(false) { _input = poly._vertices; }
122 
127 
128 #pragma mark -
129 #pragma mark Initialization
130 
144  void set(const Poly2& poly) {
145  reset();
146  _input = poly._vertices;
147  }
148 
160  void set(const std::vector<Vec2>& points) {
161  reset();
162  _input = points;
163  }
167  void reset() {
168  _calculated = false;
169  _output.clear();
170  }
171 
178  void clear() {
179  _calculated = false;
180  _input.clear(); _output.clear();
181  }
182 
183 #pragma mark -
184 #pragma mark Calculation
185 
193  void calculate(PathTraversal traversal);
194 
195 #pragma mark -
196 #pragma mark Materialization
197 
211  std::vector<unsigned short> getPath() const;
212 
226  size_t getPath(std::vector<unsigned short>& buffer) const;
227 
240  Poly2 getPolygon() const;
241 
256  Poly2* getPolygon(Poly2* buffer) const;
257 };
258 }
259 
260 #endif /* __CU_PATH_OUTLINER_H__ */
cugl::PathOutliner::clear
void clear()
Definition: CUPathOutliner.h:178
cugl::PathOutliner
Definition: CUPathOutliner.h:79
cugl::PathOutliner::set
void set(const Poly2 &poly)
Definition: CUPathOutliner.h:144
cugl::PathOutliner::PathOutliner
PathOutliner(const Poly2 &poly)
Definition: CUPathOutliner.h:121
cugl::PathOutliner::PathOutliner
PathOutliner(const std::vector< Vec2 > &points)
Definition: CUPathOutliner.h:108
cugl::PathOutliner::set
void set(const std::vector< Vec2 > &points)
Definition: CUPathOutliner.h:160
cugl::PathOutliner::getPath
std::vector< unsigned short > getPath() const
cugl::PathOutliner::~PathOutliner
~PathOutliner()
Definition: CUPathOutliner.h:126
cugl::Poly2
Definition: CUPoly2.h:109
cugl::PathOutliner::calculate
void calculate(PathTraversal traversal)
cugl::PathOutliner::PathOutliner
PathOutliner()
Definition: CUPathOutliner.h:98
cugl::DelaunayTriangulator
Definition: CUDelaunayTriangulator.h:75
cugl::PathOutliner::getPolygon
Poly2 getPolygon() const
cugl::PathOutliner::reset
void reset()
Definition: CUPathOutliner.h:167