1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.irurueta.ar.epipolar;
17
18 import com.irurueta.algebra.AlgebraException;
19 import com.irurueta.algebra.Utils;
20 import com.irurueta.geometry.GeometryException;
21 import com.irurueta.geometry.estimators.LockedException;
22 import com.irurueta.geometry.estimators.NotReadyException;
23
24
25
26
27
28
29
30
31
32
33
34 public class AlgebraicFundamentalMatrixComparator extends FundamentalMatrixComparator {
35
36
37
38
39 public AlgebraicFundamentalMatrixComparator() {
40 super();
41 }
42
43
44
45
46
47
48
49
50 public AlgebraicFundamentalMatrixComparator(
51 final FundamentalMatrix groundTruthFundamentalMatrix, final FundamentalMatrix otherFundamentalMatrix) {
52 super(groundTruthFundamentalMatrix, otherFundamentalMatrix);
53 }
54
55
56
57
58
59
60 public AlgebraicFundamentalMatrixComparator(final FundamentalMatrixComparatorListener listener) {
61 super(listener);
62 }
63
64
65
66
67
68
69
70
71
72 public AlgebraicFundamentalMatrixComparator(
73 final FundamentalMatrix groundTruthFundamentalMatrix, final FundamentalMatrix otherFundamentalMatrix,
74 final FundamentalMatrixComparatorListener listener) {
75 super(groundTruthFundamentalMatrix, otherFundamentalMatrix, listener);
76 }
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 @Override
92 public double compare() throws NotReadyException, LockedException, FundamentalMatrixComparatorException {
93 if (isLocked()) {
94 throw new LockedException();
95 }
96 if (!isReady()) {
97 throw new NotReadyException();
98 }
99
100 try {
101 locked = true;
102
103 if (listener != null) {
104 listener.onCompareStart(this);
105 }
106
107 groundTruthFundamentalMatrix.normalize();
108 otherFundamentalMatrix.normalize();
109
110 final var f1 = groundTruthFundamentalMatrix.getInternalMatrix();
111 final var f2 = otherFundamentalMatrix.getInternalMatrix();
112
113 final var diff = f1.subtractAndReturnNew(f2);
114 final var sum = f1.addAndReturnNew(f2);
115
116 var normDiff = Utils.normF(diff);
117 var normSum = Utils.normF(sum);
118
119 if (normDiff > 1.0) {
120 normDiff = 2.0 - normDiff;
121 }
122 if (normSum > 1.0) {
123 normSum = 2.0 - normSum;
124 }
125
126 if (listener != null) {
127 listener.onCompareEnd(this);
128 }
129
130 return Math.min(normDiff, normSum);
131
132 } catch (final AlgebraException | GeometryException e) {
133 throw new FundamentalMatrixComparatorException(e);
134 } finally {
135 locked = false;
136 }
137 }
138
139
140
141
142
143
144 @Override
145 public FundamentalMatrixComparatorType getType() {
146 return FundamentalMatrixComparatorType.ALGEBRAIC_COMPARATOR;
147 }
148 }