26
26
import math
27
27
import numpy
28
28
import warnings
29
+ from alinea .astk .colormap import jet_colors
29
30
30
31
display_enable = True
31
32
try :
34
35
warnings .warn ('PlantGL not installed: display is not enable!' )
35
36
display_enable = False
36
37
38
+ def sky_turtle (turtle_mesh , sky_sources ):
39
+ vertices , faces = turtle_mesh
40
+ colors = jet_colors ((lum for _ ,_ ,lum in sky_sources ))
41
+ scene = pgl .Scene ()
42
+ for i , face in enumerate (faces ):
43
+ vtx = [vertices [v ] for v in face ]
44
+ idx = range (len (face ))
45
+ mat = pgl .Material (pgl .Color3 (* colors [i ]))
46
+ shape = pgl .Shape (pgl .FaceSet (pointList = vtx , indexList = [idx ]), mat )
47
+ scene += shape
48
+ return scene
49
+
37
50
38
51
def display (vertices , faces , colors = None , view = True ):
39
52
"""3D display of a polyhedron with PlantGL
@@ -90,7 +103,7 @@ def spherical(points):
90
103
x , y , z = zip (* proj )
91
104
theta = numpy .arccos (z )
92
105
phi = numpy .arctan2 (y , x )
93
- return zip (theta , phi )
106
+ return list ( zip (theta , phi ) )
94
107
95
108
96
109
def rotation_matrix (axis , theta ):
@@ -396,21 +409,20 @@ def refine(level=0):
396
409
return iter_triangle , iter_star
397
410
398
411
399
- def turtle_dome ( refine_level = 3 ):
412
+ def turtle_mesh ( min_faces = 46 ):
400
413
"""Generate faces of a dual icosphere polyhedron mapping the Z+ hemisphere
401
414
402
415
Args:
403
- refine_level (int): the level of refinement of the dual icosphere. By
404
- default 46 polygons are returned (refine_level=3).
405
-
406
- For information, here are the number of faces obtained for the first ten
407
- refinement level: 0: 6, 1: 16, 2: 26, 3: 46, 4: 66, 5: 91, 6: 136,
408
- 7: 196, 8: 251, 9: 341, 10: 406
416
+ min_faces (int) : the minimal number of faces for the polyhedron
417
+ The number of faces obtained for the first ten polyhedrons are:
418
+ 6, 16, 26, 46, 66, 91, 136, 196, 251, 341, 406
409
419
410
420
Returns:
411
421
a list of vertices and a list of faces
412
422
"""
413
-
423
+ sectors = [ 1 , 6 , 16 , 26 , 46 , 66 , 91 , 136 , 196 , 251 , 341 , 406 ]
424
+ refines = [- 1 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]
425
+ refine_level = refines [numpy .searchsorted (sectors , min (max (sectors ), min_faces ))]
414
426
vertices , faces = dual (* icosphere (* refine (refine_level )))
415
427
# filter faces with centroids below horizontal plane
416
428
centers = [centroid ([vertices [p ] for p in face ]) for face in faces ]
@@ -431,37 +443,17 @@ def turtle_dome(refine_level=3):
431
443
return new_vertices , new_faces
432
444
433
445
434
- def turtle_sectors (nb_sectors = 46 ):
435
- """Generate faces of a dual icosphere polyhedron mapping the Z+ hemisphere
436
-
437
- Args:
438
- refine_level (int): the level of refinement of the dual icosphere. By
439
- default 46 polygons are returned (refine_level=3).
440
-
441
- For information, here are the number of faces obtained for the first ten
442
- refinement level: 0: 6, 1: 16, 2: 26, 3: 46, 4: 66, 5: 91, 6: 136,
443
- 7: 196, 8: 251, 9: 341, 10: 406
444
-
445
- Returns:
446
- a list of vertices and a list of faces
446
+ def spherical_face_centers (turtle_mesh ):
447
+ """ Spherical coordinates of turtle mesh faces centers
447
448
"""
448
- sectors = [ 1 , 6 , 16 , 26 , 46 , 66 , 91 , 136 , 196 , 251 , 341 , 406 ]
449
- refines = [- 1 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]
450
- s2r = dict (zip (sectors ,refines ))
451
-
452
- if nb_sectors not in s2r :
453
- print ('Use a value of nb_sectors in the set ' , sectors )
454
-
455
- refine_level = s2r [nb_sectors ]
456
-
457
- vertices , faces = turtle_dome (refine_level )
449
+ vertices , faces = turtle_mesh
458
450
459
451
# Compute the centroid of each face
460
452
centers = [centroid ([vertices [p ] for p in face ]) for face in faces ]
461
453
462
- elevations , azimuths = spherical (centers )
454
+ zeniths , azimuths = zip ( * spherical (centers ) )
463
455
464
- return elevations , azimuths
456
+ return list ( zip ( 90 - numpy . degrees ( zeniths ), numpy . degrees ( azimuths )))
465
457
466
458
467
459
def sample_faces (vertices , faces , iter = 2 , spheric = False ):
0 commit comments