-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathindex.ts
More file actions
149 lines (139 loc) · 5.07 KB
/
Copy pathindex.ts
File metadata and controls
149 lines (139 loc) · 5.07 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { TriangleListPrimitive, Time } from "@foxglove/schemas";
import { LaneBoundary, LaneBoundary_Classification_Type, Lane } from "@lichtblick/asam-osi-types";
import {
pointListToTriangleListPrimitive,
laneToTriangleListPrimitive,
MarkerPoint,
} from "@utils/primitives/lines";
import { PartialSceneEntity, generateSceneEntityId } from "@utils/scene";
import { DeepRequired } from "ts-essentials";
import { buildLaneBoundaryMetadata, buildLaneMetadata } from "./metadata";
import {
LANE_CENTERLINE_COLOR,
LANE_CENTERLINE_WIDTH,
LANE_CENTERLINE_ARROWS,
LANE_CENTERLINE_SHOW,
LANE_VISUALIZATION_WIDTH,
LANE_TYPE,
LANE_COLOR_HIGHLIGHT,
LANE_BOUNDARY_COLOR,
LANE_BOUNDARY_OPACITY,
LANE_BOUNDARY_MIN_RENDERING_WIDTH,
LANE_BOUNDARY_ARROWS,
} from "@/config/constants";
import { PREFIX_LANE_BOUNDARY, PREFIX_LANE } from "@/config/entityPrefixes";
/**
* Builds a PartialSceneEntity representing an OSI lane boundary.
*
* @param osiLaneBoundary - The OSI object, which can be either a MovingObject or a StationaryObject.
* @param frame_id - The frame ID to be used for the entity.
* @param time - The timestamp for the entity.
* @returns A PartialSceneEntity representing the object.
*/
export function buildLaneBoundaryEntity(
osiLaneBoundary: DeepRequired<LaneBoundary>,
frame_id: string,
time: Time,
): PartialSceneEntity {
// Create LaneBoundaryPoint objects using only necessary fields for rendering
const laneBoundaryPoints = osiLaneBoundary.boundary_line.map((point) => {
return {
position: { x: point.position.x, y: point.position.y, z: point.position.z },
width: point.width === 0 ? LANE_BOUNDARY_MIN_RENDERING_WIDTH : point.width, // prevent zero-width lane boundaries from being invisible
height: point.height,
dash: point.dash,
};
});
// Define color and opacity based on OSI classification
const rgb = LANE_BOUNDARY_COLOR[osiLaneBoundary.classification.color];
const a = LANE_BOUNDARY_OPACITY[osiLaneBoundary.classification.type];
const color = { r: rgb.r, g: rgb.g, b: rgb.b, a };
// Set option for dashed lines
const options = {
dashed: osiLaneBoundary.classification.type === LaneBoundary_Classification_Type.DASHED_LINE,
arrows: LANE_BOUNDARY_ARROWS,
invertArrows: false,
};
return {
timestamp: time,
frame_id,
id: generateSceneEntityId(PREFIX_LANE_BOUNDARY, osiLaneBoundary.id.value),
lifetime: { sec: 0, nsec: 0 },
frame_locked: true,
triangles: [pointListToTriangleListPrimitive(laneBoundaryPoints, color, options)],
metadata: buildLaneBoundaryMetadata(osiLaneBoundary),
};
}
export function buildLaneEntity(
osiLane: DeepRequired<Lane>,
frame_id: string,
time: Time,
osiLeftLaneBoundaries: DeepRequired<LaneBoundary>[],
osiRightLaneBoundaries: DeepRequired<LaneBoundary>[],
): PartialSceneEntity {
const leftLaneBoundaries: MarkerPoint[][] = [];
for (const lb of osiLeftLaneBoundaries) {
const laneBoundaryPoints = lb.boundary_line.map((point) => {
return {
position: { x: point.position.x, y: point.position.y, z: point.position.z },
width: point.width === 0 ? LANE_BOUNDARY_MIN_RENDERING_WIDTH : point.width, // prevent zero-width lane boundaries from being invisible
height: point.height,
dash: point.dash,
};
});
leftLaneBoundaries.push(laneBoundaryPoints);
}
const rightLaneBoundaries: MarkerPoint[][] = [];
for (const lb of osiRightLaneBoundaries) {
const laneBoundaryPoints = lb.boundary_line.map((point) => {
return {
position: { x: point.position.x, y: point.position.y, z: point.position.z },
width: point.width === 0 ? LANE_BOUNDARY_MIN_RENDERING_WIDTH : point.width, // prevent zero-width lane boundaries from being invisible
height: point.height,
dash: point.dash,
};
});
rightLaneBoundaries.push(laneBoundaryPoints);
}
let centerlineTrianglePrimitive: TriangleListPrimitive | undefined;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (LANE_CENTERLINE_SHOW) {
const centerlinePoints = osiLane.classification.centerline.map((point) => {
return {
position: { x: point.x, y: point.y, z: point.z },
width: LANE_CENTERLINE_WIDTH,
height: 0,
};
});
centerlineTrianglePrimitive = pointListToTriangleListPrimitive(
centerlinePoints,
LANE_CENTERLINE_COLOR,
{
dashed: false,
arrows: LANE_CENTERLINE_ARROWS,
invertArrows: !osiLane.classification.centerline_is_driving_direction,
},
);
}
let color = LANE_TYPE[osiLane.classification.type];
if (osiLane.classification.is_host_vehicle_lane) {
color = LANE_COLOR_HIGHLIGHT;
}
return {
timestamp: time,
frame_id,
id: generateSceneEntityId(PREFIX_LANE, osiLane.id.value),
lifetime: { sec: 0, nsec: 0 },
frame_locked: true,
triangles: [
laneToTriangleListPrimitive(
leftLaneBoundaries,
rightLaneBoundaries,
color,
LANE_VISUALIZATION_WIDTH,
),
centerlineTrianglePrimitive,
],
metadata: buildLaneMetadata(osiLane),
};
}