-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMesh.h
129 lines (96 loc) · 3.24 KB
/
Mesh.h
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
/*
* Mesh.h
*
* (c) 2016 Sofian Audry -- info(@)sofianaudry(.)com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MESH_H_
#define MESH_H_
#include "Quad.h"
namespace mmp {
class Mesh : public Quad
{
Q_OBJECT
Q_PROPERTY(int nColumns READ nColumns WRITE setNColumns)
Q_PROPERTY(int nRows READ nRows WRITE setNRows)
typedef QVector<QVector<int> > IndexVector2d;
public:
Q_INVOKABLE Mesh();
// This constructor creates a quad mesh (four corners) using the same order as for the quad
// constructor (ie. clockwise).
Mesh(QPointF p1, QPointF p2, QPointF p3, QPointF p4);
// Standard mesh constructor.
Mesh(const QVector<QPointF>& points, int nColumns, int nRows);
virtual ~Mesh() {}
// Performs the actual adding of points (used for loading).
void init(const QVector<QPointF>& points, int nColumns, int nRows);
virtual void build();
virtual QString getType() const { return "mesh"; }
/// Returns a polygon that is formed by all the contour points of the mesh.
virtual QPolygonF toPolygon() const;
// Override the parent, checking to make sure the vertices are displaced correctly.
virtual void setVertex(int i, const QPointF& v);
QPointF getVertex2d(int i, int j) const
{
return vertices[_vertices2d[i][j]];
}
void setVertex2d(int i, int j, const QPointF& v)
{
vertices[_vertices2d[i][j]] = v; // copy
}
void setVertex2d(int i, int j, double x, double y)
{
vertices[_vertices2d[i][j]] = QPointF(x, y);
}
void resizeVertices2d(IndexVector2d& vertices2d, int nColumns, int nRows);
//
void addColumn();
void addRow();
void removeColumn(int columnId);
void removeRow(int rowId);
void resize(int nColumns_, int nRows_);
QVector<Quad::ptr> getQuads() const;
QVector<QVector<Quad::ptr> > getQuads2d() const;
int nColumns() const { return _nColumns; }
int nRows() const { return _nRows; }
void setNColumns(int nColumns_) {
resize(nColumns_, nRows());
}
void setNRows(int nRows_) {
resize(nColumns(), nRows_);
}
int nHorizontalQuads() const { return _nColumns-1; }
int nVerticalQuads() const { return _nRows-1; }
void copyFrom(const MShape& shape);
protected:
int _nColumns;
int _nRows;
// _vertices[i][j] contains vertex id of vertex at position (i,j) where i = 0..nColumns and j = 0..nRows
IndexVector2d _vertices2d;
/**
* Reorder vertices in a standard order:
*
* 0----1----2----3
* | | | |
* 4----5----6----7
* | | | |
* 8----9---10----11
*/
void _reorderVertices();
/// Returns a new MShape (using default constructor).
virtual MShape* _create() const { return new Mesh(); }
};
}
#endif /* MESH_H_ */