MCPcopy Create free account
hub / github.com/ashawkey/camera_viewer / PoseParser

Class PoseParser

js/poseParser.js:6–528  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4 */
5
6export class PoseParser {
7 /**
8 * Parse multiple trajectories from input (separated by blank lines)
9 * Supports optional trajectory names via # comment lines before each block.
10 * Example:
11 * # My Trajectory
12 * [[[1,0,0,0], ...], ...]
13 *
14 * @param {string} input - The input string potentially containing multiple trajectories
15 * @param {string} format - The input format ('matrix', 'xyz_quat_wxyz', 'xyz_quat_xyzw')
16 * @returns {Object} - { success: boolean, trajectories: array, errors: array, totalCount: number }
17 */
18 static parseMultiple(input, format = 'matrix') {
19 const trajectories = [];
20 const errors = [];
21 let totalCount = 0;
22
23 // Split by double newlines or lines that only contain whitespace between arrays
24 const blocks = this.splitIntoBlocks(input);
25
26 if (blocks.length === 0) {
27 return {
28 success: false,
29 trajectories: [],
30 errors: ['No valid input found'],
31 totalCount: 0
32 };
33 }
34
35 blocks.forEach((block, index) => {
36 // Extract name from # comment if present
37 const { name, content } = this.extractNameFromBlock(block, index);
38
39 const result = this.parse(content, format);
40 if (result.success) {
41 trajectories.push({
42 id: index,
43 name: name,
44 poses: result.data,
45 count: result.count,
46 visible: true
47 });
48 totalCount += result.count;
49 } else {
50 errors.push(`${name}: ${result.error}`);
51 }
52 });
53
54 return {
55 success: trajectories.length > 0,
56 trajectories: trajectories,
57 errors: errors,
58 totalCount: totalCount
59 };
60 }
61
62 /**
63 * Extract trajectory name from a # comment line at the start of a block

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected