Skip to content

Commit b7cd59b

Browse files
committedJul 26, 2023
changed object id logic
1 parent 0f65850 commit b7cd59b

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed
 

‎builder.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from jax import numpy as np, tree_map
2-
from raymarch import Objects, Camera, OBJECT_IDX
2+
from raymarch import Objects, Camera, OBJECTS
33

44
# typing
55
from typeguard import check_type
@@ -18,7 +18,7 @@ class ObjectDict(TypedDict):
1818
color: Tuple[float, float, float]
1919
position: Tuple[float, float, float]
2020
rotation: Tuple[float, float, float]
21-
mirror: Tuple[float, float, float]
21+
mirror: Tuple[int, int, int]
2222
rounding: float
2323

2424

@@ -57,7 +57,7 @@ def check_scene_dict(scene_dict: Dict[str, Any]) -> SceneDict:
5757
# checking the obj_names and adding default values where needed
5858
for i in range(len(scene_dict['Objects'])):
5959
obj_name, obj_dict = next(iter(scene_dict['Objects'][i].items())) # first item of dict
60-
assert obj_name in OBJECT_IDX, f'Unknown object name {obj_name}'
60+
assert obj_name in OBJECTS, f'Unknown object name {obj_name}'
6161
scene_dict['Objects'][i] = (obj_name, add_obj_dict_defaults(**obj_dict))
6262

6363
return check_type(scene_dict, SceneDict)
@@ -72,7 +72,7 @@ def build_scene(scene_dict: SceneDict) -> Dict[str, Any]:
7272
obj_args['mirrorings'] = obj_args.pop('mirrors').astype(np.bool_) # convert mirrorings
7373
return {
7474
'objects': Objects(
75-
object_ids=np.uint8([OBJECT_IDX[o] for o in obj_names]), # type: ignore
75+
ids=np.uint8([OBJECTS.index(o) for o in obj_names]), # type: ignore
7676
**obj_args,
7777
smoothing=np.float32(scene_dict['smoothing']),
7878
),

‎raymarch.py

+5-13
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,7 @@ def sdf_ellipsoid(p: Vec3, r: Vec3) -> Scalar:
4242
return k0 * (k0 - 1) / k1
4343

4444

45-
OBJECT_IDX = {
46-
'Box': 0,
47-
'Sphere': 1,
48-
'Plane': 2,
49-
'Torus': 3,
50-
'Ellipsoid': 4,
51-
}
45+
OBJECTS = ('Box', 'Sphere', 'Plane', 'Torus', 'Ellipsoid')
5246
BRANCHES = (sdf_box, sdf_sphere, sdf_plane, sdf_torus, sdf_ellipsoid)
5347

5448

@@ -74,7 +68,7 @@ def __call__(self, view_size: Tuple[int, int]) -> Vec3s:
7468

7569

7670
class Objects(NamedTuple):
77-
object_ids: UInts
71+
ids: UInts
7872
positions: Vec3s
7973
attributes: Vec3s
8074
rotations: Vec3s
@@ -84,15 +78,13 @@ class Objects(NamedTuple):
8478
smoothing: Scalar
8579

8680
def sdfs(self, p: Vec3) -> Scalars:
87-
def switch(
88-
p: Vec3, obj_idx: UInt, pos: Vec3, attr: Vec3, rot: Vec3, mirror: Bool3
89-
) -> Scalar:
81+
def switch(p: Vec3, id: UInt, pos: Vec3, attr: Vec3, rot: Vec3, mirror: Bool3) -> Scalar:
9082
p = np.where(mirror, smoothabs(p, 1e-3), p)
9183
p = (p - pos) @ Rxyz(rot)
92-
return lax.switch(obj_idx, BRANCHES, p, attr)
84+
return lax.switch(id, BRANCHES, p, attr)
9385

9486
dists = vmap(partial(switch, p))(
95-
self.object_ids,
87+
self.ids,
9688
self.positions,
9789
self.attributes,
9890
self.rotations,

‎tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from matplotlib import pyplot as plt
66
from raymarch import render_scene, RenderedImages
77
from builder import build_scene, check_scene_dict, SceneDict
8-
from setup import SCENES_PATH
8+
from app import SCENES_PATH
99

1010

1111
def test_all_scenes():

0 commit comments

Comments
 (0)
Please sign in to comment.