(sim: Simulation)
| 1278 | |
| 1279 | |
| 1280 | def visualize_chunks(sim: Simulation): |
| 1281 | if sim.structure is None: |
| 1282 | sim.init_sim() |
| 1283 | |
| 1284 | import matplotlib.pyplot as plt |
| 1285 | import matplotlib.cm |
| 1286 | import matplotlib.colors |
| 1287 | |
| 1288 | if sim.structure.gv.dim == 2: |
| 1289 | from mpl_toolkits.mplot3d import Axes3D |
| 1290 | from mpl_toolkits.mplot3d.art3d import Poly3DCollection |
| 1291 | else: |
| 1292 | from matplotlib.collections import PolyCollection |
| 1293 | |
| 1294 | vols = sim.structure.get_chunk_volumes() |
| 1295 | owners = sim.structure.get_chunk_owners() |
| 1296 | |
| 1297 | def plot_box(box, proc, fig, ax: Axes): |
| 1298 | if sim.structure.gv.dim == 2: |
| 1299 | low = Vector3(box.low.x, box.low.y, box.low.z) |
| 1300 | high = Vector3(box.high.x, box.high.y, box.high.z) |
| 1301 | points = [low, high] |
| 1302 | |
| 1303 | x_len = Vector3(high.x) - Vector3(low.x) |
| 1304 | y_len = Vector3(y=high.y) - Vector3(y=low.y) |
| 1305 | xy_len = Vector3(high.x, high.y) - Vector3(low.x, low.y) |
| 1306 | |
| 1307 | points += [low + x_len] |
| 1308 | points += [low + y_len] |
| 1309 | points += [low + xy_len] |
| 1310 | points += [high - x_len] |
| 1311 | points += [high - y_len] |
| 1312 | points += [high - xy_len] |
| 1313 | points = np.array([np.array(v) for v in points]) |
| 1314 | |
| 1315 | edges = [ |
| 1316 | [points[0], points[2], points[4], points[3]], |
| 1317 | [points[1], points[5], points[7], points[6]], |
| 1318 | [points[0], points[3], points[5], points[7]], |
| 1319 | [points[1], points[4], points[2], points[6]], |
| 1320 | [points[3], points[4], points[1], points[5]], |
| 1321 | [points[0], points[7], points[6], points[2]], |
| 1322 | ] |
| 1323 | |
| 1324 | faces = Poly3DCollection(edges, linewidths=1, edgecolors="k") |
| 1325 | color_with_alpha = matplotlib.colors.to_rgba(chunk_colors[proc], alpha=0.2) |
| 1326 | faces.set_facecolor(color_with_alpha) |
| 1327 | ax.add_collection3d(faces) |
| 1328 | |
| 1329 | # Plot the points themselves to force the scaling of the axes |
| 1330 | ax.scatter(points[:, 0], points[:, 1], points[:, 2], s=0) |
| 1331 | else: |
| 1332 | low = Vector3(box.low.x, box.low.y) |
| 1333 | high = Vector3(box.high.x, box.high.y) |
| 1334 | points = [low, high] |
| 1335 | |
| 1336 | x_len = Vector3(high.x) - Vector3(low.x) |
| 1337 | y_len = Vector3(y=high.y) - Vector3(y=low.y) |
nothing calls this directly
no test coverage detected