TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
heat_grid.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2#pragma once
3// Coarse accumulation grid behind the viewer's heatmap overlays (design doc 09 ยง3 "Heatmap overlays", protocol
4// doc 13 `heatmap`). Visualisation only: the router writes into it while a sink is attached and never reads it
5// back, so routing results cannot depend on it (rule 2; checked by tests/integration/record_replay.py, which
6// routes with and without recording and compares the boards byte for byte).
7#include <cstdint>
8#include <string>
9#include <string_view>
10#include <vector>
11
12#include "geom/point.hpp"
13
14namespace tmk::route {
15
16class HeatGrid {
17 public:
18 // At most this many cells along the longer side: a 128 x 128 overlay is ~16k values per message, small
19 // enough to resend every few hundred thousand expansions without slowing the router or bloating recordings.
20 static constexpr int kMaxCells = 128;
21
22 // Covers `area` with square cells of at least `min_cell` nm (cell size rounded up to whole micrometres).
23 void init(const geom::Box& area, Coord min_cell);
24 bool ready() const { return w_ > 0; }
25 void clear();
26 void add(geom::Point p, std::uint64_t w); // accumulate (search effort)
27 void raise(geom::Point p, std::uint64_t v); // keep the maximum (history cost): independent of visiting order
28 std::uint64_t max() const;
29 int width() const { return w_; }
30 int height() const { return h_; }
31 Coord cell() const { return cell_; }
32 // One byte per cell, row-major: round(255 * sqrt(v / max)), at least 1 for any non-zero cell so faint activity
33 // stays visible. The square root keeps heavy-tailed counts (a few hot spots) from washing out everything else.
34 std::vector<std::uint8_t> bytes() const;
35 // The `heatmap` protocol message (layer -1 = all layers) with "scale":"sqrt" so a legend can invert it.
36 std::string message(std::string_view name, int layer) const;
37
38 private:
39 int index(geom::Point p) const;
40 Coord x0_ = 0, y0_ = 0, cell_ = 1;
41 int w_ = 0, h_ = 0;
42 std::vector<std::uint64_t> v_;
43};
44
45} // namespace tmk::route
std::string message(std::string_view name, int layer) const
The heatmap protocol message (layer -1 = all layers) with "scale":"sqrt" so a legend can invert it.
std::vector< std::uint8_t > bytes() const
One byte per cell, row-major: round(255 * sqrt(v / max)), at least 1 for any non-zero cell so faint a...
void raise(geom::Point p, std::uint64_t v)
keep the maximum (history cost): independent of visiting order
bool ready() const
Definition heat_grid.hpp:24
std::uint64_t max() const
static constexpr int kMaxCells
At most this many cells along the longer side: a 128 x 128 overlay is ~16k values per message,...
Definition heat_grid.hpp:20
void init(const geom::Box &area, Coord min_cell)
Covers area with square cells of at least min_cell nm (cell size rounded up to whole micrometres).
void add(geom::Point p, std::uint64_t w)
accumulate (search effort)
Coord cell() const
Definition heat_grid.hpp:31
std::int64_t Coord
Engine coordinate: signed 64-bit nanometres.
Definition units.hpp:12
Integer-nanometre points and KiCad-compatible rotation.