forked from Dan-Piker/K2Goals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLaplacianSmooth.cs
58 lines (52 loc) · 1.5 KB
/
LaplacianSmooth.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Rhino.Geometry;
namespace KangarooSolver.Goals
{
/// <summary>
/// Uniform Laplacian smoothing aka Umbrella operator
/// </summary>
public class LaplacianSmooth : GoalObject
{
public double Strength;
public LaplacianSmooth()
{
}
public LaplacianSmooth(int[] P, double k)
{
PIndex = P;
Move = new Vector3d[P.Length];
Weighting = new double[P.Length];
Strength = k;
}
public LaplacianSmooth(Point3d[] P, double k)
{
PPos = P;
Move = new Vector3d[P.Length];
Weighting = new double[P.Length];
Strength = k;
}
public override void Calculate(List<KangarooSolver.Particle> p)
{
Point3d Avg = new Point3d();
for (int i = 1; i < PIndex.Length; i++)
{
Avg = Avg + p[PIndex[i]].Position;
}
double Inv = 1.0 / (PIndex.Length - 1);
Avg = Avg * Inv;
Vector3d Smooth = 0.5 * (Avg - p[PIndex[0]].Position);
Move[0] = Smooth;
Weighting[0] = Strength;
Smooth *= -Inv;
for (int i = 1; i < PIndex.Length; i++)
{
Move[i] = Smooth;
Weighting[i] = Strength;
}
}
}
}