@openhps/core
Version:
Open Hybrid Positioning System - Core component
139 lines • 5.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Pose = void 0;
const tslib_1 = require("tslib");
const TimeService_1 = require("../../service/TimeService");
const utils_1 = require("../../utils");
const math_1 = require("../../utils/math/");
const decorators_1 = require("../decorators");
const Accuracy_1 = require("../values/Accuracy");
const Accuracy1D_1 = require("../values/Accuracy1D");
const Absolute3DPosition_1 = require("./Absolute3DPosition");
const Orientation_1 = require("./Orientation");
/**
* Position and orientation.
*
* In computer vision and robotics, a typical task is to identify specific objects in an image and to determine each object's position and orientation relative to some coordinate system. This information can then be used, for example, to allow a robot to manipulate an object or to avoid moving into the object. The combination of position and orientation is referred to as the pose of an object, even though this concept is sometimes used only to describe the orientation. Exterior orientation and translation are also used as synonyms of pose.
* @see {@link https://en.wikipedia.org/wiki/Pose_(computer_vision)}
*/
let Pose = class Pose extends math_1.Matrix4 {
constructor() {
super(...arguments);
/**
* Position recording timestamp
*/
this.timestamp = TimeService_1.TimeService.now();
/**
* Position unit
*/
this.unit = utils_1.LengthUnit.METER;
this._probability = 1.0;
}
/**
* Get the position probability
* @returns {number} Probability between 0 and 1
*/
get probability() {
return this._probability;
}
set probability(value) {
if (value > 1 || value < 0) {
throw new Error(`${this.constructor.name} should be between 0 and 1.`);
}
this._probability = value;
}
/**
* Position accuracy
* @returns {Accuracy} Position accuracy
*/
get accuracy() {
if (!this._accuracy) {
this._accuracy = new Accuracy1D_1.Accuracy1D(1, this.unit);
}
return this._accuracy;
}
set accuracy(value) {
this._accuracy = value;
}
/**
* Get a pose from a 4d matrix
* @param {Matrix4} matrix 4x4 Matrix
* @returns {Pose} Pose instance
*/
static fromMatrix4(matrix) {
const pose = new this();
pose.fromArray(matrix.toArray());
return pose;
}
/**
* Create a pose from a position
* @param {Absolute3DPosition} position 3D position
* @returns {Pose} Output pose
*/
static fromPosition(position) {
const pose = new this();
pose.timestamp = position.timestamp;
pose.unit = position.unit;
pose.probability = position.probability;
pose.accuracy = pose.accuracy.clone();
const vector = position.toVector3();
if (position.orientation) {
pose.makeRotationFromQuaternion(position.orientation);
}
pose.setPosition(vector.x, vector.y, vector.z);
return pose;
}
/**
* Extract the orientation from the pose
* @returns {Orientation} Orientation
*/
get orientation() {
const rotationMatrix = this.extractRotation(this);
const orientation = Orientation_1.Orientation.fromRotationMatrix(rotationMatrix);
orientation.timestamp = this.timestamp;
return orientation;
}
/**
* Extract the 3d position from the pose
* @returns {Absolute3DPosition} 3D position
*/
get position() {
const positionMatrix = this.copyPosition(this);
const position = new Absolute3DPosition_1.Absolute3DPosition(positionMatrix.elements[12], positionMatrix.elements[13], positionMatrix.elements[14]);
position.timestamp = this.timestamp;
position.unit = this.unit;
position.probability = this.probability;
position.accuracy = this.accuracy.clone();
position.orientation = this.orientation;
return position;
}
};
exports.Pose = Pose;
tslib_1.__decorate([
(0, decorators_1.SerializableMember)({
index: true,
numberType: decorators_1.NumberType.LONG,
}),
tslib_1.__metadata("design:type", Number)
], Pose.prototype, "timestamp", void 0);
tslib_1.__decorate([
(0, decorators_1.SerializableMember)(),
tslib_1.__metadata("design:type", utils_1.LengthUnit)
], Pose.prototype, "unit", void 0);
tslib_1.__decorate([
(0, decorators_1.SerializableMember)({
name: 'accuracy',
}),
tslib_1.__metadata("design:type", Accuracy_1.Accuracy)
], Pose.prototype, "_accuracy", void 0);
tslib_1.__decorate([
(0, decorators_1.SerializableMember)({
numberType: decorators_1.NumberType.DECIMAL,
}),
tslib_1.__metadata("design:type", Number),
tslib_1.__metadata("design:paramtypes", [Number])
], Pose.prototype, "probability", null);
exports.Pose = Pose = tslib_1.__decorate([
(0, decorators_1.SerializableObject)()
], Pose);
//# sourceMappingURL=Pose.js.map