-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cesium: allow using rangefinder depth for color coding, initial version
- Loading branch information
1 parent
bdbede9
commit 2539f71
Showing
3 changed files
with
159 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Color } from 'cesium' | ||
|
||
export default class ColorCoderRange { | ||
requiredMessages = ['RFND'] | ||
lastindex = 0 // lets track this so we are more efficient | ||
maxDist = 3 | ||
constructor (state) { | ||
this.state = state | ||
} | ||
|
||
getLegend () { | ||
const legend = [ | ||
{ | ||
name: 'shallow', | ||
color: 'rgb(0, 0, 255)' | ||
}, | ||
{ | ||
name: 'deep', | ||
color: 'rgb(255, 0, 0)' | ||
} | ||
] | ||
return legend | ||
} | ||
|
||
getMax () { | ||
this.maxDist = 0 | ||
for (const dist of this.state.messages.RFND.Dist) { | ||
if (dist > this.maxDist) { | ||
this.maxDist = dist | ||
} | ||
} | ||
} | ||
|
||
getColor (time) { | ||
if (this.maxDist === 0) { | ||
this.getMax() | ||
} | ||
if (this.state.messages.RFND.time_boot_ms[this.lastindex] - time > 1000) { | ||
this.lastindex = 0 | ||
} | ||
while (this.state.messages.RFND.time_boot_ms[this.lastindex] < time && | ||
this.lastindex < this.state.messages.RFND.time_boot_ms.length - 1) { | ||
this.lastindex++ | ||
} | ||
const color = this.state.messages.RFND.Dist[this.lastindex] / this.maxDist | ||
return new Color(1 - color, 0, color) | ||
} | ||
} |