1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.irurueta.ar.calibration;
17
18 import com.irurueta.geometry.InhomogeneousPoint2D;
19 import com.irurueta.geometry.Point2D;
20
21 import java.io.Serializable;
22 import java.util.ArrayList;
23 import java.util.List;
24
25
26
27
28 public class CirclesPattern2D extends Pattern2D implements Serializable {
29
30
31
32
33 public static final double DEFAULT_POINT_SEPARATION = 4.25e-2;
34
35
36
37
38 public static final int DEFAULT_COLS = 4;
39
40
41
42
43 public static final int DEFAULT_ROWS = 11;
44
45
46
47
48 public static final int DEFAULT_NUMBER_OF_POINTS = DEFAULT_COLS * DEFAULT_ROWS;
49
50
51
52
53 public static final int MIN_COLS = 2;
54
55
56
57
58 public static final int MIN_ROWS = 2;
59
60
61
62
63
64 private double pointSeparation;
65
66
67
68
69 private int cols;
70
71
72
73
74 private int rows;
75
76
77
78
79 public CirclesPattern2D() {
80 pointSeparation = DEFAULT_POINT_SEPARATION;
81 cols = DEFAULT_COLS;
82 rows = DEFAULT_ROWS;
83 }
84
85
86
87
88
89
90 public double getPointSeparation() {
91 return pointSeparation;
92 }
93
94
95
96
97
98
99
100 public void setPointSeparation(final double pointSeparation) {
101 if (pointSeparation <= 0.0) {
102 throw new IllegalArgumentException();
103 }
104
105 this.pointSeparation = pointSeparation;
106 }
107
108
109
110
111
112
113 public int getCols() {
114 return cols;
115 }
116
117
118
119
120
121
122
123 public void setCols(final int cols) {
124 if (cols < MIN_COLS) {
125 throw new IllegalArgumentException();
126 }
127
128 this.cols = cols;
129 }
130
131
132
133
134
135
136 public int getRows() {
137 return rows;
138 }
139
140
141
142
143
144
145
146 public void setRows(final int rows) {
147 if (rows < MIN_ROWS) {
148 throw new IllegalArgumentException();
149 }
150
151 this.rows = rows;
152 }
153
154
155
156
157
158
159
160 @Override
161 public List<Point2D> getIdealPoints() {
162 final var points = new ArrayList<Point2D>();
163
164 double x;
165 double y;
166 for (var i = 0; i < rows; i++) {
167 for (var j = 0; j < cols; j++) {
168 x = (2 * j + i % 2) * pointSeparation;
169 y = i * pointSeparation;
170 points.add(new InhomogeneousPoint2D(x, y));
171 }
172 }
173 return points;
174 }
175
176
177
178
179
180
181 @Override
182 public int getNumberOfPoints() {
183 return rows * cols;
184 }
185
186
187
188
189
190
191 @Override
192 public Pattern2DType getType() {
193 return Pattern2DType.CIRCLES;
194 }
195 }