@wemap/providers 12.10.8 → 12.10.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/dist/helpers/CustomMapProvider.d.ts +10 -0
  2. package/{index.ts → dist/index.d.ts} +0 -14
  3. package/dist/index.js +1 -3446
  4. package/dist/index.js.map +1 -1
  5. package/{src/ProvidersOptions.ts → dist/src/ProvidersOptions.d.ts} +7 -16
  6. package/dist/src/errors/AskImuOnDesktopError.d.ts +5 -0
  7. package/dist/src/errors/ContainsIgnoredProviderError.d.ts +5 -0
  8. package/dist/src/errors/GeolocationApiMissingError.d.ts +5 -0
  9. package/dist/src/errors/GeolocationPermissionDeniedError.d.ts +5 -0
  10. package/dist/src/errors/GeolocationPositionUnavailableError.d.ts +5 -0
  11. package/dist/src/errors/IpResolveServerError.d.ts +5 -0
  12. package/dist/src/errors/MissingAccelerometerError.d.ts +6 -0
  13. package/dist/src/errors/MissingArCoreError.d.ts +5 -0
  14. package/dist/src/errors/MissingGyroscopeError.d.ts +6 -0
  15. package/dist/src/errors/MissingMagnetometerError.d.ts +5 -0
  16. package/dist/src/errors/MissingNativeInterfaceError.d.ts +5 -0
  17. package/dist/src/errors/MissingPoleStarError.d.ts +5 -0
  18. package/dist/src/errors/MissingSensorError.d.ts +6 -0
  19. package/dist/src/errors/NoProviderFoundError.d.ts +5 -0
  20. package/dist/src/events/AvailabilityHelper.d.ts +5 -0
  21. package/dist/src/events/ProvidersLoggerOld.d.ts +24 -0
  22. package/dist/src/events/Types.d.ts +34 -0
  23. package/dist/src/mapmatching/MapMatchingHandler.d.ts +93 -0
  24. package/dist/src/providers/Constants.d.ts +4 -0
  25. package/{src/providers/NativeProviders.ts → dist/src/providers/NativeProviders.d.ts} +2 -23
  26. package/dist/src/providers/Provider.d.ts +64 -0
  27. package/dist/src/providers/attitude/EkfAttitude.d.ts +41 -0
  28. package/dist/src/providers/attitude/TurnProvider.d.ts +17 -0
  29. package/dist/src/providers/attitude/absolute/AbsoluteAttitudeFromBrowserProvider.d.ts +60 -0
  30. package/dist/src/providers/attitude/absolute/AbsoluteAttitudeProvider.d.ts +44 -0
  31. package/dist/src/providers/attitude/relative/RelativeAttitudeFromBrowserProvider.d.ts +31 -0
  32. package/dist/src/providers/attitude/relative/RelativeAttitudeFromEkfProvider.d.ts +26 -0
  33. package/dist/src/providers/attitude/relative/RelativeAttitudeFromInertialProvider.d.ts +18 -0
  34. package/dist/src/providers/attitude/relative/RelativeAttitudeProvider.d.ts +25 -0
  35. package/dist/src/providers/imu/AccelerometerProvider.d.ts +11 -0
  36. package/dist/src/providers/imu/GyroscopeProvider.d.ts +11 -0
  37. package/dist/src/providers/imu/HighRotationsProvider.d.ts +15 -0
  38. package/dist/src/providers/imu/ImuProvider.d.ts +34 -0
  39. package/dist/src/providers/imu/MagnetometerCalibrationProvider.d.ts +11 -0
  40. package/dist/src/providers/inclination/InclinationFromAccProvider.d.ts +18 -0
  41. package/dist/src/providers/inclination/InclinationFromRelativeAttitudeProvider.d.ts +19 -0
  42. package/dist/src/providers/inclination/InclinationProvider.d.ts +18 -0
  43. package/dist/src/providers/legacy/helpers/HeadingUnlocker.d.ts +12 -0
  44. package/dist/src/providers/legacy/helpers/ThugDetector.d.ts +8 -0
  45. package/dist/src/providers/others/CameraNativeProvider.d.ts +11 -0
  46. package/dist/src/providers/others/CameraProjectionMatrixProvider.d.ts +11 -0
  47. package/dist/src/providers/position/absolute/AbsolutePositionProvider.d.ts +35 -0
  48. package/dist/src/providers/position/absolute/GnssWifiProvider.d.ts +28 -0
  49. package/dist/src/providers/position/absolute/IpProvider.d.ts +16 -0
  50. package/dist/src/providers/position/absolute/PoleStarProvider.d.ts +14 -0
  51. package/dist/src/providers/position/relative/GeoRelativePositionFromArCoreProvider.d.ts +17 -0
  52. package/dist/src/providers/position/relative/GeoRelativePositionProvider.d.ts +12 -0
  53. package/dist/src/providers/position/relative/PdrProvider.d.ts +15 -0
  54. package/dist/src/providers/steps/StepDetectionLadetto.d.ts +15 -0
  55. package/dist/src/providers/steps/StepDetectionMinMaxPeaks.d.ts +19 -0
  56. package/dist/src/providers/steps/StepDetectionMinMaxPeaks2.d.ts +27 -0
  57. package/dist/src/providers/steps/StepDetectionMinMaxPeaks3.d.ts +24 -0
  58. package/dist/src/providers/steps/StepProvider.d.ts +36 -0
  59. package/dist/src/providers/steps/StraightLineProvider.d.ts +21 -0
  60. package/dist/src/providers/vision/ArCoreProvider.d.ts +50 -0
  61. package/dist/src/providers/vision/BarcodeProvider.d.ts +11 -0
  62. package/dist/src/providers/vision/vps/ImageRelocalization.d.ts +11 -0
  63. package/dist/src/providers/vision/vps/RelativeRotationCalc.d.ts +10 -0
  64. package/dist/src/providers/vision/vps/VpsMetadata.d.ts +33 -0
  65. package/dist/src/providers/vision/vps/VpsProvider.d.ts +45 -0
  66. package/dist/src/providers/vision/vps/VpsRequest.d.ts +18 -0
  67. package/dist/src/providers/vision/vps/VpsResponse.d.ts +15 -0
  68. package/dist/src/smoothers/AttitudeSmoother.d.ts +23 -0
  69. package/dist/src/smoothers/PositionSmoother.d.ts +21 -0
  70. package/package.json +16 -12
  71. package/src/errors/AskImuOnDesktopError.ts +0 -10
  72. package/src/errors/ContainsIgnoredProviderError.ts +0 -10
  73. package/src/errors/GeolocationApiMissingError.ts +0 -10
  74. package/src/errors/GeolocationPermissionDeniedError.ts +0 -10
  75. package/src/errors/GeolocationPositionUnavailableError.ts +0 -10
  76. package/src/errors/IpResolveServerError.ts +0 -10
  77. package/src/errors/MissingAccelerometerError.ts +0 -11
  78. package/src/errors/MissingArCoreError.ts +0 -10
  79. package/src/errors/MissingGyroscopeError.ts +0 -11
  80. package/src/errors/MissingMagnetometerError.ts +0 -9
  81. package/src/errors/MissingNativeInterfaceError.ts +0 -11
  82. package/src/errors/MissingPoleStarError.ts +0 -10
  83. package/src/errors/MissingSensorError.ts +0 -15
  84. package/src/errors/NoProviderFoundError.ts +0 -10
  85. package/src/events/AvailabilityHelper.spec.ts +0 -30
  86. package/src/events/AvailabilityHelper.ts +0 -28
  87. package/src/events/ProvidersLoggerOld.ts +0 -87
  88. package/src/events/Types.ts +0 -18
  89. package/src/mapmatching/MapMatchingHandler.spec.ts +0 -142
  90. package/src/mapmatching/MapMatchingHandler.ts +0 -540
  91. package/src/providers/Constants.ts +0 -5
  92. package/src/providers/FakeProvider.spec.ts +0 -49
  93. package/src/providers/Provider.spec.ts +0 -113
  94. package/src/providers/Provider.ts +0 -244
  95. package/src/providers/attitude/EkfAttitude.spec.ts +0 -115
  96. package/src/providers/attitude/EkfAttitude.ts +0 -233
  97. package/src/providers/attitude/TurnProvider.ts +0 -58
  98. package/src/providers/attitude/absolute/AbsoluteAttitudeFromBrowserProvider.ts +0 -267
  99. package/src/providers/attitude/absolute/AbsoluteAttitudeProvider.ts +0 -268
  100. package/src/providers/attitude/relative/RelativeAttitudeFromBrowserProvider.ts +0 -84
  101. package/src/providers/attitude/relative/RelativeAttitudeFromEkfProvider.ts +0 -89
  102. package/src/providers/attitude/relative/RelativeAttitudeFromInertialProvider.ts +0 -66
  103. package/src/providers/attitude/relative/RelativeAttitudeProvider.ts +0 -70
  104. package/src/providers/imu/AccelerometerProvider.ts +0 -28
  105. package/src/providers/imu/GyroscopeProvider.ts +0 -27
  106. package/src/providers/imu/HighRotationsProvider.ts +0 -49
  107. package/src/providers/imu/ImuProvider.ts +0 -110
  108. package/src/providers/imu/MagnetometerCalibrationProvider.ts +0 -21
  109. package/src/providers/inclination/InclinationFromAccProvider.ts +0 -57
  110. package/src/providers/inclination/InclinationFromRelativeAttitudeProvider.ts +0 -51
  111. package/src/providers/inclination/InclinationProvider.ts +0 -59
  112. package/src/providers/legacy/helpers/HeadingUnlocker.spec.ts +0 -53
  113. package/src/providers/legacy/helpers/HeadingUnlocker.ts +0 -44
  114. package/src/providers/legacy/helpers/ThugDetector.ts +0 -30
  115. package/src/providers/others/CameraNativeProvider.ts +0 -29
  116. package/src/providers/others/CameraProjectionMatrixProvider.ts +0 -25
  117. package/src/providers/position/absolute/AbsolutePositionProvider.spec.ts +0 -31
  118. package/src/providers/position/absolute/AbsolutePositionProvider.ts +0 -277
  119. package/src/providers/position/absolute/GnssWifiProvider.ts +0 -126
  120. package/src/providers/position/absolute/GnssWifiProviders.spec.ts +0 -90
  121. package/src/providers/position/absolute/IpProvider.ts +0 -47
  122. package/src/providers/position/absolute/PoleStarProvider.ts +0 -88
  123. package/src/providers/position/relative/GeoRelativePositionFromArCoreProvider.ts +0 -82
  124. package/src/providers/position/relative/GeoRelativePositionProvider.ts +0 -35
  125. package/src/providers/position/relative/PdrProvider.ts +0 -107
  126. package/src/providers/steps/StepDetectionLadetto.ts +0 -67
  127. package/src/providers/steps/StepDetectionMinMaxPeaks.ts +0 -70
  128. package/src/providers/steps/StepDetectionMinMaxPeaks2.ts +0 -99
  129. package/src/providers/steps/StepDetectionMinMaxPeaks3.ts +0 -192
  130. package/src/providers/steps/StepProvider.ts +0 -151
  131. package/src/providers/steps/StraightLineProvider.ts +0 -69
  132. package/src/providers/vision/ArCoreProvider.ts +0 -184
  133. package/src/providers/vision/BarcodeProvider.ts +0 -28
  134. package/src/providers/vision/vps/ImageRelocalization.ts +0 -98
  135. package/src/providers/vision/vps/RelativeRotationCalc.ts +0 -58
  136. package/src/providers/vision/vps/VpsMetadata.ts +0 -63
  137. package/src/providers/vision/vps/VpsProvider.ts +0 -251
  138. package/src/providers/vision/vps/VpsRequest.ts +0 -29
  139. package/src/providers/vision/vps/VpsResponse.ts +0 -43
  140. package/src/providers/vision/vps/VpsSchema.json +0 -90
  141. package/src/smoothers/AttitudeSmoother.ts +0 -110
  142. package/src/smoothers/PositionSmoother.spec.ts +0 -53
  143. package/src/smoothers/PositionSmoother.ts +0 -96
  144. package/tsconfig.json +0 -3
  145. package/vite.config.ts +0 -4
  146. /package/{src/providers/ProviderState.ts → dist/src/providers/ProviderState.d.ts} +0 -0
@@ -1,151 +0,0 @@
1
- import { Constants as GeoConstants } from '@wemap/geo';
2
- import { Quaternion, Quaternion_t, Vector3_t } from '@wemap/maths';
3
-
4
- import Provider from '../Provider.js';
5
- import AvailabilityHelper from '../../events/AvailabilityHelper.js';
6
- import { Acceleration, AngularRate, RelativeAttitude, Step } from '../../events/Types.js';
7
- import RelativeAttitudeFromInertialProvider from '../attitude/relative/RelativeAttitudeFromInertialProvider.js';
8
- import AccelerometerProvider from '../imu/AccelerometerProvider.js';
9
- import GyroscopeProvider from '../imu/GyroscopeProvider.js';
10
- import StepDetectionLadetto from './StepDetectionLadetto.js';
11
- import StepDetectionMinMaxPeaks from './StepDetectionMinMaxPeaks.js';
12
- import StepDetectionMinMaxPeaks2 from './StepDetectionMinMaxPeaks2.js';
13
- import StepDetectionMinMaxPeaks3 from './StepDetectionMinMaxPeaks3.js';
14
-
15
-
16
- type StepDetectorAlgorithmName = 'ladetto' | 'minMaxPeaks' | 'minMaxPeaks2' | 'minMaxPeaks3';
17
-
18
- type StepDetectorAlgorithm = {
19
- compute(timestamp: number, linearAcc: Vector3_t, angularRate?: Vector3_t): boolean;
20
- lastStepSize: number;
21
- };
22
-
23
- class StepProvider extends Provider<Step> {
24
-
25
- static DEFAULT_STEP_SIZE_MULTIPLIER = 1;
26
- static DEFAULT_ALGORITHM: StepDetectorAlgorithmName = 'minMaxPeaks3';
27
-
28
- accelerometerProviderId?: number;
29
- attitudeProviderId?: number;
30
- gyroscopeProviderId?: number;
31
- angularRateEvent?: AngularRate;
32
- attitudeEvent?: RelativeAttitude;
33
- numOfSteps = 0;
34
- stepDetector!: StepDetectorAlgorithm;
35
-
36
- _stepSizeMultiplier = StepProvider.DEFAULT_STEP_SIZE_MULTIPLIER;
37
- _algorithm: StepDetectorAlgorithmName = StepProvider.DEFAULT_ALGORITHM;
38
- _accValues: Vector3_t[] = [];
39
-
40
- constructor() {
41
- super();
42
- this.algorithm = this._algorithm;
43
- }
44
-
45
- getName = () => 'StepDetector';
46
-
47
- availability() {
48
- return AvailabilityHelper.every([
49
- AccelerometerProvider.getAvailability(),
50
- GyroscopeProvider.getAvailability(),
51
- RelativeAttitudeFromInertialProvider.getAvailability()
52
- ]);
53
- }
54
-
55
- start() {
56
-
57
- this.numOfSteps = 0;
58
-
59
- this.accelerometerProviderId = AccelerometerProvider.addEventListener(
60
- this.onAccelerometerEvent,
61
- this.notifyError
62
- );
63
-
64
- this.gyroscopeProviderId = GyroscopeProvider.addEventListener(
65
- event => this.angularRateEvent = event,
66
- this.notifyError
67
- );
68
-
69
- this.attitudeProviderId = RelativeAttitudeFromInertialProvider.addEventListener(
70
- event => this.attitudeEvent = event,
71
- this.notifyError
72
- );
73
- }
74
-
75
- stop() {
76
- AccelerometerProvider.removeEventListener(this.accelerometerProviderId);
77
- GyroscopeProvider.removeEventListener(this.gyroscopeProviderId);
78
- RelativeAttitudeFromInertialProvider.removeEventListener(this.attitudeProviderId);
79
- }
80
-
81
- onAccelerometerEvent = (accelerationEvent: Acceleration) => {
82
-
83
- if (!this.attitudeEvent || !this.angularRateEvent) {
84
- return;
85
- }
86
-
87
- const {
88
- values: acceleration, timestamp
89
- } = accelerationEvent;
90
-
91
- /**
92
- * Step Detection and Step Size Detection
93
- */
94
- const linearAcc = StepProvider.computeLinearAcceleration(
95
- this.attitudeEvent.quaternion, acceleration);
96
- const stepDetected = this.stepDetector.compute(timestamp, linearAcc, this.angularRateEvent.values);
97
-
98
- if (stepDetected) {
99
- const size = this.stepDetector.lastStepSize * this._stepSizeMultiplier;
100
- this.numOfSteps++;
101
- this.notify({ size, number: this.numOfSteps });
102
- }
103
- }
104
-
105
- // Linear acceleration in ENU
106
- static computeLinearAcceleration(quaternion: Quaternion_t, acc: Vector3_t) {
107
- const linearAcc = Quaternion.rotateMatlab(Quaternion.inverse(quaternion), acc);
108
- linearAcc[2] -= GeoConstants.EARTH_GRAVITY;
109
- return linearAcc;
110
- }
111
-
112
- set stepSizeMultiplier(stepSizeMultiplier) {
113
- this._stepSizeMultiplier = stepSizeMultiplier;
114
- }
115
-
116
- get stepSizeMultiplier() {
117
- return this._stepSizeMultiplier;
118
- }
119
-
120
- set algorithm(algorithm) {
121
- switch (algorithm) {
122
- case 'ladetto':
123
- this.stepDetector = new StepDetectionLadetto();
124
- break;
125
- case 'minMaxPeaks':
126
- this.stepDetector = new StepDetectionMinMaxPeaks();
127
- break;
128
- case 'minMaxPeaks2':
129
- this.stepDetector = new StepDetectionMinMaxPeaks2();
130
- break;
131
- case 'minMaxPeaks3':
132
- default:
133
- algorithm = 'minMaxPeaks3';
134
- this.stepDetector = new StepDetectionMinMaxPeaks3();
135
- break;
136
- }
137
- this._algorithm = algorithm;
138
- }
139
-
140
- get algorithm() {
141
- return this._algorithm;
142
- }
143
- }
144
-
145
- export function createStepProvider(algorithm: StepDetectorAlgorithmName) {
146
- const stepProvider = new StepProvider();
147
- stepProvider.algorithm = algorithm;
148
- return stepProvider;
149
- }
150
-
151
- export default new StepProvider();
@@ -1,69 +0,0 @@
1
- import Provider from '../Provider.js';
2
- import AvailabilityHelper from '../../events/AvailabilityHelper.js';
3
- import StepProvider from './StepProvider.js';
4
- import TurnProvider from '../attitude/TurnProvider.js';
5
- import { StraightLine } from '../../events/Types.js';
6
-
7
- class StraightLineProvider extends Provider<StraightLine> {
8
-
9
- static DEFAULT_STEPS_CONSIDERED_FOR_STRAIGHT_LINE = 2;
10
-
11
- _turnProviderId?: number;
12
- _stepProviderId?: number;
13
-
14
- _countSteps = 0;
15
- _stepsConsideredForStraightLine = StraightLineProvider.DEFAULT_STEPS_CONSIDERED_FOR_STRAIGHT_LINE;
16
-
17
- getName = () => 'StraightLine';
18
-
19
- availability() {
20
- return AvailabilityHelper.every([
21
- TurnProvider.getAvailability(),
22
- StepProvider.getAvailability()
23
- ]);
24
- }
25
-
26
- start() {
27
- this._turnProviderId = TurnProvider.addEventListener(this._onTurn);
28
- this._stepProviderId = StepProvider.addEventListener(this._onStep);
29
- }
30
-
31
- stop() {
32
- TurnProvider.removeEventListener(this._turnProviderId);
33
- StepProvider.removeEventListener(this._stepProviderId);
34
- }
35
-
36
- private _onTurn = () => {
37
- if (this._countSteps >= this._stepsConsideredForStraightLine) {
38
- this.notify(false);
39
- }
40
- this._countSteps = 0;
41
- }
42
-
43
- private _onStep = () => {
44
- this._countSteps++;
45
-
46
- if (this._countSteps === this._stepsConsideredForStraightLine) {
47
- this.notify(true);
48
- }
49
-
50
- }
51
-
52
- isStraight() {
53
- return this._countSteps >= this._stepsConsideredForStraightLine;
54
- }
55
-
56
- get numStepsDetectedFromLastTurn() {
57
- return this._countSteps;
58
- }
59
-
60
- get stepsConsideredForStraightLine() {
61
- return this._stepsConsideredForStraightLine;
62
- }
63
-
64
- set stepsConsideredForStraightLine(stepsConsideredForStraightLine) {
65
- this._stepsConsideredForStraightLine = stepsConsideredForStraightLine;
66
- }
67
- }
68
-
69
- export default new StraightLineProvider();
@@ -1,184 +0,0 @@
1
- import { RelativePosition } from '@wemap/geo';
2
- import { deg2rad, Quaternion_t, Vector16_t, Vector3_t } from '@wemap/maths';
3
- import { TimeUtils } from '@wemap/utils';
4
-
5
- import Provider from '../Provider.js';
6
- import MissingArCoreError from '../../errors/MissingArCoreError.js';
7
- import MissingNativeInterfaceError from '../../errors/MissingNativeInterfaceError.js';
8
- import { NativeArCore } from '../NativeProviders.js';
9
- import { Barcode, CameraProjectionMatrix, RelativeAttitude} from '../../events/Types.js';
10
-
11
-
12
- export type Payload = [number, ...[number | string]];
13
-
14
- export type ArCoreEvent = Readonly<{
15
- readonly relativePosition: RelativePosition,
16
- readonly relativeAttitude: RelativeAttitude,
17
- readonly cameraProjection?: CameraProjectionMatrix,
18
- readonly barcode?: Barcode
19
- }>;
20
-
21
- class ArCoreProvider extends Provider<ArCoreEvent> {
22
-
23
- static Payload = {
24
- Pose: {
25
- ref: 2 ** 0,
26
- size: 7
27
- },
28
- Barcode: {
29
- ref: 2 ** 1,
30
- size: 1
31
- },
32
- ProjMat: {
33
- ref: 2 ** 2,
34
- size: 16
35
- },
36
- ImageRef: {
37
- ref: 2 ** 3,
38
- size: 1
39
- }
40
- } as const;
41
-
42
- /**
43
- * default relative attitude drift in rad.second-1
44
- */
45
- static RELATIVE_ATTITUDE_DRIFT = deg2rad(3) / 60;
46
-
47
- _nativeProvider?: NativeArCore;
48
-
49
- previousPosition = [0, 0, 0];
50
-
51
- getName = () => 'ArCore';
52
-
53
- availability() {
54
- try {
55
- const nativeProvider = this.nativeProvider;
56
-
57
- if (!nativeProvider.checkAvailability()) {
58
- return Promise.resolve(new MissingArCoreError());
59
- }
60
-
61
- } catch (e) {
62
- return Promise.resolve(e as Error);
63
- }
64
-
65
- return Promise.resolve();
66
- }
67
-
68
- start() {
69
- this.nativeProvider?.start();
70
- this.pullDataLoop();
71
- }
72
-
73
- stop() {
74
- this.nativeProvider?.stop();
75
- }
76
-
77
- pullDataLoop = () => {
78
-
79
- if (this.state === 'stopped') {
80
- return;
81
- }
82
-
83
- const payload = JSON.parse(this.nativeProvider.getInfo());
84
- if (payload.length > 1) {
85
- this.parsePayload(payload);
86
- }
87
- requestAnimationFrame(this.pullDataLoop);
88
- }
89
-
90
- parsePayload(payload: Payload) {
91
-
92
- const ref = payload[0];
93
- let bufferIndex = 1;
94
-
95
- let attitude: RelativeAttitude,
96
- position: RelativePosition,
97
- cameraProjection,
98
- barcode;
99
-
100
- const time = TimeUtils.preciseTime() / 1e3;
101
-
102
- if (ref & ArCoreProvider.Payload.Pose.ref) {
103
-
104
- attitude = new RelativeAttitude(
105
- payload.slice(bufferIndex, bufferIndex + 4) as Quaternion_t,
106
- time,
107
- ArCoreProvider.RELATIVE_ATTITUDE_DRIFT,
108
- );
109
-
110
- const newPosition = [
111
- payload[bufferIndex + 4], payload[bufferIndex + 5], payload[bufferIndex + 6]
112
- ] as Vector3_t;
113
- position = new RelativePosition(
114
- newPosition[0] - this.previousPosition[0],
115
- newPosition[1] - this.previousPosition[1],
116
- newPosition[2] - this.previousPosition[2],
117
- time,
118
- 1e-4
119
- );
120
- this.previousPosition = newPosition;
121
-
122
- bufferIndex += ArCoreProvider.Payload.Pose.size;
123
- }
124
-
125
- if (ref & ArCoreProvider.Payload.Barcode.ref) {
126
- barcode = payload[bufferIndex] as Barcode;
127
- bufferIndex += ArCoreProvider.Payload.Barcode.size;
128
- }
129
-
130
- if (ref & ArCoreProvider.Payload.ProjMat.ref) {
131
- cameraProjection = payload.slice(bufferIndex, bufferIndex + ArCoreProvider.Payload.ProjMat.size) as Vector16_t;
132
- bufferIndex += ArCoreProvider.Payload.ProjMat.size;
133
- }
134
-
135
- this.notify({
136
- relativePosition: position!,
137
- relativeAttitude: attitude!,
138
- ...(barcode && { barcode }),
139
- ...(cameraProjection && { cameraProjection })
140
-
141
- })
142
- }
143
-
144
-
145
- get nativeProvider() {
146
-
147
- if (!this._nativeProvider) {
148
-
149
- if (!this.nativeInterface) {
150
- throw new MissingNativeInterfaceError();
151
- }
152
-
153
- this._nativeProvider = this.nativeInterface.getArCoreProvider();
154
- if (!this._nativeProvider) {
155
- throw new MissingArCoreError();
156
- }
157
- }
158
-
159
- return this._nativeProvider;
160
- }
161
-
162
-
163
- enableBarcodeScanner() {
164
- try {
165
- this.nativeProvider.enableBarcodeScanner();
166
- } catch (e) {
167
- this.notifyError(e as Error);
168
- }
169
- }
170
-
171
- disableBarcodeScanner() {
172
- try {
173
- this.nativeProvider.disableBarcodeScanner();
174
- } catch (e) {
175
- this.notifyError(e as Error);
176
- }
177
- }
178
-
179
- get useCameraNatively() {
180
- return true;
181
- }
182
- }
183
-
184
- export default new ArCoreProvider();
@@ -1,28 +0,0 @@
1
- import Provider from '../Provider.js';
2
- import ArCore from './ArCoreProvider.js';
3
- import { Barcode } from '../../events/Types.js';
4
-
5
- class BarcodePoleStarProvider extends Provider<Barcode> {
6
-
7
- providerId?: number;
8
-
9
- getName = () => 'Barcode';
10
-
11
- availability = () => ArCore.getAvailability();
12
-
13
- start() {
14
- ArCore.enableBarcodeScanner();
15
-
16
- this.providerId = ArCore.addEventListener(
17
- event => event.barcode && this.notify(event.barcode),
18
- this.notifyError
19
- );
20
- }
21
-
22
- stop() {
23
- ArCore.disableBarcodeScanner();
24
- ArCore.removeEventListener(this.providerId);
25
- }
26
- }
27
-
28
- export default new BarcodePoleStarProvider();
@@ -1,98 +0,0 @@
1
- import { Calibration, reduceImageSize, convertToGrayscale } from '@wemap/camera';
2
- import Logger from '@wemap/logger';
3
- import { Quaternion_t } from '@wemap/maths/index.js';
4
- import { TimeUtils, UserAgentUtils } from '@wemap/utils';
5
- import VpsMetadata, { CoarsePose } from './VpsMetadata.js';
6
-
7
- import VpsRequest from './VpsRequest.js';
8
- import VpsResponse from './VpsResponse.js';
9
-
10
- class ImageRelocalization {
11
-
12
- static _prepareRequest(
13
- imageCanvas: HTMLCanvasElement,
14
- calibration: Calibration | null = null,
15
- coarsePose: CoarsePose | null = null
16
- ) {
17
- convertToGrayscale(imageCanvas);
18
- const reducedImage = reduceImageSize(imageCanvas, 1280);
19
-
20
- const metadata = new VpsMetadata(
21
- { width: reducedImage.width, height: reducedImage.height },
22
- calibration,
23
- coarsePose,
24
- UserAgentUtils.getDeviceFromUserAgent()
25
- );
26
-
27
- return new VpsRequest(metadata, reducedImage);
28
- }
29
-
30
-
31
- static async relocalize(
32
- endpointUrl: string,
33
- imageCanvas: HTMLCanvasElement,
34
- calibration: Calibration | null = null,
35
- coarsePose: CoarsePose | null = null,
36
- customHeaders: Record<string, string> | null = null
37
- ) {
38
-
39
- const timeBeforeRequest = TimeUtils.preciseTime() / 1e3;
40
-
41
- // 1. Prepare the request
42
- const vpsRequest = this._prepareRequest(imageCanvas, calibration, coarsePose);
43
-
44
- // 2. Send the request
45
- let serverResponse;
46
- try {
47
- const body = JSON.stringify(vpsRequest.toJson());
48
- Logger.debug(`[VPS] Request (${(body.length / 1024).toFixed(0)} kB) sent to server ${endpointUrl}`);
49
- serverResponse = await fetch(endpointUrl, {
50
- method: 'POST',
51
- body,
52
- headers: Object.assign(
53
- {
54
- 'Content-Type': 'application/json',
55
- 'Accept': 'application/vnd.geopose+json; version=1'
56
- },
57
- customHeaders ? customHeaders : {}
58
- )
59
- });
60
- } catch (e) {
61
- Logger.debug('[VPS] Server respond error');
62
- return null;
63
- }
64
-
65
- if (serverResponse.status !== 200) {
66
- Logger.debug('[VPS] Server respond error');
67
- return null;
68
- }
69
-
70
- // 3. Parse the response
71
- const json = await serverResponse.json();
72
- const res = VpsResponse.fromJson(json, timeBeforeRequest);
73
- Logger.debug(`[VPS] Server respond ${res.success ? 'success' : 'not found'}`);
74
- return res;
75
- }
76
-
77
- static getHeadingFromQuaternion(quaternion: Quaternion_t) {
78
-
79
- const [qw, qx, qy, qz] = quaternion;
80
-
81
- const s = Math.sqrt(2) / 2;
82
- const C = [s * (qw - qx), s * (qw + qx), s * (qy + qz), s * (qz - qy)];
83
- return -Math.atan2(2 * C[3] * C[0] - 2 * C[2] * C[1], 1 - 2 * C[1] ** 2 - 2 * C[3] ** 2);
84
-
85
- // ---- Not optimized version ----
86
-
87
- // const eulerAnglesAR = Rotations.quaternionToEulerZXY(
88
- // Quaternion.multiply(
89
- // quaternion,
90
- // Quaternion.fromAxisAngle([1, 0, 0], Math.PI / 2)
91
- // )
92
- // );
93
-
94
- // return -eulerAnglesAR[0];
95
- }
96
- }
97
-
98
- export default ImageRelocalization;
@@ -1,58 +0,0 @@
1
- import { Attitude } from '@wemap/geo';
2
- import Logger from '@wemap/logger';
3
- import RelativeAttitudeFromBrowser from '../../attitude/relative/RelativeAttitudeFromBrowserProvider.js';
4
-
5
- export default class RelativeRotationCalc {
6
-
7
- _providerId?: number;
8
-
9
- _isRunning = false;
10
- _dataOnStart: Attitude | null = null;
11
-
12
- tickStart() {
13
- this._dataOnStart = null;
14
-
15
- if (this._isRunning) {
16
- // Do not start the provider if tickStart() has already been called without tickEnd()
17
- return;
18
- }
19
-
20
- this._isRunning = true;
21
-
22
- this._providerId = RelativeAttitudeFromBrowser.addEventListener(event => {
23
- if (!this._dataOnStart) {
24
- this._dataOnStart = event;
25
- }
26
- });
27
- }
28
-
29
- tickEnd() {
30
- if (!this._isRunning) {
31
- Logger.warn('You have to call tickStart before tickEnd');
32
- return null;
33
- }
34
-
35
- this._internalStop();
36
-
37
- if (!this._dataOnStart) {
38
- Logger.warn('Delay was too short between tickStart and tickEnd '
39
- + 'or RelativeAttitudeProvider cannot be retrieved.');
40
- return null;
41
- }
42
-
43
- const dataOnEnd = RelativeAttitudeFromBrowser.lastEvent!;
44
- return Attitude.diff(this._dataOnStart, dataOnEnd);
45
- }
46
-
47
- _internalStop() {
48
- RelativeAttitudeFromBrowser.removeEventListener(this._providerId);
49
- delete this._providerId;
50
- this._isRunning = false;
51
- }
52
-
53
- release() {
54
- if (this._isRunning) {
55
- this._internalStop();
56
- }
57
- }
58
- }
@@ -1,63 +0,0 @@
1
- import { Calibration } from '@wemap/camera';
2
- import { Attitude, AttitudeJson, UserPosition, UserPositionJson } from '@wemap/geo';
3
- import { Device } from '@wemap/utils';
4
-
5
- export type CoarsePoseJson = {
6
- attitude?: AttitudeJson,
7
- position?: UserPositionJson,
8
- };
9
-
10
- export type CoarsePose = {
11
- attitude?: Attitude,
12
- position?: UserPosition,
13
- };
14
-
15
- export type VpsMetadataJson = {
16
- size: [number, number], // [width, height]
17
- calibration?: Calibration,
18
- coarse?: CoarsePoseJson,
19
- device?: Device
20
- }
21
-
22
-
23
- class VpsMetadata {
24
-
25
- constructor(
26
- public size: { width: number, height: number },
27
- public calibration: Calibration | null = null,
28
- public coarse: CoarsePose | null = null,
29
- public device: Device | null = null,
30
- ) { }
31
-
32
- toJson(): VpsMetadataJson {
33
- return {
34
- size: [this.size.width, this.size.height],
35
- ...(this.calibration && { calibration: this.calibration }),
36
- ...(this.coarse && {
37
- coarse: {
38
- ...(this.coarse.attitude && { attitude: this.coarse.attitude.toJson() }),
39
- ...(this.coarse.position && { position: this.coarse.position.toJson() })
40
- }
41
- }),
42
- ...(typeof this.device === 'object' && { device: this.device })
43
- };
44
- }
45
-
46
-
47
- static fromJson(json: VpsMetadataJson) {
48
- return new VpsMetadata(
49
- {
50
- width: json.size[0],
51
- height: json.size[1]
52
- },
53
- json.calibration,
54
- {
55
- ...(json.coarse?.position && { position: UserPosition.fromJson(json.coarse.position) }),
56
- ...(json.coarse?.attitude && { attitude: Attitude.fromJson(json.coarse.attitude) })
57
- },
58
- json.device
59
- );
60
- }
61
- }
62
-
63
- export default VpsMetadata;