/
representation-utils.ts
71 lines (60 loc) · 1.96 KB
/
representation-utils.ts
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
/**
* @file Representation Utils
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @private
*/
import { Debug, Log, RepresentationRegistry } from '../globals'
import Viewer from '../viewer/viewer'
import Structure from '../structure/structure'
import Surface from '../surface/surface'
import Volume from '../surface/volume'
import Shape from '../geometry/shape'
import BufferRepresentation from './buffer-representation'
import SurfaceRepresentation from './surface-representation'
import DotRepresentation from './dot-representation'
import SliceRepresentation from './slice-representation'
function logReprUnknown (type: string) {
Log.error(`makeRepresentation: representation type ${type} unknown`)
}
export function makeRepresentation (type: string, object: any, viewer: Viewer, params: any) { // TODO
if (Debug) Log.time('makeRepresentation ' + type)
var ReprClass
if (object instanceof Structure) {
ReprClass = RepresentationRegistry.get(type)
if (!ReprClass) {
logReprUnknown(type)
return
}
} else if (object instanceof Surface) {
if (type === 'surface') {
ReprClass = SurfaceRepresentation
} else if (type === 'dot') {
ReprClass = DotRepresentation
} else {
logReprUnknown(type)
return
}
} else if (object instanceof Volume) {
if (type === 'surface') {
ReprClass = SurfaceRepresentation
} else if (type === 'dot') {
ReprClass = DotRepresentation
} else if (type === 'slice') {
ReprClass = SliceRepresentation
} else {
logReprUnknown(type)
return
}
} else if (object instanceof Shape) {
ReprClass = BufferRepresentation
object = object.getBufferList()
} else if (type === 'buffer') {
ReprClass = BufferRepresentation
} else {
Log.error('makeRepresentation: object ' + object + ' unknown')
return
}
const repr = new ReprClass(object, viewer, params)
if (Debug) Log.timeEnd('makeRepresentation ' + type)
return repr
}