differt 0.8.1__tar.gz → 0.8.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. {differt-0.8.1 → differt-0.8.2}/PKG-INFO +3 -3
  2. {differt-0.8.1 → differt-0.8.2}/README.md +1 -1
  3. {differt-0.8.1 → differt-0.8.2}/pyproject.toml +1 -1
  4. {differt-0.8.1 → differt-0.8.2}/src/differt/geometry/_triangle_mesh.py +469 -2
  5. {differt-0.8.1 → differt-0.8.2}/src/differt/rt/_image_method.py +0 -2
  6. {differt-0.8.1 → differt-0.8.2}/.gitignore +0 -0
  7. {differt-0.8.1 → differt-0.8.2}/LICENSE.md +0 -0
  8. {differt-0.8.1 → differt-0.8.2}/src/differt/__init__.py +0 -0
  9. {differt-0.8.1 → differt-0.8.2}/src/differt/_version.py +0 -0
  10. {differt-0.8.1 → differt-0.8.2}/src/differt/em/__init__.py +0 -0
  11. {differt-0.8.1 → differt-0.8.2}/src/differt/em/_antenna.py +0 -0
  12. {differt-0.8.1 → differt-0.8.2}/src/differt/em/_constants.py +0 -0
  13. {differt-0.8.1 → differt-0.8.2}/src/differt/em/_fresnel.py +0 -0
  14. {differt-0.8.1 → differt-0.8.2}/src/differt/em/_interaction_type.py +0 -0
  15. {differt-0.8.1 → differt-0.8.2}/src/differt/em/_material.py +0 -0
  16. {differt-0.8.1 → differt-0.8.2}/src/differt/em/_utd.py +0 -0
  17. {differt-0.8.1 → differt-0.8.2}/src/differt/em/_utils.py +0 -0
  18. {differt-0.8.1 → differt-0.8.2}/src/differt/geometry/__init__.py +0 -0
  19. {differt-0.8.1 → differt-0.8.2}/src/differt/geometry/_paths.py +0 -0
  20. {differt-0.8.1 → differt-0.8.2}/src/differt/geometry/_utils.py +0 -0
  21. {differt-0.8.1 → differt-0.8.2}/src/differt/plotting/__init__.py +0 -0
  22. {differt-0.8.1 → differt-0.8.2}/src/differt/plotting/_core.py +0 -0
  23. {differt-0.8.1 → differt-0.8.2}/src/differt/plotting/_utils.py +0 -0
  24. {differt-0.8.1 → differt-0.8.2}/src/differt/plugins/__init__.py +0 -0
  25. {differt-0.8.1 → differt-0.8.2}/src/differt/plugins/_deepmimo_types.py +0 -0
  26. {differt-0.8.1 → differt-0.8.2}/src/differt/plugins/deepmimo.py +0 -0
  27. {differt-0.8.1 → differt-0.8.2}/src/differt/py.typed +0 -0
  28. {differt-0.8.1 → differt-0.8.2}/src/differt/rt/__init__.py +0 -0
  29. {differt-0.8.1 → differt-0.8.2}/src/differt/rt/_fermat.py +0 -0
  30. {differt-0.8.1 → differt-0.8.2}/src/differt/rt/_utils.py +0 -0
  31. {differt-0.8.1 → differt-0.8.2}/src/differt/scene/__init__.py +0 -0
  32. {differt-0.8.1 → differt-0.8.2}/src/differt/scene/_sionna.py +0 -0
  33. {differt-0.8.1 → differt-0.8.2}/src/differt/scene/_triangle_scene.py +0 -0
  34. {differt-0.8.1 → differt-0.8.2}/src/differt/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DiffeRT
3
- Version: 0.8.1
3
+ Version: 0.8.2
4
4
  Summary: Differentiable Ray Tracing Toolbox for Radio Propagation Simulations
5
5
  Project-URL: Changelog, https://github.com/jeertmans/DiffeRT/releases
6
6
  Project-URL: Documentation, https://eertmans.be/DiffeRT
@@ -21,7 +21,7 @@ Classifier: Programming Language :: Python :: Free Threading
21
21
  Classifier: Topic :: Scientific/Engineering
22
22
  Requires-Python: >=3.11
23
23
  Requires-Dist: chex>=0.1.86
24
- Requires-Dist: differt-core==0.8.1
24
+ Requires-Dist: differt-core==0.8.2
25
25
  Requires-Dist: equinox>=0.13.7
26
26
  Requires-Dist: filelock>=3.15.4
27
27
  Requires-Dist: fpt-jax==0.1.0
@@ -156,7 +156,7 @@ or:
156
156
  author = {Eertmans, Jérome},
157
157
  url = {https://github.com/jeertmans/DiffeRT},
158
158
  license = {MIT},
159
- version = {v0.8.1}
159
+ version = {v0.8.2}
160
160
  }
161
161
  ```
162
162
 
@@ -100,7 +100,7 @@ or:
100
100
  author = {Eertmans, Jérome},
101
101
  url = {https://github.com/jeertmans/DiffeRT},
102
102
  license = {MIT},
103
- version = {v0.8.1}
103
+ version = {v0.8.2}
104
104
  }
105
105
  ```
106
106
 
@@ -16,7 +16,7 @@ classifiers = [
16
16
  ]
17
17
  dependencies = [
18
18
  "chex>=0.1.86",
19
- "differt-core==0.8.1",
19
+ "differt-core==0.8.2",
20
20
  "equinox>=0.13.7",
21
21
  "filelock>=3.15.4",
22
22
  "fpt-jax==0.1.0",
@@ -1,4 +1,5 @@
1
1
  import typing
2
+ import warnings
2
3
  from collections.abc import Callable, Iterator, Mapping, Sequence
3
4
  from dataclasses import replace
4
5
  from typing import (
@@ -770,6 +771,18 @@ class TriangleMesh(eqx.Module):
770
771
  if self.mask is None:
771
772
  return jax.tree.map(lambda m: m, self)
772
773
 
774
+ triangles = self.triangles[self.mask, :]
775
+ # We will need to re-index the vertices, so we first get the unique vertex indices used by the active triangles,
776
+ used_indices = jnp.unique(triangles.reshape(-1))
777
+ # Then we create a lookup table to re-index the triangles, where the indices of the used vertices are replaced by their new indices.
778
+ lookup = jnp.empty((self.vertices.shape[0],), dtype=triangles.dtype)
779
+ lookup = lookup.at[used_indices].set(
780
+ jnp.arange(used_indices.shape[0], dtype=triangles.dtype)
781
+ )
782
+ # Keep unique vertices
783
+ vertices = self.vertices[used_indices, :]
784
+ triangles = lookup[triangles]
785
+
773
786
  return eqx.tree_at(
774
787
  lambda m: (
775
788
  m.vertices,
@@ -781,8 +794,8 @@ class TriangleMesh(eqx.Module):
781
794
  ),
782
795
  self,
783
796
  (
784
- self.vertices,
785
- self.triangles[self.mask, :],
797
+ vertices,
798
+ triangles,
786
799
  self.face_colors[self.mask, :]
787
800
  if self.face_colors is not None
788
801
  else None,
@@ -843,6 +856,59 @@ class TriangleMesh(eqx.Module):
843
856
  self.vertices + jnp.asarray(translation),
844
857
  )
845
858
 
859
+ def clip(
860
+ self,
861
+ x_min: Float[ArrayLike, ""] | None = None,
862
+ x_max: Float[ArrayLike, ""] | None = None,
863
+ y_min: Float[ArrayLike, ""] | None = None,
864
+ y_max: Float[ArrayLike, ""] | None = None,
865
+ z_min: Float[ArrayLike, ""] | None = None,
866
+ z_max: Float[ArrayLike, ""] | None = None,
867
+ ) -> Self:
868
+ """
869
+ Clip all vertex coordinates to the given bounds.
870
+
871
+ Args:
872
+ x_min: The minimum x coordinate.
873
+ x_max: The maximum x coordinate.
874
+ y_min: The minimum y coordinate.
875
+ y_max: The maximum y coordinate.
876
+ z_min: The minimum z coordinate.
877
+ z_max: The maximum z coordinate.
878
+
879
+ Returns:
880
+ A new mesh with clipped vertices.
881
+
882
+ Examples:
883
+ The following example shows the effect on a plotted mesh before and after clipping.
884
+
885
+ .. plotly::
886
+ :context: reset
887
+
888
+ >>> from differt.geometry import TriangleMesh
889
+ >>>
890
+ >>> mesh = TriangleMesh.box(length=4.0, width=2.0, height=1.0)
891
+ >>> fig = mesh.plot(backend="plotly")
892
+ >>> fig # doctest: +SKIP
893
+
894
+ .. plotly::
895
+ :context:
896
+
897
+ >>> clipped = mesh.clip(x_min=-1.0, x_max=1.0, y_min=-0.5, y_max=0.5)
898
+ >>> fig = clipped.plot(backend="plotly")
899
+ >>> fig # doctest: +SKIP
900
+ """
901
+ vertices = self.vertices
902
+
903
+ if x_min is not None or x_max is not None:
904
+ vertices = vertices.at[:, 0].apply(lambda x: x.clip(min=x_min, max=x_max))
905
+ if y_min is not None or y_max is not None:
906
+ vertices = vertices.at[:, 1].apply(lambda y: y.clip(min=y_min, max=y_max))
907
+ if z_min is not None or z_max is not None:
908
+ vertices = vertices.at[:, 2].apply(lambda z: z.clip(min=z_min, max=z_max))
909
+
910
+ return eqx.tree_at(lambda m: m.vertices, self, vertices)
911
+
846
912
  @classmethod
847
913
  def empty(cls) -> Self:
848
914
  """
@@ -1892,3 +1958,404 @@ class TriangleMesh(eqx.Module):
1892
1958
  if return_indices:
1893
1959
  return mesh, indices
1894
1960
  return mesh
1961
+
1962
+ def _keep_within(
1963
+ self,
1964
+ x_min: Float[ArrayLike, ""] | None = None,
1965
+ x_max: Float[ArrayLike, ""] | None = None,
1966
+ y_min: Float[ArrayLike, ""] | None = None,
1967
+ y_max: Float[ArrayLike, ""] | None = None,
1968
+ z_min: Float[ArrayLike, ""] | None = None,
1969
+ z_max: Float[ArrayLike, ""] | None = None,
1970
+ preserve_objects: bool = True,
1971
+ keep_any: bool = False,
1972
+ clip: bool = False,
1973
+ ) -> Self:
1974
+ if preserve_objects and self.object_bounds is not None:
1975
+ warnings.warn(
1976
+ "Preserving objects is not fully supported yet, and some bugs may occur. Use with caution.",
1977
+ UserWarning,
1978
+ stacklevel=2,
1979
+ )
1980
+
1981
+ triangle_vertices = self.triangle_vertices
1982
+ xs, ys, zs = jnp.unstack(triangle_vertices, axis=-1)
1983
+
1984
+ vertex_mask = jnp.ones_like(xs, dtype=bool)
1985
+ if x_min is not None:
1986
+ vertex_mask &= xs >= x_min
1987
+ if x_max is not None:
1988
+ vertex_mask &= xs <= x_max
1989
+ if y_min is not None:
1990
+ vertex_mask &= ys >= y_min
1991
+ if y_max is not None:
1992
+ vertex_mask &= ys <= y_max
1993
+ if z_min is not None:
1994
+ vertex_mask &= zs >= z_min
1995
+ if z_max is not None:
1996
+ vertex_mask &= zs <= z_max
1997
+
1998
+ mask = (
1999
+ jnp.any(vertex_mask, axis=-1) if keep_any else jnp.all(vertex_mask, axis=-1)
2000
+ )
2001
+
2002
+ if self.mask is not None:
2003
+ mask &= self.mask
2004
+
2005
+ if preserve_objects and self.object_bounds is not None:
2006
+ object_ends = self.object_bounds[:, 1]
2007
+ object_ids = jnp.searchsorted(
2008
+ object_ends, jnp.arange(self.num_triangles), side="right"
2009
+ )
2010
+ object_counts = (
2011
+ jnp.zeros(self.object_bounds.shape[0], dtype=int).at[object_ids].add(1)
2012
+ )
2013
+ object_kept_counts = (
2014
+ jnp
2015
+ .zeros(self.object_bounds.shape[0], dtype=int)
2016
+ .at[object_ids]
2017
+ .add(mask.astype(int))
2018
+ )
2019
+ object_mask = (
2020
+ object_kept_counts > 0
2021
+ if keep_any
2022
+ else object_kept_counts == object_counts
2023
+ )
2024
+ mask = object_mask[object_ids]
2025
+ if self.mask is not None:
2026
+ mask &= self.mask
2027
+
2028
+ mesh = eqx.tree_at(lambda m: m.mask, self, mask, is_leaf=lambda x: x is None)
2029
+ if clip:
2030
+ mesh = mesh.clip(
2031
+ x_min=x_min,
2032
+ x_max=x_max,
2033
+ y_min=y_min,
2034
+ y_max=y_max,
2035
+ z_min=z_min,
2036
+ z_max=z_max,
2037
+ )
2038
+ return mesh
2039
+
2040
+ def keep_all_within(
2041
+ self,
2042
+ x_min: Float[ArrayLike, ""] | None = None,
2043
+ x_max: Float[ArrayLike, ""] | None = None,
2044
+ y_min: Float[ArrayLike, ""] | None = None,
2045
+ y_max: Float[ArrayLike, ""] | None = None,
2046
+ z_min: Float[ArrayLike, ""] | None = None,
2047
+ z_max: Float[ArrayLike, ""] | None = None,
2048
+ *,
2049
+ preserve_objects: bool = True,
2050
+ clip: bool = False,
2051
+ ) -> Self:
2052
+ """
2053
+ Return a new mesh, keeping only the triangles with all vertices within the given bounds.
2054
+
2055
+ If ``preserve_objects`` is set to :data:`True`, and :attr:`object_bounds` is not
2056
+ :data:`None`, then all triangles belonging to the same object as a triangle with all
2057
+ vertices within the given bounds are kept, but only if all triangles in that object
2058
+ satisfy the bounds.
2059
+
2060
+ Warning:
2061
+ Using setting ``preserve_objects`` to :data:`True` with this method may lead to unexpected results, as it is not fully supported yet. Use with caution.
2062
+
2063
+ Args:
2064
+ x_min: The minimum x coordinate.
2065
+ x_max: The maximum x coordinate.
2066
+ y_min: The minimum y coordinate.
2067
+ y_max: The maximum y coordinate.
2068
+ z_min: The minimum z coordinate.
2069
+ z_max: The maximum z coordinate.
2070
+ preserve_objects: Whether to preserve objects.
2071
+ clip: Whether to clip the vertices of the returned mesh to the given bounds.
2072
+
2073
+ Returns:
2074
+ A new mesh with the triangles filtered according to the given bounds.
2075
+
2076
+ :seealso::
2077
+
2078
+ :meth:`keep_any_within`
2079
+
2080
+ Examples:
2081
+ The following example shows how to filter the simple street canyon scene.
2082
+
2083
+ .. plotly::
2084
+ :context: reset
2085
+
2086
+ >>> from differt.scene import (
2087
+ ... TriangleScene,
2088
+ ... download_sionna_scenes,
2089
+ ... get_sionna_scene,
2090
+ ... )
2091
+ >>>
2092
+ >>> download_sionna_scenes() # doctest: +SKIP
2093
+ >>> file = get_sionna_scene("simple_street_canyon")
2094
+ >>> mesh = TriangleScene.load_xml(file).mesh
2095
+ >>> fig = mesh.plot(backend="plotly")
2096
+ >>> fig # doctest: +SKIP
2097
+
2098
+ Here, we keep the objects that have all vertices inside the selected range.
2099
+
2100
+ .. plotly::
2101
+ :context:
2102
+
2103
+ >>> fig = mesh.keep_all_within(y_min=-20.0).plot(
2104
+ ... backend="plotly",
2105
+ ... )
2106
+ >>> fig # doctest: +SKIP
2107
+
2108
+ By default, and if :attr:`object_bounds` is not :data:`None`, the filtering is done by objects. You can disable this behavior by setting ``preserve_objects`` to :data:`False`.
2109
+
2110
+ .. plotly::
2111
+ :context:
2112
+
2113
+ >>> fig = mesh.keep_all_within(
2114
+ ... y_min=-20.0,
2115
+ ... preserve_objects=False,
2116
+ ... ).plot(backend="plotly")
2117
+ >>> fig # doctest: +SKIP
2118
+ """
2119
+ return self._keep_within(
2120
+ x_min=x_min,
2121
+ x_max=x_max,
2122
+ y_min=y_min,
2123
+ y_max=y_max,
2124
+ z_min=z_min,
2125
+ z_max=z_max,
2126
+ preserve_objects=preserve_objects,
2127
+ keep_any=False,
2128
+ clip=clip,
2129
+ )
2130
+
2131
+ def keep_any_within(
2132
+ self,
2133
+ x_min: Float[ArrayLike, ""] | None = None,
2134
+ x_max: Float[ArrayLike, ""] | None = None,
2135
+ y_min: Float[ArrayLike, ""] | None = None,
2136
+ y_max: Float[ArrayLike, ""] | None = None,
2137
+ z_min: Float[ArrayLike, ""] | None = None,
2138
+ z_max: Float[ArrayLike, ""] | None = None,
2139
+ *,
2140
+ preserve_objects: bool = True,
2141
+ clip: bool = False,
2142
+ ) -> Self:
2143
+ """
2144
+ Return a new mesh, keeping only the triangles with at least one vertex within the given bounds.
2145
+
2146
+ If ``preserve_objects`` is set to :data:`True`, and :attr:`object_bounds` is not
2147
+ :data:`None`, then all triangles belonging to the same object as a triangle with at
2148
+ least one vertex within the given bounds are kept.
2149
+
2150
+ Warning:
2151
+ Using setting ``preserve_objects`` to :data:`True` with this method may lead to unexpected results, as it is not fully supported yet. Use with caution.
2152
+
2153
+ Args:
2154
+ x_min: The minimum x coordinate.
2155
+ x_max: The maximum x coordinate.
2156
+ y_min: The minimum y coordinate.
2157
+ y_max: The maximum y coordinate.
2158
+ z_min: The minimum z coordinate.
2159
+ z_max: The maximum z coordinate.
2160
+ preserve_objects: Whether to preserve objects.
2161
+ clip: Whether to clip the vertices of the returned mesh to the given bounds.
2162
+
2163
+ Returns:
2164
+ A new mesh with the triangles filtered according to the given bounds.
2165
+
2166
+ :seealso::
2167
+
2168
+ :meth:`keep_all_within`
2169
+
2170
+ Examples:
2171
+ The following example shows how to filter the simple street canyon scene.
2172
+
2173
+ .. plotly::
2174
+ :context: reset
2175
+
2176
+ >>> from differt.scene import (
2177
+ ... TriangleScene,
2178
+ ... download_sionna_scenes,
2179
+ ... get_sionna_scene,
2180
+ ... )
2181
+ >>>
2182
+ >>> download_sionna_scenes() # doctest: +SKIP
2183
+ >>> file = get_sionna_scene("simple_street_canyon")
2184
+ >>> mesh = TriangleScene.load_xml(file).mesh
2185
+ >>> fig = mesh.plot(backend="plotly")
2186
+ >>> fig # doctest: +SKIP
2187
+
2188
+ Here, we keep the objects that have all vertices inside the selected range.
2189
+
2190
+ .. plotly::
2191
+ :context:
2192
+
2193
+ >>> fig = mesh.keep_any_within(x_max=0.0).plot(
2194
+ ... backend="plotly",
2195
+ ... )
2196
+ >>> fig # doctest: +SKIP
2197
+
2198
+ By default, and if :attr:`object_bounds` is not :data:`None`, the filtering is done by objects. You can disable this behavior by setting ``preserve_objects`` to :data:`False`.
2199
+
2200
+ .. plotly::
2201
+ :context:
2202
+
2203
+ >>> fig = mesh.keep_any_within(
2204
+ ... x_max=0.0,
2205
+ ... preserve_objects=False,
2206
+ ... ).plot(backend="plotly")
2207
+ >>> fig # doctest: +SKIP
2208
+
2209
+ Finally, we can also clip the vertices of the returned mesh to the given bounds. This is especially useful to trim the plane of the ground in outdoor scenes.
2210
+
2211
+ .. plotly::
2212
+ :context:
2213
+
2214
+ >>> fig = mesh.keep_any_within(
2215
+ ... x_max=+15.0,
2216
+ ... clip=True,
2217
+ ... ).plot(backend="plotly")
2218
+ >>> fig # doctest: +SKIP
2219
+ """
2220
+ return self._keep_within(
2221
+ x_min=x_min,
2222
+ x_max=x_max,
2223
+ y_min=y_min,
2224
+ y_max=y_max,
2225
+ z_min=z_min,
2226
+ z_max=z_max,
2227
+ preserve_objects=preserve_objects,
2228
+ keep_any=True,
2229
+ clip=clip,
2230
+ )
2231
+
2232
+ def center(self) -> Self:
2233
+ """
2234
+ Return a new mesh, centered around the origin.
2235
+
2236
+ The center of the mesh is computed as the center of its bounding box,
2237
+ and the mesh is translated so that this center is at the origin in the (x, y) plane.
2238
+ The z-coordinate remains unchanged.
2239
+
2240
+ This method is useful for centering scenes after filtering operations that may
2241
+ have removed parts of the mesh (e.g., using :meth:`keep_all_within` or :meth:`keep_any_within`).
2242
+
2243
+ Returns:
2244
+ A new centered mesh with the same structure but with vertices translated.
2245
+
2246
+ Examples:
2247
+ The following example shows how to center a mesh around the origin.
2248
+
2249
+ .. plotly::
2250
+ :context: reset
2251
+
2252
+ >>> from differt.geometry import TriangleMesh
2253
+ >>>
2254
+ >>> mesh = TriangleMesh.box(
2255
+ ... length=4.0, width=2.0, height=1.0
2256
+ ... ).translate(jnp.array([2.0, 1.0, 0.0]))
2257
+ >>> fig = mesh.plot(backend="plotly")
2258
+ >>> fig # doctest: +SKIP
2259
+
2260
+ After centering, the mesh is translated to the origin in the (x, y) plane:
2261
+
2262
+ .. plotly::
2263
+ :context:
2264
+
2265
+ >>> centered = mesh.center()
2266
+ >>> fig = centered.plot(backend="plotly")
2267
+ >>> fig # doctest: +SKIP
2268
+ """
2269
+ (x_min, y_min, _), (x_max, y_max, _) = self.bounding_box
2270
+ center = jnp.array([(x_min + x_max) * 0.5, (y_min + y_max) * 0.5, 0.0])
2271
+ return eqx.tree_at(lambda m: m.vertices, self, self.vertices - center)
2272
+
2273
+ def add_ground(
2274
+ self,
2275
+ x_scale: Float[ArrayLike, ""] = 1.0,
2276
+ y_scale: Float[ArrayLike, ""] = 1.0,
2277
+ z: Float[ArrayLike, ""] | None = None,
2278
+ material_name: str = "itu_concrete",
2279
+ face_color: Float[ArrayLike, "3"] = jnp.array([0.539, 0.539, 0.539]),
2280
+ ) -> Self:
2281
+ """
2282
+ Add a ground plane to this mesh.
2283
+
2284
+ The ground plane is a quadrilateral (represented as two triangles) added at the bottom of the mesh,
2285
+ i.e., below all existing triangles. The ground plane is scaled based on the bounding box of the mesh
2286
+ to create a realistic proportional ground.
2287
+
2288
+ This method is particularly useful for scenes that have been filtered or clipped (e.g., using
2289
+ :meth:`keep_all_within` or :meth:`keep_any_within`), as these operations may remove the original ground plane.
2290
+
2291
+ Args:
2292
+ x_scale: The scale factor of the ground plane along the x-axis. A value of 1.0 means the ground
2293
+ has the same width as the mesh's bounding box. Default is 1.0.
2294
+ y_scale: The scale factor of the ground plane along the y-axis. A value of 1.0 means the ground
2295
+ has the same depth as the mesh's bounding box. Default is 1.0.
2296
+ z: The z coordinate of the ground plane. If :data:`None`, the ground is placed at the minimum
2297
+ z coordinate of the mesh's bounding box. Default is :data:`None`.
2298
+ material_name: The name of the material for the ground plane. Default is ``"itu_concrete"``.
2299
+ face_color: The RGB color of the ground plane faces, with values in the range [0, 1].
2300
+ Default is ``[0.539, 0.539, 0.539]`` (concrete gray).
2301
+
2302
+ Returns:
2303
+ A new mesh with a ground plane appended.
2304
+
2305
+ Examples:
2306
+ The following example shows how to add a ground plane to a simple mesh.
2307
+
2308
+ .. plotly::
2309
+ :context: reset
2310
+
2311
+ >>> from differt.geometry import TriangleMesh
2312
+ >>>
2313
+ >>> mesh = TriangleMesh.box(length=2.0, width=2.0, height=1.0)
2314
+ >>> fig = mesh.plot(backend="plotly")
2315
+ >>> fig # doctest: +SKIP
2316
+
2317
+ After adding a ground plane, the mesh includes an additional quadrilateral at the bottom:
2318
+
2319
+ .. plotly::
2320
+ :context:
2321
+
2322
+ >>> with_ground = mesh.add_ground()
2323
+ >>> fig = with_ground.plot(backend="plotly")
2324
+ >>> fig # doctest: +SKIP
2325
+
2326
+ You can customize the ground plane size and appearance. For example, a larger ground plane with a different color:
2327
+
2328
+ .. plotly::
2329
+ :context:
2330
+
2331
+ >>> custom_ground = mesh.add_ground(
2332
+ ... x_scale=2.0, y_scale=2.0, face_color=jnp.array([0.2, 0.2, 0.2])
2333
+ ... )
2334
+ >>> fig = custom_ground.plot(backend="plotly")
2335
+ >>> fig # doctest: +SKIP
2336
+ """
2337
+ (x_min, y_min, z_min), (x_max, y_max, _) = self.bounding_box
2338
+ if z is None:
2339
+ z = z_min
2340
+
2341
+ center = jnp.array([(x_min + x_max) * 0.5, (y_min + y_max) * 0.5, z])
2342
+ u = jnp.array([(x_max - x_min) * x_scale * 0.5, 0.0, 0.0])
2343
+ v = jnp.array([0.0, (y_max - y_min) * y_scale * 0.5, 0.0])
2344
+ vertices = jnp.array([
2345
+ center + u + v,
2346
+ center - u + v,
2347
+ center - u - v,
2348
+ center + u - v,
2349
+ ])
2350
+ triangles = jnp.array([[0, 1, 2], [0, 2, 3]], dtype=int)
2351
+
2352
+ ground = TriangleMesh(
2353
+ vertices=vertices,
2354
+ triangles=triangles,
2355
+ object_bounds=jnp.array([[0, 2]]),
2356
+ face_colors=jnp.array([face_color, face_color]),
2357
+ face_materials=jnp.array([0, 0]),
2358
+ material_names=(material_name,),
2359
+ assume_quads=True,
2360
+ )
2361
+ return self.append(ground)
@@ -192,14 +192,12 @@ def _image_method(
192
192
  _forward,
193
193
  init=from_vertex,
194
194
  xs=(mirror_vertices, mirror_normals),
195
- unroll=True,
196
195
  )
197
196
  _, paths = jax.lax.scan(
198
197
  _backward,
199
198
  init=to_vertex,
200
199
  xs=(mirror_vertices, mirror_normals, images),
201
200
  reverse=True,
202
- unroll=True,
203
201
  )
204
202
 
205
203
  return paths
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes