-
Notifications
You must be signed in to change notification settings - Fork 4
/
DisplacementCombinerOp.cs
97 lines (73 loc) · 2.86 KB
/
DisplacementCombinerOp.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
// Copyright (c) Ryan Schmidt (rms@gradientspace.com) - All Rights Reserved
// Unauthorized copying of this file, via any medium is strictly prohibited. Proprietary and confidential.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using g3;
namespace gs
{
public class DisplacementCombinerOp : BaseSingleOutputModelingOperator, IVectorDisplacementSourceOp
{
ShapeModelingOpList<IVectorDisplacementSourceOp> Displacements;
VectorDisplacement CombinedDisplacement;
public DisplacementCombinerOp()
{
Displacements = new ShapeModelingOpList<IVectorDisplacementSourceOp>();
Displacements.CollectionModified += on_collection_modified;
Displacements.CollectionItemModified += on_child_modified;
CombinedDisplacement = new VectorDisplacement();
}
public void Append(IVectorDisplacementSourceOp op)
{
Displacements.Append(op);
}
public void Remove(IVectorDisplacementSourceOp op)
{
Displacements.Remove(op);
}
public IReadOnlyList<IVectorDisplacementSourceOp> DisplacementOps {
get { return Displacements.Operators; }
}
void on_collection_modified(ModelingOpCollection collection)
{
base.invalidate();
}
void on_child_modified(ModelingOpCollection collection, ModelingOperator op)
{
base.invalidate();
}
public virtual void Update()
{
base.begin_update();
int Nd = Displacements.Count;
if ( Nd == 0 ) {
for ( int i = 0; i < CombinedDisplacement.Count; ++i ) {
CombinedDisplacement[i] = Vector3d.Zero;
}
base.complete_update();
return;
}
IVectorDisplacement[] children = new IVectorDisplacement[Nd];
for ( int i = 0; i < Nd; ++i ) {
children[i] = Displacements[i].GetDisplacement();
if (children[i].Count != children[0].Count)
throw new Exception("DisplacementCombinerOp.Update: child " + i.ToString() + " Count inconsistent: " + children[i].Count + " != " + children[0].Count);
}
int Nv = children[0].Count;
CombinedDisplacement.Resize(Nv);
for ( int vi = 0; vi < Nv; ++vi ) {
Vector3d sum = Vector3d.Zero;
for (int di = 0; di < Nd; ++di)
sum += children[di].GetDisplacementForIndex(vi);
CombinedDisplacement[vi] = sum;
}
base.complete_update();
}
public IVectorDisplacement GetDisplacement() {
if (base.requires_update())
Update();
return CombinedDisplacement;
}
}
}