differt 0.5.0__tar.gz → 0.6.0__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.
- {differt-0.5.0 → differt-0.6.0}/PKG-INFO +13 -7
- {differt-0.5.0 → differt-0.6.0}/README.md +9 -1
- {differt-0.5.0 → differt-0.6.0}/pyproject.toml +3 -5
- {differt-0.5.0 → differt-0.6.0}/src/differt/em/_antenna.py +4 -4
- {differt-0.5.0 → differt-0.6.0}/src/differt/em/_fresnel.py +6 -7
- {differt-0.5.0 → differt-0.6.0}/src/differt/em/_material.py +3 -8
- {differt-0.5.0 → differt-0.6.0}/src/differt/em/_utd.py +0 -2
- {differt-0.5.0 → differt-0.6.0}/src/differt/em/_utils.py +4 -5
- {differt-0.5.0 → differt-0.6.0}/src/differt/geometry/__init__.py +0 -2
- {differt-0.5.0 → differt-0.6.0}/src/differt/geometry/_paths.py +7 -12
- {differt-0.5.0 → differt-0.6.0}/src/differt/geometry/_triangle_mesh.py +64 -104
- {differt-0.5.0 → differt-0.6.0}/src/differt/geometry/_utils.py +38 -51
- {differt-0.5.0 → differt-0.6.0}/src/differt/plotting/__init__.py +2 -0
- {differt-0.5.0 → differt-0.6.0}/src/differt/plotting/_core.py +1 -2
- {differt-0.5.0 → differt-0.6.0}/src/differt/plotting/_utils.py +44 -7
- {differt-0.5.0 → differt-0.6.0}/src/differt/plugins/deepmimo.py +9 -9
- {differt-0.5.0 → differt-0.6.0}/src/differt/rt/_image_method.py +9 -6
- {differt-0.5.0 → differt-0.6.0}/src/differt/rt/_utils.py +232 -137
- {differt-0.5.0 → differt-0.6.0}/src/differt/scene/_triangle_scene.py +106 -40
- differt-0.6.0/src/differt/utils.py +91 -0
- differt-0.5.0/src/differt/utils.py +0 -214
- {differt-0.5.0 → differt-0.6.0}/.gitignore +0 -0
- {differt-0.5.0 → differt-0.6.0}/LICENSE.md +0 -0
- {differt-0.5.0 → differt-0.6.0}/src/differt/__init__.py +0 -0
- {differt-0.5.0 → differt-0.6.0}/src/differt/_version.py +0 -0
- {differt-0.5.0 → differt-0.6.0}/src/differt/em/__init__.py +0 -0
- {differt-0.5.0 → differt-0.6.0}/src/differt/em/_constants.py +0 -0
- {differt-0.5.0 → differt-0.6.0}/src/differt/em/_interaction_type.py +0 -0
- {differt-0.5.0 → differt-0.6.0}/src/differt/plugins/__init__.py +0 -0
- {differt-0.5.0 → differt-0.6.0}/src/differt/plugins/_deepmimo_types.py +0 -0
- {differt-0.5.0 → differt-0.6.0}/src/differt/py.typed +0 -0
- {differt-0.5.0 → differt-0.6.0}/src/differt/rt/__init__.py +0 -0
- {differt-0.5.0 → differt-0.6.0}/src/differt/rt/_fermat.py +0 -0
- {differt-0.5.0 → differt-0.6.0}/src/differt/scene/__init__.py +0 -0
- {differt-0.5.0 → differt-0.6.0}/src/differt/scene/_sionna.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: DiffeRT
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
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
|
|
@@ -14,23 +14,21 @@ Keywords: differentiable,jax,propagation,radio,ray tracing
|
|
|
14
14
|
Classifier: License :: OSI Approved :: MIT License
|
|
15
15
|
Classifier: Operating System :: OS Independent
|
|
16
16
|
Classifier: Programming Language :: Python :: 3
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
18
17
|
Classifier: Programming Language :: Python :: 3.11
|
|
19
18
|
Classifier: Programming Language :: Python :: 3.12
|
|
20
19
|
Classifier: Programming Language :: Python :: 3.13
|
|
21
20
|
Classifier: Topic :: Scientific/Engineering
|
|
22
|
-
Requires-Python: >=3.
|
|
21
|
+
Requires-Python: >=3.11
|
|
23
22
|
Requires-Dist: chex>=0.1.86
|
|
24
|
-
Requires-Dist: differt-core==0.
|
|
23
|
+
Requires-Dist: differt-core==0.6.0
|
|
25
24
|
Requires-Dist: equinox>=0.12.2
|
|
26
25
|
Requires-Dist: filelock>=3.15.4
|
|
27
|
-
Requires-Dist: jax>=0.
|
|
26
|
+
Requires-Dist: jax>=0.7.0
|
|
28
27
|
Requires-Dist: jaxtyping>=0.3.2
|
|
29
28
|
Requires-Dist: numpy>=1.26.1
|
|
30
29
|
Requires-Dist: optax>=0.1.7
|
|
31
30
|
Requires-Dist: requests>=2.32.0
|
|
32
31
|
Requires-Dist: tqdm>=4.66.2
|
|
33
|
-
Requires-Dist: typing-extensions>=4.9.0; python_version < '3.11'
|
|
34
32
|
Provides-Extra: all
|
|
35
33
|
Requires-Dist: ipympl>=0.9.4; extra == 'all'
|
|
36
34
|
Requires-Dist: jupyter-rfb>=0.4.2; extra == 'all'
|
|
@@ -132,6 +130,8 @@ for a detailed step-by-step procedure.
|
|
|
132
130
|
|
|
133
131
|
## Citing
|
|
134
132
|
|
|
133
|
+
<!-- start citing -->
|
|
134
|
+
|
|
135
135
|
If you use this software, please cite it as:
|
|
136
136
|
|
|
137
137
|
```bibtex
|
|
@@ -140,10 +140,16 @@ If you use this software, please cite it as:
|
|
|
140
140
|
author = {Eertmans, Jérome},
|
|
141
141
|
url = {https://github.com/jeertmans/DiffeRT},
|
|
142
142
|
license = {MIT},
|
|
143
|
-
version = {v0.
|
|
143
|
+
version = {v0.6.0}
|
|
144
144
|
}
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
+
For other citation formats, please refer to the [*Cite this repository*](https://github.com/jeertmans/DiffeRT) button the main page of our GitHub repository or to our [Zenodo records](https://doi.org/10.5281/zenodo.11386432).
|
|
148
|
+
|
|
149
|
+
Thank you for using this software and helping us!
|
|
150
|
+
|
|
151
|
+
<!-- end citing -->
|
|
152
|
+
|
|
147
153
|
[pypi-version-badge]: https://img.shields.io/pypi/v/DiffeRT?label=DiffeRT&color=blueviolet
|
|
148
154
|
[pypi-version-url]: https://pypi.org/project/DiffeRT/
|
|
149
155
|
[pypi-python-version-badge]: https://img.shields.io/pypi/pyversions/DiffeRT?color=orange
|
|
@@ -75,6 +75,8 @@ for a detailed step-by-step procedure.
|
|
|
75
75
|
|
|
76
76
|
## Citing
|
|
77
77
|
|
|
78
|
+
<!-- start citing -->
|
|
79
|
+
|
|
78
80
|
If you use this software, please cite it as:
|
|
79
81
|
|
|
80
82
|
```bibtex
|
|
@@ -83,10 +85,16 @@ If you use this software, please cite it as:
|
|
|
83
85
|
author = {Eertmans, Jérome},
|
|
84
86
|
url = {https://github.com/jeertmans/DiffeRT},
|
|
85
87
|
license = {MIT},
|
|
86
|
-
version = {v0.
|
|
88
|
+
version = {v0.6.0}
|
|
87
89
|
}
|
|
88
90
|
```
|
|
89
91
|
|
|
92
|
+
For other citation formats, please refer to the [*Cite this repository*](https://github.com/jeertmans/DiffeRT) button the main page of our GitHub repository or to our [Zenodo records](https://doi.org/10.5281/zenodo.11386432).
|
|
93
|
+
|
|
94
|
+
Thank you for using this software and helping us!
|
|
95
|
+
|
|
96
|
+
<!-- end citing -->
|
|
97
|
+
|
|
90
98
|
[pypi-version-badge]: https://img.shields.io/pypi/v/DiffeRT?label=DiffeRT&color=blueviolet
|
|
91
99
|
[pypi-version-url]: https://pypi.org/project/DiffeRT/
|
|
92
100
|
[pypi-python-version-badge]: https://img.shields.io/pypi/pyversions/DiffeRT?color=orange
|
|
@@ -6,7 +6,6 @@ requires = ["hatchling", "hatch-fancy-pypi-readme"]
|
|
|
6
6
|
authors = [{name = "Jérome Eertmans", email = "jeertmans@icloud.com"}]
|
|
7
7
|
classifiers = [
|
|
8
8
|
"Programming Language :: Python :: 3",
|
|
9
|
-
"Programming Language :: Python :: 3.10",
|
|
10
9
|
"Programming Language :: Python :: 3.11",
|
|
11
10
|
"Programming Language :: Python :: 3.12",
|
|
12
11
|
"Programming Language :: Python :: 3.13",
|
|
@@ -16,14 +15,13 @@ classifiers = [
|
|
|
16
15
|
]
|
|
17
16
|
dependencies = [
|
|
18
17
|
"chex>=0.1.86",
|
|
19
|
-
"differt-core==0.
|
|
18
|
+
"differt-core==0.6.0",
|
|
20
19
|
"equinox>=0.12.2",
|
|
21
20
|
"filelock>=3.15.4",
|
|
22
|
-
"jax>=0.
|
|
21
|
+
"jax>=0.7.0",
|
|
23
22
|
"jaxtyping>=0.3.2",
|
|
24
23
|
"numpy>=1.26.1",
|
|
25
24
|
"optax>=0.1.7",
|
|
26
|
-
"typing-extensions>=4.9.0;python_version<'3.11'",
|
|
27
25
|
"requests>=2.32.0",
|
|
28
26
|
"tqdm>=4.66.2",
|
|
29
27
|
]
|
|
@@ -32,7 +30,7 @@ dynamic = ["readme", "version"]
|
|
|
32
30
|
keywords = ["ray tracing", "differentiable", "propagation", "radio", "jax"]
|
|
33
31
|
license = "MIT"
|
|
34
32
|
name = "DiffeRT"
|
|
35
|
-
requires-python = ">=3.
|
|
33
|
+
requires-python = ">=3.11"
|
|
36
34
|
|
|
37
35
|
[project.optional-dependencies]
|
|
38
36
|
all = [
|
|
@@ -13,7 +13,7 @@ from differt.geometry import (
|
|
|
13
13
|
spherical_to_cartesian,
|
|
14
14
|
)
|
|
15
15
|
from differt.plotting import PlotOutput, draw_surface
|
|
16
|
-
from differt.utils import
|
|
16
|
+
from differt.utils import safe_divide
|
|
17
17
|
|
|
18
18
|
from ._constants import c, epsilon_0, mu_0
|
|
19
19
|
|
|
@@ -576,7 +576,7 @@ class RadiationPattern(BaseAntenna):
|
|
|
576
576
|
|
|
577
577
|
s, p = self.polarization_vectors(r)
|
|
578
578
|
|
|
579
|
-
g =
|
|
579
|
+
g = jnp.sum(s * s, axis=-1) + jnp.sum(p * p, axis=-1)
|
|
580
580
|
|
|
581
581
|
# TODO: check if this is correct
|
|
582
582
|
|
|
@@ -672,12 +672,12 @@ class HWDipolePattern(RadiationPattern):
|
|
|
672
672
|
r = jnp.asarray(r)
|
|
673
673
|
r_hat, r = normalize(r - self.center, keepdims=True)
|
|
674
674
|
|
|
675
|
-
cos_theta =
|
|
675
|
+
cos_theta = jnp.sum(r_hat * self.direction, axis=-1)
|
|
676
676
|
sin_theta = jnp.sqrt(1 - cos_theta**2)
|
|
677
677
|
|
|
678
678
|
d = 1.640922376984585 # Directive gain: 4 / Cin(2*pi)
|
|
679
679
|
|
|
680
|
-
cos_theta =
|
|
680
|
+
cos_theta = jnp.sum(d * d, axis=-1)
|
|
681
681
|
sin_theta = jnp.sin(d)
|
|
682
682
|
_d = safe_divide(jnp.cos(0.5 * jnp.pi * cos_theta), sin_theta)
|
|
683
683
|
raise NotImplementedError
|
|
@@ -258,7 +258,6 @@ def reflection_coefficients(
|
|
|
258
258
|
... )
|
|
259
259
|
>>> from differt.geometry import normalize
|
|
260
260
|
>>> from differt.rt import image_method
|
|
261
|
-
>>> from differt.utils import dot
|
|
262
261
|
|
|
263
262
|
The first step is to define the antenna and the geometry of the scene.
|
|
264
263
|
Here, we place a dipole antenna above the origin, and generate a
|
|
@@ -344,7 +343,7 @@ def reflection_coefficients(
|
|
|
344
343
|
>>> # [num_positions 3]
|
|
345
344
|
>>> E_i, B_i = ant.fields(reflection_points - tx_position, t=-tau)
|
|
346
345
|
>>> # [num_positions 1]
|
|
347
|
-
>>> cos_theta =
|
|
346
|
+
>>> cos_theta = jnp.sum(ground_normal * -k_i, axis=-1, keepdims=True)
|
|
348
347
|
>>> n_r = 1.5 # Air to glass
|
|
349
348
|
>>> # [num_positions 1]
|
|
350
349
|
>>> r_s, r_p = reflection_coefficients(n_r, cos_theta)
|
|
@@ -366,10 +365,10 @@ def reflection_coefficients(
|
|
|
366
365
|
We then transform XYZ-components into local s and p components.
|
|
367
366
|
|
|
368
367
|
>>> # [num_positions 1]
|
|
369
|
-
>>> E_i_s =
|
|
370
|
-
>>> E_i_p =
|
|
371
|
-
>>> B_i_s =
|
|
372
|
-
>>> B_i_p =
|
|
368
|
+
>>> E_i_s = jnp.sum(E_i * e_i_s, axis=-1, keepdims=True)
|
|
369
|
+
>>> E_i_p = jnp.sum(E_i * e_i_p, axis=-1, keepdims=True)
|
|
370
|
+
>>> B_i_s = jnp.sum(B_i * e_i_s, axis=-1, keepdims=True)
|
|
371
|
+
>>> B_i_p = jnp.sum(B_i * e_i_p, axis=-1, keepdims=True)
|
|
373
372
|
|
|
374
373
|
Then, we apply reflection coefficients to the local s and p components.
|
|
375
374
|
|
|
@@ -446,7 +445,7 @@ def reflection_coefficients(
|
|
|
446
445
|
... color="green",
|
|
447
446
|
... label="Exact",
|
|
448
447
|
... ) # doctest: +SKIP
|
|
449
|
-
>>> P_tot_pw = A_e *
|
|
448
|
+
>>> P_tot_pw = A_e * jnp.sum(E_tot * E_tot, axis=-1) / z_0
|
|
450
449
|
>>> plt.semilogx(
|
|
451
450
|
... x,
|
|
452
451
|
... 10 * jnp.log10(P_tot_pw / ant.reference_power),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# ruff: noqa: FURB152
|
|
2
2
|
|
|
3
3
|
import operator
|
|
4
|
-
import
|
|
4
|
+
import typing
|
|
5
5
|
from collections.abc import Callable
|
|
6
6
|
from functools import partial
|
|
7
7
|
from typing import TYPE_CHECKING, Any
|
|
@@ -11,13 +11,8 @@ import jax
|
|
|
11
11
|
import jax.numpy as jnp
|
|
12
12
|
from jaxtyping import Array, ArrayLike, Float
|
|
13
13
|
|
|
14
|
-
if TYPE_CHECKING or "
|
|
15
|
-
import
|
|
16
|
-
|
|
17
|
-
if sys.version_info >= (3, 11):
|
|
18
|
-
from typing import Self
|
|
19
|
-
else:
|
|
20
|
-
from typing_extensions import Self
|
|
14
|
+
if TYPE_CHECKING or hasattr(typing, "GENERATING_DOCS"):
|
|
15
|
+
from typing import Self
|
|
21
16
|
else:
|
|
22
17
|
Self = Any # Because runtime type checking from 'beartype' will fail when combined with 'jaxtyping'
|
|
23
18
|
|
|
@@ -6,7 +6,6 @@ import jax.numpy as jnp
|
|
|
6
6
|
from jaxtyping import Array, ArrayLike, Float, Int
|
|
7
7
|
|
|
8
8
|
from differt.geometry import normalize, path_lengths, perpendicular_vectors
|
|
9
|
-
from differt.utils import dot
|
|
10
9
|
|
|
11
10
|
from ._constants import c
|
|
12
11
|
from ._interaction_type import InteractionType
|
|
@@ -293,10 +292,10 @@ def sp_rotation_matrix(
|
|
|
293
292
|
e_a_p = jnp.asarray(e_a_p)
|
|
294
293
|
e_b_s = jnp.asarray(e_b_s)
|
|
295
294
|
e_b_p = jnp.asarray(e_b_p)
|
|
296
|
-
r11 =
|
|
297
|
-
r12 =
|
|
298
|
-
r21 =
|
|
299
|
-
r22 =
|
|
295
|
+
r11 = jnp.sum(e_b_s * e_a_s, axis=-1, keepdims=True)
|
|
296
|
+
r12 = jnp.sum(e_b_s * e_a_p, axis=-1, keepdims=True)
|
|
297
|
+
r21 = jnp.sum(e_b_p * e_a_s, axis=-1, keepdims=True)
|
|
298
|
+
r22 = jnp.sum(e_b_p * e_a_p, axis=-1, keepdims=True)
|
|
300
299
|
|
|
301
300
|
r11, r12, r21, r22 = jnp.broadcast_arrays(r11, r12, r21, r22)
|
|
302
301
|
|
|
@@ -11,7 +11,6 @@ __all__ = (
|
|
|
11
11
|
"min_distance_between_cells",
|
|
12
12
|
"normalize",
|
|
13
13
|
"orthogonal_basis",
|
|
14
|
-
"pairwise_cross",
|
|
15
14
|
"path_lengths",
|
|
16
15
|
"perpendicular_vectors",
|
|
17
16
|
"rotation_matrix_along_axis",
|
|
@@ -35,7 +34,6 @@ from ._utils import (
|
|
|
35
34
|
min_distance_between_cells,
|
|
36
35
|
normalize,
|
|
37
36
|
orthogonal_basis,
|
|
38
|
-
pairwise_cross,
|
|
39
37
|
path_lengths,
|
|
40
38
|
perpendicular_vectors,
|
|
41
39
|
rotation_matrix_along_axis,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import math
|
|
2
|
-
import
|
|
2
|
+
import typing
|
|
3
3
|
import warnings
|
|
4
4
|
from collections.abc import Callable, Iterator, Sequence
|
|
5
5
|
from dataclasses import KW_ONLY
|
|
@@ -12,13 +12,8 @@ from jaxtyping import Array, ArrayLike, Bool, Float, Int, Num, Shaped
|
|
|
12
12
|
|
|
13
13
|
from differt.plotting import PlotOutput, draw_paths, reuse
|
|
14
14
|
|
|
15
|
-
if TYPE_CHECKING or "
|
|
16
|
-
import
|
|
17
|
-
|
|
18
|
-
if sys.version_info >= (3, 11):
|
|
19
|
-
from typing import Self
|
|
20
|
-
else:
|
|
21
|
-
from typing_extensions import Self
|
|
15
|
+
if TYPE_CHECKING or hasattr(typing, "GENERATING_DOCS"):
|
|
16
|
+
from typing import Self
|
|
22
17
|
else:
|
|
23
18
|
Self = Any # Because runtime type checking from 'beartype' will fail when combined with 'jaxtyping'
|
|
24
19
|
|
|
@@ -147,7 +142,7 @@ class Paths(eqx.Module):
|
|
|
147
142
|
|
|
148
143
|
def reshape(self, *batch: int) -> Self:
|
|
149
144
|
"""
|
|
150
|
-
Return a
|
|
145
|
+
Return a new paths instance with reshaped paths' batch dimensions to match a given shape.
|
|
151
146
|
|
|
152
147
|
Args:
|
|
153
148
|
batch: The new batch shapes.
|
|
@@ -182,7 +177,7 @@ class Paths(eqx.Module):
|
|
|
182
177
|
|
|
183
178
|
def squeeze(self, axis: int | Sequence[int] | None = None) -> Self:
|
|
184
179
|
"""
|
|
185
|
-
Return a
|
|
180
|
+
Return a new paths instance by squeezing one or more axes of paths' batch dimensions.
|
|
186
181
|
|
|
187
182
|
Args:
|
|
188
183
|
axis: See :func:`jax.numpy.squeeze` for allowed values.
|
|
@@ -235,7 +230,7 @@ class Paths(eqx.Module):
|
|
|
235
230
|
@eqx.filter_jit
|
|
236
231
|
def mask_duplicate_objects(self, axis: int = -1) -> Self:
|
|
237
232
|
"""
|
|
238
|
-
Return a
|
|
233
|
+
Return a new paths instance by masking duplicate objects along a given axis.
|
|
239
234
|
|
|
240
235
|
E.g., when generating path candidates from a generative Machine Learning model,
|
|
241
236
|
see :ref:`sampling-paths`, it is possible that the model generates the same
|
|
@@ -363,7 +358,7 @@ class Paths(eqx.Module):
|
|
|
363
358
|
return objects
|
|
364
359
|
|
|
365
360
|
def masked(self) -> Self:
|
|
366
|
-
"""Return a flattened
|
|
361
|
+
"""Return a flattened version of this object that only keeps valid paths.
|
|
367
362
|
|
|
368
363
|
The returned object has all batch dimensions flattened into one,
|
|
369
364
|
keeping only the paths where :attr:`mask` is :data:`True` (or where :attr:`confidence` is greater than or equal to :attr:`confidence_threshold`), and :attr:`mask` and :attr:`confidence` attributes are set to :data:`None`.
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
# ruff: noqa: ERA001
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import typing
|
|
4
4
|
from collections.abc import Callable, Iterator, Mapping
|
|
5
5
|
from dataclasses import replace
|
|
6
|
-
from typing import
|
|
6
|
+
from typing import (
|
|
7
|
+
TYPE_CHECKING,
|
|
8
|
+
Any,
|
|
9
|
+
Generic,
|
|
10
|
+
NotRequired,
|
|
11
|
+
TypedDict,
|
|
12
|
+
TypeVar,
|
|
13
|
+
overload,
|
|
14
|
+
)
|
|
7
15
|
|
|
8
16
|
import equinox as eqx
|
|
9
17
|
import jax
|
|
@@ -15,15 +23,25 @@ from differt.plotting import PlotOutput, draw_mesh, draw_paths, draw_rays, reuse
|
|
|
15
23
|
|
|
16
24
|
from ._utils import normalize, orthogonal_basis, rotation_matrix_along_axis
|
|
17
25
|
|
|
18
|
-
if TYPE_CHECKING or "
|
|
19
|
-
import
|
|
20
|
-
|
|
21
|
-
if sys.version_info >= (3, 11):
|
|
22
|
-
from typing import Self
|
|
23
|
-
else:
|
|
24
|
-
from typing_extensions import Self
|
|
26
|
+
if TYPE_CHECKING or hasattr(typing, "GENERATING_DOCS"):
|
|
27
|
+
from typing import Self
|
|
25
28
|
else:
|
|
26
|
-
Self = Any # Because runtime type checking from 'beartype' will fail when combined with 'jaxtyping
|
|
29
|
+
Self = Any # Because runtime type checking from 'beartype' will fail when combined with 'jaxtyping
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class _AtIndexingKwargs(TypedDict):
|
|
33
|
+
indices_are_sorted: bool
|
|
34
|
+
unique_indices: bool
|
|
35
|
+
wrap_negative_indices: NotRequired[bool]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
_AT_INDEXING_KWARGS: _AtIndexingKwargs = {
|
|
39
|
+
"indices_are_sorted": True,
|
|
40
|
+
"unique_indices": True,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if jax.__version_info__ >= (0, 7, 0):
|
|
44
|
+
_AT_INDEXING_KWARGS["wrap_negative_indices"] = False
|
|
27
45
|
|
|
28
46
|
|
|
29
47
|
@jax.jit
|
|
@@ -134,16 +152,12 @@ class _TriangleMeshVerticesUpdateRef(Generic[_T]):
|
|
|
134
152
|
return eqx.tree_at(
|
|
135
153
|
lambda m: m.vertices,
|
|
136
154
|
self.mesh,
|
|
137
|
-
self.mesh.vertices.at[index, :].set(
|
|
138
|
-
values, indices_are_sorted=True, unique_indices=True
|
|
139
|
-
),
|
|
155
|
+
self.mesh.vertices.at[index, :].set(values, **_AT_INDEXING_KWARGS),
|
|
140
156
|
)
|
|
141
157
|
|
|
142
158
|
def get(self, **kwargs: Any) -> Float[ArrayLike, "num_indexed_triangles 3"]:
|
|
143
159
|
index = self._triangles_index(**kwargs)
|
|
144
|
-
return self.mesh.vertices.at[index, :].get(
|
|
145
|
-
indices_are_sorted=True, unique_indices=True
|
|
146
|
-
)
|
|
160
|
+
return self.mesh.vertices.at[index, :].get(**_AT_INDEXING_KWARGS)
|
|
147
161
|
|
|
148
162
|
def apply(
|
|
149
163
|
self,
|
|
@@ -157,9 +171,7 @@ class _TriangleMeshVerticesUpdateRef(Generic[_T]):
|
|
|
157
171
|
return eqx.tree_at(
|
|
158
172
|
lambda m: m.vertices,
|
|
159
173
|
self.mesh,
|
|
160
|
-
self.mesh.vertices.at[index, :].apply(
|
|
161
|
-
func, indices_are_sorted=True, unique_indices=True
|
|
162
|
-
),
|
|
174
|
+
self.mesh.vertices.at[index, :].apply(func, **_AT_INDEXING_KWARGS),
|
|
163
175
|
)
|
|
164
176
|
|
|
165
177
|
def add(self, values: Any, **kwargs: Any) -> _T:
|
|
@@ -167,9 +179,7 @@ class _TriangleMeshVerticesUpdateRef(Generic[_T]):
|
|
|
167
179
|
return eqx.tree_at(
|
|
168
180
|
lambda m: m.vertices,
|
|
169
181
|
self.mesh,
|
|
170
|
-
self.mesh.vertices.at[index, :].add(
|
|
171
|
-
values, indices_are_sorted=True, unique_indices=True
|
|
172
|
-
),
|
|
182
|
+
self.mesh.vertices.at[index, :].add(values, **_AT_INDEXING_KWARGS),
|
|
173
183
|
)
|
|
174
184
|
|
|
175
185
|
def mul(self, values: Any, **kwargs: Any) -> _T:
|
|
@@ -177,9 +187,7 @@ class _TriangleMeshVerticesUpdateRef(Generic[_T]):
|
|
|
177
187
|
return eqx.tree_at(
|
|
178
188
|
lambda m: m.vertices,
|
|
179
189
|
self.mesh,
|
|
180
|
-
self.mesh.vertices.at[index, :].mul(
|
|
181
|
-
values, indices_are_sorted=True, unique_indices=True
|
|
182
|
-
),
|
|
190
|
+
self.mesh.vertices.at[index, :].mul(values, **_AT_INDEXING_KWARGS),
|
|
183
191
|
)
|
|
184
192
|
|
|
185
193
|
|
|
@@ -264,7 +272,7 @@ class TriangleMesh(eqx.Module):
|
|
|
264
272
|
raise ValueError(msg)
|
|
265
273
|
|
|
266
274
|
def __getitem__(self, key: slice | Int[ArrayLike, " n"]) -> Self:
|
|
267
|
-
"""Return a
|
|
275
|
+
"""Return a new instance of this mesh, taking only specific triangles.
|
|
268
276
|
|
|
269
277
|
Warning:
|
|
270
278
|
As it is not possible to guarantee that indexing would not break existing
|
|
@@ -275,7 +283,7 @@ class TriangleMesh(eqx.Module):
|
|
|
275
283
|
along the first axis.
|
|
276
284
|
|
|
277
285
|
Returns:
|
|
278
|
-
A new mesh.
|
|
286
|
+
A new mesh with selected triangles.
|
|
279
287
|
"""
|
|
280
288
|
return eqx.tree_at(
|
|
281
289
|
lambda m: (
|
|
@@ -323,15 +331,25 @@ class TriangleMesh(eqx.Module):
|
|
|
323
331
|
self,
|
|
324
332
|
(
|
|
325
333
|
self.vertices,
|
|
326
|
-
self.triangles[start:stop, :]
|
|
327
|
-
|
|
334
|
+
self.triangles.at[start:stop, :].get(
|
|
335
|
+
**_AT_INDEXING_KWARGS,
|
|
336
|
+
),
|
|
337
|
+
self.face_colors.at[start:stop, :].get(
|
|
338
|
+
**_AT_INDEXING_KWARGS,
|
|
339
|
+
)
|
|
328
340
|
if self.face_colors is not None
|
|
329
341
|
else None,
|
|
330
|
-
self.face_materials[start:stop]
|
|
342
|
+
self.face_materials.at[start:stop].get(
|
|
343
|
+
**_AT_INDEXING_KWARGS,
|
|
344
|
+
)
|
|
331
345
|
if self.face_materials is not None
|
|
332
346
|
else None,
|
|
333
347
|
jnp.array([[0, stop - start]]),
|
|
334
|
-
self.mask[start:stop]
|
|
348
|
+
self.mask.at[start:stop].get(
|
|
349
|
+
**_AT_INDEXING_KWARGS,
|
|
350
|
+
)
|
|
351
|
+
if self.mask is not None
|
|
352
|
+
else None,
|
|
335
353
|
),
|
|
336
354
|
is_leaf=lambda x: x is None,
|
|
337
355
|
)
|
|
@@ -373,7 +391,7 @@ class TriangleMesh(eqx.Module):
|
|
|
373
391
|
|
|
374
392
|
def set_assume_quads(self, flag: bool = True) -> Self:
|
|
375
393
|
"""
|
|
376
|
-
Return a
|
|
394
|
+
Return a new instance of this scene with :attr:`TriangleMesh.assume_quads<differt.geometry.TriangleMesh.assume_quads>` set to ``flag``.
|
|
377
395
|
|
|
378
396
|
Unlike with using :func:`equinox.tree_at`, this function will also
|
|
379
397
|
perform runtime checks.
|
|
@@ -382,7 +400,7 @@ class TriangleMesh(eqx.Module):
|
|
|
382
400
|
flag: The new flag value.
|
|
383
401
|
|
|
384
402
|
Returns:
|
|
385
|
-
A new mesh.
|
|
403
|
+
A new mesh with the same structure with :attr:`TriangleMesh.assume_quads<differt.geometry.TriangleMesh.assume_quads>` set to ``flag``.
|
|
386
404
|
"""
|
|
387
405
|
mesh = eqx.tree_at(lambda m: m.assume_quads, self, flag)
|
|
388
406
|
mesh.__check_init__()
|
|
@@ -573,7 +591,7 @@ class TriangleMesh(eqx.Module):
|
|
|
573
591
|
return _TriangleMeshVerticesUpdateHelper(self)
|
|
574
592
|
|
|
575
593
|
def masked(self) -> Self:
|
|
576
|
-
"""Return a
|
|
594
|
+
"""Return a new instance of this object that only keeps masked (i.e., active) triangles.
|
|
577
595
|
|
|
578
596
|
.. important::
|
|
579
597
|
This method does not preserve the :attr:`object_bounds` attribute.
|
|
@@ -696,14 +714,14 @@ class TriangleMesh(eqx.Module):
|
|
|
696
714
|
|
|
697
715
|
Two important exceptions are:
|
|
698
716
|
|
|
699
|
-
* If one mesh is empty, a
|
|
700
|
-
* If both meshes are empty, then a
|
|
717
|
+
* If one mesh is empty, a new instance of the other mesh is returned as is;
|
|
718
|
+
* If both meshes are empty, then a new instance of ``self`` is returned.
|
|
701
719
|
|
|
702
720
|
Args:
|
|
703
721
|
other: The mesh to append.
|
|
704
722
|
|
|
705
723
|
Returns:
|
|
706
|
-
The new mesh.
|
|
724
|
+
The new mesh with a structure that is the result of combining both input meshes.
|
|
707
725
|
|
|
708
726
|
Examples:
|
|
709
727
|
The following example shows how to create a mesh of nested cubes.
|
|
@@ -847,13 +865,11 @@ class TriangleMesh(eqx.Module):
|
|
|
847
865
|
"""
|
|
848
866
|
Return a new mesh with duplicate vertices removed.
|
|
849
867
|
|
|
850
|
-
Vertices are also sorted in ascending order
|
|
851
|
-
will not change the order of the vertices.
|
|
868
|
+
Vertices are also sorted in ascending order
|
|
852
869
|
|
|
853
870
|
Returns:
|
|
854
871
|
A new mesh with duplicate vertices removed.
|
|
855
872
|
"""
|
|
856
|
-
# TODO: handle mask
|
|
857
873
|
vertices, unique_inverse = jnp.unique(
|
|
858
874
|
self.vertices, axis=0, return_inverse=True
|
|
859
875
|
)
|
|
@@ -864,62 +880,6 @@ class TriangleMesh(eqx.Module):
|
|
|
864
880
|
(vertices, triangles),
|
|
865
881
|
)
|
|
866
882
|
|
|
867
|
-
def sort(self) -> Self:
|
|
868
|
-
"""
|
|
869
|
-
Return a new mesh with vertices sorted in ascending order.
|
|
870
|
-
|
|
871
|
-
Returns:
|
|
872
|
-
A new mesh with vertices sorted in ascending order.
|
|
873
|
-
|
|
874
|
-
Examples:
|
|
875
|
-
The following example shows how sorting a mesh
|
|
876
|
-
affects the order of the vertices, and thus the triangles numbering,
|
|
877
|
-
but not the actual geometry.
|
|
878
|
-
|
|
879
|
-
.. plotly::
|
|
880
|
-
:context: reset
|
|
881
|
-
|
|
882
|
-
>>> from differt.geometry import TriangleMesh
|
|
883
|
-
>>>
|
|
884
|
-
>>> mesh = TriangleMesh.plane(
|
|
885
|
-
... jnp.array([0.0, 0.0, 0.0]), normal=jnp.array([1.0, 0.0, 0.0])
|
|
886
|
-
... )
|
|
887
|
-
>>> mesh.vertices
|
|
888
|
-
Array([[ 0. , 0.5, 0.5],
|
|
889
|
-
[ 0. , -0.5, 0.5],
|
|
890
|
-
[ 0. , -0.5, -0.5],
|
|
891
|
-
[ 0. , 0.5, -0.5]], dtype=float32)
|
|
892
|
-
>>> mesh.triangles
|
|
893
|
-
Array([[0, 1, 2],
|
|
894
|
-
[0, 2, 3]], dtype=int32)
|
|
895
|
-
>>> fig = mesh.plot(opacity=0.5, backend="plotly")
|
|
896
|
-
>>> fig # doctest: +SKIP
|
|
897
|
-
|
|
898
|
-
.. plotly::
|
|
899
|
-
:context:
|
|
900
|
-
|
|
901
|
-
>>> sorted_mesh = mesh.sort()
|
|
902
|
-
>>> sorted_mesh.vertices
|
|
903
|
-
Array([[ 0. , -0.5, -0.5],
|
|
904
|
-
[ 0. , -0.5, 0.5],
|
|
905
|
-
[ 0. , 0.5, -0.5],
|
|
906
|
-
[ 0. , 0.5, 0.5]], dtype=float32)
|
|
907
|
-
>>> sorted_mesh.triangles
|
|
908
|
-
Array([[3, 1, 0],
|
|
909
|
-
[3, 0, 2]], dtype=int32)
|
|
910
|
-
>>> fig = sorted_mesh.plot(opacity=0.5, backend="plotly")
|
|
911
|
-
>>> fig # doctest: +SKIP
|
|
912
|
-
"""
|
|
913
|
-
# TODO: handle mask
|
|
914
|
-
indices = jnp.lexsort(self.vertices.T[::-1])
|
|
915
|
-
vertices = self.vertices[indices]
|
|
916
|
-
triangles = jnp.argsort(indices)[self.triangles]
|
|
917
|
-
return eqx.tree_at(
|
|
918
|
-
lambda m: (m.vertices, m.triangles),
|
|
919
|
-
self,
|
|
920
|
-
(vertices, triangles),
|
|
921
|
-
)
|
|
922
|
-
|
|
923
883
|
@overload
|
|
924
884
|
def set_face_colors(
|
|
925
885
|
self,
|
|
@@ -945,7 +905,7 @@ class TriangleMesh(eqx.Module):
|
|
|
945
905
|
key: PRNGKeyArray | None = None,
|
|
946
906
|
) -> Self:
|
|
947
907
|
"""
|
|
948
|
-
Return a
|
|
908
|
+
Return a new instance of this mesh, with new face colors.
|
|
949
909
|
|
|
950
910
|
Args:
|
|
951
911
|
colors: The array of RGB colors.
|
|
@@ -1088,7 +1048,7 @@ class TriangleMesh(eqx.Module):
|
|
|
1088
1048
|
|
|
1089
1049
|
def set_materials(self, *names: str) -> Self:
|
|
1090
1050
|
"""
|
|
1091
|
-
Return a
|
|
1051
|
+
Return a new instance of this mesh, with new face materials from material names.
|
|
1092
1052
|
|
|
1093
1053
|
If a material name is not in :attr:`material_names`, it is added.
|
|
1094
1054
|
|
|
@@ -1129,7 +1089,7 @@ class TriangleMesh(eqx.Module):
|
|
|
1129
1089
|
self, materials: Int[ArrayLike, " "] | Int[ArrayLike, "#num_triangles"]
|
|
1130
1090
|
) -> Self:
|
|
1131
1091
|
"""
|
|
1132
|
-
Return a
|
|
1092
|
+
Return a new instance of this mesh, with new face materials.
|
|
1133
1093
|
|
|
1134
1094
|
Args:
|
|
1135
1095
|
materials: The material indices.
|
|
@@ -1156,9 +1116,9 @@ class TriangleMesh(eqx.Module):
|
|
|
1156
1116
|
@classmethod
|
|
1157
1117
|
def plane(
|
|
1158
1118
|
cls,
|
|
1159
|
-
vertex_a: Float[
|
|
1160
|
-
vertex_b: Float[
|
|
1161
|
-
vertex_c: Float[
|
|
1119
|
+
vertex_a: Float[ArrayLike, "3"],
|
|
1120
|
+
vertex_b: Float[ArrayLike, "3"],
|
|
1121
|
+
vertex_c: Float[ArrayLike, "3"],
|
|
1162
1122
|
*,
|
|
1163
1123
|
normal: None = None,
|
|
1164
1124
|
side_length: Float[ArrayLike, " "] = 1.0,
|
|
@@ -1169,11 +1129,11 @@ class TriangleMesh(eqx.Module):
|
|
|
1169
1129
|
@classmethod
|
|
1170
1130
|
def plane(
|
|
1171
1131
|
cls,
|
|
1172
|
-
vertex_a: Float[
|
|
1132
|
+
vertex_a: Float[ArrayLike, "3"],
|
|
1173
1133
|
vertex_b: None = None,
|
|
1174
1134
|
vertex_c: None = None,
|
|
1175
1135
|
*,
|
|
1176
|
-
normal: Float[
|
|
1136
|
+
normal: Float[ArrayLike, "3"],
|
|
1177
1137
|
side_length: Float[ArrayLike, " "] = 1.0,
|
|
1178
1138
|
rotate: Float[ArrayLike, " "] | None = None,
|
|
1179
1139
|
) -> Self: ...
|