-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[viz] Use inlined byte array for heatmap png; remove VTK as dep (#307)
- Loading branch information
1 parent
5e77466
commit dc2f2e4
Showing
7 changed files
with
68 additions
and
55 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
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,9 @@ | ||
// AUTOGENERATED, DO NOT EDIT | ||
{ | ||
137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 4, 0, 0, | ||
0, 0, 1, 8, 2, 0, 0, 0, 207, 108, 75, 98, 0, 0, 0, 44, 73, 68, 65, 84, | ||
120, 156, 237, 212, 193, 13, 0, 48, 12, 194, 64, 188, 255, 208, 205, 167, | ||
91, 216, 209, 45, 0, 72, 97, 255, 72, 148, 198, 158, 150, 60, 126, 232, | ||
247, 155, 181, 62, 85, 16, 175, 3, 112, 247, 1, 14, 225, 11, 252, 43, 0, | ||
0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130, | ||
} |
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,54 @@ | ||
#!/usr/bin/env python | ||
""" | ||
PNG encoding of a heatmap for hydroelastic. | ||
Requires Python, PIL, and NumPy. | ||
""" | ||
|
||
import io | ||
import os | ||
|
||
import numpy as np | ||
from PIL import Image | ||
|
||
|
||
def main(): | ||
h = 1 | ||
w = 1024 | ||
c = 3 | ||
array = np.zeros((h, w, c), dtype=np.uint8) | ||
values = np.linspace(0, 1, w) | ||
|
||
red = np.clip((values - 0.25) * 4.0, 0.0, 1.0) | ||
green = np.clip((values - 0.5) * 4.0, 0.0, 1.0) | ||
blue = np.clip(1.0 - (values - 0.25) * 4.0, 0.0, 1.0) | ||
mask = values < 0.25 | ||
blue[mask] = np.clip(values[mask] * 4.0, 0.0, 1.0) | ||
mask = values > 0.75 | ||
blue[mask] = np.clip((values[mask] - 0.75) * 4.0, 0.0, 1.0) | ||
mask = values > 0.75 | ||
|
||
array[0, :, 0] = red * 255.0 | ||
array[0, :, 1] = green * 255.0 | ||
array[0, :, 2] = blue * 255.0 | ||
|
||
image = Image.fromarray(array) | ||
stream = io.BytesIO() | ||
image.save(stream, format='png') | ||
raw = stream.getvalue() | ||
|
||
out = "// AUTOGENERATED, DO NOT EDIT\n" | ||
out += "{\n" | ||
for byte in raw: | ||
out += str(int(byte)) + ", " | ||
out += "\n}\n" | ||
|
||
os.chdir(os.path.dirname(__file__)) | ||
with open("heatmap_png.inc", "w") as f: | ||
f.write(out) | ||
|
||
print("This may need to get reformatted by ament_clang_format") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |