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 ranging and 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 RangingReading} type.
29   */
30  public class RangingAndRssiFingerprintLocated<S extends RadioSource, R extends RangingAndRssiReading<S>,
31          P extends Point<?>> extends RangingAndRssiFingerprint<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 ranging and RSSI readings defining the
48       *                 fingerprint.
49       * @param position position where readings were made.
50       * @throws IllegalArgumentException if either readings or position are
51       *                                  null.
52       */
53      public RangingAndRssiFingerprintLocated(final List<R> readings, final P position) {
54          super(readings);
55  
56          if (position == null) {
57              throw new IllegalArgumentException();
58          }
59  
60          this.position = position;
61      }
62  
63      /**
64       * Constructor.
65       *
66       * @param readings           non-located ranging and RSSI readings defining the
67       *                           fingerprint.
68       * @param position           position where readings were made.
69       * @param positionCovariance covariance of inhomogeneous coordinates of current
70       *                           position (if available).
71       * @throws IllegalArgumentException if either readings or position are null, or
72       *                                  covariance has invalid size.
73       */
74      public RangingAndRssiFingerprintLocated(final List<R> readings, final P position, final Matrix positionCovariance) {
75          this(readings, position);
76  
77          if (positionCovariance != null) {
78              final var dims = position.getDimensions();
79              if (positionCovariance.getRows() != dims || positionCovariance.getColumns() != dims) {
80                  throw new IllegalArgumentException();
81              }
82          }
83          this.positionCovariance = positionCovariance;
84      }
85  
86      /**
87       * Empty constructor.
88       */
89      public RangingAndRssiFingerprintLocated() {
90          super();
91      }
92  
93      /**
94       * Gets position where fingerprint readings were made.
95       *
96       * @return position where fingerprint readings were made.
97       */
98      public P getPosition() {
99          return position;
100     }
101 
102     /**
103      * Gets covariance of inhomogeneous coordinates of current position (if available).
104      *
105      * @return covariance of position or null.
106      */
107     public Matrix getPositionCovariance() {
108         return positionCovariance;
109     }
110 }