-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathBehavior.cs
248 lines (214 loc) · 6.39 KB
/
Behavior.cs
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
// -----------------------------------------------------------------------
// <copyright file="Behavior.cs">
// Original Triangle code by Jonathan Richard Shewchuk, http://www.cs.cmu.edu/~quake/triangle.html
// Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
// </copyright>
// -----------------------------------------------------------------------
namespace TriangleNet
{
using System;
using TriangleNet.Geometry;
/// <summary>
/// Controls the behavior of the meshing software.
/// </summary>
class Behavior
{
bool poly = false;
bool quality = false;
bool varArea = false;
bool convex = false;
bool jettison = false;
bool boundaryMarkers = true;
bool noHoles = false;
bool conformDel = false;
Func<ITriangle, double, bool> usertest;
int noBisect = 0;
double minAngle = 0.0;
double maxAngle = 0.0;
double maxArea = -1.0;
internal bool fixedArea = false;
internal bool useSegments = true;
internal bool useRegions = false;
internal double goodAngle = 0.0;
internal double maxGoodAngle = 0.0;
internal double offconstant = 0.0;
/// <summary>
/// Creates an instance of the Behavior class.
/// </summary>
public Behavior(bool quality = false, double minAngle = 20.0)
{
if (quality)
{
this.quality = true;
this.minAngle = minAngle;
Update();
}
}
/// <summary>
/// Update quality options dependencies.
/// </summary>
private void Update()
{
this.quality = true;
if (this.minAngle < 0 || this.minAngle > 60)
{
this.minAngle = 0;
this.quality = false;
Log.Instance.Warning("Invalid quality option (minimum angle).", "Mesh.Behavior");
}
if ((this.maxAngle != 0.0) && (this.maxAngle < 60 || this.maxAngle > 180))
{
this.maxAngle = 0;
this.quality = false;
Log.Instance.Warning("Invalid quality option (maximum angle).", "Mesh.Behavior");
}
this.useSegments = this.Poly || this.Quality || this.Convex;
this.goodAngle = Math.Cos(this.MinAngle * Math.PI / 180.0);
this.maxGoodAngle = Math.Cos(this.MaxAngle * Math.PI / 180.0);
if (this.goodAngle == 1.0)
{
this.offconstant = 0.0;
}
else
{
this.offconstant = 0.475 * Math.Sqrt((1.0 + this.goodAngle) / (1.0 - this.goodAngle));
}
this.goodAngle *= this.goodAngle;
}
#region Static properties
/// <summary>
/// No exact arithmetic.
/// </summary>
public static bool NoExact { get; set; }
#endregion
#region Public properties
/// <summary>
/// Quality mesh generation.
/// </summary>
public bool Quality
{
get { return quality; }
set
{
quality = value;
if (quality)
{
Update();
}
}
}
/// <summary>
/// Minimum angle constraint.
/// </summary>
public double MinAngle
{
get { return minAngle; }
set { minAngle = value; Update(); }
}
/// <summary>
/// Maximum angle constraint.
/// </summary>
public double MaxAngle
{
get { return maxAngle; }
set { maxAngle = value; Update(); }
}
/// <summary>
/// Maximum area constraint.
/// </summary>
public double MaxArea
{
get { return maxArea; }
set
{
maxArea = value;
fixedArea = value > 0.0;
}
}
/// <summary>
/// Apply a maximum triangle area constraint.
/// </summary>
public bool VarArea
{
get { return varArea; }
set { varArea = value; }
}
/// <summary>
/// Input is a Planar Straight Line Graph.
/// </summary>
public bool Poly
{
get { return poly; }
set { poly = value; }
}
/// <summary>
/// Apply a user-defined triangle constraint.
/// </summary>
public Func<ITriangle, double, bool> UserTest
{
get { return usertest; }
set { usertest = value; }
}
/// <summary>
/// Enclose the convex hull with segments.
/// </summary>
public bool Convex
{
get { return convex; }
set { convex = value; }
}
/// <summary>
/// Conforming Delaunay (all triangles are truly Delaunay).
/// </summary>
public bool ConformingDelaunay
{
get { return conformDel; }
set { conformDel = value; }
}
/// <summary>
/// Suppresses boundary segment splitting.
/// </summary>
/// <remarks>
/// 0 = split segments
/// 1 = no new vertices on the boundary
/// 2 = prevent all segment splitting, including internal boundaries
/// </remarks>
public int NoBisect
{
get { return noBisect; }
set
{
noBisect = value;
if (noBisect < 0 || noBisect > 2)
{
noBisect = 0;
}
}
}
/// <summary>
/// Compute boundary information.
/// </summary>
public bool UseBoundaryMarkers
{
get { return boundaryMarkers; }
set { boundaryMarkers = value; }
}
/// <summary>
/// Ignores holes in polygons.
/// </summary>
public bool NoHoles
{
get { return noHoles; }
set { noHoles = value; }
}
/// <summary>
/// Jettison unused vertices from output.
/// </summary>
public bool Jettison
{
get { return jettison; }
set { jettison = value; }
}
#endregion
}
}