1 /*
2 * Copyright (C) 2018 Alberto Irurueta Carro (alberto@irurueta.com)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package com.irurueta.navigation.indoor.fingerprint;
17
18 import com.irurueta.geometry.InhomogeneousPoint2D;
19 import com.irurueta.geometry.Point2D;
20 import com.irurueta.navigation.indoor.RadioSource;
21 import com.irurueta.navigation.indoor.RadioSourceLocated;
22 import com.irurueta.navigation.indoor.RssiFingerprint;
23 import com.irurueta.navigation.indoor.RssiFingerprintLocated;
24 import com.irurueta.navigation.indoor.RssiReading;
25
26 import java.util.List;
27
28 /**
29 * 2D position estimator based on located fingerprints containing only RSSI readings and
30 * having as well prior knowledge of the location of radio sources associated to those
31 * readings.
32 * This implementation uses a first-order Taylor approximation over provided located
33 * fingerprints to determine an approximate position for a non-located fingerprint.
34 */
35 public class LinearFingerprintPositionEstimator2D extends LinearFingerprintPositionEstimator<Point2D> {
36
37 /**
38 * Constructor.
39 */
40 public LinearFingerprintPositionEstimator2D() {
41 }
42
43 /**
44 * Constructor.
45 *
46 * @param listener listener in charge of handling events.
47 */
48 public LinearFingerprintPositionEstimator2D(final FingerprintPositionEstimatorListener<Point2D> listener) {
49 super(listener);
50 }
51
52 /**
53 * Constructor.
54 *
55 * @param locatedFingerprints located fingerprints containing RSSI readings.
56 * @param fingerprint fingerprint containing readings at an unknown location
57 * for provided located fingerprints.
58 * @param sources located radio sources.
59 * @throws IllegalArgumentException if provided non located fingerprint is null,
60 * located fingerprints value is null or there are not enough fingerprints or
61 * readings within provided fingerprints (for 2D position estimation at least 2
62 * located total readings are required among all fingerprints, for example 2
63 * readings are required in a single fingerprint, or at least 2 fingerprints at
64 * different locations containing a single reading are required).
65 */
66 public LinearFingerprintPositionEstimator2D(
67 final List<? extends RssiFingerprintLocated<? extends RadioSource,
68 ? extends RssiReading<? extends RadioSource>, Point2D>> locatedFingerprints,
69 final RssiFingerprint<? extends RadioSource,
70 ? extends RssiReading<? extends RadioSource>> fingerprint,
71 final List<? extends RadioSourceLocated<Point2D>> sources) {
72 super(locatedFingerprints, fingerprint, sources);
73 }
74
75 /**
76 * Constructor.
77 *
78 * @param locatedFingerprints located fingerprints containing RSSI readings.
79 * @param fingerprint fingerprint containing readings at an unknown location
80 * for provided located fingerprints.
81 * @param sources located radio sources.
82 * @param listener listener in charge of handling events.
83 * @throws IllegalArgumentException if provided non located fingerprint is null,
84 * located fingerprints value is null or there are not enough fingerprints or
85 * readings within provided fingerprints (for 2D position estimation at least 2
86 * located total readings are required among all fingerprints, for example 2
87 * readings are required in a single fingerprint, or at least 2 fingerprints at
88 * different locations containing a single reading are required).
89 */
90 public LinearFingerprintPositionEstimator2D(
91 final List<? extends RssiFingerprintLocated<? extends RadioSource,
92 ? extends RssiReading<? extends RadioSource>, Point2D>> locatedFingerprints,
93 final RssiFingerprint<? extends RadioSource,
94 ? extends RssiReading<? extends RadioSource>> fingerprint,
95 final List<? extends RadioSourceLocated<Point2D>> sources,
96 final FingerprintPositionEstimatorListener<Point2D> listener) {
97 super(locatedFingerprints, fingerprint, sources, listener);
98 }
99
100 /**
101 * Gets number of dimensions of points.
102 *
103 * @return number of dimensions of points.
104 */
105 @Override
106 public int getNumberOfDimensions() {
107 return Point2D.POINT2D_INHOMOGENEOUS_COORDINATES_LENGTH;
108 }
109
110 /**
111 * Gets estimated position or null if not available yet.
112 *
113 * @return estimated position or null.
114 */
115 @Override
116 public Point2D getEstimatedPosition() {
117 if (estimatedPositionCoordinates == null) {
118 return null;
119 }
120
121 final var result = new InhomogeneousPoint2D();
122 getEstimatedPosition(result);
123 return result;
124 }
125 }