-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShapeTools.hh
175 lines (145 loc) · 5.17 KB
/
ShapeTools.hh
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
#ifndef SHAPETOOLS_HH
#define SHAPETOOLS_HH
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <Solver.h>
#include <Constraint.h>
#define N_ITERATIONS_DEFAULT 50
#define WEIGHT_MIN 0.0
#define WEIGHT_MAX 10.0
#define WEIGHT_STEP 0.01
#define WEIGHT_DEFAULT 0.1
#define WEIGHT_HANDLE 1.0
#define RANGE_MIN 0.0
#define RANGE_MAX 2.0
#define RANGE_STEP 0.1
#define RANGE_DEFAULT 1.0
#define ANGLE_MIN 0.0
#define ANGLE_MAX M_PI
#define ANGLE_STEP M_PI/180.0
#define ANGLE_DEFAULT M_PI/3.0
#define DEG2RAD M_PI/180.0
#define RAD2DEG 180.0/M_PI
class ShapeTools {
private:
ShapeOp::Solver* solver_;
size_t solver_iterations_;
bool update_needed_;
int object_id_;
TriMesh* triMesh_;
PolyMesh* polyMesh_;
// Fixed vertices
double fixedConstraintWeight_;
std::set<int> fixedVerticesIdx_;
// Handle vertices
double handleConstraintWeight_;
std::vector<int> handleIdxs_;
std::map<int,int> handleConstraintIds_;
// Rigid
double rigidConstraintWeight_;
std::vector<int> rigidIdxs_;
// Edge strain
double edgeStrainWeight_;
bool edgeStrainActive_;
// Triangle strain
double triangleStrainWeight_;
bool triangleStrainActive_;
// Area
double areaConstraintWeight_;
double areaMin_;
double areaMax_;
bool areaConstraintActive_;
// Bending
double bendingConstraintWeight_;
double bendingMin_;
double bendingMax_;
bool bendingConstraintActive_;
// Rectangle
double rectConstraintWeight_;
bool rectConstraintActive_;
// Angle
double angleConstraintWeight_;
double angleMin_;
double angleMax_;
bool angleConstraintActive_;
void setConstraints();
void moveHandles();
public:
ShapeTools() : solver_(NULL), solver_iterations_(N_ITERATIONS_DEFAULT), update_needed_(true), object_id_(-1), triMesh_(0), polyMesh_(0),
fixedConstraintWeight_(WEIGHT_MAX), fixedVerticesIdx_(),
handleConstraintWeight_(WEIGHT_HANDLE), handleIdxs_(), handleConstraintIds_(),
rigidConstraintWeight_(WEIGHT_MAX), rigidIdxs_(),
edgeStrainWeight_(WEIGHT_DEFAULT), edgeStrainActive_(false),
triangleStrainWeight_(WEIGHT_DEFAULT), triangleStrainActive_(false),
areaConstraintWeight_(WEIGHT_DEFAULT), areaMin_(RANGE_DEFAULT), areaMax_(RANGE_DEFAULT), areaConstraintActive_(false),
bendingConstraintWeight_(WEIGHT_DEFAULT), bendingMin_(RANGE_DEFAULT), bendingMax_(RANGE_DEFAULT), bendingConstraintActive_(false),
rectConstraintWeight_(WEIGHT_DEFAULT), rectConstraintActive_(false),
angleConstraintWeight_(WEIGHT_DEFAULT), angleMin_(ANGLE_MIN), angleMax_(ANGLE_DEFAULT), angleConstraintActive_(false) {}
~ShapeTools() { if (solver_ != NULL) delete solver_; }
void setMesh(TriMesh* _mesh, int _object_id);
void setMesh(PolyMesh* _mesh, int _object_id);
void flagUpdateNeeded() { update_needed_ = true; }
bool updateNeeded() { return update_needed_; }
void setIterationNumber(size_t _n_its) { solver_iterations_ = _n_its; }
void fixVertices(std::set<int> v_idxs) { fixedVerticesIdx_ = v_idxs; }
void setRigid(std::vector<int> v_idxs) { rigidIdxs_ = v_idxs; }
/**
* @brief setHandles Saves the given handle indices and flags an update if it has changed
* @param _handleIdxs The handle indices
*/
void setHandles(std::vector<int> _handleIdxs) {
if (_handleIdxs != handleIdxs_) {
handleIdxs_ = _handleIdxs;
flagUpdateNeeded();
}
}
void setWeightsAndRanges(double _edgeStrainWeight, double _triangleStrainWeight,
double _areaMin, double _areaMax, double _areaWeight,
double _bendingMin, double _bendingMax, double _bendingWeight,
double _rectWeight,
double _angleMin, double _angleMax, double _angleWeight) {
edgeStrainWeight_ = _edgeStrainWeight;
triangleStrainWeight_ = _triangleStrainWeight;
areaMin_ = _areaMin;
areaMax_ = _areaMax;
areaConstraintWeight_ = _areaWeight;
bendingMin_ = _bendingMin;
bendingMax_ = _bendingMax;
bendingConstraintWeight_ = _bendingWeight;
rectConstraintWeight_ = _rectWeight;
angleMin_ = _angleMin;
angleMax_ = _angleMax;
angleConstraintWeight_ = _angleWeight;
}
// Activation of constraints
enum ConstraintType { EDGE_STRAIN, TRIANGLE_STRAIN, AREA, BENDING, RECT, ANGLE };
void toggleConstraint(int _constraintType, bool _active) {
switch (_constraintType) {
case EDGE_STRAIN:
edgeStrainActive_ = _active;
break;
case TRIANGLE_STRAIN:
triangleStrainActive_ = _active;
break;
case AREA:
areaConstraintActive_ = _active;
break;
case BENDING:
bendingConstraintActive_ = _active;
break;
case RECT:
rectConstraintActive_ = _active;
break;
case ANGLE:
angleConstraintActive_ = _active;
break;
default:
break;
}
}
int getObjId() { return object_id_; }
// Solve linear system and set the new positions of vertices
bool solveUpdateMesh();
bool solveUpdateMesh(size_t _n_iterations);
};
#endif // SHAPETOOLS_HH