View Javadoc
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;
17  
18  import com.irurueta.algebra.Matrix;
19  import com.irurueta.geometry.Point;
20  
21  import java.util.List;
22  
23  /**
24   * Contains located RSSI readings from several radio sources.
25   *
26   * @param <S> a {@link RadioSource} type.
27   * @param <P> a {@link Point} type.
28   * @param <R> a {@link RssiReading} type.
29   */
30  public abstract class RssiFingerprintLocated<S extends RadioSource, R extends RssiReading<S>, P extends Point<?>>
31          extends RssiFingerprint<S, R> implements FingerprintLocated<P> {
32  
33      /**
34       * Position where fingerprint readings were made.
35       */
36      private P position;
37  
38      /**
39       * Covariance of inhomogeneous coordinates of current
40       * position (if available).
41       */
42      private Matrix positionCovariance;
43  
44      /**
45       * Constructor.
46       *
47       * @param readings non-located RSSI readings defining the fingerprint.
48       * @param position position where readings were made.
49       * @throws IllegalArgumentException if either readings or position are
50       *                                  null.
51       */
52      protected RssiFingerprintLocated(final List<R> readings, final P position) {
53          super(readings);
54  
55          if (position == null) {
56              throw new IllegalArgumentException();
57          }
58  
59          this.position = position;
60      }
61  
62      /**
63       * Constructor.
64       *
65       * @param readings           non-located RSSI readings defining the fingerprint.
66       * @param position           position where readings were made.
67       * @param positionCovariance covariance of inhomogeneous coordinates of current
68       *                           position (if available).
69       * @throws IllegalArgumentException if either readings or position are null, or
70       *                                  covariance has invalid size.
71       */
72      protected RssiFingerprintLocated(final List<R> readings, final P position, final Matrix positionCovariance) {
73          this(readings, position);
74  
75          if (positionCovariance != null) {
76              final var dims = position.getDimensions();
77              if (positionCovariance.getRows() != dims || positionCovariance.getColumns() != dims) {
78                  throw new IllegalArgumentException();
79              }
80          }
81          this.positionCovariance = positionCovariance;
82      }
83  
84      /**
85       * Empty constructor.
86       */
87      protected RssiFingerprintLocated() {
88          super();
89      }
90  
91      /**
92       * Gets position where fingerprint readings were made.
93       *
94       * @return position where fingerprint readings were made.
95       */
96      public P getPosition() {
97          return position;
98      }
99  
100     /**
101      * Gets covariance of inhomogeneous coordinates of current position (if available).
102      *
103      * @return covariance of position or null.
104      */
105     public Matrix getPositionCovariance() {
106         return positionCovariance;
107     }
108 }