-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathexport-articulations.js
executable file
·53 lines (48 loc) · 2.52 KB
/
export-articulations.js
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
#!/usr/bin/env node
/* jshint esversion: 6 */
const VERSION = '0.0.1';
const STK = require('../stk-ssc');
const _ = STK.util;
const cmd = require('commander');
cmd
.version(VERSION)
.description('Export articulations as json files')
.option('--id <id>', 'Model id')
.option('--source <source>', 'Model source')
.option('--annotation_filename <filename>', 'Annotations filename')
.option('--precomputed_filename <filename>', 'Precomputed connectivity filename')
.option('--output <filename>', 'Output filename')
.parse(process.argv);
const ArticulationAnnotationsLoader = STK.articulations.ArticulationAnnotationsLoader;
function exportArticulations(annotation_filename, precomputed_filename, output_filename) {
ArticulationAnnotationsLoader.loadArticulationAnnotations(annotation_filename, precomputed_filename, function(err, res) {
if (err) {
console.error(`Error loading parts model=${annotation_filename} parts=${precomputed_filename}`, err);
} else {
const articulations = res.articulations.data.articulations;
if (res.precomputed) {
const connectivityGraph = STK.parts.PartConnectivityGraph.fromJson(res.precomputed);
const reducedConnectivityGraph = connectivityGraph.clone();
reducedConnectivityGraph.cutExtraConnections(articulations);
res.precomputed.reducedConnectivityGraph = reducedConnectivityGraph.connectivityAsArray();
STK.fs.writeToFile(output_filename + '.artpost.json', JSON.stringify(res.precomputed));
}
STK.fs.writeToFile(output_filename + '.articulations.json', JSON.stringify(articulations));
}
});
}
function exportArticulationsWithId(source, id, output_filename) {
const modelId = `${source}.${id}`;
const annotation_filename = `${STK.Constants.baseUrl}/articulation-annotations/load-annotations?modelId=${modelId}`;
const precomputed_filename = (cmd.precomputed_filename === 'none' || cmd.precomputed_filename == null)?
"none" : `${STK.Constants.baseUrl}/articulations/${source}/precomputed/${modelId}.artpre.json`;
if (output_filename == null) {
output_filename = `${modelId}`;
}
exportArticulations(annotation_filename, precomputed_filename, output_filename);
}
if (cmd.precomputed_filename != null && cmd.annotation_filename != null) {
exportArticulations(cmd.annotation_filename, cmd.precomputed_filename, cmd.output_filename);
} else {
exportArticulationsWithId(cmd.source, cmd.id, cmd.output);
}