-
Notifications
You must be signed in to change notification settings - Fork 316
Expand file tree
/
Copy pathLasNodeBase.ts
More file actions
108 lines (83 loc) · 3.3 KB
/
LasNodeBase.ts
File metadata and controls
108 lines (83 loc) · 3.3 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { Vector3, type Group } from 'three';
import type { Hierarchy } from 'copc';
import PointCloudNode, { PointCloudSource } from 'Core/PointCloudNode';
const size = new Vector3();
const position = new Vector3();
const translation = new Vector3();
function buildVoxelKey(depth: number, x: number, y: number, z: number): string {
return `${depth}-${x}-${y}-${z}`;
}
abstract class LasNodeBase extends PointCloudNode {
/** X position within the octree */
x: number;
/** Y position within the octree */
y: number;
/** Z position within the octree */
z: number;
/** The depth of the node in the tree */
/** The id of the node, constituted of the four
* components: `depth-x-y-z`. */
voxelKey: string;
crs: string;
constructor(depth: number,
x: number, y: number, z: number,
source: PointCloudSource,
numPoints: number = 0,
crs: string,
) {
super(depth, numPoints);
this.x = x;
this.y = y;
this.z = z;
this.voxelKey = buildVoxelKey(depth, x, y, z);
this.crs = crs;
}
override get networkOptions(): RequestInit {
return this.source.networkOptions;
}
override get octreeIsLoaded(): boolean {
return this.numPoints >= 0;
}
override get id(): string {
return `${this.depth}${this.x}${this.y}${this.z}`;
}
abstract findAndCreateChild(
depth: number,
x: number, y: number, z: number,
hierarchy: Record<string, number> | Hierarchy.Subtree,
stack: this[],
): void;
/**
* Create an (A)xis (A)ligned (B)ounding (B)ox for the given node given
* `this` is its parent.
* @param childNode - The child node
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
override createChildAABB(childNode: this, _indexChild: number): void {
// initialize the child node obb
const voxelBBox = this.voxelOBB.natBox;
const childVoxelBBox = voxelBBox.clone();
// factor to apply, based on the depth difference (can be > 1)
const f = 2 ** (childNode.depth - this.depth);
// size of the child node bbox (Vector3), based on the size of the
// parent node, and divided by the factor
voxelBBox.getSize(size).divideScalar(f);
// position of the parent node, if it was at the same depth as the
// child, found by multiplying the tree position by the factor
position.copy(this).multiplyScalar(f);
// difference in position between the two nodes, at child depth, and
// scale it using the size
translation.subVectors(childNode, position).multiply(size);
// apply the translation to the child node bbox
childVoxelBBox.min.add(translation);
// use the size computed above to set the max
childVoxelBBox.max.copy(childVoxelBBox.min).add(size);
childNode.voxelOBB.setFromBox3(childVoxelBBox).projOBB(this.source.crs, this.crs);
// get a clamped bbox from the voxel bbox
childNode.clampOBB.copy(childNode.voxelOBB).clampZ(this.source.zmin, this.source.zmax);
(this.clampOBB.parent as Group).add(childNode.clampOBB);
childNode.voxelOBB.updateMatrixWorld(true);
childNode.clampOBB.updateMatrixWorld(true);
}
}
export default LasNodeBase;