@ -79,6 +79,7 @@ export const movingColor = (p) => p.color(255, 0, 255); // Magenta
* @ param { object } plotScales - The calculated scales for plotting .
* @ param { object } plotScales - The calculated scales for plotting .
* /
* /
export function drawStaticRegionsToBuffer ( p , b , plotScales ) {
export function drawStaticRegionsToBuffer ( p , b , plotScales ) {
try {
b . clear ( ) ;
b . clear ( ) ;
// 1. Draw Axes (Grid)
// 1. Draw Axes (Grid)
@ -129,10 +130,14 @@ export function drawStaticRegionsToBuffer(p, b, plotScales) {
b . drawingContext . setLineDash ( [ ] ) ;
b . drawingContext . setLineDash ( [ ] ) ;
b . pop ( ) ;
b . pop ( ) ;
} catch ( error ) {
console . error ( "Error in drawStaticRegionsToBuffer:" , error ) ;
}
}
}
export function drawAxes ( p , plotScales ) {
export function drawAxes ( p , plotScales ) {
try {
p . push ( ) ;
p . push ( ) ;
// Determine axis and text colors based on the current theme (dark/light mode).
// Determine axis and text colors based on the current theme (dark/light mode).
const axisColor = document . documentElement . classList . contains ( "dark" )
const axisColor = document . documentElement . classList . contains ( "dark" )
@ -209,10 +214,14 @@ export function drawAxes(p, plotScales) {
p . pop ( ) ;
p . pop ( ) ;
}
}
p . pop ( ) ;
p . pop ( ) ;
} catch ( error ) {
console . error ( "Error in drawAxes:" , error ) ;
}
}
}
export function drawPointCloud ( p , points , plotScales ) {
export function drawPointCloud ( p , points , plotScales ) {
try {
// Set stroke weight for points.
// Set stroke weight for points.
p . strokeWeight ( 4 ) ;
p . strokeWeight ( 4 ) ;
// Get state of various toggles from the DOM.
// Get state of various toggles from the DOM.
@ -300,9 +309,13 @@ export function drawPointCloud(p, points, plotScales) {
p . point ( pt . x * plotScales . plotScaleX , pt . y * plotScales . plotScaleY ) ;
p . point ( pt . x * plotScales . plotScaleX , pt . y * plotScales . plotScaleY ) ;
}
}
}
}
} catch ( error ) {
console . error ( "Error in drawPointCloud:" , error ) ;
}
}
}
export function drawTrajectories ( p , plotScales ) {
export function drawTrajectories ( p , plotScales ) {
try {
const localTtcColors = ttcColors ( p ) ;
const localTtcColors = ttcColors ( p ) ;
for ( const track of appState . vizData . tracks ) {
for ( const track of appState . vizData . tracks ) {
@ -376,10 +389,13 @@ export function drawTrajectories(p, plotScales) {
// MODE 2: DEFAULT TTC SCHEME (Use pre-calculated category from JSON)
// MODE 2: DEFAULT TTC SCHEME (Use pre-calculated category from JSON)
// FIND the TTC category from the new timeline
// FIND the TTC category from the new timeline
let ttcCategory = null ;
if ( track . ttcCategoryTimeline ) {
const ttcEntry = track . ttcCategoryTimeline . find (
const ttcEntry = track . ttcCategoryTimeline . find (
( entry ) => entry . frameIdx === lastLog . frameIdx
( entry ) => entry . frameIdx === lastLog . frameIdx
) ;
) ;
const ttcCategory = ttcEntry ? ttcEntry . ttcCategory : null ; // Get the category if found
ttcCategory = ttcEntry ? ttcEntry . ttcCategory : null ; // Get the category if found
}
switch ( ttcCategory ) {
switch ( ttcCategory ) {
case 3 :
case 3 :
@ -426,9 +442,13 @@ export function drawTrajectories(p, plotScales) {
p . pop ( ) ; // This was the missing pop call for each trajectory loop
p . pop ( ) ; // This was the missing pop call for each trajectory loop
}
}
} catch ( error ) {
console . error ( "Error in drawTrajectories:" , error ) ;
}
}
}
export function drawTrackMarkers ( p , plotScales ) {
export function drawTrackMarkers ( p , plotScales ) {
try {
const showDetails = toggleVelocity . checked ;
const showDetails = toggleVelocity . checked ;
const useStationary = toggleStationaryColor . checked ;
const useStationary = toggleStationaryColor . checked ;
const textColor = document . documentElement . classList . contains ( "dark" )
const textColor = document . documentElement . classList . contains ( "dark" )
@ -533,10 +553,14 @@ export function drawTrackMarkers(p, plotScales) {
}
}
p . pop ( ) ;
p . pop ( ) ;
}
}
} catch ( error ) {
console . error ( "Error in drawTrackMarkers:" , error ) ;
}
}
}
export function handleCloseUpDisplay ( p , plotScales , mouseX , mouseY ) {
export function handleCloseUpDisplay ( p , plotScales , mouseX , mouseY ) {
try {
// --- Step 1: Gather Hovered Items ---
// --- Step 1: Gather Hovered Items ---
const frameData = appState . vizData . radarFrames [ appState . currentFrame ] ;
const frameData = appState . vizData . radarFrames [ appState . currentFrame ] ;
if ( ! frameData ) return [ ] ; // Return empty array if no data
if ( ! frameData ) return [ ] ; // Return empty array if no data
@ -819,6 +843,10 @@ export function handleCloseUpDisplay(p, plotScales, mouseX, mouseY) {
// Return the list of hovered items for other functions (like the zoom window) to use.
// Return the list of hovered items for other functions (like the zoom window) to use.
return hoveredItems ;
return hoveredItems ;
} catch ( error ) {
console . error ( "Error in handleCloseUpDisplay:" , error ) ;
return [ ] ;
}
}
}
export function drawCovarianceEllipse (
export function drawCovarianceEllipse (
@ -829,6 +857,7 @@ export function drawCovarianceEllipse(
plotScales ,
plotScales ,
isStationary
isStationary
) {
) {
try {
// Only draw the ellipse for tracks that are not stationary.
// Only draw the ellipse for tracks that are not stationary.
if ( isStationary ) return ;
if ( isStationary ) return ;
const [ radiusA , radiusB ] = radii ;
const [ radiusA , radiusB ] = radii ;
@ -849,10 +878,14 @@ export function drawCovarianceEllipse(
radiusB * 2 * plotScales . plotScaleY // in p5 library expect
radiusB * 2 * plotScales . plotScaleY // in p5 library expect
) ;
) ;
p . pop ( ) ;
p . pop ( ) ;
} catch ( error ) {
console . error ( "Error in drawCovarianceEllipse:" , error ) ;
}
}
}
export function drawEgoVehicle ( p , plotScales ) {
export function drawEgoVehicle ( p , plotScales ) {
try {
const isDark = document . documentElement . classList . contains ( "dark" ) ;
const isDark = document . documentElement . classList . contains ( "dark" ) ;
const carColor = isDark ? p . color ( 150 , 150 , 220 ) : p . color ( 151 , 151 , 220 ) ;
const carColor = isDark ? p . color ( 150 , 150 , 220 ) : p . color ( 151 , 151 , 220 ) ;
@ -869,9 +902,13 @@ export function drawEgoVehicle(p, plotScales) {
p . rect ( 0 , - 10 , carWidthPixels , carLengthPixels , 5 ) ;
p . rect ( 0 , - 10 , carWidthPixels , carLengthPixels , 5 ) ;
p . pop ( ) ;
p . pop ( ) ;
} catch ( error ) {
console . error ( "Error in drawEgoVehicle:" , error ) ;
}
}
}
export function drawRegionsOfInterest ( p , frameData , plotScales ) {
export function drawRegionsOfInterest ( p , frameData , plotScales ) {
try {
// --- THIS CHECK IS ESSENTIAL AND MUST NOT BE REMOVED ---
// --- THIS CHECK IS ESSENTIAL AND MUST NOT BE REMOVED ---
// It gracefully handles frames that do not have the barrier data.
// It gracefully handles frames that do not have the barrier data.
if ( ! frameData || ! frameData . filtered_barrier_x ) {
if ( ! frameData || ! frameData . filtered_barrier_x ) {
@ -918,9 +955,13 @@ export function drawRegionsOfInterest(p, frameData, plotScales) {
) ;
) ;
p . pop ( ) ;
p . pop ( ) ;
} catch ( error ) {
console . error ( "Error in drawRegionsOfInterest:" , error ) ;
}
}
}
export function drawClusterCentroids ( p , clustersInput , plotScales ) {
export function drawClusterCentroids ( p , clustersInput , plotScales ) {
try {
if ( ! clustersInput ) {
if ( ! clustersInput ) {
return ; // Do nothing if there's no cluster data
return ; // Do nothing if there's no cluster data
}
}
@ -977,4 +1018,7 @@ export function drawClusterCentroids(p, clustersInput, plotScales) {
p . pop ( ) ;
p . pop ( ) ;
}
}
}
}
} catch ( error ) {
console . error ( "Error in drawClusterCentroids:" , error ) ;
}
}
}