Skip to content

Commit 733b413

Browse files
committed
add render of density distance hits normals
1 parent cff6b6a commit 733b413

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

threedgrut/utils/viser_gui_util.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -309,36 +309,37 @@ def update_render_view(self, client, force: bool = False):
309309
client.scene.set_background_image(rgb_np)
310310
elif style == "density":
311311
# Convert density to grayscale image
312-
density_np = to_np(sple_odns[0]) # Remove batch dimension
313-
# Normalize to 0-1 range for visualization
314-
density_np = np.clip(density_np, 0, 1)
315-
# Convert to RGB by repeating the channel
316-
rgb_np = np.stack([density_np, density_np, density_np], axis=-1)
317-
client.scene.set_background_image(rgb_np)
312+
density_np = to_np(sple_odns)
313+
density_255 = 255 * (density_np - density_np.min()) / (density_np.max() - density_np.min() + 1e-8)
314+
density_255 = density_255.astype(np.uint8)
315+
img = np.repeat(density_255[0], 3, axis=2)
316+
client.scene.set_background_image(img)
317+
318318
elif style == "distance":
319-
# Convert distance to grayscale image
320-
distance_np = to_np(sple_odist[0]) # Remove batch dimension
321-
# Apply scale factor like polyscope version
322-
distance_np = (distance_np * self.viz_render_style_scale) / np.clip(to_np(sple_odns[0]), 1e-06, None)
323-
# Normalize to 0-1 range
324-
distance_np = np.clip(distance_np, 0, 1)
325-
# Convert to RGB by repeating the channel
326-
rgb_np = np.stack([distance_np, distance_np, distance_np], axis=-1)
327-
client.scene.set_background_image(rgb_np)
319+
distance_np = to_np(sple_odist)
320+
distance_255 = 255 * (distance_np - distance_np.min()) / (distance_np.max() - distance_np.min() + 1e-8)
321+
distance_255 = distance_255.astype(np.uint8)
322+
img = np.repeat(distance_255[0], 3, axis=2)
323+
img[:, :, 1:] = 0
324+
client.scene.set_background_image(img)
325+
326+
328327
elif style == "hits":
329328
# Convert hits count to grayscale image
330-
hits_np = to_np(sple_ohit[0]) # Remove batch dimension
331-
# Normalize to 0-1 range
332-
hits_np = np.clip(hits_np, 0, 1)
333-
# Convert to RGB by repeating the channel
334-
rgb_np = np.stack([hits_np, hits_np, hits_np], axis=-1)
335-
client.scene.set_background_image(rgb_np)
329+
hits_np = to_np(sple_ohit)
330+
hits_255 = 255 * (hits_np - hits_np.min()) / (hits_np.max() - hits_np.min() + 1e-8)
331+
hits_255 = hits_255.astype(np.uint8)
332+
img = np.repeat(hits_255[0], 3, axis=2)
333+
img[:, :, 2:] = 0
334+
client.scene.set_background_image(img)
336335
elif style == "normals":
337336
# Convert normals to RGB image
338-
normals_np = to_np(sple_onrm[0]) # Remove batch dimension
339-
# Scale from [-1,1] to [0,1] like polyscope version
340-
normals_np = 0.5 * (normals_np + 1)
341-
client.scene.set_background_image(normals_np)
337+
normals_np = to_np(sple_onrm)
338+
normals_255 = 255 * (normals_np - normals_np.min()) / (normals_np.max() - normals_np.min() + 1e-8)
339+
normals_255 = normals_255.astype(np.uint8)
340+
img = np.repeat(normals_255[0], 3, axis=2)
341+
# img[:, :, 0] = 0
342+
client.scene.set_background_image(img)
342343

343344
def block_in_rendering_loop(self, fps: int = 60):
344345
"""Block in rendering loop"""

0 commit comments

Comments
 (0)