Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | 1x | import { Inject, Injectable } from '@angular/core'; import { HttpClient, HttpResponse } from '@angular/common/http'; import { fromEventPattern, Observable, using } from 'rxjs'; import { SignalRBaseService } from './signalR.base.service'; import { concatMap, map } from 'rxjs/operators'; import { LogService } from 'src/app/log/log.service'; import { Calibration, CalibrationPoint, CalibrationTransform, CompleteInteractionData, FrameSizeDefinition, Interaction, Point3 } from '@reflex/shared-types'; @Injectable({ providedIn: 'root' }) export class CalibrationService extends SignalRBaseService<string> { private readonly calibrationRoute = 'api/Calibration/'; private readonly getFrameSizeRoute = `${this.calibrationRoute}FrameSize`; private readonly getSourceValuesRoute = `${this.calibrationRoute}SourceValues`; private readonly getTargetValuesRoute = `${this.calibrationRoute}TargetValues`; private readonly getCalibrationMatrixRoute = `${this.calibrationRoute}GetCalibrationMatrix`; private readonly applyCalibrationRoute = `${this.calibrationRoute}ApplyCalibration`; private readonly restartCalibrationRoute = `${this.calibrationRoute}Restart`; private readonly saveCalibrationRoute = `${this.calibrationRoute}SaveCalibration`; private readonly calibrateInteractionsRoute = `${this.calibrationRoute}CalibratedInteractions`; private readonly updateFrameSizeRoute = `${this.calibrationRoute}UpdateFrameSize`; private readonly updateCalibrationPointRoute = `${this.calibrationRoute}UpdateCalibrationPoint/`; // eslint-disable-next-line new-cap public constructor(private readonly http: HttpClient, @Inject('BASE_URL') private readonly baseUrl: string, logService: LogService) { super(`${baseUrl}calibhub`, 'calibrationState', logService); } public getFrameSize(): Observable<FrameSizeDefinition> { return this.http.get<FrameSizeDefinition>(this.baseUrl + this.getFrameSizeRoute); } public getCalibrationSourcePoints(): Observable<Array<CalibrationPoint>> { return this.http.get<Array<CalibrationPoint>>(this.baseUrl + this.getSourceValuesRoute); } public getCurrentCalibrationTargetPoints(): Observable<Array<CalibrationPoint>> { return this.http.get<Array<CalibrationPoint>>(this.baseUrl + this.getTargetValuesRoute); } public getCalibrationMatrix(): Observable<CalibrationTransform> { return this.http.get<CalibrationTransform>(this.baseUrl + this.getCalibrationMatrixRoute); } public applyCalibration(): Observable<CalibrationTransform> { return this.http.get<CalibrationTransform>(this.baseUrl + this.applyCalibrationRoute); } public restartCalibration(): Observable<CalibrationTransform> { return this.http.get<CalibrationTransform>(this.baseUrl + this.restartCalibrationRoute); } public saveCalibration(): Observable<CalibrationTransform> { return this.http.get<CalibrationTransform>(this.baseUrl + this.saveCalibrationRoute); } public updateFrameSize(newSize: FrameSizeDefinition): Observable<HttpResponse<FrameSizeDefinition>> { return this.http.post<FrameSizeDefinition>(this.baseUrl + this.updateFrameSizeRoute, newSize, { observe: 'response' }); } public updateCalibrationPoint(idx: number, target: CalibrationPoint): Observable<HttpResponse<CalibrationTransform>> { return this.http.post<CalibrationTransform>(`${this.baseUrl}${this.updateCalibrationPointRoute}${idx}`, target, { observe: 'response' }); } public computeCalibratedPosition(rawInteractions: Array<Interaction>): Observable<HttpResponse<Array<Interaction>>> { return this.http.post<Array<Interaction>>(`${this.baseUrl}${this.calibrateInteractionsRoute}`, rawInteractions, { observe: 'response' }); } public computeCalibratedAbsolutePosition(rawInteractions: Array<Interaction>): Observable<CompleteInteractionData> { return this.computeCalibratedPosition(rawInteractions).pipe( concatMap((result) => { let normalized: Array<Interaction> = []; Iif (result.body && result.ok) { normalized = result.body; } return this.getFrameSize().pipe(map((frame) => ({ raw: rawInteractions, normalized: normalized, absolute: this.transform(frame, normalized) }))); }) ); } public getCalibration(): Observable<Calibration> { const calibration$ = fromEventPattern<Calibration>( (handler) => this.connection.on('Calibration', handler), (handler) => this.connection.off('Calibration', handler) ); return using(() => { this.connection.send('StartCalibrationSubscription').catch((error) => { console.error(error); this.logService.sendErrorLog(`${error}`); }); // eslint-disable-next-line @typescript-eslint/no-misused-promises return { unsubscribe: async () => this.connection.send('StopCalibrationSubscription').catch((error) => { console.error(error); this.logService.sendErrorLog(`${error}`); }) }; }, () => calibration$); } private transform(borders: FrameSizeDefinition, normalized: Array<Interaction>): Array<Interaction> { const calibrated: Array<Interaction> = []; normalized.forEach((norm) => { const x = (norm.position.x * borders.width) + borders.left; const y = (norm.position.y * borders.height) + borders.top; const absolutePos: Point3 = { x: x, y: y, z: norm.position.z, isValid: norm.position.isValid, isFiltered: norm.position.isFiltered }; calibrated.push({ touchId: norm.touchId, position: absolutePos, confidence: norm.confidence, time: norm.time, type: norm.type, extremumDescription: norm.extremumDescription }); }); return calibrated; } } |