jerboapy 0.2rc332__cp313-cp313-win_amd64.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.
@@ -0,0 +1,7 @@
1
+ from . import * # Importer les bindings C++ générés par pybind11
2
+ from jerboapy import * # Importer les bindings C++ générés par pybind11
3
+ from .Point3 import Point3 # Importer la classe Python Point3
4
+ from .Color4 import Color4 # Importer la classe Python Color4
5
+ from .utils import * # Importer les utilitaires Python
6
+ from .rules import * # Importer les règles Python
7
+ from .render import * # Importer les fonctions de rendu Python
jerboapy_ext/render.py ADDED
@@ -0,0 +1,222 @@
1
+
2
+ import pyvista as pv
3
+ import numpy as np
4
+ from tqdm import tqdm
5
+
6
+ from .Point3 import Point3
7
+ from .Color4 import Color4
8
+
9
+ from jerboapy import *
10
+
11
+ def convert_vertices_attributes(gmap):
12
+ vertices = []
13
+ normals = []
14
+ colors = []
15
+ for dart in tqdm(gmap, desc="Extraction of vertices attributes"):
16
+ p = dart.ebd123.get("pos", Point3(0.0, 0.0, 0.0))
17
+ if isinstance(p, Point3) or isinstance(p, Color4):
18
+ p = p.toNumpy()
19
+ vertices.append(p)
20
+
21
+ n = dart.ebd01.get("normal", Point3(0.0, 0.0, 1.0))
22
+ if isinstance(n, Point3) or isinstance(n, Color4):
23
+ n = n.toNumpy()
24
+ else:
25
+ print(">>> normal is not a Point3 or Color4: ", n)
26
+ normals.append(n)
27
+
28
+ c = dart.ebd01.get("color", Color4(1.0, 1.0, 1.0))
29
+ if isinstance(c, Point3) or isinstance(c, Color4):
30
+ c = c.toNumpy()
31
+ # else:
32
+ # print(">>> color is not a Point3 or Color4: ", c)
33
+ c = np.resize(c, 4) if len(c) > 4 else np.pad(c, (0, 4 - len(c)), constant_values=1.0)
34
+ colors.append(c)
35
+ return (
36
+ np.array(vertices, dtype=np.float32),
37
+ np.array(normals, dtype=np.float32),
38
+ np.array(colors, dtype=np.float32),
39
+ )
40
+
41
+
42
+ def convert_faces(gmap):
43
+ islet01 = Islet([0,1])
44
+ ilot01 = islet01(gmap)
45
+ # print(">>> ilot01 : ", ilot01)
46
+ faces_flat = []
47
+ # print("islet done.")
48
+ faces_darts = set(ilot01)
49
+
50
+ for id in tqdm(faces_darts, desc="Extraction of faces"):
51
+ # print(">>> FaceID: ", id)
52
+ face = []
53
+ size = 0
54
+ cur = id
55
+ marks = []
56
+ while cur not in marks:
57
+ if size%2 == 0:
58
+ # print(" >>> point : ", cur, " -> ", gmap[cur].ebd123.get("pos", [-10.0, -11.0, -12.0]))
59
+ face.append(cur)
60
+ marks.append(cur)
61
+ cur = gmap.alpha(cur, size%2)
62
+ size += 1
63
+ # print(">>> new face : {} - size : {}".format(id, len(face)))
64
+ faces_flat.append(len(face))
65
+ faces_flat.extend(face)
66
+
67
+ return faces_flat
68
+ def extract_geometries(gmap,ebdpos="pos", ebdnormal="normal", ebdcolor="color"):
69
+ """
70
+ Extracts vertices, normals, colors and faces from the given gmap.
71
+
72
+ Parameters:
73
+ - gmap: The GMap3D object to extract geometries from.
74
+ - ebdpos: The key for position in the edge-based data (default is "pos").
75
+ - ebdnormal: The key for normal in the edge-based data (default is "normal").
76
+ - ebdcolor: The key for color in the edge-based data (default is "color").
77
+
78
+ Returns:
79
+ - A tuple containing vertices, normals, colors, and faces.
80
+ """
81
+ (vertdart, faces_flat) = gmap.extractGeometryCompacted3D()
82
+
83
+ vertices = []
84
+ normals = []
85
+ colors = []
86
+ for did in tqdm(vertdart, desc="Extraction of the geometry"):
87
+ p = gmap[did].ebd123.get(ebdpos, Point3(0.0, 0.0, 0.0)).toNumpy()
88
+ vertices.append(p)
89
+
90
+ n = gmap[did].ebd01.get(ebdnormal, Point3(0.0, 0.0, 1.0)).toNumpy()
91
+ normals.append(n)
92
+
93
+ c = gmap[did].ebd01.get(ebdcolor, Color4.LIGHTGRAY).toNumpy()
94
+ c = np.resize(c, 4) if len(c) > 4 else np.pad(c, (0, 4 - len(c)), constant_values=1.0)
95
+ colors.append(c)
96
+
97
+ faces_flat = [item for sublist in faces_flat for item in [len(sublist)] + sublist]
98
+
99
+ return (
100
+ np.array(vertices, dtype=np.float32),
101
+ np.array(normals, dtype=np.float32),
102
+ np.array(colors, dtype=np.float32),
103
+ faces_flat
104
+ )
105
+
106
+
107
+
108
+ # @numba.jit(nopython=True, parallel=True)
109
+ def extract_geometries_old(gmap,ebdpos="pos", ebdnormal="normal", ebdcolor="color"):
110
+ vertices = []
111
+ normals = []
112
+ colors = []
113
+ faces_flat = []
114
+ # islet01 = Islet([0,1])
115
+ # ilot01 = islet01(gmap)
116
+
117
+
118
+ for dart in tqdm(gmap, desc="Extraction of the geometry"):
119
+
120
+ p = dart.ebd123.get(ebdpos, Point3(0.0, 0.0, 0.0)).toNumpy()
121
+ vertices.append(p)
122
+
123
+ n = dart.ebd01.get(ebdnormal, Point3(0.0, 0.0, 1.0)).toNumpy()
124
+ normals.append(n)
125
+
126
+ c = dart.ebd01.get(ebdcolor, Color4.LIGHTGRAY).toNumpy()
127
+ c = np.resize(c, 4) if len(c) > 4 else np.pad(c, (0, 4 - len(c)), constant_values=1.0)
128
+ colors.append(c)
129
+
130
+
131
+ faces_flat = gmap.extractFaces2D()
132
+ faces_flat = [item for sublist in faces_flat for item in [len(sublist)] + sublist]
133
+
134
+ return (
135
+ np.array(vertices, dtype=np.float32),
136
+ np.array(normals, dtype=np.float32),
137
+ np.array(colors, dtype=np.float32),
138
+ faces_flat
139
+ )
140
+
141
+
142
+ def extract_geometries_compact(gmap,ebdpos="pos", ebdnormal="normal", ebdcolor="color"):
143
+ vertices = []
144
+ normals = []
145
+ colors = []
146
+ faces_flat = []
147
+ islet01 = Islet([0,1])
148
+ ilot01 = islet01(gmap)
149
+
150
+
151
+ for dart in tqdm(gmap, desc="Extraction of the geometry"):
152
+ id = dart.id
153
+
154
+ if id == ilot01[id]:
155
+ # print(">>> FaceID: ", id)
156
+ face = []
157
+ size = 0
158
+ cur = id
159
+ marks = []
160
+ while cur not in marks:
161
+ if size%2 == 0:
162
+ # print(" >>> point : ", cur, " -> ", gmap[cur].ebd123.get("pos", [-10.0, -11.0, -12.0]))
163
+ newid = len(vertices)
164
+ p = dart.ebd123.get(ebdpos, Point3(0.0, 0.0, 0.0))
165
+ if isinstance(p, Point3) or isinstance(p, Color4):
166
+ p = p.toNumpy()
167
+ vertices.append(p)
168
+
169
+ n = dart.ebd01.get(ebdnormal, Point3(0.0, 0.0, 1.0))
170
+ if isinstance(n, Point3) or isinstance(n, Color4):
171
+ n = n.toNumpy()
172
+ else:
173
+ print(">>> normal is not a Point3 or Color4: ", n)
174
+ normals.append(n)
175
+
176
+ c = dart.ebd01.get(ebdcolor, Color4(1.0, 1.0, 1.0))
177
+ if isinstance(c, Point3) or isinstance(c, Color4):
178
+ c = c.toNumpy()
179
+ c = np.resize(c, 4) if len(c) > 4 else np.pad(c, (0, 4 - len(c)), constant_values=1.0)
180
+ colors.append(c)
181
+ face.append(newid)
182
+ # face.append(cur)
183
+ marks.append(cur)
184
+ cur = gmap.alpha(cur, size%2)
185
+ size += 1
186
+ # print(">>> new face : {} - size : {}".format(id, len(face)))
187
+ faces_flat.append(len(face))
188
+ faces_flat.extend(face)
189
+
190
+
191
+ return (
192
+ np.array(vertices, dtype=np.float32),
193
+ np.array(normals, dtype=np.float32),
194
+ np.array(colors, dtype=np.float32),
195
+ faces_flat
196
+ )
197
+
198
+
199
+ def show(gmap, title="Jerboa display"):
200
+ # vertices, normals, colors = convert_vertices_attributes(gmap)
201
+ # faces = convert_faces(gmap)
202
+
203
+ vertices, normals, colors, faces = extract_geometries(gmap)
204
+ # vertices, normals, colors, faces = extract_geometries_compact(gmap)
205
+
206
+ print("Prepare polydata by pyvista...")
207
+ # Create a PyVista PolyData object
208
+ mesh = pv.PolyData(vertices, faces)
209
+
210
+ # Add normals and colors to the mesh
211
+ mesh["Normals"] = normals
212
+ mesh["Colors"] = colors
213
+
214
+ print("Prepare plotter for pyvista...")
215
+ # Create a PyVista plotter
216
+ plotter = pv.Plotter(window_size=(1280, 960), notebook=False, off_screen=False, title=title)
217
+
218
+ # Ajouter les normales sous forme de flèches
219
+ plotter.add_mesh(mesh, scalars="Colors", rgb=True, show_edges=True, line_width=6.0)
220
+
221
+ plotter.add_axes(interactive=True)
222
+ plotter.show()