Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ __pycache__/
.vscode/
doc/_build/
doc/**/figures/*.svg
doc/_extra/
# Drawn by doc/banner.py at build time; the other files in doc/_extra are committed
doc/_extra/banner.png
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

**[Read the book](https://shisatoyano.github.io/AutonomousVehicleControlBeginnersGuide/)** · **[See all simulations](/doc/EXAMPLES.md)** · **[Quick start](#quick-start)**

<!-- The same demos as doc/social_preview.py, which draws the social preview image from them -->
<!-- The same demos as doc/banner.py, which draws the banner of the book's front page from them -->
<table>
<tr>
<td align="center" width="33%"><img src="src/simulations/localization/ekf_ukf_pf_comparison/ekf_ukf_pf_comparison.gif" alt="Localization: EKF vs UKF vs PF" width="260"><br><a href="https://shisatoyano.github.io/AutonomousVehicleControlBeginnersGuide/localization/index.html">Localization: EKF vs UKF vs PF</a></td>
Expand Down
Binary file added doc/_extra/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/_extra/social_preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions doc/banner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""
banner.py

Draws the banner of the book's front page (1280x360 px): a frame of the first four demos
shown at the top of the README. The book build saves it in doc/_extra

Author: Shisato Yano
"""

from pathlib import Path

import matplotlib.pyplot as plt
from PIL import Image, ImageChops

REPO_DIR = Path(__file__).absolute().parent.parent

# The same demos, in the same order, as the grid at the top of README.md (the banner shows the first four)
DEMOS = [
("Localization: EKF vs UKF vs PF", "localization/ekf_ukf_pf_comparison/ekf_ukf_pf_comparison.gif"),
("Path tracking: MPPI", "path_tracking/mppi_path_tracking/mppi_path_tracking.gif"),
("Path planning: Hybrid A*", "path_planning/astar_hybrid_path_planning/astar_hybrid_navigate.gif"),
("Mapping: NDT", "mapping/ndt_map_construction/ndt_map_construction.gif"),
("Mapping: cost map", "mapping/cost_grid_map_construction/cost_grid_map_construction.gif"),
("Perception: rectangle fitting", "perception/point_cloud_rectangle_fitting/point_cloud_rectangle_fitting.gif"),
]


def frame(gif_path: Path) -> Image.Image:
"""A frame two thirds into the demo, when the result is mostly drawn, without its white margins"""
gif = Image.open(gif_path)
gif.seek(gif.n_frames * 2 // 3)
image = gif.convert("RGB")
# Some demos have an off-white background, so nearly white counts as margin too
difference = ImageChops.difference(image, Image.new("RGB", image.size, "white")).convert("L")
content = difference.point(lambda value: 255 if value > 16 else 0).getbbox()
return image.crop(content) if content else image


def draw_banner(out_path: Path) -> None:
"""Save the banner of the front page (1280x360 px): the first four demos"""
fig = plt.figure(figsize=(12.8, 3.6), dpi=100, facecolor="white")
for i, (label, gif) in enumerate(DEMOS[:4]):
left = 0.01 + i * 0.25
ax = fig.add_axes((left, 0.02, 0.23, 0.74))
ax.imshow(frame(REPO_DIR / "src" / "simulations" / gif))
ax.set_axis_off()
# The banner is shown at about half its width, so the labels are large and on two lines
fig.text(left + 0.115, 0.88, label.replace(": ", "\n"), ha="center", va="center",
fontsize=20, linespacing=1.3, color="#1f2933")

out_path.parent.mkdir(parents=True, exist_ok=True)
fig.savefig(out_path, dpi=100, facecolor="white")
plt.close(fig)


if __name__ == "__main__":
extra_dir = Path(__file__).absolute().parent / "_extra"
draw_banner(extra_dir / "banner.png")
15 changes: 7 additions & 8 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@
html_title = "Autonomous Vehicle Control Beginners Guide"
html_theme_options = {
"navigation_depth": 3,
# The logo already shows the title, which the theme would otherwise repeat above it
"logo_only": True,
}
templates_path = ["_templates"]
# Drawn by social_preview.py at build time, like the banner of the front page
html_logo = "_extra/logo.png"

# Search engines and link previews: canonical URLs and sitemap.xml come from html_baseurl,
Expand All @@ -53,7 +54,7 @@
ogp_site_url = BOOK_URL
ogp_site_name = html_title
ogp_description_length = 160
# Drawn by social_preview.py at build time; also uploaded as the repository's social preview
# The preview image is also uploaded as the repository's social preview
html_extra_path = ["_extra"]
html_static_path = ["_static"]
html_css_files = ["custom.css"]
Expand Down Expand Up @@ -159,12 +160,10 @@ def set_front_page_context(app: Sphinx, pagename: str, templatename: str,
context["metatags"] += f'\n<meta name="google-site-verification" content="{GOOGLE_SITE_VERIFICATION}" />'


def draw_social_preview(app: Sphinx, config) -> None:
import social_preview
def draw_banner(app: Sphinx, config) -> None:
import banner

social_preview.draw(DOC_DIR / "_extra" / "social_preview.png")
social_preview.draw_banner(DOC_DIR / "_extra" / "banner.png")
social_preview.draw_logo(DOC_DIR / "_extra" / "logo.png")
banner.draw_banner(DOC_DIR / "_extra" / "banner.png")


def draw_figures(app: Sphinx) -> None:
Expand All @@ -191,7 +190,7 @@ def draw_figures(app: Sphinx) -> None:
def setup(app: Sphinx) -> None:
app.connect("builder-inited", draw_figures)
# Before Sphinx checks that html_extra_path exists (priority 800)
app.connect("config-inited", draw_social_preview, priority=100)
app.connect("config-inited", draw_banner, priority=100)
app.connect("source-read", rewrite_links)
app.connect("source-read", add_section_toctree)
app.connect("html-page-context", set_front_page_context)
162 changes: 0 additions & 162 deletions doc/social_preview.py

This file was deleted.

Loading