trajectoryClassifier.d.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import type { DeepImmutable, Nullable } from "../types";
  2. import { Vector3 } from "../Maths/math.vector";
  3. /**
  4. * A 3D trajectory consisting of an order list of vectors describing a
  5. * path of motion through 3D space.
  6. */
  7. export declare class Trajectory {
  8. private _points;
  9. private readonly _segmentLength;
  10. /**
  11. * Serialize to JSON.
  12. * @returns serialized JSON string
  13. */
  14. serialize(): string;
  15. /**
  16. * Deserialize from JSON.
  17. * @param json serialized JSON string
  18. * @returns deserialized Trajectory
  19. */
  20. static Deserialize(json: string): Trajectory;
  21. /**
  22. * Create a new empty Trajectory.
  23. * @param segmentLength radius of discretization for Trajectory points
  24. */
  25. constructor(segmentLength?: number);
  26. /**
  27. * Get the length of the Trajectory.
  28. * @returns length of the Trajectory
  29. */
  30. getLength(): number;
  31. /**
  32. * Append a new point to the Trajectory.
  33. * NOTE: This implementation has many allocations.
  34. * @param point point to append to the Trajectory
  35. */
  36. add(point: DeepImmutable<Vector3>): void;
  37. /**
  38. * Create a new Trajectory with a segment length chosen to make it
  39. * probable that the new Trajectory will have a specified number of
  40. * segments. This operation is imprecise.
  41. * @param targetResolution number of segments desired
  42. * @returns new Trajectory with approximately the requested number of segments
  43. */
  44. resampleAtTargetResolution(targetResolution: number): Trajectory;
  45. /**
  46. * Convert Trajectory segments into tokenized representation. This
  47. * representation is an array of numbers where each nth number is the
  48. * index of the token which is most similar to the nth segment of the
  49. * Trajectory.
  50. * @param tokens list of vectors which serve as discrete tokens
  51. * @returns list of indices of most similar token per segment
  52. */
  53. tokenize(tokens: DeepImmutable<Vector3[]>): number[];
  54. private static _ForwardDir;
  55. private static _InverseFromVec;
  56. private static _UpDir;
  57. private static _FromToVec;
  58. private static _LookMatrix;
  59. /**
  60. * Transform the rotation (i.e., direction) of a segment to isolate
  61. * the relative transformation represented by the segment. This operation
  62. * may or may not succeed due to singularities in the equations that define
  63. * motion relativity in this context.
  64. * @param priorVec the origin of the prior segment
  65. * @param fromVec the origin of the current segment
  66. * @param toVec the destination of the current segment
  67. * @param result reference to output variable
  68. * @returns whether or not transformation was successful
  69. */
  70. private static _TransformSegmentDirToRef;
  71. private static _BestMatch;
  72. private static _Score;
  73. private static _BestScore;
  74. /**
  75. * Determine which token vector is most similar to the
  76. * segment vector.
  77. * @param segment segment vector
  78. * @param tokens token vector list
  79. * @returns index of the most similar token to the segment
  80. */
  81. private static _TokenizeSegment;
  82. }
  83. /**
  84. * Class representing a set of known, named trajectories to which Trajectories can be
  85. * added and using which Trajectories can be recognized.
  86. */
  87. export declare class TrajectoryClassifier {
  88. private _maximumAllowableMatchCost;
  89. private _vector3Alphabet;
  90. private _levenshteinAlphabet;
  91. private _nameToDescribedTrajectory;
  92. /**
  93. * Serialize to JSON.
  94. * @returns JSON serialization
  95. */
  96. serialize(): string;
  97. /**
  98. * Deserialize from JSON.
  99. * @param json JSON serialization
  100. * @returns deserialized TrajectorySet
  101. */
  102. static Deserialize(json: string): TrajectoryClassifier;
  103. /**
  104. * Initialize a new empty TrajectorySet with auto-generated Alphabets.
  105. * VERY naive, need to be generating these things from known
  106. * sets. Better version later, probably eliminating this one.
  107. * @returns auto-generated TrajectorySet
  108. */
  109. static Generate(): TrajectoryClassifier;
  110. private constructor();
  111. /**
  112. * Add a new Trajectory to the set with a given name.
  113. * @param trajectory new Trajectory to be added
  114. * @param classification name to which to add the Trajectory
  115. */
  116. addTrajectoryToClassification(trajectory: Trajectory, classification: string): void;
  117. /**
  118. * Remove a known named trajectory and all Trajectories associated with it.
  119. * @param classification name to remove
  120. * @returns whether anything was removed
  121. */
  122. deleteClassification(classification: string): boolean;
  123. /**
  124. * Attempt to recognize a Trajectory from among all the classifications
  125. * already known to the classifier.
  126. * @param trajectory Trajectory to be recognized
  127. * @returns classification of Trajectory if recognized, null otherwise
  128. */
  129. classifyTrajectory(trajectory: Trajectory): Nullable<string>;
  130. }