Chris@108
|
1 module yetilab.plot.plot;
|
Chris@108
|
2
|
Chris@108
|
3 import org.jzy3d.plot3d.builder: Mapper;
|
Chris@119
|
4 import org.jzy3d.maths: Range, Coord3d;
|
Chris@108
|
5 import org.jzy3d.chart: Chart, ChartLauncher;
|
Chris@108
|
6 import org.jzy3d.plot3d.builder: Builder;
|
Chris@108
|
7 import org.jzy3d.plot3d.builder.concrete: OrthonormalGrid;
|
Chris@108
|
8 import org.jzy3d.colors.colormaps: ColorMapRainbow;
|
Chris@119
|
9 import org.jzy3d.colors: ColorMapper, Color;
|
Chris@108
|
10 import org.jzy3d.plot3d.rendering.canvas: Quality;
|
Chris@119
|
11 import org.jzy3d.plot3d.rendering.view.modes: ViewPositionMode;
|
Chris@148
|
12 import org.jzy3d.plot3d.primitives: FlatLine2d, Point;
|
Chris@108
|
13
|
Chris@108
|
14 newMatrixMapper matrix =
|
Chris@108
|
15 (class MMapper extends Mapper
|
Chris@108
|
16 double f(double x, double y)
|
Chris@117
|
17 result = matrix.getAt y x;
|
Chris@117
|
18 println "f(\(x),\(y)) -> \(result)";
|
Chris@117
|
19 result
|
Chris@108
|
20 end;
|
Chris@108
|
21 new MMapper());
|
Chris@108
|
22
|
Chris@108
|
23 newMatrixLogMapper matrix =
|
Chris@108
|
24 (class MMapper extends Mapper
|
Chris@108
|
25 double f(double x, double y)
|
Chris@108
|
26 ln (matrix.getAt y x)
|
Chris@108
|
27 end;
|
Chris@108
|
28 new MMapper());
|
Chris@108
|
29
|
Chris@108
|
30 newMapper mapFunction =
|
Chris@108
|
31 (class FMapper extends Mapper
|
Chris@108
|
32 double f(double x, double y)
|
Chris@108
|
33 mapFunction x y
|
Chris@108
|
34 end;
|
Chris@108
|
35 new FMapper());
|
Chris@108
|
36
|
Chris@151
|
37 plotMatrix chart matrix is ~Chart -> 'a -> () =
|
Chris@117
|
38 (mapper = newMatrixMapper matrix;
|
Chris@108
|
39 size = matrix.size;
|
Chris@119
|
40 xrange = new Range(0, size.columns - 1);
|
Chris@119
|
41 yrange = new Range(0, size.rows - 1);
|
Chris@108
|
42 grid = new OrthonormalGrid(xrange, size.columns, yrange, size.rows);
|
Chris@112
|
43 println "Matrix size: \(size)";
|
Chris@117
|
44 surface = Builder#buildOrthonormal(grid, mapper); //??? big?
|
Chris@117
|
45 println "Z Bounds: \(surface#getBounds()#getZmin()) -> \(surface#getBounds()#getZmax())";
|
Chris@121
|
46 surface#setFaceDisplayed(true);
|
Chris@108
|
47 surface#setWireframeDisplayed(true);
|
Chris@108
|
48 surface#setWireframeColor(Color#BLACK);
|
Chris@108
|
49 chart#getScene()#getGraph()#add(surface);
|
Chris@115
|
50 ());
|
Chris@108
|
51
|
Chris@151
|
52 plotCurve chart curve is ~Chart -> 'a -> () =
|
Chris@151
|
53 (scene = chart#getScene();
|
Chris@149
|
54 xx = map (.time) curve;
|
Chris@149
|
55 yy = map (.value) curve;
|
Chris@149
|
56 line = new FlatLine2d(xx as ~float[], yy as ~float[], 0);
|
Chris@148
|
57 line#setWireframeDisplayed(true);
|
Chris@148
|
58 line#setWireframeColor(Color#BLACK);
|
Chris@148
|
59 line#setWireframeWidth(2);
|
Chris@148
|
60 line#setFaceDisplayed(false);
|
Chris@148
|
61 scene#add(line);
|
Chris@148
|
62 chart#getView()#setViewPoint(new Coord3d(0, 0, 0));
|
Chris@149
|
63 /*
|
Chris@148
|
64 axes = chart#getAxeLayout();
|
Chris@148
|
65 axes#setXAxeLabelDisplayed(false);
|
Chris@148
|
66 axes#setYAxeLabelDisplayed(false);
|
Chris@148
|
67 axes#setZAxeLabelDisplayed(true);
|
Chris@148
|
68 axes#setZAxeLabel("unit goes here"); //!!!
|
Chris@148
|
69 axes#setYTickLabelDisplayed(false);
|
Chris@149
|
70 */
|
Chris@148
|
71 ());
|
Chris@148
|
72
|
Chris@151
|
73 plotSeries chart { start, step, values } is ~Chart -> 'a -> () =
|
Chris@151
|
74 (scene = chart#getScene();
|
Chris@151
|
75 xx = map do i: start + step * i done [0..length values - 1];
|
Chris@151
|
76 yy = list values;
|
Chris@150
|
77 line = new FlatLine2d(xx as ~float[], yy as ~float[], 0);
|
Chris@150
|
78 line#setWireframeDisplayed(true);
|
Chris@150
|
79 line#setWireframeColor(Color#BLACK);
|
Chris@150
|
80 line#setWireframeWidth(2);
|
Chris@150
|
81 line#setFaceDisplayed(false);
|
Chris@150
|
82 scene#add(line);
|
Chris@150
|
83 chart#getView()#setViewPoint(new Coord3d(0, 0, 0));
|
Chris@150
|
84 /*
|
Chris@150
|
85 axes = chart#getAxeLayout();
|
Chris@150
|
86 axes#setXAxeLabelDisplayed(false);
|
Chris@150
|
87 axes#setYAxeLabelDisplayed(false);
|
Chris@150
|
88 axes#setZAxeLabelDisplayed(true);
|
Chris@150
|
89 axes#setZAxeLabel("unit goes here"); //!!!
|
Chris@150
|
90 axes#setYTickLabelDisplayed(false);
|
Chris@150
|
91 */
|
Chris@150
|
92 ());
|
Chris@150
|
93
|
Chris@151
|
94 plot structures =
|
Chris@151
|
95 (chart = new Chart(Quality#Nicest);
|
Chris@151
|
96 for structures
|
Chris@151
|
97 \case of
|
Chris@151
|
98 Grid matrix:
|
Chris@151
|
99 plotMatrix chart matrix;
|
Chris@151
|
100 Curve curve:
|
Chris@151
|
101 plotCurve chart curve;
|
Chris@151
|
102 Series series:
|
Chris@151
|
103 plotSeries chart series;
|
Chris@151
|
104 other:
|
Chris@151
|
105 failWith "Unable to plot \(other)";
|
Chris@151
|
106 esac;
|
Chris@151
|
107 ChartLauncher#openChart(chart);
|
Chris@151
|
108 chart);
|
Chris@108
|
109
|
Chris@115
|
110 {
|
Chris@119
|
111 newMatrixMapper,
|
Chris@119
|
112 newMatrixLogMapper,
|
Chris@119
|
113 newMapper,
|
Chris@115
|
114 plotMatrix,
|
Chris@151
|
115 plotCurve,
|
Chris@151
|
116 plotSeries,
|
Chris@151
|
117 plot,
|
Chris@115
|
118 }
|
Chris@110
|
119
|