-
Notifications
You must be signed in to change notification settings - Fork 5
/
LayoutComparisonTestFigure2.java
128 lines (101 loc) · 3.7 KB
/
LayoutComparisonTestFigure2.java
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
package org.genericsystem.layout;
import org.genericsystem.cv.AbstractApp;
import org.genericsystem.cv.Img;
import org.genericsystem.cv.utils.NativeLibraryLoader;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
public class LayoutComparisonTestFigure2 extends AbstractApp {
static {
NativeLibraryLoader.load();
}
public static void main(String[] args) {
launch(args);
}
@Override
protected void fillGrid(GridPane mainGrid) {
Img binary = new Img(new Mat(new Size(800, 800), CvType.CV_8UC3, new Scalar(255, 255, 255)), false);
// Containing Layout A
Layout layoutA = new Layout(null, 0.05, 0.7, 0.3, 0.95);
// 1st child
double x1A1 = 0.1;
double x2A1 = 0.6;
double y1A1 = 0.1;
double y2A1 = 0.3;
Layout childA1 = new Layout(layoutA, x1A1, x2A1, y1A1, y2A1);
// 2nd child
double x1A2 = 0.7;
double x2A2 = 0.9;
double y1A2 = 0.1;
double y2A2 = 0.3;
Layout childA2 = new Layout(layoutA, x1A2, x2A2, y1A2, y2A2);
// 3rd child
double x1A3 = 0.1;
double x2A3 = 0.3;
double y1A3 = 0.4;
double y2A3 = 0.9;
Layout childA3 = new Layout(layoutA, x1A3, x2A3, y1A3, y2A3);
// 4th child
double x1A4 = 0.4;
double x2A4 = 0.9;
double y1A4 = 0.4;
double y2A4 = 0.9;
Layout childA4 = new Layout(layoutA, x1A4, x2A4, y1A4, y2A4);
layoutA.addChild(childA1);
layoutA.addChild(childA2);
layoutA.addChild(childA3);
layoutA.addChild(childA4);
// 1st child of the 4th child
double x1A41 = 0.1;
double x2A41 = 0.5;
double y1A41 = 0.1;
double y2A41 = 0.9;
Layout childA41 = new Layout(childA4, x1A41, x2A41, y1A41, y2A41);
// 2nd child of the 4th child
double x1A42 = 0.6;
double x2A42 = 0.9;
double y1A42 = 0.1;
double y2A42 = 0.9;
Layout childA42 = new Layout(childA4, x1A42, x2A42, y1A42, y2A42);
childA4.addChild(childA41);
childA4.addChild(childA42);
// Contained Layout B
Layout layoutB = new Layout(null, 0.05, 0.25, 0.05, 0.25);
// 1st child similar (or not) to the 1st child of the containing layout A
double x1B1 = x1A1 + 0.01 * (x2A1 - x1A1);
double x2B1 = x2A1 + 0.01 * (x2A1 - x1A1);
double y1B1 = y1A1 + 0.01 * (y2A1 - y1A1);
double y2B1 = y2A1 - 0.01 * (y2A1 - y1A1);
Layout childB1 = new Layout(layoutB, x1B1, x2B1, y1B1, y2B1);
// 2nd child similar (or not) to the 4th child of the containing layout A
double x1B2 = x1A4 + 0.01 * (x2A4 - x1A4);
double x2B2 = x2A4 + 0.01 * (x2A4 - x1A4);
double y1B2 = y1A4 + 0.01 * (y2A4 - y1A4);
double y2B2 = y2A4 + 0.01 * (y2A4 - y1A4);
Layout childB2 = new Layout(layoutB, x1B2, x2B2, y1B2, y2B2);
layoutB.addChild(childB1);
layoutB.addChild(childB2);
// child of the 2nd child similar (or not) to the 2nd child of the 4th child of the containing layout A
double x1B21 = x1A42 + 0.01 * (x2A42 - x1A42);
double x2B21 = x2A42 + 0.01 * (x2A42 - x1A42);
double y1B21 = y1A42 + 0.01 * (y2A42 - y1A42);
double y2B21 = y2A42 + 0.01 * (y2A42 - y1A42);
Layout childB21 = new Layout(childB2, x1B21, x2B21, y1B21, y2B21);
childB2.addChild(childB21);
// adding child A2 a child similar to Layout B
Layout childA21 = new Layout(childA2, 0.1, 0.9, 0.1, 0.9);
Layout childA211 = new Layout(childA21, x1B1, x2B1, y1B1, y2B1);
Layout childA212 = new Layout(childA21, x1B2, x2B2, y1B2, y2B2);
Layout childA2121 = new Layout(childA212, x1B21, x2B21, y1B21, y2B21);
childA2.addChild(childA21);
childA21.addChild(childA211);
childA21.addChild(childA212);
childA212.addChild(childA2121);
layoutA.draw(binary, new Scalar(0, 255, 0), 2);
layoutB.draw(binary, new Scalar(255, 0, 0), 2);
mainGrid.add(new ImageView(binary.toJfxImage()), 0, 0);
}
}