-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpfeimage.js
86 lines (72 loc) · 1.98 KB
/
pfeimage.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const sharp = require('sharp');
const constants = require('./constants.json');
const io = require('./io.js');
const Thermo = require('./thermo.js');
module.exports = class extends Thermo {
constructor(pfe, Canvas, image, imageIndex) {
super({uri: pfe.data.uri + `?${imageIndex}`},
pfe.data.name + ` - ${imageIndex}`,
Canvas
);
const {image: imageData, points} = image;
this.data.points = points;
this.data.files.points = Object.keys(points);
this.data.magnification = imageData.ImageMag;
this.data.rawImageData = imageData;
}
staticInit() {
io.checkBIMExists(this.data.files.entry.split('?')[0]);
this.data.files.base = this.data.files.entry;
this.data.files.layers = [{
element: 'base',
file: this.data.files.base
}, {
element: 'solid',
file: ''
}];
//this.data.points = {};
this.data.files.points = [];
this.data.data.map = {};
//this.data.magnification = 40;
}
async init() {
if (!this.data.layers.base) {
await Promise.all(this.data.files.layers.map(async ({file, element}) => {
if (element !== 'base')
if (element !== 'solid')
return this.addLayerFile(this.data.uri + file);
else
this.data.layers['solid'] = {
element,
file: '',
image: undefined,
metadata: {}
};
else {
const image = sharp(await io.readBIM(this.data.files.base), {
raw: {
width: this.data.rawImageData.ImageIx,
height: this.data.rawImageData.ImageIy,
channels: 1
}
}).flip();
this.data.layers['base'] = {
element,
file: this.data.files.base,
image,
metadata: await image.metadata()
};
const baseUri = this.data.uri.split('/');
baseUri.pop();
this.data.files.base = `${baseUri.join('/')}/${this.data.name}_${this.data.rawImageData.ImageTitle}_${this.data.rawImageData.ImageNumber}`;
}
}));
}
return await this.internalInit();
}
serialize() {
return this.internalSerialize({
name: this.data.name
});
}
};