-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathChart3D_Surface.fs
More file actions
395 lines (366 loc) · 20 KB
/
Chart3D_Surface.fs
File metadata and controls
395 lines (366 loc) · 20 KB
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
namespace Plotly.NET
open Plotly.NET.LayoutObjects
open Plotly.NET.TraceObjects
open DynamicObj
open System
open System.IO
//open FSharp.Care.Collections
open StyleParam
open System.Runtime.InteropServices
open System.Runtime.CompilerServices
[<AutoOpen>]
module Chart3D_Surface =
[<Extension>]
type Chart =
/// <summary>
/// Creates a surface plot.
///
/// Surface plots plot a z value as a function of x and y, creating a three-dimensional surface.
///
/// The data the describes the coordinates of the surface is set in `z`. Data in `z` should be a 2D array.
/// Coordinates in `x` and `y` can either be 1D arrays or 2D arrays (e.g. to graph parametric surfaces). If not provided in `x` and `y`, the x and y coordinates are assumed to be linear starting at 0 with a unit step.
/// The color scale corresponds to the `z` values by default. For custom color scales, use `surfacecolor` which should be a 2D array, where its bounds can be controlled using `cmin` and `cmax`.
/// </summary>
/// <param name="zData">Two-dimensional data array representing the surface's z values</param>
/// <param name="X">Sets the x coordinates.</param>
/// <param name="Y">Sets the y coordinates.</param>
/// <param name="Name">Sets the trace name. The trace name appear as the legend item and on hover</param>
/// <param name="ShowLegend">Determines whether or not an item corresponding to this trace is shown in the legend.</param>
/// <param name="Opacity">Sets the opactity of the trace</param>
/// <param name="Text">Sets a text associated with each datum</param>
/// <param name="MultiText">Sets individual text for each datum</param>
/// <param name="Contours">Sets the contours on the surface</param>
/// <param name="ColorScale">Sets the colorscale of the surface</param>
/// <param name="ShowScale">Whether or not to show the colorbar/colorscale</param>
/// <param name="CameraProjectionType">Sets the camera projection type of this trace.</param>
/// <param name="Camera">Sets the camera of this trace.</param>
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
[<Extension>]
static member Surface
(
zData,
?X: seq<#IConvertible>,
?Y: seq<#IConvertible>,
?Name: string,
?ShowLegend: bool,
?Opacity: float,
?Text: #IConvertible,
?MultiText: seq<#IConvertible>,
?Contours: Contours,
?ColorScale: StyleParam.Colorscale,
?ShowScale: bool,
?CameraProjectionType: StyleParam.CameraProjectionType,
?Camera: Camera,
?UseDefaults: bool
) =
let useDefaults =
defaultArg UseDefaults true
let cameraProjection =
defaultArg CameraProjectionType StyleParam.CameraProjectionType.Perspective
let camera =
Camera
|> Option.defaultValue (LayoutObjects.Camera.init ())
|> LayoutObjects.Camera.style (Projection = CameraProjection.init (ProjectionType = cameraProjection))
Trace3D.initSurface (
Trace3DStyle.Surface(
Z = zData,
?X = X,
?Y = Y,
?Name = Name,
?ShowLegend = ShowLegend,
?Opacity = Opacity,
?Text = Text,
?MultiText = MultiText,
?Contours = Contours,
?ColorScale = ColorScale,
?ShowScale = ShowScale
)
)
|> GenericChart.ofTraceObject useDefaults
|> GenericChart.addLayout (
Layout.init () |> Layout.setScene (StyleParam.SubPlotId.Scene 1, Scene.init (Camera = camera))
)
/// <summary>
/// Creates a surface plot from an encoded z matrix and optional encoded x and y coordinates.
/// </summary>
[<Extension>]
static member Surface
(
zEncoded: EncodedTypedArray,
?xEncoded: EncodedTypedArray,
?yEncoded: EncodedTypedArray,
?Name: string,
?ShowLegend: bool,
?Opacity: float,
?Text: #IConvertible,
?MultiText: seq<#IConvertible>,
?Contours: Contours,
?ColorScale: StyleParam.Colorscale,
?ShowScale: bool,
?CameraProjectionType: StyleParam.CameraProjectionType,
?Camera: Camera,
?UseDefaults: bool
) =
let useDefaults =
defaultArg UseDefaults true
let cameraProjection =
defaultArg CameraProjectionType StyleParam.CameraProjectionType.Perspective
let camera =
Camera
|> Option.defaultValue (LayoutObjects.Camera.init ())
|> LayoutObjects.Camera.style (Projection = CameraProjection.init (ProjectionType = cameraProjection))
Trace3D.initSurface (
Trace3DStyle.Surface(
ZEncoded = zEncoded,
?XEncoded = xEncoded,
?YEncoded = yEncoded,
?Name = Name,
?ShowLegend = ShowLegend,
?Opacity = Opacity,
?Text = Text,
?MultiText = MultiText,
?Contours = Contours,
?ColorScale = ColorScale,
?ShowScale = ShowScale
)
)
|> GenericChart.ofTraceObject useDefaults
|> GenericChart.addLayout (
Layout.init () |> Layout.setScene (StyleParam.SubPlotId.Scene 1, Scene.init (Camera = camera))
)
/// <summary>
/// Visualizes a 3D mesh.
///
/// Draws sets of triangles with coordinates given by three 1-dimensional arrays in `x`, `y`, `z` and
///
/// (1) a sets of `i`, `j`, `k` indices or
///
/// (2) Delaunay triangulation or
///
/// (3) the Alpha-shape algorithm or
///
/// (4) the Convex-hull algorithm
/// </summary>
/// <param name="x">Sets the X coordinates of the vertices. The nth element of vectors `x`, `y` and `z` jointly represent the X, Y and Z coordinates of the nth vertex.</param>
/// <param name="y">Sets the Y coordinates of the vertices. The nth element of vectors `x`, `y` and `z` jointly represent the X, Y and Z coordinates of the nth vertex.</param>
/// <param name="z">Sets the Z coordinates of the vertices. The nth element of vectors `x`, `y` and `z` jointly represent the X, Y and Z coordinates of the nth vertex.</param>
/// <param name="I">A vector of vertex indices, i.e. integer values between 0 and the length of the vertex vectors, representing the "first" vertex of a triangle. For example, `{i[m], j[m], k[m]}` together represent face m (triangle m) in the mesh, where `i[m] = n` points to the triplet `{x[n], y[n], z[n]}` in the vertex arrays. Therefore, each element in `i` represents a point in space, which is the first vertex of a triangle.</param>
/// <param name="J">A vector of vertex indices, i.e. integer values between 0 and the length of the vertex vectors, representing the "second" vertex of a triangle. For example, `{i[m], j[m], k[m]}` together represent face m (triangle m) in the mesh, where `j[m] = n` points to the triplet `{x[n], y[n], z[n]}` in the vertex arrays. Therefore, each element in `j` represents a point in space, which is the second vertex of a triangle.</param>
/// <param name="K">A vector of vertex indices, i.e. integer values between 0 and the length of the vertex vectors, representing the "third" vertex of a triangle. For example, `{i[m], j[m], k[m]}` together represent face m (triangle m) in the mesh, where `k[m] = n` points to the triplet `{x[n], y[n], z[n]}` in the vertex arrays. Therefore, each element in `k` represents a point in space, which is the third vertex of a triangle.</param>
/// <param name="Name">Sets the trace name. The trace name appear as the legend item and on hover</param>
/// <param name="ShowLegend">Determines whether or not an item corresponding to this trace is shown in the legend.</param>
/// <param name="Opacity">Sets the opactity of the trace</param>
/// <param name="Text">Sets a text associated with each datum</param>
/// <param name="MultiText">Sets individual text for each datum</param>
/// <param name="Color">Sets the color of the whole mesh</param>
/// <param name="Contour">Sets the style and visibility of contours</param>
/// <param name="ColorScale">Sets the colorscale</param>
/// <param name="ShowScale">Whether or not to show the colorbar/colorscale</param>
/// <param name="ColorBar">Sets the colorbar</param>
/// <param name="FlatShading">Determines whether or not normal smoothing is applied to the meshes, creating meshes with an angular, low-poly look via flat reflections.</param>
/// <param name="TriangulationAlgorithm">Determines how the mesh surface triangles are derived from the set of vertices (points) represented by the `x`, `y` and `z` arrays, if the `i`, `j`, `k` arrays are not supplied.</param>
/// <param name="CameraProjectionType">Sets the camera projection type of this trace.</param>
/// <param name="Camera">Sets the camera of this trace.</param>
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
[<Extension>]
static member Mesh3D
(
x: seq<#IConvertible>,
y: seq<#IConvertible>,
z: seq<#IConvertible>,
?I: seq<#IConvertible>,
?J: seq<#IConvertible>,
?K: seq<#IConvertible>,
?Name: string,
?ShowLegend: bool,
?Opacity: float,
?Text: #IConvertible,
?MultiText: seq<#IConvertible>,
?Color: Color,
?Contour: Contour,
?ColorScale: StyleParam.Colorscale,
?ShowScale: bool,
?ColorBar: ColorBar,
?FlatShading: bool,
?TriangulationAlgorithm: StyleParam.TriangulationAlgorithm,
?CameraProjectionType: StyleParam.CameraProjectionType,
?Camera: Camera,
?UseDefaults: bool
) =
let useDefaults =
defaultArg UseDefaults true
let cameraProjection =
defaultArg CameraProjectionType StyleParam.CameraProjectionType.Perspective
let camera =
Camera
|> Option.defaultValue (LayoutObjects.Camera.init ())
|> LayoutObjects.Camera.style (Projection = CameraProjection.init (ProjectionType = cameraProjection))
Trace3D.initMesh3D (
Trace3DStyle.Mesh3D(
X = x,
Y = y,
Z = z,
?I = I,
?J = J,
?K = K,
?Name = Name,
?ShowLegend = ShowLegend,
?Opacity = Opacity,
?Text = Text,
?MultiText = MultiText,
?Color = Color,
?Contour = Contour,
?ColorScale = ColorScale,
?ShowScale = ShowScale,
?ColorBar = ColorBar,
?FlatShading = FlatShading,
?AlphaHull = TriangulationAlgorithm
)
)
|> GenericChart.ofTraceObject useDefaults
|> GenericChart.addLayout (
Layout.init () |> Layout.setScene (StyleParam.SubPlotId.Scene 1, Scene.init (Camera = camera))
)
/// <summary>
/// Visualizes a 3D mesh from encoded coordinate and optional encoded topology/intensity arrays.
/// </summary>
[<Extension>]
static member Mesh3D
(
xEncoded: EncodedTypedArray,
yEncoded: EncodedTypedArray,
zEncoded: EncodedTypedArray,
?iEncoded: EncodedTypedArray,
?jEncoded: EncodedTypedArray,
?kEncoded: EncodedTypedArray,
?intensityEncoded: EncodedTypedArray,
?Name: string,
?ShowLegend: bool,
?Opacity: float,
?Text: #IConvertible,
?MultiText: seq<#IConvertible>,
?Color: Color,
?Contour: Contour,
?ColorScale: StyleParam.Colorscale,
?ShowScale: bool,
?ColorBar: ColorBar,
?FlatShading: bool,
?TriangulationAlgorithm: StyleParam.TriangulationAlgorithm,
?CameraProjectionType: StyleParam.CameraProjectionType,
?Camera: Camera,
?UseDefaults: bool
) =
let useDefaults =
defaultArg UseDefaults true
let cameraProjection =
defaultArg CameraProjectionType StyleParam.CameraProjectionType.Perspective
let camera =
Camera
|> Option.defaultValue (LayoutObjects.Camera.init ())
|> LayoutObjects.Camera.style (Projection = CameraProjection.init (ProjectionType = cameraProjection))
Trace3D.initMesh3D (
Trace3DStyle.Mesh3D(
XEncoded = xEncoded,
YEncoded = yEncoded,
ZEncoded = zEncoded,
?IEncoded = iEncoded,
?JEncoded = jEncoded,
?KEncoded = kEncoded,
?IntensityEncoded = intensityEncoded,
?Name = Name,
?ShowLegend = ShowLegend,
?Opacity = Opacity,
?Text = Text,
?MultiText = MultiText,
?Color = Color,
?Contour = Contour,
?ColorScale = ColorScale,
?ShowScale = ShowScale,
?ColorBar = ColorBar,
?FlatShading = FlatShading,
?AlphaHull = TriangulationAlgorithm
)
)
|> GenericChart.ofTraceObject useDefaults
|> GenericChart.addLayout (
Layout.init () |> Layout.setScene (StyleParam.SubPlotId.Scene 1, Scene.init (Camera = camera))
)
/// <summary>
/// Visualizes a 3D mesh.
///
/// Draws sets of triangles with coordinates given by three 1-dimensional arrays in `x`, `y`, `z` and
///
/// (1) a sets of `i`, `j`, `k` indices or
///
/// (2) Delaunay triangulation or
///
/// (3) the Alpha-shape algorithm or
///
/// (4) the Convex-hull algorithm
/// </summary>
/// <param name="xyz">Sets the X, Y, and Z coordinates of the vertices. The nth element of vectors `x`, `y` and `z` jointly represent the X, Y and Z coordinates of the nth vertex.</param>
/// <param name="I">A vector of vertex indices, i.e. integer values between 0 and the length of the vertex vectors, representing the "first" vertex of a triangle. For example, `{i[m], j[m], k[m]}` together represent face m (triangle m) in the mesh, where `i[m] = n` points to the triplet `{x[n], y[n], z[n]}` in the vertex arrays. Therefore, each element in `i` represents a point in space, which is the first vertex of a triangle.</param>
/// <param name="J">A vector of vertex indices, i.e. integer values between 0 and the length of the vertex vectors, representing the "second" vertex of a triangle. For example, `{i[m], j[m], k[m]}` together represent face m (triangle m) in the mesh, where `j[m] = n` points to the triplet `{x[n], y[n], z[n]}` in the vertex arrays. Therefore, each element in `j` represents a point in space, which is the second vertex of a triangle.</param>
/// <param name="K">A vector of vertex indices, i.e. integer values between 0 and the length of the vertex vectors, representing the "third" vertex of a triangle. For example, `{i[m], j[m], k[m]}` together represent face m (triangle m) in the mesh, where `k[m] = n` points to the triplet `{x[n], y[n], z[n]}` in the vertex arrays. Therefore, each element in `k` represents a point in space, which is the third vertex of a triangle.</param>
/// <param name="Name">Sets the trace name. The trace name appear as the legend item and on hover</param>
/// <param name="ShowLegend">Determines whether or not an item corresponding to this trace is shown in the legend.</param>
/// <param name="Opacity">Sets the opactity of the trace</param>
/// <param name="Text">Sets a text associated with each datum</param>
/// <param name="MultiText">Sets individual text for each datum</param>
/// <param name="Color">Sets the color of the whole mesh</param>
/// <param name="Contour">Sets the style and visibility of contours</param>
/// <param name="ColorScale">Sets the colorscale</param>
/// <param name="ShowScale">Whether or not to show the colorbar/colorscale</param>
/// <param name="ColorBar">Sets the colorbar</param>
/// <param name="FlatShading">Determines whether or not normal smoothing is applied to the meshes, creating meshes with an angular, low-poly look via flat reflections.</param>
/// <param name="TriangulationAlgorithm">Determines how the mesh surface triangles are derived from the set of vertices (points) represented by the `x`, `y` and `z` arrays, if the `i`, `j`, `k` arrays are not supplied.</param>
/// <param name="CameraProjectionType">Sets the camera projection type of this trace.</param>
/// <param name="Camera">Sets the camera of this trace.</param>
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
[<Extension>]
static member Mesh3D
(
xyz: seq<#IConvertible * #IConvertible * #IConvertible>,
?I: seq<#IConvertible>,
?J: seq<#IConvertible>,
?K: seq<#IConvertible>,
?Name: string,
?ShowLegend: bool,
?Opacity: float,
?Text: #IConvertible,
?MultiText: seq<#IConvertible>,
?Color: Color,
?Contour: Contour,
?ColorScale: StyleParam.Colorscale,
?ShowScale: bool,
?ColorBar: ColorBar,
?FlatShading: bool,
?TriangulationAlgorithm: StyleParam.TriangulationAlgorithm,
?CameraProjectionType: StyleParam.CameraProjectionType,
?Camera: Camera,
?UseDefaults: bool
) =
let x, y, z = Seq.unzip3 xyz
Chart.Mesh3D(
x,
y,
z,
?I = I,
?J = J,
?K = K,
?Name = Name,
?ShowLegend = ShowLegend,
?Opacity = Opacity,
?Text = Text,
?MultiText = MultiText,
?Color = Color,
?Contour = Contour,
?ColorScale = ColorScale,
?ShowScale = ShowScale,
?ColorBar = ColorBar,
?FlatShading = FlatShading,
?TriangulationAlgorithm = TriangulationAlgorithm,
?CameraProjectionType = CameraProjectionType,
?Camera = Camera,
?UseDefaults = UseDefaults
)