lsurf 1.0.0__py3-none-any.whl
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.
- lsurf/__init__.py +471 -0
- lsurf/analysis/__init__.py +107 -0
- lsurf/analysis/healpix_utils.py +418 -0
- lsurf/analysis/sphere_viz.py +1280 -0
- lsurf/cli/__init__.py +48 -0
- lsurf/cli/build.py +398 -0
- lsurf/cli/config_schema.py +318 -0
- lsurf/cli/gui_cmd.py +76 -0
- lsurf/cli/interactive.py +850 -0
- lsurf/cli/main.py +81 -0
- lsurf/cli/run.py +806 -0
- lsurf/detectors/__init__.py +266 -0
- lsurf/detectors/analysis.py +289 -0
- lsurf/detectors/base.py +284 -0
- lsurf/detectors/constant_size_rings.py +485 -0
- lsurf/detectors/directional.py +45 -0
- lsurf/detectors/extended/__init__.py +73 -0
- lsurf/detectors/extended/local_sphere.py +353 -0
- lsurf/detectors/extended/recording_sphere.py +368 -0
- lsurf/detectors/planar.py +45 -0
- lsurf/detectors/protocol.py +187 -0
- lsurf/detectors/recording_spheres.py +63 -0
- lsurf/detectors/results.py +1140 -0
- lsurf/detectors/small/__init__.py +79 -0
- lsurf/detectors/small/directional.py +330 -0
- lsurf/detectors/small/planar.py +401 -0
- lsurf/detectors/small/spherical.py +450 -0
- lsurf/detectors/spherical.py +45 -0
- lsurf/geometry/__init__.py +199 -0
- lsurf/geometry/builder.py +478 -0
- lsurf/geometry/cell.py +228 -0
- lsurf/geometry/cell_geometry.py +247 -0
- lsurf/geometry/detector_arrays.py +1785 -0
- lsurf/geometry/geometry.py +222 -0
- lsurf/geometry/surface_analysis.py +375 -0
- lsurf/geometry/validation.py +91 -0
- lsurf/gui/__init__.py +51 -0
- lsurf/gui/app.py +903 -0
- lsurf/gui/core/__init__.py +39 -0
- lsurf/gui/core/scene.py +343 -0
- lsurf/gui/core/simulation.py +264 -0
- lsurf/gui/renderers/__init__.py +40 -0
- lsurf/gui/renderers/ray_renderer.py +353 -0
- lsurf/gui/renderers/source_renderer.py +505 -0
- lsurf/gui/renderers/surface_renderer.py +477 -0
- lsurf/gui/views/__init__.py +48 -0
- lsurf/gui/views/config_editor.py +3199 -0
- lsurf/gui/views/properties.py +257 -0
- lsurf/gui/views/results.py +291 -0
- lsurf/gui/views/scene_tree.py +180 -0
- lsurf/gui/views/viewport_3d.py +555 -0
- lsurf/gui/views/visualizations.py +712 -0
- lsurf/materials/__init__.py +169 -0
- lsurf/materials/base/__init__.py +64 -0
- lsurf/materials/base/full_inhomogeneous.py +208 -0
- lsurf/materials/base/grid_inhomogeneous.py +319 -0
- lsurf/materials/base/homogeneous.py +342 -0
- lsurf/materials/base/material_field.py +527 -0
- lsurf/materials/base/simple_inhomogeneous.py +418 -0
- lsurf/materials/base/spectral_inhomogeneous.py +497 -0
- lsurf/materials/implementations/__init__.py +120 -0
- lsurf/materials/implementations/data/alpha_values_typical_atmosphere_updated.txt +24 -0
- lsurf/materials/implementations/duct_atmosphere.py +390 -0
- lsurf/materials/implementations/exponential_atmosphere.py +435 -0
- lsurf/materials/implementations/gaussian_lens.py +120 -0
- lsurf/materials/implementations/interpolated_data.py +123 -0
- lsurf/materials/implementations/layered_atmosphere.py +134 -0
- lsurf/materials/implementations/linear_gradient.py +109 -0
- lsurf/materials/implementations/linsley_atmosphere.py +764 -0
- lsurf/materials/implementations/standard_materials.py +126 -0
- lsurf/materials/implementations/turbulent_atmosphere.py +135 -0
- lsurf/materials/implementations/us_standard_atmosphere.py +149 -0
- lsurf/materials/utils/__init__.py +77 -0
- lsurf/materials/utils/constants.py +45 -0
- lsurf/materials/utils/device_functions.py +117 -0
- lsurf/materials/utils/dispersion.py +160 -0
- lsurf/materials/utils/factories.py +142 -0
- lsurf/propagation/__init__.py +91 -0
- lsurf/propagation/detector_gpu.py +67 -0
- lsurf/propagation/gpu_device_rays.py +294 -0
- lsurf/propagation/kernels/__init__.py +175 -0
- lsurf/propagation/kernels/absorption/__init__.py +61 -0
- lsurf/propagation/kernels/absorption/grid.py +240 -0
- lsurf/propagation/kernels/absorption/simple.py +232 -0
- lsurf/propagation/kernels/absorption/spectral.py +410 -0
- lsurf/propagation/kernels/detection/__init__.py +64 -0
- lsurf/propagation/kernels/detection/protocol.py +102 -0
- lsurf/propagation/kernels/detection/spherical.py +255 -0
- lsurf/propagation/kernels/device_functions.py +790 -0
- lsurf/propagation/kernels/fresnel/__init__.py +64 -0
- lsurf/propagation/kernels/fresnel/protocol.py +97 -0
- lsurf/propagation/kernels/fresnel/standard.py +258 -0
- lsurf/propagation/kernels/intersection/__init__.py +79 -0
- lsurf/propagation/kernels/intersection/annular_plane.py +207 -0
- lsurf/propagation/kernels/intersection/bounded_plane.py +205 -0
- lsurf/propagation/kernels/intersection/plane.py +166 -0
- lsurf/propagation/kernels/intersection/protocol.py +95 -0
- lsurf/propagation/kernels/intersection/signed_distance.py +742 -0
- lsurf/propagation/kernels/intersection/sphere.py +190 -0
- lsurf/propagation/kernels/propagation/__init__.py +85 -0
- lsurf/propagation/kernels/propagation/grid.py +527 -0
- lsurf/propagation/kernels/propagation/protocol.py +105 -0
- lsurf/propagation/kernels/propagation/simple.py +460 -0
- lsurf/propagation/kernels/propagation/spectral.py +875 -0
- lsurf/propagation/kernels/registry.py +331 -0
- lsurf/propagation/kernels/surface/__init__.py +72 -0
- lsurf/propagation/kernels/surface/bisection.py +232 -0
- lsurf/propagation/kernels/surface/detection.py +402 -0
- lsurf/propagation/kernels/surface/reduction.py +166 -0
- lsurf/propagation/propagator_protocol.py +222 -0
- lsurf/propagation/propagators/__init__.py +101 -0
- lsurf/propagation/propagators/detector_handler.py +354 -0
- lsurf/propagation/propagators/factory.py +200 -0
- lsurf/propagation/propagators/fresnel_handler.py +305 -0
- lsurf/propagation/propagators/gpu_gradient.py +566 -0
- lsurf/propagation/propagators/gpu_surface_propagator.py +707 -0
- lsurf/propagation/propagators/gradient.py +429 -0
- lsurf/propagation/propagators/intersection_handler.py +327 -0
- lsurf/propagation/propagators/material_propagator.py +398 -0
- lsurf/propagation/propagators/signed_distance_handler.py +522 -0
- lsurf/propagation/propagators/spectral_gpu_gradient.py +553 -0
- lsurf/propagation/propagators/surface_interaction.py +616 -0
- lsurf/propagation/propagators/surface_propagator.py +719 -0
- lsurf/py.typed +1 -0
- lsurf/simulation/__init__.py +70 -0
- lsurf/simulation/config.py +164 -0
- lsurf/simulation/orchestrator.py +462 -0
- lsurf/simulation/result.py +299 -0
- lsurf/simulation/simulation.py +262 -0
- lsurf/sources/__init__.py +128 -0
- lsurf/sources/base.py +264 -0
- lsurf/sources/collimated.py +252 -0
- lsurf/sources/custom.py +409 -0
- lsurf/sources/diverging.py +228 -0
- lsurf/sources/gaussian.py +272 -0
- lsurf/sources/parallel_from_positions.py +197 -0
- lsurf/sources/point.py +172 -0
- lsurf/sources/uniform_diverging.py +258 -0
- lsurf/surfaces/__init__.py +184 -0
- lsurf/surfaces/cpu/__init__.py +50 -0
- lsurf/surfaces/cpu/curved_wave.py +463 -0
- lsurf/surfaces/cpu/gerstner_wave.py +381 -0
- lsurf/surfaces/cpu/wave_params.py +118 -0
- lsurf/surfaces/gpu/__init__.py +72 -0
- lsurf/surfaces/gpu/annular_plane.py +453 -0
- lsurf/surfaces/gpu/bounded_plane.py +390 -0
- lsurf/surfaces/gpu/curved_wave.py +483 -0
- lsurf/surfaces/gpu/gerstner_wave.py +377 -0
- lsurf/surfaces/gpu/multi_curved_wave.py +520 -0
- lsurf/surfaces/gpu/plane.py +299 -0
- lsurf/surfaces/gpu/recording_sphere.py +587 -0
- lsurf/surfaces/gpu/sphere.py +311 -0
- lsurf/surfaces/protocol.py +336 -0
- lsurf/surfaces/registry.py +373 -0
- lsurf/utilities/__init__.py +175 -0
- lsurf/utilities/detector_analysis.py +814 -0
- lsurf/utilities/fresnel.py +628 -0
- lsurf/utilities/interactions.py +1215 -0
- lsurf/utilities/propagation.py +602 -0
- lsurf/utilities/ray_data.py +532 -0
- lsurf/utilities/recording_sphere.py +745 -0
- lsurf/utilities/time_spread.py +463 -0
- lsurf/visualization/__init__.py +329 -0
- lsurf/visualization/absorption_plots.py +334 -0
- lsurf/visualization/atmospheric_plots.py +754 -0
- lsurf/visualization/common.py +348 -0
- lsurf/visualization/detector_plots.py +1350 -0
- lsurf/visualization/detector_sphere_plots.py +1173 -0
- lsurf/visualization/fresnel_plots.py +1061 -0
- lsurf/visualization/ocean_simulation_plots.py +999 -0
- lsurf/visualization/polarization_plots.py +916 -0
- lsurf/visualization/raytracing_plots.py +1521 -0
- lsurf/visualization/ring_detector_plots.py +1867 -0
- lsurf/visualization/time_spread_plots.py +531 -0
- lsurf-1.0.0.dist-info/METADATA +381 -0
- lsurf-1.0.0.dist-info/RECORD +180 -0
- lsurf-1.0.0.dist-info/WHEEL +5 -0
- lsurf-1.0.0.dist-info/entry_points.txt +2 -0
- lsurf-1.0.0.dist-info/licenses/LICENSE +32 -0
- lsurf-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
# The Clear BSD License
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2026 Tobias Heibges
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
#
|
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
|
7
|
+
# modification, are permitted (subject to the limitations in the disclaimer
|
|
8
|
+
# below) provided that the following conditions are met:
|
|
9
|
+
#
|
|
10
|
+
# * Redistributions of source code must retain the above copyright notice,
|
|
11
|
+
# this list of conditions and the following disclaimer.
|
|
12
|
+
#
|
|
13
|
+
# * Redistributions in binary form must reproduce the above copyright
|
|
14
|
+
# notice, this list of conditions and the following disclaimer in the
|
|
15
|
+
# documentation and/or other materials provided with the distribution.
|
|
16
|
+
#
|
|
17
|
+
# * Neither the name of the copyright holder nor the names of its
|
|
18
|
+
# contributors may be used to endorse or promote products derived from this
|
|
19
|
+
# software without specific prior written permission.
|
|
20
|
+
#
|
|
21
|
+
# NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
|
|
22
|
+
# THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
23
|
+
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
24
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
25
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
26
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
27
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
28
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
29
|
+
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
|
30
|
+
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
31
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
32
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
|
33
|
+
|
|
34
|
+
"""
|
|
35
|
+
Bounded Plane Surface (GPU-Capable)
|
|
36
|
+
|
|
37
|
+
Implements a bounded rectangular plane surface with GPU acceleration support.
|
|
38
|
+
Can be used as DETECTOR, OPTICAL, or ABSORBER.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
from __future__ import annotations
|
|
42
|
+
|
|
43
|
+
from dataclasses import dataclass, field
|
|
44
|
+
from typing import TYPE_CHECKING, Any
|
|
45
|
+
|
|
46
|
+
import numpy as np
|
|
47
|
+
import numpy.typing as npt
|
|
48
|
+
|
|
49
|
+
from ..protocol import Surface, SurfaceRole
|
|
50
|
+
from ..registry import register_surface_type
|
|
51
|
+
|
|
52
|
+
if TYPE_CHECKING:
|
|
53
|
+
from ...propagation.kernels.registry import IntersectionKernelID
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@dataclass
|
|
57
|
+
class BoundedPlaneSurface(Surface):
|
|
58
|
+
"""
|
|
59
|
+
Bounded rectangular plane surface with GPU acceleration.
|
|
60
|
+
|
|
61
|
+
The plane is defined by a center point, normal vector, and dimensions.
|
|
62
|
+
The rectangle is centered at the point with the given width and height.
|
|
63
|
+
|
|
64
|
+
Parameters
|
|
65
|
+
----------
|
|
66
|
+
point : tuple of float
|
|
67
|
+
Center point (px, py, pz) of the rectangle.
|
|
68
|
+
normal : tuple of float
|
|
69
|
+
Unit normal vector (nx, ny, nz) pointing "outward" (front side).
|
|
70
|
+
width : float
|
|
71
|
+
Width of the rectangle (size in local U direction).
|
|
72
|
+
height : float
|
|
73
|
+
Height of the rectangle (size in local V direction).
|
|
74
|
+
role : SurfaceRole
|
|
75
|
+
What happens when a ray hits (DETECTOR, OPTICAL, or ABSORBER).
|
|
76
|
+
name : str
|
|
77
|
+
Human-readable name.
|
|
78
|
+
material_front : MaterialField, optional
|
|
79
|
+
Material on front side (where normal points). Required for OPTICAL.
|
|
80
|
+
material_back : MaterialField, optional
|
|
81
|
+
Material on back side. Required for OPTICAL.
|
|
82
|
+
|
|
83
|
+
Examples
|
|
84
|
+
--------
|
|
85
|
+
>>> # Square detector at 33 km altitude
|
|
86
|
+
>>> detector = BoundedPlaneSurface(
|
|
87
|
+
... point=(0, 0, 33000),
|
|
88
|
+
... normal=(0, 0, -1), # Facing down toward origin
|
|
89
|
+
... width=100.0,
|
|
90
|
+
... height=100.0,
|
|
91
|
+
... role=SurfaceRole.DETECTOR,
|
|
92
|
+
... name="detector_100m",
|
|
93
|
+
... )
|
|
94
|
+
>>>
|
|
95
|
+
>>> # Rectangular glass window
|
|
96
|
+
>>> window = BoundedPlaneSurface(
|
|
97
|
+
... point=(0, 0, 0),
|
|
98
|
+
... normal=(0, 0, 1),
|
|
99
|
+
... width=1.0,
|
|
100
|
+
... height=0.5,
|
|
101
|
+
... role=SurfaceRole.OPTICAL,
|
|
102
|
+
... material_front=air,
|
|
103
|
+
... material_back=glass,
|
|
104
|
+
... name="window",
|
|
105
|
+
... )
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
point: tuple[float, float, float]
|
|
109
|
+
normal: tuple[float, float, float]
|
|
110
|
+
width: float
|
|
111
|
+
height: float
|
|
112
|
+
role: SurfaceRole
|
|
113
|
+
name: str = "bounded_plane"
|
|
114
|
+
material_front: Any = None
|
|
115
|
+
material_back: Any = None
|
|
116
|
+
|
|
117
|
+
# GPU capability
|
|
118
|
+
_gpu_capable: bool = field(default=True, init=False, repr=False)
|
|
119
|
+
_geometry_id: int = field(default=6, init=False, repr=False) # bounded plane = 6
|
|
120
|
+
|
|
121
|
+
# Internal normalized normal (set in __post_init__)
|
|
122
|
+
_normal: tuple[float, float, float] = field(
|
|
123
|
+
default=(0, 0, 1), init=False, repr=False
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
# Local U/V axes for bounds checking (set in __post_init__)
|
|
127
|
+
_u_axis: tuple[float, float, float] = field(
|
|
128
|
+
default=(1, 0, 0), init=False, repr=False
|
|
129
|
+
)
|
|
130
|
+
_v_axis: tuple[float, float, float] = field(
|
|
131
|
+
default=(0, 1, 0), init=False, repr=False
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
# Kernel ID for this instance (set in __post_init__)
|
|
135
|
+
_kernel_id: IntersectionKernelID | None = field(
|
|
136
|
+
default=None, init=False, repr=False
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
@classmethod
|
|
140
|
+
def _get_supported_kernels(cls) -> list[IntersectionKernelID]:
|
|
141
|
+
"""Get supported intersection kernels (lazy initialization)."""
|
|
142
|
+
from ...propagation.kernels.registry import IntersectionKernelID
|
|
143
|
+
|
|
144
|
+
return [IntersectionKernelID.BOUNDED_PLANE_ANALYTICAL]
|
|
145
|
+
|
|
146
|
+
@classmethod
|
|
147
|
+
def _get_default_kernel(cls) -> IntersectionKernelID:
|
|
148
|
+
"""Get default intersection kernel."""
|
|
149
|
+
from ...propagation.kernels.registry import IntersectionKernelID
|
|
150
|
+
|
|
151
|
+
return IntersectionKernelID.BOUNDED_PLANE_ANALYTICAL
|
|
152
|
+
|
|
153
|
+
@classmethod
|
|
154
|
+
def supported_kernels(cls) -> list[IntersectionKernelID]:
|
|
155
|
+
"""Return list of intersection kernels supported by this surface type."""
|
|
156
|
+
return cls._get_supported_kernels()
|
|
157
|
+
|
|
158
|
+
@classmethod
|
|
159
|
+
def default_kernel(cls) -> IntersectionKernelID:
|
|
160
|
+
"""Return the default intersection kernel for this surface type."""
|
|
161
|
+
return cls._get_default_kernel()
|
|
162
|
+
|
|
163
|
+
def __post_init__(self) -> None:
|
|
164
|
+
# Validate dimensions
|
|
165
|
+
if self.width <= 0:
|
|
166
|
+
raise ValueError("Width must be positive")
|
|
167
|
+
if self.height <= 0:
|
|
168
|
+
raise ValueError("Height must be positive")
|
|
169
|
+
|
|
170
|
+
# Normalize the normal vector
|
|
171
|
+
n = np.array(self.normal, dtype=np.float64)
|
|
172
|
+
norm = np.linalg.norm(n)
|
|
173
|
+
if norm < 1e-12:
|
|
174
|
+
raise ValueError("Normal vector cannot be zero")
|
|
175
|
+
n = n / norm
|
|
176
|
+
self._normal = tuple(n.tolist())
|
|
177
|
+
|
|
178
|
+
# Compute local U/V axes
|
|
179
|
+
self._compute_local_axes()
|
|
180
|
+
|
|
181
|
+
# Set default kernel
|
|
182
|
+
self._kernel_id = self._get_default_kernel()
|
|
183
|
+
|
|
184
|
+
def _compute_local_axes(self) -> None:
|
|
185
|
+
"""Compute orthonormal U/V axes on the plane."""
|
|
186
|
+
n = np.array(self._normal)
|
|
187
|
+
|
|
188
|
+
# Choose reference vector not parallel to normal
|
|
189
|
+
if abs(n[2]) < 0.9:
|
|
190
|
+
ref = np.array([0.0, 0.0, 1.0])
|
|
191
|
+
else:
|
|
192
|
+
ref = np.array([1.0, 0.0, 0.0])
|
|
193
|
+
|
|
194
|
+
# U = normalize(ref - (ref·n)n)
|
|
195
|
+
u = ref - np.dot(ref, n) * n
|
|
196
|
+
u = u / np.linalg.norm(u)
|
|
197
|
+
|
|
198
|
+
# V = n × U (right-handed coordinate system)
|
|
199
|
+
v = np.cross(n, u)
|
|
200
|
+
|
|
201
|
+
self._u_axis = tuple(u.tolist())
|
|
202
|
+
self._v_axis = tuple(v.tolist())
|
|
203
|
+
|
|
204
|
+
@property
|
|
205
|
+
def gpu_capable(self) -> bool:
|
|
206
|
+
"""This surface supports GPU acceleration."""
|
|
207
|
+
return True
|
|
208
|
+
|
|
209
|
+
@property
|
|
210
|
+
def geometry_id(self) -> int:
|
|
211
|
+
"""GPU geometry type ID (bounded plane = 6)."""
|
|
212
|
+
return 6
|
|
213
|
+
|
|
214
|
+
@property
|
|
215
|
+
def half_width(self) -> float:
|
|
216
|
+
"""Half-width for bounds checking."""
|
|
217
|
+
return self.width / 2.0
|
|
218
|
+
|
|
219
|
+
@property
|
|
220
|
+
def half_height(self) -> float:
|
|
221
|
+
"""Half-height for bounds checking."""
|
|
222
|
+
return self.height / 2.0
|
|
223
|
+
|
|
224
|
+
def get_gpu_parameters(self) -> tuple:
|
|
225
|
+
"""
|
|
226
|
+
Return parameters for GPU kernel.
|
|
227
|
+
|
|
228
|
+
Returns
|
|
229
|
+
-------
|
|
230
|
+
tuple
|
|
231
|
+
(normal_x, normal_y, normal_z, point_x, point_y, point_z,
|
|
232
|
+
u_axis_x, u_axis_y, u_axis_z, v_axis_x, v_axis_y, v_axis_z,
|
|
233
|
+
half_width, half_height)
|
|
234
|
+
"""
|
|
235
|
+
return (
|
|
236
|
+
self._normal[0],
|
|
237
|
+
self._normal[1],
|
|
238
|
+
self._normal[2],
|
|
239
|
+
self.point[0],
|
|
240
|
+
self.point[1],
|
|
241
|
+
self.point[2],
|
|
242
|
+
self._u_axis[0],
|
|
243
|
+
self._u_axis[1],
|
|
244
|
+
self._u_axis[2],
|
|
245
|
+
self._v_axis[0],
|
|
246
|
+
self._v_axis[1],
|
|
247
|
+
self._v_axis[2],
|
|
248
|
+
self.half_width,
|
|
249
|
+
self.half_height,
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
def get_materials(self) -> tuple | None:
|
|
253
|
+
"""
|
|
254
|
+
Return (material_front, material_back) for Fresnel calculation.
|
|
255
|
+
|
|
256
|
+
Returns
|
|
257
|
+
-------
|
|
258
|
+
tuple or None
|
|
259
|
+
(material_front, material_back) or None if not OPTICAL
|
|
260
|
+
"""
|
|
261
|
+
if self.role == SurfaceRole.OPTICAL:
|
|
262
|
+
return (self.material_front, self.material_back)
|
|
263
|
+
return None
|
|
264
|
+
|
|
265
|
+
def signed_distance(
|
|
266
|
+
self,
|
|
267
|
+
positions: npt.NDArray[np.float32],
|
|
268
|
+
) -> npt.NDArray[np.float32]:
|
|
269
|
+
"""
|
|
270
|
+
Compute signed distance from positions to plane.
|
|
271
|
+
|
|
272
|
+
Note: This returns signed distance to the infinite plane.
|
|
273
|
+
Bounds checking is performed in the intersection kernel.
|
|
274
|
+
|
|
275
|
+
Parameters
|
|
276
|
+
----------
|
|
277
|
+
positions : ndarray, shape (N, 3)
|
|
278
|
+
Points to compute distance for
|
|
279
|
+
|
|
280
|
+
Returns
|
|
281
|
+
-------
|
|
282
|
+
ndarray, shape (N,)
|
|
283
|
+
Signed distance (positive on normal side, negative on back side)
|
|
284
|
+
"""
|
|
285
|
+
normal = np.array(self._normal, dtype=np.float32)
|
|
286
|
+
point = np.array(self.point, dtype=np.float32)
|
|
287
|
+
|
|
288
|
+
# d = dot(p - point, normal)
|
|
289
|
+
diff = positions - point
|
|
290
|
+
return np.dot(diff, normal)
|
|
291
|
+
|
|
292
|
+
def intersect(
|
|
293
|
+
self,
|
|
294
|
+
origins: npt.NDArray[np.float32],
|
|
295
|
+
directions: npt.NDArray[np.float32],
|
|
296
|
+
min_distance: float = 1e-6,
|
|
297
|
+
) -> tuple[npt.NDArray[np.float32], npt.NDArray[np.bool_]]:
|
|
298
|
+
"""
|
|
299
|
+
Compute ray-plane intersection with bounds checking.
|
|
300
|
+
|
|
301
|
+
Parameters
|
|
302
|
+
----------
|
|
303
|
+
origins : ndarray, shape (N, 3)
|
|
304
|
+
Ray origins
|
|
305
|
+
directions : ndarray, shape (N, 3)
|
|
306
|
+
Ray directions (normalized)
|
|
307
|
+
min_distance : float
|
|
308
|
+
Minimum valid intersection distance
|
|
309
|
+
|
|
310
|
+
Returns
|
|
311
|
+
-------
|
|
312
|
+
distances : ndarray, shape (N,)
|
|
313
|
+
Distance to intersection (inf if no hit)
|
|
314
|
+
hit_mask : ndarray, shape (N,)
|
|
315
|
+
Boolean mask of valid intersections
|
|
316
|
+
"""
|
|
317
|
+
normal = np.array(self._normal, dtype=np.float32)
|
|
318
|
+
point = np.array(self.point, dtype=np.float32)
|
|
319
|
+
u_axis = np.array(self._u_axis, dtype=np.float32)
|
|
320
|
+
v_axis = np.array(self._v_axis, dtype=np.float32)
|
|
321
|
+
|
|
322
|
+
# t = dot(point - origin, normal) / dot(direction, normal)
|
|
323
|
+
denom = np.dot(directions, normal)
|
|
324
|
+
|
|
325
|
+
# Parallel rays don't intersect
|
|
326
|
+
parallel_mask = np.abs(denom) < 1e-10
|
|
327
|
+
|
|
328
|
+
diff = point - origins
|
|
329
|
+
t = np.dot(diff, normal) / np.where(parallel_mask, 1.0, denom)
|
|
330
|
+
|
|
331
|
+
# Valid intersection: not parallel, t >= min_distance
|
|
332
|
+
valid_t = (~parallel_mask) & (t >= min_distance)
|
|
333
|
+
|
|
334
|
+
# Compute intersection points
|
|
335
|
+
intersection_points = origins + t[:, np.newaxis] * directions
|
|
336
|
+
|
|
337
|
+
# Compute local coordinates relative to center
|
|
338
|
+
rel = intersection_points - point
|
|
339
|
+
|
|
340
|
+
# Project onto local axes
|
|
341
|
+
u_coord = np.dot(rel, u_axis)
|
|
342
|
+
v_coord = np.dot(rel, v_axis)
|
|
343
|
+
|
|
344
|
+
# Check bounds
|
|
345
|
+
within_bounds = (np.abs(u_coord) <= self.half_width) & (
|
|
346
|
+
np.abs(v_coord) <= self.half_height
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
# Final hit mask
|
|
350
|
+
hit_mask = valid_t & within_bounds
|
|
351
|
+
distances = np.where(hit_mask, t, np.inf)
|
|
352
|
+
|
|
353
|
+
return distances.astype(np.float32), hit_mask
|
|
354
|
+
|
|
355
|
+
def normal_at(
|
|
356
|
+
self,
|
|
357
|
+
positions: npt.NDArray[np.float32],
|
|
358
|
+
incoming_directions: npt.NDArray[np.float32] | None = None,
|
|
359
|
+
) -> npt.NDArray[np.float32]:
|
|
360
|
+
"""
|
|
361
|
+
Compute surface normal at positions.
|
|
362
|
+
|
|
363
|
+
For a plane, normal is constant everywhere.
|
|
364
|
+
|
|
365
|
+
Parameters
|
|
366
|
+
----------
|
|
367
|
+
positions : ndarray, shape (N, 3)
|
|
368
|
+
Points on the surface
|
|
369
|
+
incoming_directions : ndarray, shape (N, 3), optional
|
|
370
|
+
Ray directions (used to flip normal if needed)
|
|
371
|
+
|
|
372
|
+
Returns
|
|
373
|
+
-------
|
|
374
|
+
ndarray, shape (N, 3)
|
|
375
|
+
Normal vectors at each position
|
|
376
|
+
"""
|
|
377
|
+
n = len(positions)
|
|
378
|
+
normals = np.tile(np.array(self._normal, dtype=np.float32), (n, 1))
|
|
379
|
+
|
|
380
|
+
# Optionally flip normals to face incoming rays
|
|
381
|
+
if incoming_directions is not None:
|
|
382
|
+
dot = np.sum(normals * incoming_directions, axis=1)
|
|
383
|
+
flip_mask = dot > 0 # Normal facing same direction as ray
|
|
384
|
+
normals[flip_mask] = -normals[flip_mask]
|
|
385
|
+
|
|
386
|
+
return normals
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
# Register class with registry
|
|
390
|
+
register_surface_type("bounded_plane", "gpu", 6, BoundedPlaneSurface)
|