Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('XVIZWriter#default-ctor', t => {
/* eslint-disable no-unused-vars */
// Ensure no parameter ctor
const sink = new MemorySourceSink();
const jsBuilder = new XVIZJSONWriter(sink);
const binBuilder = new XVIZBinaryWriter(sink);
t.end();
/* eslint-enable no-unused-vars */
});
XVIZBinaryWriter,
XVIZData,
XVIZFormatWriter,
XVIZ_FORMAT
} from '@xviz/io';
// Source test data
import TestXVIZSnapshot from 'test-data/sample-xviz';
// Various formats for the test data
const TestXVIZSnapshotString = JSON.stringify(TestXVIZSnapshot);
const TestXVIZSnapshotBuffer = new TextEncoder().encode(JSON.stringify(TestXVIZSnapshot));
let TestXVIZSnapshotGLB = null;
// make binary in memory
const writer = new XVIZBinaryWriter({
writeSync: (n, d) => {
TestXVIZSnapshotGLB = d;
}
});
writer.writeMessage(0, TestXVIZSnapshot);
tape('XVIZFormatWriter#full matrix', t => {
const dataSources = [
TestXVIZSnapshot,
TestXVIZSnapshotString,
TestXVIZSnapshotBuffer,
TestXVIZSnapshotGLB
];
for (const source of dataSources) {
const xvizObj = new XVIZData(source);
import {XVIZData, XVIZBinaryWriter, XVIZ_FORMAT, TextEncoder} from '@xviz/io';
// Enveloped glb as ArrayBuffer
import MinimalBinaryMetadata from 'test-data/minimal-metadata';
import MinimalBinaryStateUpdate from 'test-data/minimal-state-update';
// Source test data
import TestXVIZSnapshot from 'test-data/sample-xviz';
// Various formats for the test data
const TestXVIZSnapshotString = JSON.stringify(TestXVIZSnapshot);
const TestXVIZSnapshotBuffer = new TextEncoder().encode(JSON.stringify(TestXVIZSnapshot));
let TestXVIZSnapshotGLB = null;
// make binary in memory
const writer = new XVIZBinaryWriter({
writeSync: (n, d) => {
TestXVIZSnapshotGLB = d;
}
});
writer.writeMessage(0, TestXVIZSnapshot);
// Load the data in XVIZData and verify the format
const TestCases = [
{
data: TestXVIZSnapshot,
description: 'XVIZ Object',
format: XVIZ_FORMAT.OBJECT
},
{
data: TestXVIZSnapshotString,
description: 'XVIZ String',
].forEach(frame => {
// Test that each "points" field is properly replaced.
const sink = new MemorySourceSink();
const writer = new XVIZBinaryWriter(sink);
writer.writeMessage(0, frame);
t.ok(sink.has('2-frame.glb'), 'wrote binary frame');
const data = sink.readSync('2-frame.glb');
const msg = new XVIZData(data).message();
const writtenPoints = msg.data.updates[0].primitives['/test/points'].points[0];
t.ok(writtenPoints.points, 'Has points');
t.ok(writtenPoints.colors, 'Has colors');
t.equals(writtenPoints.points[0], 1, 'point 1 matches input data');
t.equals(writtenPoints.points[3], 2, 'point 2 matches input data');
t.equals(writtenPoints.points[6], 3, 'point 3 matches input data');
disabledStreams,
sceneName,
fakeStreams,
imageMaxWidth,
imageMaxHeight,
keyframes
});
console.log(`Converting NuScenes data scene ${sceneName} at ${inputDir}`); // eslint-disable-line
console.log(`Saving to ${outputDir}`); // eslint-disable-line
converter.initialize();
// This abstracts the details of the filenames expected by our server
const sink = new FileSink(outputDir);
const xvizWriter = new XVIZBinaryWriter(sink);
// Write metadata file
const xvizMetadata = converter.getMetadata();
xvizWriter.writeMetadata(xvizMetadata);
const start = Date.now();
const limit = Math.min(messageLimit, converter.messageCount());
for (let i = 0; i < limit; i++) {
const xvizMessage = await converter.convertMessage(i);
if (xvizMessage) {
xvizWriter.writeMessage(i, xvizMessage);
}
}
xvizWriter.close();
});
console.log(`Converting KITTI data at ${inputDir}`); // eslint-disable-line
console.log(`Saving to ${outputDir}`); // eslint-disable-line
converter.initialize();
// This abstracts the details of the filenames expected by our server
const sink = new FileSink(outputDir);
let xvizWriter = null;
if (writeJson) {
xvizWriter = new XVIZJSONWriter(sink);
} else if (writeProtobuf) {
xvizWriter = new XVIZProtobufWriter(sink);
} else {
xvizWriter = new XVIZBinaryWriter(sink);
}
// Write metadata file
const xvizMetadata = converter.getMetadata();
xvizWriter.writeMetadata(xvizMetadata);
// If we get interrupted make sure the index is written out
signalWriteIndexOnInterrupt(xvizWriter);
const start = Date.now();
const limit = Math.min(messageLimit, converter.messageCount());
// Convert each message and write it to a file
//
// A *message* is a point in time, where each message will contain
// a *pose* and any number of XVIZ data sets.
test('XVIZWriter#default-ctor messages close()', t => {
const sink = new MemorySourceSink();
const jsBuilder = new XVIZJSONWriter(sink);
const binBuilder = new XVIZBinaryWriter(sink);
const data = SAMPLE_STATE_UPDATE;
for (const builder of [jsBuilder, binBuilder]) {
builder.writeMessage(0, data);
builder.close();
t.ok(sink.has('0-frame.json'), 'wrote index for messages');
const expected = {
timing: [[100, 100, 0, '2-frame']]
};
t.deepEquals(
JSON.parse(sink.readSync('0-frame.json')),
expected,