Skip to content
This repository was archived by the owner on Nov 21, 2024. It is now read-only.

Democratizing rendering #6

Merged
merged 5 commits into from
Mar 3, 2024
Merged

Conversation

giorgioangel
Copy link
Collaborator

This PR democratizes rendering with the following scripts:

  1. obj_to_ppm.py
  2. torch_ppm.py
  3. memmap_to_layers.py

obj_to_ppm.py and torch_ppm.py allow one to convert a segment mesh (.obj) into a per-pixel-map saved as a numpy memory mapped file. The conversion is very FAST. When reading the flattened UVs, the centroid of each triangle face is batch computed using torch, and a KDTree is built on this structure. A grid of new points is added in 2D at integer locations. These points will be the pixels of the rendered image. The KDTree is queried to quickly identify the M (--tri_batch parameter) closest triangles to each point. In a batched and parallelized way, always using torch, the barycentric coordinates for every point in each of its M candidate triangles are computed. If for some couple (point - triangle) the barycentric coordinates are in [0,1] and sum up to 1, then the said pair is chosen. Always in a batched and parallelized way with torch, exploiting the barycentric coordinates, the position (and normals) in the 3D scroll volume are obtained by barycentric interpolation. Periodically (and automatically lol) the computed information for the batches is flushed into the ppm memmap.

memmap_to_layers.py is a modification of Julian's ppm_to_layers.py. It reads the saved ppm that is saved as a numpy memmap in batches, exploiting the slicing properties of a numpy array, and updates the rendered pixels. Since the operation is batched, one can render even a huge segment on a cheap laptop (mine is an i7 with 16GB RAM and no GPU).

At the moment, GPU compatibility isn't working since I could not test it locally. But the scripts can be easily readapted to make it work.

Bonus ppm_writer.py could be used to save the computed ppm in the .ppm format used by Virtual Cartographer, however, the logic of obj_to_ppm.py should be changed (I was using it in an older version, before switching to numpy memmap).

@schillij95 schillij95 merged commit caa3237 into schillij95:main Mar 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants