-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathShape.pde
142 lines (119 loc) · 3.3 KB
/
Shape.pde
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
class Shape extends BaseModel {
boolean isMeshCollection;
boolean isCustom;
ShapeCreator shapeCreator;
File file;
Shape (String name, int parameters) {
super(name, parameters);
this.isMeshCollection = false;
this.isCustom = false;
this.file = null;
}
Shape setMaxValues(float[] maxValues) {
this.maxValues = maxValues;
return this;
}
Shape setMinValues(float[] minValues) {
this.minValues = minValues;
return this;
}
Shape setDefaultValues(float[] defaultValues) {
this.defaultValues = defaultValues;
this.values = defaultValues;
return this;
}
Shape setLabels(String[] labels) {
this.labels = labels;
return this;
}
Shape setMeshCollection(boolean isMeshCollection) {
this.isMeshCollection = isMeshCollection;
return this;
}
Shape setCustom(boolean isCustom) {
this.isCustom = isCustom;
return this;
}
boolean getCustom() {
return this.isCustom;
}
Shape setFile(File file) {
this.file = file;
return this;
}
Shape setFileFromBase64String(String fileContents, String fileExtension) {
UUID uuid = UUID.randomUUID();
String path = System.getProperty("java.io.tmpdir") + "/" + uuid.toString() + "." + fileExtension;
try {
FileOutputStream stream = new FileOutputStream(path);
stream.write(Base64.getDecoder().decode(fileContents));
stream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
this.file = new File(path);
return this;
}
String getBase64EncodedFile() {
String encodedFile = null;
try {
FileInputStream stream = new FileInputStream(this.file);
byte[] bytes = new byte[(int)this.file.length()];
stream.read(bytes);
encodedFile = new String(Base64.getEncoder().encode(bytes));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return encodedFile;
}
boolean getMeshCollection() {
return this.isMeshCollection;
}
File getFile() {
return this.file;
}
Shape setCreator(ShapeCreator creator) {
this.shapeCreator = creator;
return this;
}
void create() {
if (this.shapeCreator != null) {
if (this.isCustom) {
this.shapeCreator.create(values, file);
} else {
this.shapeCreator.create(values);
}
} else {
println("No creator found");
}
}
void validate(HE_Mesh mesh) {
HET_Diagnosis.validate(mesh);
}
}
interface ShapeCreator {
public void create(float[] values);
public void create(float[] values, File file);
}
class UVFunction implements WB_VectorParameter {
public double sq = 2.0;
public double dv = 2.0;
public UVFunction(double sq, double dv) {
this.sq = sq;
this.dv = dv;
}
WB_Point evaluate(double... u) {
double pi23 = TWO_PI / this.dv;
double ua = Math.PI * 2 * u[0];
double va = Math.PI * 2 * u[1];
double sqrt2 = Math.sqrt(this.sq);
double px = Math.sin(ua) / Math.abs(sqrt2+ Math.cos(va));
double py = Math.sin(ua + pi23) / Math.abs(sqrt2 + Math.cos(va + pi23));
double pz = Math.cos(ua - pi23) / Math.abs(sqrt2 + Math.cos(va - pi23));
return new WB_Point(px, py, pz);
}
}