MCPcopy Create free account
hub / github.com/dcharatan/flowmap / render_background_scene_flow

Function render_background_scene_flow

paper/render_point_cloud.py:170–230  ·  view source on GitHub ↗
(
    device: torch.device,
    birds: LoadedScene,
    proj: Callable,
    background_mask: Bool[Tensor, "height width"],
)

Source from the content-addressed store, hash-verified

168
169
170def render_background_scene_flow(
171 device: torch.device,
172 birds: LoadedScene,
173 proj: Callable,
174 background_mask: Bool[Tensor, "height width"],
175) -> None:
176 # Render the background points and lines.
177 mask = background_mask & (~birds.highlight_mask)
178 xyz_background_original = birds.xyz_camera_space[0][mask]
179 num_points = xyz_background_original.shape[0]
180 xyz_background_other = einsum(
181 birds.exports.extrinsics[0, SECOND_FRAME].inverse(),
182 homogenize_points(xyz_background_original),
183 "i j, p j -> p i",
184 )[..., :3]
185 xyz_background = torch.cat((xyz_background_original, xyz_background_other), dim=0)
186 is_other_background = (
187 torch.zeros((num_points,), dtype=torch.bool, device=device),
188 torch.ones((num_points,), dtype=torch.bool, device=device),
189 )
190 is_other_background = torch.cat(is_other_background, dim=0)
191 xy_background, ordering_background = proj(xyz_background)
192 lines_background = rearrange(xy_background, "(e l) xy -> l e xy", e=2)
193 xy_background = xy_background[ordering_background]
194 is_other_background = is_other_background[ordering_background]
195
196 # Export to SVG.
197 fig = svg.SVG(
198 width=CANVAS_SIZE,
199 height=CANVAS_SIZE,
200 elements=[],
201 viewBox=svg.ViewBoxSpec(0, 0, CANVAS_SIZE, CANVAS_SIZE),
202 )
203
204 # Draw the connecting lines.
205 for start, end in lines_background.tolist():
206 line = svg.Line(
207 x1=start[0],
208 y1=start[1],
209 x2=end[0],
210 y2=end[1],
211 stroke="#cccccc",
212 stroke_width=4,
213 stroke_linecap="round",
214 )
215 fig.elements.append(line)
216
217 # Draw the endpoints.
218 for (x, y), is_background in zip(xy_background.tolist(), is_other_background):
219 line = svg.Line(
220 x1=x,
221 y1=y,
222 x2=x,
223 y2=y,
224 stroke=DISTINCT_COLORS[1 if is_background else 0],
225 stroke_width=12,
226 stroke_linecap="round",
227 )

Callers

nothing calls this directly

Calls 3

homogenize_pointsFunction · 0.90
save_svgFunction · 0.85
catMethod · 0.80

Tested by

no test coverage detected