pyviewfactor 0.1.16__tar.gz → 1.0.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.
- {pyviewfactor-0.1.16 → pyviewfactor-1.0.0}/PKG-INFO +7 -7
- {pyviewfactor-0.1.16 → pyviewfactor-1.0.0}/pyviewfactor/__init__.py +7 -1
- {pyviewfactor-0.1.16 → pyviewfactor-1.0.0}/pyviewfactor/_version.py +1 -1
- {pyviewfactor-0.1.16 → pyviewfactor-1.0.0}/pyviewfactor/pvf_geometry_preprocess.py +17 -13
- {pyviewfactor-0.1.16 → pyviewfactor-1.0.0}/pyviewfactor/pvf_viewfactor_computations.py +12 -5
- {pyviewfactor-0.1.16 → pyviewfactor-1.0.0}/pyviewfactor/pvf_visibility_obstruction.py +87 -48
- {pyviewfactor-0.1.16 → pyviewfactor-1.0.0}/pyviewfactor.egg-info/PKG-INFO +7 -7
- pyviewfactor-1.0.0/pyviewfactor.egg-info/requires.txt +4 -0
- {pyviewfactor-0.1.16 → pyviewfactor-1.0.0}/setup.cfg +6 -6
- {pyviewfactor-0.1.16 → pyviewfactor-1.0.0}/test/test_view_factor.py +35 -39
- pyviewfactor-1.0.0/test/test_visibility_obstruction.py +415 -0
- pyviewfactor-0.1.16/pyviewfactor.egg-info/requires.txt +0 -4
- pyviewfactor-0.1.16/test/test_visibility_obstruction.py +0 -194
- {pyviewfactor-0.1.16 → pyviewfactor-1.0.0}/LICENSE.txt +0 -0
- {pyviewfactor-0.1.16 → pyviewfactor-1.0.0}/README.md +0 -0
- {pyviewfactor-0.1.16 → pyviewfactor-1.0.0}/pyviewfactor/pvf_integrators.py +0 -0
- {pyviewfactor-0.1.16 → pyviewfactor-1.0.0}/pyviewfactor/pvf_plot.py +0 -0
- {pyviewfactor-0.1.16 → pyviewfactor-1.0.0}/pyviewfactor.egg-info/SOURCES.txt +0 -0
- {pyviewfactor-0.1.16 → pyviewfactor-1.0.0}/pyviewfactor.egg-info/dependency_links.txt +0 -0
- {pyviewfactor-0.1.16 → pyviewfactor-1.0.0}/pyviewfactor.egg-info/top_level.txt +0 -0
- {pyviewfactor-0.1.16 → pyviewfactor-1.0.0}/setup.py +0 -0
- {pyviewfactor-0.1.16 → pyviewfactor-1.0.0}/test/__init__.py +0 -0
- {pyviewfactor-0.1.16 → pyviewfactor-1.0.0}/test/test_geometry_preprocess.py +0 -0
- {pyviewfactor-0.1.16 → pyviewfactor-1.0.0}/test/test_plot.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pyviewfactor
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: A
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: "A lightweight open-source Python library for exact view-factor computations on polygonal meshes"
|
|
5
5
|
Home-page: https://gitlab.com/arep-dev/pyViewFactor/
|
|
6
6
|
Author: Mateusz BOGDAN, Edouard WALTHER, Marc ALECIAN, Mina CHAPON
|
|
7
7
|
Author-email: mateusz.bogdan@arep.fr
|
|
@@ -11,13 +11,13 @@ Classifier: Programming Language :: Python :: 3
|
|
|
11
11
|
Classifier: License :: OSI Approved :: MIT License
|
|
12
12
|
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
13
13
|
Classifier: Operating System :: OS Independent
|
|
14
|
-
Requires-Python: >=3.
|
|
14
|
+
Requires-Python: >=3.9
|
|
15
15
|
Description-Content-Type: text/markdown
|
|
16
16
|
License-File: LICENSE.txt
|
|
17
|
-
Requires-Dist: numpy>=1.
|
|
18
|
-
Requires-Dist: scipy>=1.
|
|
19
|
-
Requires-Dist: numba>=0.
|
|
20
|
-
Requires-Dist: pyvista>=0.
|
|
17
|
+
Requires-Dist: numpy>=1.26
|
|
18
|
+
Requires-Dist: scipy>=1.11
|
|
19
|
+
Requires-Dist: numba>=0.61
|
|
20
|
+
Requires-Dist: pyvista>=0.45
|
|
21
21
|
|
|
22
22
|
# PyViewFactor
|
|
23
23
|
|
|
@@ -17,11 +17,17 @@ from .pvf_visibility_obstruction import (
|
|
|
17
17
|
get_visibility,
|
|
18
18
|
get_visibility_from_cache,
|
|
19
19
|
get_obstruction,
|
|
20
|
-
get_obstruction_from_cache
|
|
20
|
+
get_obstruction_from_cache,
|
|
21
|
+
ray_intersects_triangle,
|
|
22
|
+
is_ray_blocked
|
|
21
23
|
)
|
|
22
24
|
|
|
23
25
|
from .pvf_integrators import (
|
|
24
26
|
set_quadrature_order,
|
|
27
|
+
integrand_dblquad,
|
|
28
|
+
compute_viewfactor_dblquad,
|
|
29
|
+
integrand_gauss_legendre,
|
|
30
|
+
compute_viewfactor_gauss_legendre
|
|
25
31
|
)
|
|
26
32
|
|
|
27
33
|
from .pvf_viewfactor_computations import (
|
|
@@ -47,7 +47,7 @@ def fc_unstruc2poly(mesh_unstruc):
|
|
|
47
47
|
return pv.PolyData(points, faces)
|
|
48
48
|
|
|
49
49
|
|
|
50
|
-
def face_to_array(face):
|
|
50
|
+
def face_to_array(face,rounding_decimal=8):
|
|
51
51
|
"""
|
|
52
52
|
Extract the vertex coordinates of a single PolyData face as a NumPy array.
|
|
53
53
|
|
|
@@ -63,7 +63,7 @@ def face_to_array(face):
|
|
|
63
63
|
|
|
64
64
|
> The (x, y, z) coordinates of the face's vertices.
|
|
65
65
|
"""
|
|
66
|
-
return face.get_cell(0).points.astype(np.float64)
|
|
66
|
+
return face.get_cell(0).points.round(decimals=rounding_decimal).astype(np.float64)
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
@njit
|
|
@@ -288,12 +288,14 @@ class ProcessedGeometry:
|
|
|
288
288
|
self.sizes = np.zeros(self.N, dtype=np.float64)
|
|
289
289
|
|
|
290
290
|
for i in range(self.N):
|
|
291
|
+
# raw = mesh.extract_cells(i)
|
|
292
|
+
# face = fc_unstruc2poly(raw)
|
|
293
|
+
# faces_i = face.faces
|
|
294
|
+
# n_i = int(faces_i[0])
|
|
295
|
+
# idxs = faces_i[1:1 + n_i]
|
|
291
296
|
raw = mesh.extract_cells(i)
|
|
292
297
|
face = fc_unstruc2poly(raw)
|
|
293
|
-
|
|
294
|
-
n_i = int(faces_i[0])
|
|
295
|
-
idxs = faces_i[1:1 + n_i]
|
|
296
|
-
pts = np.round(face.points[idxs], rounding_decimal)
|
|
298
|
+
pts = face.get_cell(0).points.round(rounding_decimal).astype(np.float64)
|
|
297
299
|
|
|
298
300
|
self.points.append(pts)
|
|
299
301
|
self.centroids[i] = polygon_centroid(pts)
|
|
@@ -354,10 +356,11 @@ class FaceMeshPreprocessor:
|
|
|
354
356
|
|
|
355
357
|
> Remove triangles that exactly match either pts1 or pts2.
|
|
356
358
|
"""
|
|
357
|
-
def __init__(self, mesh: pv.PolyData):
|
|
359
|
+
def __init__(self, mesh: pv.PolyData, rounding_decimal=8):
|
|
358
360
|
if not mesh.is_all_triangles:
|
|
359
361
|
mesh = mesh.triangulate()
|
|
360
|
-
self.
|
|
362
|
+
self.rounding_decimal = rounding_decimal
|
|
363
|
+
self.points = mesh.points.round(rounding_decimal).astype(np.float64)
|
|
361
364
|
# cells array is [n, i0, i1, i2, n, ...]
|
|
362
365
|
cells = mesh.faces.reshape(-1, 4)[:, 1:]
|
|
363
366
|
self.faces = cells # shape (n_cells,3)
|
|
@@ -370,14 +373,15 @@ class FaceMeshPreprocessor:
|
|
|
370
373
|
kept.append(tri)
|
|
371
374
|
return np.array(kept, dtype=np.float64)
|
|
372
375
|
|
|
373
|
-
def exclude_exact_match(self, pts1, pts2, tris):
|
|
376
|
+
def exclude_exact_match(self, pts1, pts2, tris, rounding_decimal=8):
|
|
374
377
|
# build frozensets of each vertex array
|
|
375
|
-
vs1 = frozenset(sorted(tuple(np.round(p,
|
|
376
|
-
vs2 = frozenset(sorted(tuple(np.round(p,
|
|
378
|
+
vs1 = frozenset(sorted(tuple(np.round(p, rounding_decimal)) for p in pts1))
|
|
379
|
+
vs2 = frozenset(sorted(tuple(np.round(p, rounding_decimal)) for p in pts2))
|
|
377
380
|
out = []
|
|
378
381
|
for tri in tris:
|
|
379
|
-
tri_set = frozenset(sorted(tuple(np.round(p,
|
|
380
|
-
if not tri_set.isdisjoint(vs1) or not tri_set.isdisjoint(vs2):
|
|
382
|
+
tri_set = frozenset(sorted(tuple(np.round(p, rounding_decimal)) for p in tri))
|
|
383
|
+
# if not tri_set.isdisjoint(vs1) or not tri_set.isdisjoint(vs2):
|
|
384
|
+
if tri_set == vs1 or tri_set == vs2:
|
|
381
385
|
continue
|
|
382
386
|
out.append(tri)
|
|
383
387
|
return np.array(out, dtype=np.float64)
|
|
@@ -225,7 +225,8 @@ def compute_viewfactor_matrix(
|
|
|
225
225
|
touching_pairs.append((i, j))
|
|
226
226
|
else:
|
|
227
227
|
disconnected_pairs.append((i, j))
|
|
228
|
-
|
|
228
|
+
# print("Touching pairs:", touching_pairs)
|
|
229
|
+
# print("Disconnected pairs:", disconnected_pairs)
|
|
229
230
|
N_touching = len(touching_pairs)
|
|
230
231
|
if verbose:
|
|
231
232
|
print(f"[PVF] >>> Touching pairs: {N_touching}")
|
|
@@ -242,8 +243,8 @@ def compute_viewfactor_matrix(
|
|
|
242
243
|
if not skip_obstruction and obs_pre:
|
|
243
244
|
blocked = False
|
|
244
245
|
for obs in obs_pre:
|
|
245
|
-
if not get_obstruction_from_cache(i, j, pg, obs, strict=
|
|
246
|
-
|
|
246
|
+
if not get_obstruction_from_cache(i, j, pg, obs, strict=strict_obstruction,
|
|
247
|
+
verbose=False, eps=1e-6)[0]:
|
|
247
248
|
blocked = True
|
|
248
249
|
break
|
|
249
250
|
if blocked:
|
|
@@ -256,12 +257,18 @@ def compute_viewfactor_matrix(
|
|
|
256
257
|
c2 = pg.get_centroid(j)
|
|
257
258
|
direction = c2 - c1
|
|
258
259
|
norm = np.linalg.norm(direction)
|
|
260
|
+
# print("Cells")
|
|
261
|
+
# print(i)
|
|
262
|
+
# print(j)
|
|
263
|
+
# print("norm :", norm)
|
|
259
264
|
# eps_ij = epsilon * 0.5 * (pg.get_size(i) + pg.get_size(j))
|
|
260
265
|
if norm > 0.0:
|
|
261
266
|
direction /= norm
|
|
262
267
|
pts2_adj = pts2_adj + epsilon * direction
|
|
263
268
|
constante = 4.0 * np.pi * pg.get_area(j)
|
|
269
|
+
# print("constante :", constante)
|
|
264
270
|
vf = compute_viewfactor_dblquad(pts1, pts2_adj, constante)
|
|
271
|
+
# print("VF :", vf)
|
|
265
272
|
F[i, j] = vf
|
|
266
273
|
# if use_reciprocity:
|
|
267
274
|
F[j, i] = vf * (pg.get_area(j) / pg.get_area(i))
|
|
@@ -295,8 +302,8 @@ def compute_viewfactor_matrix(
|
|
|
295
302
|
blocked = False
|
|
296
303
|
for obs in obs_pre:
|
|
297
304
|
if not get_obstruction_from_cache(i, j, pg, obs,
|
|
298
|
-
strict=
|
|
299
|
-
|
|
305
|
+
strict=strict_obstruction,
|
|
306
|
+
verbose=False,
|
|
300
307
|
eps=1e-6)[0]:
|
|
301
308
|
blocked = True
|
|
302
309
|
break
|
|
@@ -14,7 +14,7 @@ from .pvf_geometry_preprocess import (
|
|
|
14
14
|
# Visibility
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
def get_visibility(c1, c2, strict=False,
|
|
17
|
+
def get_visibility(c1, c2, strict=False, verbose=False, rounding_decimal=8):
|
|
18
18
|
"""Facets visibility:
|
|
19
19
|
|
|
20
20
|
A test to check if two facets can "see" each other, taking the normals
|
|
@@ -38,7 +38,7 @@ def get_visibility(c1, c2, strict=False, print_warning=False, rounding_decimal=8
|
|
|
38
38
|
> Else, compute the centroids visibility, and might print a warning if
|
|
39
39
|
some points are "behind".
|
|
40
40
|
|
|
41
|
-
* **
|
|
41
|
+
* **verbose** : *Bool*
|
|
42
42
|
|
|
43
43
|
> If *True*, warning messages will be printed in addition to be returned
|
|
44
44
|
|
|
@@ -64,7 +64,7 @@ def get_visibility(c1, c2, strict=False, print_warning=False, rounding_decimal=8
|
|
|
64
64
|
>>> import pyviewfactor as pvf
|
|
65
65
|
>>> tri1 = pv.Triangle([[0.0, 1.0, 1.0],[1.0, 1.0, 1.0],[1.0, 0.0, 1.0]])
|
|
66
66
|
>>> tri2 = pv.Triangle([[1.0, 0.0, 0.0],[1.0, 1.0, 0.0],[0.0, 1.0, 0.0]])
|
|
67
|
-
>>> pvf.get_visibility(tri1, tri2,strict=False,
|
|
67
|
+
>>> pvf.get_visibility(tri1, tri2,strict=False, verbose=True)
|
|
68
68
|
"""
|
|
69
69
|
center1 = polygon_centroid(np.round(c1.points, rounding_decimal))
|
|
70
70
|
center2 = polygon_centroid(np.round(c2.points, rounding_decimal))
|
|
@@ -78,7 +78,10 @@ def get_visibility(c1, c2, strict=False, print_warning=False, rounding_decimal=8
|
|
|
78
78
|
neg_dot_prod = np.dot(v21, n1)
|
|
79
79
|
|
|
80
80
|
if not (pos_dot_prod > 0 and neg_dot_prod < 0):
|
|
81
|
-
|
|
81
|
+
warning = "[PVF] [Visibility] Cells are not visible"
|
|
82
|
+
if verbose:
|
|
83
|
+
print(warning)
|
|
84
|
+
return False, warning
|
|
82
85
|
|
|
83
86
|
if strict:
|
|
84
87
|
for cel_i, cel_j in [(c1, c2), (c2, c1)]:
|
|
@@ -88,10 +91,10 @@ def get_visibility(c1, c2, strict=False, print_warning=False, rounding_decimal=8
|
|
|
88
91
|
dot_products = np.dot(vectors, normal)
|
|
89
92
|
if np.any(dot_products > 0) and np.any(dot_products < 0):
|
|
90
93
|
warning_str = (
|
|
91
|
-
"[PVF Visibility] strict
|
|
92
|
-
"
|
|
94
|
+
"[PVF] [Visibility] strict=True, "
|
|
95
|
+
"Cells are considered not visible, but partially are"
|
|
93
96
|
)
|
|
94
|
-
if
|
|
97
|
+
if verbose:
|
|
95
98
|
print(warning_str)
|
|
96
99
|
return False, warning_str
|
|
97
100
|
else:
|
|
@@ -102,17 +105,19 @@ def get_visibility(c1, c2, strict=False, print_warning=False, rounding_decimal=8
|
|
|
102
105
|
dot_products = np.dot(vectors, normal)
|
|
103
106
|
if np.any(dot_products > 0) and np.any(dot_products < 0):
|
|
104
107
|
warning_str = (
|
|
105
|
-
"[PVF Visibility] strict
|
|
106
|
-
"
|
|
108
|
+
"[PVF] [Visibility] strict=False, "
|
|
109
|
+
"Cells are considered visible, but are only partially"
|
|
107
110
|
)
|
|
108
|
-
if
|
|
111
|
+
if verbose:
|
|
109
112
|
print(warning_str)
|
|
110
113
|
return True, warning_str
|
|
114
|
+
warning = "[PVF] [Visibility] Cells are visible"
|
|
115
|
+
if verbose:
|
|
116
|
+
print(warning)
|
|
117
|
+
return True, warning
|
|
111
118
|
|
|
112
|
-
return True, ""
|
|
113
119
|
|
|
114
|
-
|
|
115
|
-
def get_visibility_from_cache(i, j, cache, strict=False, print_warning=False,
|
|
120
|
+
def get_visibility_from_cache(i, j, cache, strict=False, verbose=False,
|
|
116
121
|
rounding_decimal=8):
|
|
117
122
|
"""
|
|
118
123
|
Check geometric visibility (normals/orientation only) between faces i and j using a
|
|
@@ -141,9 +146,9 @@ def get_visibility_from_cache(i, j, cache, strict=False, print_warning=False,
|
|
|
141
146
|
visibility. If any points are "behind", returns *False*.
|
|
142
147
|
> If **False**, uses centroids only and prints a warning if partially visible.
|
|
143
148
|
|
|
144
|
-
* **
|
|
149
|
+
* **verbose** : *bool*, optional
|
|
145
150
|
|
|
146
|
-
> If
|
|
151
|
+
> If *True*, warning messages will be printed in addition to be returned
|
|
147
152
|
|
|
148
153
|
* **rounding_decimal** : *int*, optional
|
|
149
154
|
|
|
@@ -177,7 +182,10 @@ def get_visibility_from_cache(i, j, cache, strict=False, print_warning=False,
|
|
|
177
182
|
pos_dot_prod = np.dot(v21, n2)
|
|
178
183
|
neg_dot_prod = np.dot(v21, n1)
|
|
179
184
|
if not (pos_dot_prod > 0 and neg_dot_prod < 0):
|
|
180
|
-
|
|
185
|
+
warning = "[PVF] [Visibility] Cells are not visible"
|
|
186
|
+
if verbose:
|
|
187
|
+
print(warning)
|
|
188
|
+
return False, warning
|
|
181
189
|
|
|
182
190
|
pts1 = cache.get_face(i)
|
|
183
191
|
pts2 = cache.get_face(j)
|
|
@@ -189,9 +197,10 @@ def get_visibility_from_cache(i, j, cache, strict=False, print_warning=False,
|
|
|
189
197
|
dot_products = np.dot(vectors, nB)
|
|
190
198
|
if np.any(dot_products > 0) and np.any(dot_products < 0):
|
|
191
199
|
warning_str = (
|
|
192
|
-
"[PVF Visibility] strict=True,
|
|
200
|
+
"[PVF] [Visibility] strict=True, "
|
|
201
|
+
"Cells are considered not visible, but partially are"
|
|
193
202
|
)
|
|
194
|
-
if
|
|
203
|
+
if verbose:
|
|
195
204
|
print(warning_str)
|
|
196
205
|
return False, warning_str
|
|
197
206
|
else:
|
|
@@ -200,13 +209,16 @@ def get_visibility_from_cache(i, j, cache, strict=False, print_warning=False,
|
|
|
200
209
|
dot_products = np.dot(vectors, nB)
|
|
201
210
|
if np.any(dot_products > 0) and np.any(dot_products < 0):
|
|
202
211
|
warning_str = (
|
|
203
|
-
"[PVF Visibility] strict=False,
|
|
212
|
+
"[PVF] [Visibility] strict=False, "
|
|
213
|
+
"Cells are considered visible, but are only partially"
|
|
204
214
|
)
|
|
205
|
-
if
|
|
215
|
+
if verbose:
|
|
206
216
|
print(warning_str)
|
|
207
217
|
return True, warning_str
|
|
208
|
-
|
|
209
|
-
|
|
218
|
+
warning = "[PVF] [Visibility] Cells are visible"
|
|
219
|
+
if verbose:
|
|
220
|
+
print(warning)
|
|
221
|
+
return True, warning
|
|
210
222
|
|
|
211
223
|
|
|
212
224
|
# #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
|
|
@@ -318,8 +330,9 @@ def is_ray_blocked(start, end, triangles, eps=1e-6):
|
|
|
318
330
|
|
|
319
331
|
def get_obstruction(cell1, cell2, obstacle,
|
|
320
332
|
strict=False,
|
|
321
|
-
|
|
322
|
-
eps=1e-6
|
|
333
|
+
verbose=False,
|
|
334
|
+
eps=1e-6,
|
|
335
|
+
rounding_decimal=8
|
|
323
336
|
):
|
|
324
337
|
"""
|
|
325
338
|
Test for geometric obstruction (occlusion) between two facets and an obstacle mesh.
|
|
@@ -347,9 +360,9 @@ def get_obstruction(cell1, cell2, obstacle,
|
|
|
347
360
|
> If **True**, checks all-to-all vertex rays; otherwise checks
|
|
348
361
|
centroid-to-centroid only.
|
|
349
362
|
|
|
350
|
-
* **
|
|
363
|
+
* **verbose** : *bool*, optional
|
|
351
364
|
|
|
352
|
-
> If
|
|
365
|
+
> If *True*, warning messages will be printed in addition to be returned
|
|
353
366
|
|
|
354
367
|
* **eps** : *float*, optional
|
|
355
368
|
|
|
@@ -368,12 +381,12 @@ def get_obstruction(cell1, cell2, obstacle,
|
|
|
368
381
|
"""
|
|
369
382
|
# 1) Convert inputs to numpy arrays
|
|
370
383
|
if isinstance(cell1, pv.PolyData):
|
|
371
|
-
pts1 = face_to_array(cell1)
|
|
384
|
+
pts1 = face_to_array(cell1,rounding_decimal=rounding_decimal)
|
|
372
385
|
else:
|
|
373
386
|
pts1 = np.asarray(cell1, dtype=np.float64)
|
|
374
387
|
|
|
375
388
|
if isinstance(cell2, pv.PolyData):
|
|
376
|
-
pts2 = face_to_array(cell2)
|
|
389
|
+
pts2 = face_to_array(cell2,rounding_decimal=rounding_decimal)
|
|
377
390
|
else:
|
|
378
391
|
pts2 = np.asarray(cell2, dtype=np.float64)
|
|
379
392
|
|
|
@@ -381,7 +394,7 @@ def get_obstruction(cell1, cell2, obstacle,
|
|
|
381
394
|
if isinstance(obstacle, FaceMeshPreprocessor):
|
|
382
395
|
pre = obstacle
|
|
383
396
|
else:
|
|
384
|
-
pre = FaceMeshPreprocessor(obstacle)
|
|
397
|
+
pre = FaceMeshPreprocessor(obstacle, rounding_decimal=rounding_decimal)
|
|
385
398
|
# 3) AABB cull
|
|
386
399
|
# 2) Build combined AABB & cull triangles
|
|
387
400
|
# 3) AABB cull
|
|
@@ -390,27 +403,43 @@ def get_obstruction(cell1, cell2, obstacle,
|
|
|
390
403
|
cand = pre.aabb_filter(amin, amax)
|
|
391
404
|
|
|
392
405
|
# 4) Exclude self‐triangles
|
|
393
|
-
cand = pre.exclude_exact_match(pts1, pts2, cand)
|
|
406
|
+
cand = pre.exclude_exact_match(pts1, pts2, cand, rounding_decimal=rounding_decimal)
|
|
394
407
|
if cand.size == 0:
|
|
395
|
-
|
|
408
|
+
warning = "[PVF] [Obstruction] Unobstructed (no candidate within c1-c2 AABB)"
|
|
409
|
+
if verbose:
|
|
410
|
+
print(warning)
|
|
411
|
+
return True, warning
|
|
396
412
|
|
|
397
413
|
# 5) non‐strict: centroid ray
|
|
398
414
|
if not strict:
|
|
399
415
|
c1 = polygon_centroid(pts1)
|
|
400
416
|
c2 = polygon_centroid(pts2)
|
|
401
417
|
if is_ray_blocked(c1, c2, cand, eps=eps):
|
|
402
|
-
|
|
403
|
-
|
|
418
|
+
warning = "[PVF] [Obstruction] strict=False, cells obstructed (centroid to centroid)"
|
|
419
|
+
if verbose:
|
|
420
|
+
print(warning)
|
|
421
|
+
return False, warning
|
|
422
|
+
warning = "[PVF] [Obstruction] strict=False, cells not obstructed (centroid to centroid)"
|
|
423
|
+
if verbose:
|
|
424
|
+
print(warning)
|
|
425
|
+
return True, warning
|
|
404
426
|
# 6) strict: every vertex‐to‐vertex
|
|
405
427
|
for p1 in pts1:
|
|
406
428
|
for p2 in pts2:
|
|
407
429
|
if is_ray_blocked(p1, p2, cand, eps=eps):
|
|
408
|
-
|
|
409
|
-
|
|
430
|
+
warning = "[PVF] [Obstruction] strict=True, cells obstructed (at least one vertex to vertex ray)"
|
|
431
|
+
if verbose:
|
|
432
|
+
print(warning)
|
|
433
|
+
return False, warning
|
|
434
|
+
|
|
435
|
+
warning = "[PVF] [Obstruction] strict=True, cells not obstructed (fully, all vertex to vertex rays clear)"
|
|
436
|
+
if verbose:
|
|
437
|
+
print(warning)
|
|
438
|
+
return True, warning
|
|
410
439
|
|
|
411
440
|
|
|
412
441
|
def get_obstruction_from_cache(i, j, cache, obstacle_mesh, strict=False,
|
|
413
|
-
|
|
442
|
+
verbose=False, eps=1e-6, rounding_decimal=8):
|
|
414
443
|
"""
|
|
415
444
|
Test for geometric obstruction between cached faces i and j, using a preprocessed
|
|
416
445
|
obstacle mesh.
|
|
@@ -441,9 +470,9 @@ def get_obstruction_from_cache(i, j, cache, obstacle_mesh, strict=False,
|
|
|
441
470
|
> If **True**, checks all-to-all vertex rays,
|
|
442
471
|
otherwise checks centroids only.
|
|
443
472
|
|
|
444
|
-
* **
|
|
473
|
+
* **verbose** : *bool*, optional
|
|
445
474
|
|
|
446
|
-
> If
|
|
475
|
+
> If *True*, warning messages will be printed in addition to be returned
|
|
447
476
|
|
|
448
477
|
* **eps** : *float*, optional
|
|
449
478
|
|
|
@@ -473,24 +502,34 @@ def get_obstruction_from_cache(i, j, cache, obstacle_mesh, strict=False,
|
|
|
473
502
|
cand_tris = obstacle_mesh.exclude_exact_match(pts1, pts2, cand_tris)
|
|
474
503
|
|
|
475
504
|
if cand_tris.size == 0:
|
|
476
|
-
|
|
505
|
+
warning = "[PVF] [Obstruction] Unobstructed (no candidate within c1-c2 AABB)"
|
|
506
|
+
if verbose:
|
|
507
|
+
print(warning)
|
|
508
|
+
return True, warning
|
|
477
509
|
|
|
478
510
|
# Strict/non-strict logic:
|
|
479
511
|
if not strict:
|
|
480
512
|
blocked = is_ray_blocked(c1, c2, cand_tris, eps=eps)
|
|
481
513
|
if blocked:
|
|
482
|
-
|
|
514
|
+
warning = "[PVF] [Obstruction] strict=False, cells obstructed (centroid to centroid)"
|
|
515
|
+
if verbose:
|
|
516
|
+
print(warning)
|
|
517
|
+
return False, warning
|
|
483
518
|
else:
|
|
484
|
-
|
|
519
|
+
warning = "[PVF] [Obstruction] strict=False, cells not obstructed (centroid to centroid)"
|
|
520
|
+
if verbose:
|
|
521
|
+
print(warning)
|
|
522
|
+
return True, warning
|
|
485
523
|
else:
|
|
486
524
|
for p1 in pts1:
|
|
487
525
|
for p2 in pts2:
|
|
488
526
|
if is_ray_blocked(p1, p2, cand_tris, eps=eps):
|
|
489
|
-
warning = "[PVF Obstruction]
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
527
|
+
warning = "[PVF] [Obstruction] strict=True, cells obstructed (at least one vertex to vertex ray)"
|
|
528
|
+
if verbose:
|
|
529
|
+
print(warning)
|
|
530
|
+
return False, warning
|
|
531
|
+
warning = "[PVF] [Obstruction] strict=True, cells not obstructed (fully, all vertex to vertex rays clear)"
|
|
532
|
+
if verbose:
|
|
533
|
+
print(warning)
|
|
534
|
+
return True, warning
|
|
496
535
|
# End of File
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pyviewfactor
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: A
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: "A lightweight open-source Python library for exact view-factor computations on polygonal meshes"
|
|
5
5
|
Home-page: https://gitlab.com/arep-dev/pyViewFactor/
|
|
6
6
|
Author: Mateusz BOGDAN, Edouard WALTHER, Marc ALECIAN, Mina CHAPON
|
|
7
7
|
Author-email: mateusz.bogdan@arep.fr
|
|
@@ -11,13 +11,13 @@ Classifier: Programming Language :: Python :: 3
|
|
|
11
11
|
Classifier: License :: OSI Approved :: MIT License
|
|
12
12
|
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
13
13
|
Classifier: Operating System :: OS Independent
|
|
14
|
-
Requires-Python: >=3.
|
|
14
|
+
Requires-Python: >=3.9
|
|
15
15
|
Description-Content-Type: text/markdown
|
|
16
16
|
License-File: LICENSE.txt
|
|
17
|
-
Requires-Dist: numpy>=1.
|
|
18
|
-
Requires-Dist: scipy>=1.
|
|
19
|
-
Requires-Dist: numba>=0.
|
|
20
|
-
Requires-Dist: pyvista>=0.
|
|
17
|
+
Requires-Dist: numpy>=1.26
|
|
18
|
+
Requires-Dist: scipy>=1.11
|
|
19
|
+
Requires-Dist: numba>=0.61
|
|
20
|
+
Requires-Dist: pyvista>=0.45
|
|
21
21
|
|
|
22
22
|
# PyViewFactor
|
|
23
23
|
|
|
@@ -3,7 +3,7 @@ name = pyviewfactor
|
|
|
3
3
|
version = attr: pyviewfactor._version.__version__
|
|
4
4
|
author = Mateusz BOGDAN, Edouard WALTHER, Marc ALECIAN, Mina CHAPON
|
|
5
5
|
author_email = mateusz.bogdan@arep.fr
|
|
6
|
-
description = A
|
|
6
|
+
description = "A lightweight open-source Python library for exact view-factor computations on polygonal meshes"
|
|
7
7
|
long_description = file: README.md
|
|
8
8
|
long_description_content_type = text/markdown
|
|
9
9
|
url = https://gitlab.com/arep-dev/pyViewFactor/
|
|
@@ -24,11 +24,11 @@ classifiers =
|
|
|
24
24
|
[options]
|
|
25
25
|
packages = find:
|
|
26
26
|
install_requires =
|
|
27
|
-
numpy>=1.
|
|
28
|
-
scipy>=1.
|
|
29
|
-
numba>=0.
|
|
30
|
-
pyvista>=0.
|
|
31
|
-
python_requires = >=3.
|
|
27
|
+
numpy>=1.26
|
|
28
|
+
scipy>=1.11
|
|
29
|
+
numba>=0.61
|
|
30
|
+
pyvista>=0.45
|
|
31
|
+
python_requires = >=3.9
|
|
32
32
|
|
|
33
33
|
[options.packages.find]
|
|
34
34
|
where = .
|
|
@@ -3,18 +3,12 @@ import pyvista as pv
|
|
|
3
3
|
import pytest
|
|
4
4
|
import pyviewfactor as pvf
|
|
5
5
|
import numpy as np
|
|
6
|
-
|
|
7
|
-
from pyviewfactor.pyviewfactor import _integrand_gauss_legendre
|
|
8
|
-
from pyviewfactor.pyviewfactor import _integrand_dblquad
|
|
9
|
-
from pyviewfactor.pyviewfactor import _compute_pair
|
|
10
|
-
from pyviewfactor import compute_viewfactor_matrix
|
|
11
|
-
from pyviewfactor import compute_viewfactor
|
|
12
|
-
from pyviewfactor import fc_unstruc2poly
|
|
6
|
+
|
|
13
7
|
|
|
14
8
|
|
|
15
9
|
def test_integrand_raw_kernel():
|
|
16
10
|
# at (0,0) → log(nqp)*spq
|
|
17
|
-
v =
|
|
11
|
+
v = pvf.integrand_dblquad.py_func(0.0, 0.0, 2.0, 3.0,
|
|
18
12
|
0.0, 0.0, 5.0, 4.0)
|
|
19
13
|
assert v == pytest.approx(np.log(4.0) * 5.0)
|
|
20
14
|
|
|
@@ -67,11 +61,12 @@ def test_closed_geometry_parrallel():
|
|
|
67
61
|
sphere,
|
|
68
62
|
skip_visibility=True,
|
|
69
63
|
skip_obstruction=True,
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
epsilon= 1e-2,
|
|
65
|
+
rounding_decimal= 8,
|
|
66
|
+
verbose=False
|
|
72
67
|
)
|
|
73
68
|
sum_vf = F[:, cell_extracted_id].sum()
|
|
74
|
-
assert sum_vf == pytest.approx(1.0, rel=1e-
|
|
69
|
+
assert sum_vf == pytest.approx(1.0, rel=1e-2)
|
|
75
70
|
|
|
76
71
|
|
|
77
72
|
def test_skip_obstruction_flag_respected():
|
|
@@ -89,36 +84,38 @@ def test_skip_obstruction_flag_respected():
|
|
|
89
84
|
tri0 = mesh.extract_cells(0)
|
|
90
85
|
# tri1 = mesh.extract_cells(1)
|
|
91
86
|
# obstacle: a small triangle between centroids
|
|
92
|
-
obs = tri0.translate([0.1, 0.
|
|
87
|
+
obs = tri0.translate([0.1, -0.1, 0.1])
|
|
93
88
|
obs = pvf.fc_unstruc2poly(obs)
|
|
94
89
|
# compute with obstruction
|
|
95
|
-
|
|
90
|
+
F_no_block = pvf.compute_viewfactor_matrix(
|
|
96
91
|
mesh,
|
|
97
|
-
|
|
92
|
+
obstacles=obs,
|
|
98
93
|
skip_visibility=True,
|
|
99
|
-
skip_obstruction=
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
94
|
+
skip_obstruction=True,
|
|
95
|
+
strict_visibility = False,
|
|
96
|
+
strict_obstruction = False,
|
|
97
|
+
epsilon= 1e-4,
|
|
98
|
+
rounding_decimal= 8,
|
|
99
|
+
verbose=False
|
|
104
100
|
)
|
|
105
101
|
# compute with skip_obstruction=True
|
|
106
|
-
|
|
102
|
+
F_block = pvf.compute_viewfactor_matrix(
|
|
107
103
|
mesh,
|
|
108
|
-
|
|
109
|
-
skip_visibility=
|
|
110
|
-
skip_obstruction=
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
104
|
+
obstacles=obs,
|
|
105
|
+
skip_visibility=False,
|
|
106
|
+
skip_obstruction=False,
|
|
107
|
+
strict_visibility = True,
|
|
108
|
+
strict_obstruction = True,
|
|
109
|
+
epsilon= 1e-4,
|
|
110
|
+
rounding_decimal= 8,
|
|
111
|
+
verbose=False
|
|
115
112
|
)
|
|
116
113
|
# now only in the first case do we zero out the blocked direction
|
|
117
|
-
assert
|
|
118
|
-
assert
|
|
114
|
+
assert F_no_block[0, 1] == pytest.approx(0.21125482)
|
|
115
|
+
assert F_block[0, 1] == pytest.approx(0.0)
|
|
119
116
|
|
|
120
117
|
|
|
121
|
-
def test_compute_matrix_against_individual_calls():
|
|
118
|
+
def test_compute_matrix_against_individual_calls():
|
|
122
119
|
pts = np.array([
|
|
123
120
|
[0.0, 0.0, 0.0],
|
|
124
121
|
[1.0, 0.0, 0.0],
|
|
@@ -130,18 +127,18 @@ def test_compute_matrix_against_individual_calls():
|
|
|
130
127
|
mesh = pv.PolyData(pts, faces)
|
|
131
128
|
mesh.triangulate(inplace=True)
|
|
132
129
|
|
|
133
|
-
F = compute_viewfactor_matrix(
|
|
130
|
+
F = pvf.compute_viewfactor_matrix(
|
|
134
131
|
mesh,
|
|
135
132
|
skip_visibility=True,
|
|
136
133
|
skip_obstruction=True,
|
|
137
|
-
|
|
138
|
-
|
|
134
|
+
epsilon= 1e-6,
|
|
135
|
+
rounding_decimal= 6,
|
|
139
136
|
)
|
|
140
137
|
|
|
141
138
|
# convert to PolyData
|
|
142
|
-
f0 = fc_unstruc2poly(mesh.extract_cells(0))
|
|
143
|
-
f1 = fc_unstruc2poly(mesh.extract_cells(1))
|
|
144
|
-
direct = compute_viewfactor(f0, f1, epsilon=1e-6, rounding_decimal=6)
|
|
139
|
+
f0 = pvf.fc_unstruc2poly(mesh.extract_cells(0))
|
|
140
|
+
f1 = pvf.fc_unstruc2poly(mesh.extract_cells(1))
|
|
141
|
+
direct = pvf.compute_viewfactor(f0, f1, epsilon=1e-6, rounding_decimal=6)
|
|
145
142
|
assert F[0, 1] == pytest.approx(direct)
|
|
146
143
|
|
|
147
144
|
|
|
@@ -151,7 +148,7 @@ def test_compute_viewfactor_fixed_nonzero_overlap():
|
|
|
151
148
|
pts2 = pts1 + np.array([0.5, 0.0, 1.0])
|
|
152
149
|
pts2 = pts2[::-1]
|
|
153
150
|
constante = 4.0 * np.pi * 0.5
|
|
154
|
-
vf =
|
|
151
|
+
vf = pvf.compute_viewfactor_gauss_legendre.py_func(pts1, pts2, constante)
|
|
155
152
|
# Should be positive but <1
|
|
156
153
|
assert vf > 0.0
|
|
157
154
|
assert vf < 1.0
|
|
@@ -168,7 +165,7 @@ def test_fast_integrand_zero_when_scal_pq_zero():
|
|
|
168
165
|
sqpq = -0.5
|
|
169
166
|
sqpp = 0.8
|
|
170
167
|
nqp = 10.0
|
|
171
|
-
val =
|
|
168
|
+
val = pvf.integrand_gauss_legendre.py_func(nq, np_, sqpq, sqpp, 0.0, nqp)
|
|
172
169
|
assert val == pytest.approx(0.0, abs=0.0)
|
|
173
170
|
|
|
174
171
|
|
|
@@ -186,7 +183,6 @@ def test_compute_matrix_len3_visibility_cull():
|
|
|
186
183
|
mesh,
|
|
187
184
|
skip_visibility=False,
|
|
188
185
|
skip_obstruction=True,
|
|
189
|
-
n_jobs=1
|
|
190
186
|
)
|
|
191
187
|
|
|
192
188
|
# We only have 2 cells
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
# import numpy as np
|
|
2
|
+
import pyvista as pv
|
|
3
|
+
# import pytest
|
|
4
|
+
import pyviewfactor as pvf
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
# two parallel triangles facing each other
|
|
8
|
+
tri1 = pv.Triangle([[0.0, 0.0, 0.0],
|
|
9
|
+
[1.0, 0.0, 0.0],
|
|
10
|
+
[0.0, 1.0, 0.0]])
|
|
11
|
+
|
|
12
|
+
tri2 = pv.Triangle([[0.0, 0.0, 1.0],
|
|
13
|
+
[0.0, 1.0, 1.0],
|
|
14
|
+
[1.0, 0.0, 1.0]])
|
|
15
|
+
|
|
16
|
+
triP = pv.Triangle([[0.0, 0.0, 0.0],
|
|
17
|
+
[0.0, 0.0, 1.0],
|
|
18
|
+
[1.0, 0.0, 0.0]])
|
|
19
|
+
|
|
20
|
+
triP.translate([0.0, 0.0, -0.25], inplace=True)
|
|
21
|
+
|
|
22
|
+
# obstacle blocking in between
|
|
23
|
+
obs = pv.Plane(i_size=2, j_size=2, i_resolution=1, j_resolution=1)
|
|
24
|
+
obs.translate([0.0, 0.0, 0.5], inplace=True)
|
|
25
|
+
obs3 = obs.copy()
|
|
26
|
+
obs3.translate([1.7, 0.0, 0.0], inplace=True)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
obs4 = obs.copy()
|
|
30
|
+
obs4.translate([5.0, 0.0, 0.0], inplace=True)
|
|
31
|
+
|
|
32
|
+
obs_multi = pv.Plane(i_size=2, j_size=2, i_resolution=5, j_resolution=5)
|
|
33
|
+
obs_multi.translate([0, 0, 0.5], inplace=True)
|
|
34
|
+
obs_multi2 = obs_multi.copy()
|
|
35
|
+
obs_multi2.translate([1.7, 0.0, 0.0], inplace=True)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# VISIBILITY TESTS
|
|
39
|
+
|
|
40
|
+
def test_visibility_strict_true(capsys):
|
|
41
|
+
vis, warn = pvf.get_visibility(tri1, tri2, strict=True, verbose=True)
|
|
42
|
+
captured = capsys.readouterr()
|
|
43
|
+
msg = "[PVF] [Visibility] Cells are visible"
|
|
44
|
+
assert msg in captured.out
|
|
45
|
+
assert vis and warn == msg
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_visibility_strict_false(capsys):
|
|
49
|
+
# flip tri2 so normals face away
|
|
50
|
+
tri3 = tri2.copy()
|
|
51
|
+
tri3.flip_faces(inplace=True)
|
|
52
|
+
msg = "[PVF] [Visibility] Cells are not visible"
|
|
53
|
+
vis, warn = pvf.get_visibility(tri1, tri3, strict=False, verbose=True)
|
|
54
|
+
captured = capsys.readouterr()
|
|
55
|
+
assert not vis and warn == msg
|
|
56
|
+
assert msg in captured.out
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_visibility_strict_false1(capsys):
|
|
60
|
+
# flip tri2 so normals face away
|
|
61
|
+
tri3 = tri2.copy()
|
|
62
|
+
tri3.flip_faces(inplace=True)
|
|
63
|
+
msg = "[PVF] [Visibility] Cells are not visible"
|
|
64
|
+
vis, warn = pvf.get_visibility(tri1, tri3, strict=True, verbose=True)
|
|
65
|
+
captured = capsys.readouterr()
|
|
66
|
+
assert not vis and warn == msg
|
|
67
|
+
assert msg in captured.out
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_visibility_strict_false_warn2(capsys):
|
|
71
|
+
# flip tri2 so normals face away
|
|
72
|
+
tri3 = tri2.copy()
|
|
73
|
+
tri3.flip_faces(inplace=True)
|
|
74
|
+
vis, warn = pvf.get_visibility(tri1, tri3, strict=True, verbose=True)
|
|
75
|
+
msg = "[PVF] [Visibility] Cells are not visible"
|
|
76
|
+
captured = capsys.readouterr()
|
|
77
|
+
assert not vis and warn == msg
|
|
78
|
+
assert msg in captured.out
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_visibility_partial_strict_true(capsys):
|
|
82
|
+
vis, warn = pvf.get_visibility(tri1, triP, strict=True, verbose = True)
|
|
83
|
+
msg = "[PVF] [Visibility] strict=True, Cells are considered not visible, but partially are"
|
|
84
|
+
captured = capsys.readouterr()
|
|
85
|
+
assert not vis and msg in warn
|
|
86
|
+
assert msg in captured.out
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def test_visibility_partial_strict_false(capsys):
|
|
90
|
+
vis, warn = pvf.get_visibility(tri1, triP, strict=False, verbose = True)
|
|
91
|
+
msg = "[PVF] [Visibility] strict=False, Cells are considered visible, but are only partially"
|
|
92
|
+
captured = capsys.readouterr()
|
|
93
|
+
assert vis and msg in warn
|
|
94
|
+
assert msg in captured.out
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def test_get_visibility_from_cache_simple(capsys):
|
|
98
|
+
"""
|
|
99
|
+
Test get_visibility_from_cache on two well-separated triangles facing each other.
|
|
100
|
+
"""
|
|
101
|
+
# Two triangles facing each other along z
|
|
102
|
+
tri1 = pv.Triangle([[0.0, 0.0, 0.0],
|
|
103
|
+
[1.0, 0.0, 0.0],
|
|
104
|
+
[0.0, 1.0, 0.0]])
|
|
105
|
+
tri2 = pv.Triangle([[0.0, 0.0, 1.0],
|
|
106
|
+
[1.0, 0.0, 1.0],
|
|
107
|
+
[0.0, 1.0, 1.0]])
|
|
108
|
+
mesh = pv.PolyData()
|
|
109
|
+
mesh.points = np.vstack([tri1.points, tri2.points])
|
|
110
|
+
# Add faces (as triangle cells)
|
|
111
|
+
faces = np.array([
|
|
112
|
+
3, 0, 1, 2, # tri1
|
|
113
|
+
3, 3, 4, 5 # tri2
|
|
114
|
+
], dtype=np.int32)
|
|
115
|
+
mesh.faces = faces
|
|
116
|
+
|
|
117
|
+
cache = pvf.ProcessedGeometry(mesh)
|
|
118
|
+
|
|
119
|
+
# Indices: 0 (tri1), 1 (tri2)
|
|
120
|
+
vis, warn = pvf.get_visibility_from_cache(0, 1, cache, strict=False, verbose = True)
|
|
121
|
+
msg = "[PVF] [Visibility] Cells are not visible"
|
|
122
|
+
captured = capsys.readouterr()
|
|
123
|
+
assert not vis
|
|
124
|
+
assert msg in warn
|
|
125
|
+
assert msg in captured.out
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def test_get_visibility_from_cache_simple1(capsys):
|
|
129
|
+
"""
|
|
130
|
+
Test get_visibility_from_cache on two well-separated triangles facing each other.
|
|
131
|
+
"""
|
|
132
|
+
# Two triangles facing each other along z
|
|
133
|
+
tri1 = pv.Triangle([[0.0, 0.0, 0.0],
|
|
134
|
+
[1.0, 0.0, 0.0],
|
|
135
|
+
[0.0, 1.0, 0.0]])
|
|
136
|
+
tri2 = pv.Triangle([[0.0, 0.0, 1.0],
|
|
137
|
+
[1.0, 0.0, 1.0],
|
|
138
|
+
[0.0, 1.0, 1.0]])
|
|
139
|
+
mesh = pv.PolyData()
|
|
140
|
+
mesh.points = np.vstack([tri1.points, tri2.points])
|
|
141
|
+
# Add faces (as triangle cells)
|
|
142
|
+
faces = np.array([
|
|
143
|
+
3, 0, 1, 2, # tri1
|
|
144
|
+
3, 3, 4, 5 # tri2
|
|
145
|
+
], dtype=np.int32)
|
|
146
|
+
mesh.faces = faces
|
|
147
|
+
|
|
148
|
+
cache = pvf.ProcessedGeometry(mesh)
|
|
149
|
+
# If we flip one triangle, they will not be mutually visible
|
|
150
|
+
# Reverse the normal of tri2 by flipping vertex order
|
|
151
|
+
mesh.points[3:6] = mesh.points[3:6][::-1]
|
|
152
|
+
cache2 = pvf.ProcessedGeometry(mesh)
|
|
153
|
+
vis2, warn2 = pvf.get_visibility_from_cache(0, 1, cache2, strict=False, verbose = True)
|
|
154
|
+
msg = "[PVF] [Visibility] Cells are visible"
|
|
155
|
+
captured = capsys.readouterr()
|
|
156
|
+
assert vis2 == True
|
|
157
|
+
assert msg in warn2
|
|
158
|
+
assert msg in captured.out
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def test_get_visibility_from_cache_partial(capsys):
|
|
162
|
+
"""
|
|
163
|
+
Test get_visibility_from_cache on two well-separated triangles facing each other.
|
|
164
|
+
"""
|
|
165
|
+
# Two triangles facing each other along z
|
|
166
|
+
tri1 = pv.Triangle([[0.0, 0.0, 0.0],
|
|
167
|
+
[1.0, 0.0, 0.0],
|
|
168
|
+
[0.0, 1.0, 0.0]])
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
triP = pv.Triangle([[0.0, 0.0, 0.0],
|
|
172
|
+
[0.0, 0.0, 1.0],
|
|
173
|
+
[1.0, 0.0, 0.0]])
|
|
174
|
+
triP.translate([0.0, 0.0, -0.25], inplace=True)
|
|
175
|
+
mesh = pv.PolyData()
|
|
176
|
+
mesh.points = np.vstack([tri1.points, triP.points])
|
|
177
|
+
|
|
178
|
+
faces = np.array([
|
|
179
|
+
3, 0, 1, 2, # tri1
|
|
180
|
+
3, 3, 4, 5 # tri2
|
|
181
|
+
], dtype=np.int32)
|
|
182
|
+
mesh.faces = faces
|
|
183
|
+
|
|
184
|
+
cache = pvf.ProcessedGeometry(mesh)
|
|
185
|
+
vis, warn = pvf.get_visibility_from_cache(0, 1, cache, strict=False, verbose = True)
|
|
186
|
+
msg = "[PVF] [Visibility] strict=False, Cells are considered visible, but are only partially"
|
|
187
|
+
captured = capsys.readouterr()
|
|
188
|
+
assert vis == True
|
|
189
|
+
assert msg in warn
|
|
190
|
+
assert msg in captured.out
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def test_get_visibility_from_cache_partial1(capsys):
|
|
194
|
+
"""
|
|
195
|
+
Test get_visibility_from_cache on two well-separated triangles facing each other.
|
|
196
|
+
"""
|
|
197
|
+
# Two triangles facing each other along z
|
|
198
|
+
tri1 = pv.Triangle([[0.0, 0.0, 0.0],
|
|
199
|
+
[1.0, 0.0, 0.0],
|
|
200
|
+
[0.0, 1.0, 0.0]])
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
triP = pv.Triangle([[0.0, 0.0, 0.0],
|
|
204
|
+
[0.0, 0.0, 1.0],
|
|
205
|
+
[1.0, 0.0, 0.0]])
|
|
206
|
+
triP.translate([0.0, 0.0, -0.25], inplace=True)
|
|
207
|
+
mesh = pv.PolyData()
|
|
208
|
+
mesh.points = np.vstack([tri1.points, triP.points])
|
|
209
|
+
|
|
210
|
+
faces = np.array([
|
|
211
|
+
3, 0, 1, 2, # tri1
|
|
212
|
+
3, 3, 4, 5 # tri2
|
|
213
|
+
], dtype=np.int32)
|
|
214
|
+
mesh.faces = faces
|
|
215
|
+
|
|
216
|
+
cache = pvf.ProcessedGeometry(mesh)
|
|
217
|
+
vis, warn = pvf.get_visibility_from_cache(0, 1, cache, strict=True, verbose = True)
|
|
218
|
+
msg = "[PVF] [Visibility] strict=True, Cells are considered not visible, but partially are"
|
|
219
|
+
captured = capsys.readouterr()
|
|
220
|
+
assert not vis
|
|
221
|
+
assert msg in warn
|
|
222
|
+
assert msg in captured.out
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
# OBSTRUCTION TESTS
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def test_is_ray_obstructed_hit_and_miss_no_skip():
|
|
230
|
+
# A single triangle at z=0
|
|
231
|
+
blocker = np.array([[[0.0, 0.0, 0.0], [1.0, 0.0, 0.0],
|
|
232
|
+
[0.0, 1.0, 0.0]]], dtype=np.float64)
|
|
233
|
+
# Ray from above → below, passing through (0.2,0.2)
|
|
234
|
+
start = np.array([0.2, 0.2, 1.0])
|
|
235
|
+
end = np.array([0.2, 0.2, -1.0])
|
|
236
|
+
# Without skip, it must be blocked
|
|
237
|
+
assert pvf.is_ray_blocked.py_func(start, end, blocker, eps=1e-6) is True
|
|
238
|
+
|
|
239
|
+
# Ray that misses (offset in x)
|
|
240
|
+
start2 = np.array([2.0, 2.0, 1.0])
|
|
241
|
+
end2 = np.array([2.0, 2.0,-1.0])
|
|
242
|
+
assert pvf.is_ray_blocked.py_func(start2, end2, blocker) is False
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def test_batch_ray_obstruction_misses():
|
|
246
|
+
tri_arr = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0],
|
|
247
|
+
[0.0, 1.0, 0.0]], dtype=np.float64)
|
|
248
|
+
# one ray misses, one hits
|
|
249
|
+
starts = np.array([2.0, 2.0, 1.0], dtype=np.float64)
|
|
250
|
+
ends = np.array([2.0, 2.0, -1.0], dtype=np.float64)
|
|
251
|
+
mask = pvf.ray_intersects_triangle.py_func(starts, ends, tri_arr[0], tri_arr[1], tri_arr[2])
|
|
252
|
+
assert mask == False
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def test_batch_ray_obstruction_hit():
|
|
256
|
+
tri_arr = np.array([[0.0, 0.0, 0.0], [10.0, 0.0, 0.0],
|
|
257
|
+
[0.0, 10.0, 0.0]], dtype=np.float64)
|
|
258
|
+
# one ray misses, one hits
|
|
259
|
+
starts = np.array([2.0, 2.0, 1.0], dtype=np.float64)
|
|
260
|
+
ends = np.array([2.0, 2.0, -1.0], dtype=np.float64)
|
|
261
|
+
mask = pvf.ray_intersects_triangle.py_func(starts, ends, tri_arr[0], tri_arr[1], tri_arr[2])
|
|
262
|
+
assert mask == True
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def test_obstruction_strict_true(capsys):
|
|
267
|
+
# obstacle sits between tri1 and tri2
|
|
268
|
+
vis, warn = pvf.get_obstruction(tri1, tri2, obs4, strict=False, verbose=True)
|
|
269
|
+
msg = "[PVF] [Obstruction] Unobstructed (no candidate within c1-c2 AABB)"
|
|
270
|
+
captured = capsys.readouterr()
|
|
271
|
+
assert vis == True
|
|
272
|
+
assert msg in warn
|
|
273
|
+
assert msg in captured.out
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def test_obstruction_strict_false(capsys):
|
|
278
|
+
# obstacle sits between tri1 and tri2
|
|
279
|
+
vis, warn = pvf.get_obstruction(tri1, tri2, obs, strict=False, verbose = True)
|
|
280
|
+
msg = "[PVF] [Obstruction] strict=False, cells obstructed (centroid to centroid)"
|
|
281
|
+
captured = capsys.readouterr()
|
|
282
|
+
assert not vis
|
|
283
|
+
assert msg in warn
|
|
284
|
+
assert msg in captured.out
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def test_partial_obstruction_strict_false(capsys):
|
|
288
|
+
vis, warn = pvf.get_obstruction(tri1, tri2, obs3, strict=False, verbose = True)
|
|
289
|
+
msg = "[PVF] [Obstruction] strict=False, cells not obstructed (centroid to centroid)"
|
|
290
|
+
captured = capsys.readouterr()
|
|
291
|
+
assert vis == True
|
|
292
|
+
assert msg in warn
|
|
293
|
+
assert msg in captured.out
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def test_partial_obstruction_strict_true(capsys):
|
|
297
|
+
vis, warn = pvf.get_obstruction(tri1, tri2, obs3, strict=True, verbose = True)
|
|
298
|
+
msg = "[PVF] [Obstruction] strict=True, cells obstructed (at least one vertex to vertex ray)"
|
|
299
|
+
captured = capsys.readouterr()
|
|
300
|
+
assert not vis
|
|
301
|
+
assert msg in warn
|
|
302
|
+
assert msg in captured.out
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def test_get_obstruction_from_cache_simple_block(capsys):
|
|
310
|
+
"""
|
|
311
|
+
Test get_obstruction_from_cache: triangle faces are blocked by a plane in between.
|
|
312
|
+
"""
|
|
313
|
+
# Triangles facing each other
|
|
314
|
+
tri1 = pv.Triangle([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]])
|
|
315
|
+
tri2 = pv.Triangle([[0.0, 0.0, 1.0], [1.0, 0.0, 1.0], [0.0, 1.0, 1.0]])
|
|
316
|
+
mesh = pv.PolyData()
|
|
317
|
+
mesh.points = np.vstack([tri1.points, tri2.points])
|
|
318
|
+
mesh.faces = np.array([3, 0, 1, 2, 3, 3, 4, 5], dtype=np.int32)
|
|
319
|
+
cache = pvf.ProcessedGeometry(mesh)
|
|
320
|
+
|
|
321
|
+
# Obstacle: a square at z=0.5
|
|
322
|
+
rect = pv.Rectangle([[10.0, 10.0, 10.0], [11.0, 10.0, 10.0], [11.0, 11.0, 10.0]])
|
|
323
|
+
rect.points = rect.points.astype(np.float64)
|
|
324
|
+
rect.triangulate(inplace=True)
|
|
325
|
+
obs_pre = pvf.FaceMeshPreprocessor(rect)
|
|
326
|
+
|
|
327
|
+
# Should be blocked (strict or not)
|
|
328
|
+
vis, warn = pvf.get_obstruction_from_cache(0, 1, cache, obs_pre, strict=False, verbose=True)
|
|
329
|
+
captured = capsys.readouterr()
|
|
330
|
+
msg = "[PVF] [Obstruction] Unobstructed (no candidate within c1-c2 AABB)"
|
|
331
|
+
assert vis is True
|
|
332
|
+
assert msg in warn
|
|
333
|
+
assert msg in captured.out
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def test_get_obstruction_from_cache_simple_block2(capsys):
|
|
337
|
+
"""
|
|
338
|
+
Test get_obstruction_from_cache: triangle faces are blocked by a plane in between.
|
|
339
|
+
"""
|
|
340
|
+
# Triangles facing each other
|
|
341
|
+
tri1 = pv.Triangle([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]])
|
|
342
|
+
tri2 = pv.Triangle([[0.0, 0.0, 1.0], [1.0, 0.0, 1.0], [0.0, 1.0, 1.0]])
|
|
343
|
+
mesh = pv.PolyData()
|
|
344
|
+
mesh.points = np.vstack([tri1.points, tri2.points])
|
|
345
|
+
mesh.faces = np.array([3, 0, 1, 2, 3, 3, 4, 5], dtype=np.int32)
|
|
346
|
+
cache = pvf.ProcessedGeometry(mesh)
|
|
347
|
+
|
|
348
|
+
# Obstacle: a square at z=0.5
|
|
349
|
+
rect = pv.Rectangle([[0.0, 0.0, 0.5], [0.0, 10.0, 0.5], [10.0, 10.0, 0.5]])
|
|
350
|
+
rect.points = rect.points.astype(np.float64)
|
|
351
|
+
rect.triangulate(inplace=True)
|
|
352
|
+
obs_pre = pvf.FaceMeshPreprocessor(rect)
|
|
353
|
+
|
|
354
|
+
# Should be blocked (strict or not)
|
|
355
|
+
vis, warn = pvf.get_obstruction_from_cache(0, 1, cache, obs_pre, strict=False, verbose=True)
|
|
356
|
+
captured = capsys.readouterr()
|
|
357
|
+
msg = "[PVF] [Obstruction] strict=False, cells obstructed (centroid to centroid)"
|
|
358
|
+
assert vis is False
|
|
359
|
+
assert msg in warn
|
|
360
|
+
assert msg in captured.out
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
def test_get_obstruction_from_cache_simple_block3(capsys):
|
|
364
|
+
"""
|
|
365
|
+
Test get_obstruction_from_cache: triangle faces are blocked by a plane in between.
|
|
366
|
+
"""
|
|
367
|
+
# Triangles facing each other
|
|
368
|
+
tri1 = pv.Triangle([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]])
|
|
369
|
+
tri2 = pv.Triangle([[0.0, 0.0, 1.0], [1.0, 0.0, 1.0], [0.0, 1.0, 1.0]])
|
|
370
|
+
mesh = pv.PolyData()
|
|
371
|
+
mesh.points = np.vstack([tri1.points, tri2.points])
|
|
372
|
+
mesh.faces = np.array([3, 0, 1, 2, 3, 3, 4, 5], dtype=np.int32)
|
|
373
|
+
cache = pvf.ProcessedGeometry(mesh)
|
|
374
|
+
|
|
375
|
+
# Obstacle: a square at z=0.5
|
|
376
|
+
rect = pv.Rectangle([[0.1, 0.1, 0.1], [0.1, 0.8, 0.1], [0.1, 0.8, 0.8]])
|
|
377
|
+
rect.points = rect.points.astype(np.float64)
|
|
378
|
+
rect.triangulate(inplace=True)
|
|
379
|
+
obs_pre = pvf.FaceMeshPreprocessor(rect)
|
|
380
|
+
|
|
381
|
+
# Should be blocked (strict or not)
|
|
382
|
+
vis, warn = pvf.get_obstruction_from_cache(0, 1, cache, obs_pre, strict=False, verbose=True)
|
|
383
|
+
captured = capsys.readouterr()
|
|
384
|
+
msg = "[PVF] [Obstruction] strict=False, cells not obstructed (centroid to centroid)"
|
|
385
|
+
assert vis is True
|
|
386
|
+
assert msg in warn
|
|
387
|
+
assert msg in captured.out
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
def test_get_obstruction_from_cache_simple_block5(capsys):
|
|
392
|
+
"""
|
|
393
|
+
Test get_obstruction_from_cache: triangle faces are blocked by a plane in between.
|
|
394
|
+
"""
|
|
395
|
+
# Triangles facing each other
|
|
396
|
+
tri1 = pv.Triangle([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]])
|
|
397
|
+
tri2 = pv.Triangle([[0.0, 0.0, 1.0], [1.0, 0.0, 1.0], [0.0, 1.0, 1.0]])
|
|
398
|
+
mesh = pv.PolyData()
|
|
399
|
+
mesh.points = np.vstack([tri1.points, tri2.points])
|
|
400
|
+
mesh.faces = np.array([3, 0, 1, 2, 3, 3, 4, 5], dtype=np.int32)
|
|
401
|
+
cache = pvf.ProcessedGeometry(mesh)
|
|
402
|
+
|
|
403
|
+
# Obstacle: a square at z=0.5
|
|
404
|
+
rect = pv.Rectangle([[0.0, 0.0, 0.5], [0.0, 10.0, 0.5], [10.0, 10.0, 0.5]])
|
|
405
|
+
rect.points = rect.points.astype(np.float64)
|
|
406
|
+
rect.triangulate(inplace=True)
|
|
407
|
+
obs_pre = pvf.FaceMeshPreprocessor(rect)
|
|
408
|
+
|
|
409
|
+
# Should be blocked (strict or not)
|
|
410
|
+
vis, warn = pvf.get_obstruction_from_cache(0, 1, cache, obs_pre, strict=True, verbose=True)
|
|
411
|
+
captured = capsys.readouterr()
|
|
412
|
+
msg = "[PVF] [Obstruction] strict=True, cells obstructed (at least one vertex to vertex ray)"
|
|
413
|
+
assert vis is False
|
|
414
|
+
assert msg in warn
|
|
415
|
+
assert msg in captured.out
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
# import numpy as np
|
|
2
|
-
import pyvista as pv
|
|
3
|
-
# import pytest
|
|
4
|
-
import pyviewfactor as pvf
|
|
5
|
-
|
|
6
|
-
import numpy as np
|
|
7
|
-
|
|
8
|
-
# two parallel triangles facing each other
|
|
9
|
-
tri1 = pv.Triangle([[0.0, 0.0, 0.0],
|
|
10
|
-
[1.0, 0.0, 0.0],
|
|
11
|
-
[0.0, 1.0, 0.0]])
|
|
12
|
-
|
|
13
|
-
tri2 = pv.Triangle([[0.0, 0.0, 1.0],
|
|
14
|
-
[0.0, 1.0, 1.0],
|
|
15
|
-
[1.0, 0.0, 1.0]])
|
|
16
|
-
|
|
17
|
-
triP = pv.Triangle([[0.0, 0.0, 0.0],
|
|
18
|
-
[0.0, 0.0, 1.0],
|
|
19
|
-
[1.0, 0.0, 0.0]])
|
|
20
|
-
|
|
21
|
-
triP.translate([0.0, 0.0, -0.25], inplace=True)
|
|
22
|
-
|
|
23
|
-
# obstacle blocking in between
|
|
24
|
-
obs = pv.Plane(i_size=2, j_size=2, i_resolution=1, j_resolution=1)
|
|
25
|
-
obs.translate([0.0, 0.0, 0.5], inplace=True)
|
|
26
|
-
obs3 = obs.copy()
|
|
27
|
-
obs3.translate([1.7, 0.0, 0.0], inplace=True)
|
|
28
|
-
|
|
29
|
-
obs_multi = pv.Plane(i_size=2, j_size=2, i_resolution=5, j_resolution=5)
|
|
30
|
-
obs_multi.translate([0, 0, 0.5], inplace=True)
|
|
31
|
-
obs_multi2 = obs_multi.copy()
|
|
32
|
-
obs_multi2.translate([1.7, 0.0, 0.0], inplace=True)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
# VISIBILITY TESTS
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def test_visibility_strict_true():
|
|
39
|
-
vis, warn = pvf.get_visibility(tri1, tri2, strict=True)
|
|
40
|
-
assert vis and warn == ""
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def test_visibility_not_strict_true():
|
|
44
|
-
vis, warn = pvf.get_visibility(tri1, tri2, strict=False)
|
|
45
|
-
assert vis and warn == ""
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def test_visibility_strict_false():
|
|
49
|
-
# flip tri2 so normals face away
|
|
50
|
-
tri3 = tri2.copy()
|
|
51
|
-
tri3.flip_faces(inplace=True)
|
|
52
|
-
vis, warn = pvf.get_visibility(tri1, tri3, strict=False)
|
|
53
|
-
assert not vis and warn == ""
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
def test_visibility_strict_false_warn():
|
|
57
|
-
# flip tri2 so normals face away
|
|
58
|
-
tri3 = tri2.copy()
|
|
59
|
-
tri3.flip_faces(inplace=True)
|
|
60
|
-
vis, warn = pvf.get_visibility(tri1, tri3, strict=False, print_warning=True)
|
|
61
|
-
assert not vis and warn == ""
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
def test_visibility_not_strict_false():
|
|
65
|
-
# flip tri2 so normals face away
|
|
66
|
-
tri3 = tri2.copy()
|
|
67
|
-
tri3.flip_faces(inplace=True)
|
|
68
|
-
vis, warn = pvf.get_visibility(tri1, tri3, strict=True)
|
|
69
|
-
assert not vis and warn == ""
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
def test_visibility_partial_strict_true():
|
|
73
|
-
vis, warn = pvf.get_visibility(tri1, triP, strict=True)
|
|
74
|
-
assert not vis and "[PVF Visibility]" in warn
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
def test_visibility_partial_strict_true_debug():
|
|
78
|
-
vis, warn = pvf.get_visibility(tri1, triP, strict=True, print_warning=True)
|
|
79
|
-
assert not vis and "[PVF Visibility]" in warn
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
def test_visibility_partial_strict_false():
|
|
83
|
-
vis, warn = pvf.get_visibility(tri1, triP, strict=False)
|
|
84
|
-
assert vis and "[PVF Visibility]" in warn
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
def test_visibility_partial_strict_false_debug():
|
|
88
|
-
vis, warn = pvf.get_visibility(tri1, triP, strict=False, print_warning=True)
|
|
89
|
-
assert vis and "[PVF Visibility]" in warn
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
# OBSTRUCTION TESTS
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
def test_obstruction_strict_true():
|
|
96
|
-
# obstacle sits between tri1 and tri2
|
|
97
|
-
vis, warn = pvf.get_obstruction(tri1, tri2, obs, strict=True)
|
|
98
|
-
assert not vis and warn == ""
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
def test_obstruction_strict_false():
|
|
102
|
-
# obstacle sits between tri1 and tri2
|
|
103
|
-
vis, warn = pvf.get_obstruction(tri1, tri2, obs, strict=False)
|
|
104
|
-
assert not vis and warn == ""
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
def test_partial_obstruction_strict_false():
|
|
108
|
-
vis, warn = pvf.get_obstruction(tri1, tri2, obs3, strict=False)
|
|
109
|
-
assert vis and warn == ""
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
def test_partial_obstruction_strict_true():
|
|
113
|
-
vis, warn = pvf.get_obstruction(tri1, tri2, obs3, strict=True)
|
|
114
|
-
assert not vis
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
def test_obstruction_multi_strict_true():
|
|
118
|
-
# obstacle sits between tri1 and tri2
|
|
119
|
-
vis, warn = pvf.get_obstruction(tri1, tri2, obs_multi, strict=True)
|
|
120
|
-
assert not vis and warn == ""
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
def test_obstruction_multi_strict_false():
|
|
124
|
-
# obstacle sits between tri1 and tri2
|
|
125
|
-
vis, warn = pvf.get_obstruction(tri1, tri2, obs_multi, strict=False)
|
|
126
|
-
assert not vis and warn == ""
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
def test_partial_multi_obstruction_strict_false():
|
|
130
|
-
vis, warn = pvf.get_obstruction(tri1, tri2, obs_multi2, strict=False)
|
|
131
|
-
assert vis and warn == ""
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
def test_partial_multi_obstruction_strict_true():
|
|
135
|
-
vis, warn = pvf.get_obstruction(tri1, tri2, obs_multi2, strict=True)
|
|
136
|
-
assert not vis and "" in warn
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
def test_batch_ray_obstruction_hits_and_misses():
|
|
140
|
-
tri_arr = np.array([[[0.0, 0.0, 0.0], [1.0, 0.0, 0.0],
|
|
141
|
-
[0.0, 1.0, 0.0]]], dtype=np.float64)
|
|
142
|
-
# one ray misses, one hits
|
|
143
|
-
starts = np.array([[2.0, 2.0, 1.0], [0.2, 0.2, 1.0]], dtype=np.float64)
|
|
144
|
-
ends = np.array([[2.0, 2.0, -1.0], [0.2, 0.2, -1.0]], dtype=np.float64)
|
|
145
|
-
mask = pvf.ray_intersects_triangle(starts, ends, tri_arr[0], tri_arr[1], tri_arr[2])
|
|
146
|
-
assert mask.tolist() == [True, False]
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
def test_is_ray_obstructed_hit_and_miss_no_skip():
|
|
150
|
-
# A single triangle at z=0
|
|
151
|
-
blocker = pv.Triangle([[0,0,0],[1,0,0],[0,1,0]])
|
|
152
|
-
# Ray from above → below, passing through (0.2,0.2)
|
|
153
|
-
start = np.array([0.2, 0.2, 1.0])
|
|
154
|
-
end = np.array([0.2, 0.2, -1.0])
|
|
155
|
-
# Without skip, it must be blocked
|
|
156
|
-
assert pvf.is_ray_blocked(start, end, blocker, eps=1e-6, print_debug=False) is True
|
|
157
|
-
|
|
158
|
-
# Ray that misses (offset in x)
|
|
159
|
-
start2 = np.array([2.0, 2.0, 1.0])
|
|
160
|
-
end2 = np.array([2.0, 2.0,-1.0])
|
|
161
|
-
assert pvf.is_ray_blocked(start2, end2, blocker) is False
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
def test_get_obstruction_non_strict_centroid():
|
|
165
|
-
# Two triangles facing each other at z=±1, no obstacle in between → always visible
|
|
166
|
-
tri1 = pv.Triangle([[0,0,-1],[1,0,-1],[0,1,-1]])
|
|
167
|
-
tri2 = pv.Triangle([[0,0, 1],[1,0, 1],[0,1, 1]])
|
|
168
|
-
# Use an obstacle that is far away (so no intersection)
|
|
169
|
-
far_blocker = pv.Triangle([[10,10,10],[11,10,10],[10,11,10]])
|
|
170
|
-
vis, warn = pvf.get_obstruction(tri1, tri2, far_blocker, strict=False)
|
|
171
|
-
assert vis is True
|
|
172
|
-
assert warn == ""
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
def test_get_obstruction_non_strict_self_obstacle():
|
|
176
|
-
# If obstacle=face1 itself (triangle), centroid test should skip it and remain visible
|
|
177
|
-
tri1 = pv.Triangle([[0,0,0],[1,0,0],[0,1,0]])
|
|
178
|
-
tri2 = pv.Triangle([[0,0,1],[1,0,1],[0,1,1]])
|
|
179
|
-
# obstacle is exactly tri1: non-strict should skip same‐triangle
|
|
180
|
-
vis, warn = pvf.get_obstruction(tri1, tri2, tri1, strict=False)
|
|
181
|
-
assert vis is True
|
|
182
|
-
assert warn == ""
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
def test_get_obstruction_strict_full_block():
|
|
186
|
-
# Now obstacle sits exactly between centroids as well as corners
|
|
187
|
-
tri1 = pv.Triangle([[0,0,0],[1,0,0],[0,1,0]])
|
|
188
|
-
tri2 = pv.Triangle([[0,0,1],[1,0,1],[0,1,1]])
|
|
189
|
-
# A square (as two triangles) at z=0.5 that fully covers the XY-span [0,1]
|
|
190
|
-
blocker = pv.Rectangle([[0,0,0.5],[1,0,0.5],[0,1,0.5]])
|
|
191
|
-
blocker.triangulate(inplace=True)
|
|
192
|
-
vis, warn = pvf.get_obstruction(tri1, tri2, blocker, strict=True, print_debug=False)
|
|
193
|
-
assert vis is False
|
|
194
|
-
assert warn == ""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|