-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPatternGenerator.h
More file actions
205 lines (160 loc) · 5.95 KB
/
PatternGenerator.h
File metadata and controls
205 lines (160 loc) · 5.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#ifndef PATTERNGENERATOR_H
#define PATTERNGENERATOR_H
#include <QOpenGLVertexArrayObject>
#include <QOpenGLBuffer>
#include <QOpenGLShaderProgram>
#include <QMatrix3x3>
#include "ALine.h"
#include "AVector.h"
#include "TilingData.h"
#include "RibbonSegment.h"
class PatternGenerator
{
public:
PatternGenerator();
~PatternGenerator();
/*
* Read xml files which contain tiling specifications
*/
void InitTiling();
/*
* 1. generate an islamic ornamental tiling given a name of a tiling
* 2. Call InferenceAlgorithm()
* 3. Create vertex data
*/
void GeneratePattern(std::string tilingName);
/*
* Pain function, nothing special
*/
void Paint(float zoomFactor);
/*
* These functions are called by GLWidget to render an SVG file
*/
std::vector<ALine> GetTilingLines() { return _tilingLines; }
std::vector<ALine> GetTriangleLines() { return _triangleLines; }
std::vector<ALine> GetBackTriangleLines() { return _backTriangleLines; }
std::vector<ALine> GetAddTriangleLines() { return _addTriangleLines; }
std::vector<ALine> GetULines() { return _uLines; }
std::vector<ALine> GetOLines() { return _oLines; }
private:
/*
* Generate an N-Gon, this function has a numerical problem so I use epsilon
*/
std::vector<AVector> GenerateNGon(float sides, float radius, float angleOffset, AVector centerPt);
/*
* Copy sourcePolygon to destinationLines
*/
void ConcatNGon(std::vector<AVector> sourcePolygon, std::vector<ALine> &destinationLines);
/*
* Copy sourcePolygon to shapes
*/
void ConcatShapes(std::vector<AVector> sourcePolygon, std::vector<std::vector<ALine>> &shapes);
/*
* The greedy inference algorithm
*/
void InferenceAlgorithm(std::vector<std::vector<ALine>> shapes);
/*
* Affine transformation
*/
AVector MultiplyVector(QMatrix3x3 mat, AVector vec);
/*
* Affine transformation
*/
void MultiplyShape(QMatrix3x3 mat, std::vector<AVector>& shape);
/*
* Unsigned angle in radian
*/
float AngleInBetween(AVector vec1, AVector vec2);
/*
* Read an XML file with TinyXML
*/
void ReadXML(std::string filename);
/*
*
*/
TilingData GetTiling(std::string tilingName);
/*
* Signed angle in radian
*/
float GetRotation(AVector pt1, AVector pt2);
/*
* Get a center of mass of a polygon
*/
AVector GetPolygonCentroid(std::vector<ALine> shapes);
/*
* Do both rays are collinear ?
*/
bool CheckCollinearCase(ALine ray1, ALine ray2);
/*
* Do both rays create a 90 degree corner
*/
bool CheckHorizontalVerticalCase(ALine ray1, ALine ray2);
/*
*
*/
void CalculateInterlace(std::pair<ALine, ALine> segment, std::vector<ALine> aShape, std::vector<ALine> &uLines, std::vector<ALine> &oLines);
void BuildPointsVertexData(std::vector<AVector> points, QOpenGLBuffer* ptsVbo, QOpenGLVertexArrayObject* ptsVao, QVector3D vecCol);
void BuildLinesVertexData0(std::vector<ALine> lines, QOpenGLBuffer* linesVbo, QOpenGLVertexArrayObject* linesVao, QVector3D vecCol1, QVector3D vecCol2);
void BuildLinesVertexData1(std::vector<ALine> lines, QOpenGLBuffer* linesVbo, QOpenGLVertexArrayObject* linesVao, QVector3D vecCol);
void BuildLinesVertexData2(std::vector<ALine> lines, QOpenGLBuffer* linesVbo, QOpenGLVertexArrayObject* linesVao);
void BuildQuadsVertexData(std::vector<ALine> lines, QOpenGLBuffer* vbo, QOpenGLVertexArrayObject* vao, QVector3D vecCol);
void BuildTrianglesVertexData(std::vector<ALine> lines, QOpenGLBuffer* vbo, QOpenGLVertexArrayObject* vao, QVector3D vecCol);
// to do: fix this
public:
QOpenGLShaderProgram* _shaderProgram;
int _colorLocation;
int _vertexLocation;
int _use_color_location;
int _img_width;
int _img_height;
// to do: delete me
//float sideDiv;
private:
std::vector<ALine> _rayLines;
QOpenGLBuffer _rayLinesVbo;
QOpenGLVertexArrayObject _rayLinesVao;
// to do: delete this
std::vector<ALine> _tempLines;
QOpenGLBuffer _tempLinesVbo;
QOpenGLVertexArrayObject _tempLinesVao;
// to do: delete this
std::vector<AVector> _tempPoints;
QOpenGLBuffer _tempPointsVbo;
QOpenGLVertexArrayObject _tempPointsVao;
// triangles
std::vector<ALine> _triangleLines;
QOpenGLBuffer _trianglesVbo;
QOpenGLVertexArrayObject _trianglesVao;
// triangles
std::vector<ALine> _backTriangleLines;
QOpenGLBuffer _backTrianglesVbo;
QOpenGLVertexArrayObject _backTrianglesVao;
// triangles
std::vector<ALine> _addTriangleLines;
QOpenGLBuffer _addTrianglesVbo;
QOpenGLVertexArrayObject _addTrianglesVao;
// under
//std::vector<RibbonSegment> _uSegments;
std::vector<ALine> _uLines;
// over
//std::vector<RibbonSegment> _oSegments;
std::vector<ALine> _oLines;
// lines under
QOpenGLBuffer _uLinesVbo;
QOpenGLVertexArrayObject _uLinesVao;
// lines over
QOpenGLBuffer _oLinesVbo;
QOpenGLVertexArrayObject _oLinesVao;
// quads under
QOpenGLBuffer _uQuadsVbo;
QOpenGLVertexArrayObject _uQuadsVao;
// quads over
QOpenGLBuffer _oQuadsVbo;
QOpenGLVertexArrayObject _oQuadsVao;
std::vector<ALine> _tilingLines;
QOpenGLBuffer _tilingLinesVbo;
QOpenGLVertexArrayObject _tilingLinesVao;
std::vector<TilingData> _tilings;
std::vector<std::vector<ALine>> _shapes;
};
#endif // PATTERNGENERATOR_H