-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from autotwin/spheres
- Loading branch information
Showing
16 changed files
with
1,950 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Examples | ||
|
||
Following are examples created with `automesh`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# Spheres | ||
|
||
## Segmentation | ||
|
||
Using [spheres.py](spheres.py), | ||
|
||
```python | ||
<!-- cmdrun cat spheres.py --> | ||
``` | ||
|
||
create very coarse spheres of varying | ||
resolution (`radius=1`, `radius=3`, and `radius=5`), as shown below: | ||
|
||
![spheres.png](spheres.png) | ||
|
||
For the `radius=1` case, the underyling data structure appears as: | ||
|
||
```python | ||
spheres["ball_1"] | ||
|
||
array([[[0, 0, 0], | ||
[0, 1, 0], | ||
[0, 0, 0]], | ||
|
||
[[0, 1, 0], | ||
[1, 1, 1], | ||
[0, 1, 0]], | ||
|
||
[[0, 0, 0], | ||
[0, 1, 0], | ||
[0, 0, 0]]], dtype=uint8) | ||
``` | ||
|
||
For the `radius=3` case, the underyling data structure appears as: | ||
|
||
```python | ||
spheres["ball_3"] | ||
|
||
array([[[0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 1, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0]], | ||
|
||
[[0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 1, 1, 1, 0, 0], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[0, 0, 1, 1, 1, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0]], | ||
|
||
[[0, 0, 0, 0, 0, 0, 0], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[0, 0, 0, 0, 0, 0, 0]], | ||
|
||
[[0, 0, 0, 1, 0, 0, 0], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[1, 1, 1, 1, 1, 1, 1], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[0, 0, 0, 1, 0, 0, 0]], | ||
|
||
[[0, 0, 0, 0, 0, 0, 0], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[0, 0, 0, 0, 0, 0, 0]], | ||
|
||
[[0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 1, 1, 1, 0, 0], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[0, 0, 1, 1, 1, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0]], | ||
|
||
[[0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 1, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0]]], dtype=uint8) | ||
``` | ||
|
||
Because of the large size of `ball_5`, its data structure is not shown | ||
here. | ||
|
||
These data structures are saved to | ||
|
||
* [spheres_ball_1_.npy](spheres_ball_1_.npy) | ||
* [spheres_ball_3_.npy](spheres_ball_3_.npy) | ||
* [spheres_ball_5_.npy](spheres_ball_5_.npy) | ||
|
||
## Mesh | ||
|
||
```sh | ||
cargo run -- -i book/examples/spheres/spheres_ball_1_.npy -o book/examples/spheres/spheres_ball_1_.inp -x 3 -y 3 -z 3 | ||
``` | ||
|
||
```sh | ||
cargo run -- -i book/examples/spheres/spheres_ball_3_.npy -o book/examples/spheres/spheres_ball_3_.inp -x 7 -y 7 -z 7 | ||
``` | ||
|
||
```sh | ||
cargo run -- -i book/examples/spheres/spheres_ball_5_.npy -o book/examples/spheres/spheres_ball_5_.inp -x 11 -y 11 -z 11 | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
"""This module demonstrates how to create a voxelized sphere and export | ||
it as a .npy file. | ||
Items that need to be installed into the virtual environment: | ||
pip install scikit-image | ||
""" | ||
|
||
import matplotlib.pyplot as plt | ||
from matplotlib.colors import LightSource | ||
from mpl_toolkits.mplot3d import Axes3D | ||
import numpy as np | ||
from pathlib import Path | ||
from typing import Final | ||
|
||
from skimage.morphology import ball | ||
|
||
|
||
# User input begin | ||
|
||
spheres = { | ||
"ball_1": ball(radius=1), | ||
"ball_3": ball(radius=3), | ||
"ball_5": ball(radius=5), | ||
} | ||
|
||
aa = Path(__file__) | ||
bb = aa.with_suffix(".png") | ||
|
||
# Visualize the elements. | ||
# width, height = 8, 4 | ||
width, height = 6, 3 | ||
fig = plt.figure(figsize=(width, height)) | ||
# fig = plt.figure(figsize=(8, 8)) | ||
|
||
el, az, roll = 63, -110, 0 | ||
cmap = plt.get_cmap(name="tab10") | ||
num_colors = len(spheres) | ||
voxel_alpha: Final[float] = 0.9 | ||
|
||
colors = cmap(np.linspace(0, 1, num_colors)) | ||
lightsource = LightSource(azdeg=325, altdeg=45) # azimuth, elevation | ||
# lightsource = LightSource(azdeg=325, altdeg=90) # azimuth, elevation | ||
dpi: Final[int] = 300 # resolution, dots per inch | ||
serialize: Final[bool] = False # turn to True to save .png and .npy files | ||
# User input end | ||
|
||
|
||
idx = 1 | ||
for title, struc in spheres.items(): | ||
ax = fig.add_subplot(1, 3, idx, projection=Axes3D.name) | ||
ax.voxels( | ||
struc, | ||
facecolors=colors[idx-1], | ||
edgecolor=colors[idx-1], | ||
alpha=voxel_alpha, | ||
lightsource=lightsource) | ||
ax.set_title(title) | ||
idx += 1 | ||
|
||
# Set labels for the axes | ||
ax.set_xlabel("x") | ||
ax.set_ylabel("y") | ||
ax.set_zlabel("z") | ||
|
||
# Set the camera view | ||
ax.set_aspect("equal") | ||
ax.view_init(elev=el, azim=az, roll=roll) | ||
|
||
if serialize: | ||
cc = aa.with_stem("spheres_" + title + "_") | ||
dd = cc.with_suffix(".npy") | ||
# Save the data in .npy format | ||
np.save(dd, struc) | ||
print(f"Saved: {dd}") | ||
|
||
fig.tight_layout() | ||
plt.show() | ||
|
||
if serialize: | ||
fig.savefig(bb, dpi=dpi) | ||
print(f"Saved: {bb}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
*HEADING | ||
autotwin.automesh | ||
version 0.1.3 | ||
autogenerated on 2024-09-11 23:05:42.323084 UTC | ||
** | ||
*NODE, NSET=ALLNODES | ||
1, 1.000000e0, 1.000000e0, 0.000000e0 | ||
2, 2.000000e0, 1.000000e0, 0.000000e0 | ||
3, 1.000000e0, 2.000000e0, 0.000000e0 | ||
4, 2.000000e0, 2.000000e0, 0.000000e0 | ||
5, 1.000000e0, 0.000000e0, 1.000000e0 | ||
6, 2.000000e0, 0.000000e0, 1.000000e0 | ||
7, 0.000000e0, 1.000000e0, 1.000000e0 | ||
8, 1.000000e0, 1.000000e0, 1.000000e0 | ||
9, 2.000000e0, 1.000000e0, 1.000000e0 | ||
10, 3.000000e0, 1.000000e0, 1.000000e0 | ||
11, 0.000000e0, 2.000000e0, 1.000000e0 | ||
12, 1.000000e0, 2.000000e0, 1.000000e0 | ||
13, 2.000000e0, 2.000000e0, 1.000000e0 | ||
14, 3.000000e0, 2.000000e0, 1.000000e0 | ||
15, 1.000000e0, 3.000000e0, 1.000000e0 | ||
16, 2.000000e0, 3.000000e0, 1.000000e0 | ||
17, 1.000000e0, 0.000000e0, 2.000000e0 | ||
18, 2.000000e0, 0.000000e0, 2.000000e0 | ||
19, 0.000000e0, 1.000000e0, 2.000000e0 | ||
20, 1.000000e0, 1.000000e0, 2.000000e0 | ||
21, 2.000000e0, 1.000000e0, 2.000000e0 | ||
22, 3.000000e0, 1.000000e0, 2.000000e0 | ||
23, 0.000000e0, 2.000000e0, 2.000000e0 | ||
24, 1.000000e0, 2.000000e0, 2.000000e0 | ||
25, 2.000000e0, 2.000000e0, 2.000000e0 | ||
26, 3.000000e0, 2.000000e0, 2.000000e0 | ||
27, 1.000000e0, 3.000000e0, 2.000000e0 | ||
28, 2.000000e0, 3.000000e0, 2.000000e0 | ||
29, 1.000000e0, 1.000000e0, 3.000000e0 | ||
30, 2.000000e0, 1.000000e0, 3.000000e0 | ||
31, 1.000000e0, 2.000000e0, 3.000000e0 | ||
32, 2.000000e0, 2.000000e0, 3.000000e0 | ||
** | ||
*ELEMENT, TYPE=C3D8R, ELSET=EB1 | ||
1, 1, 2, 4, 3, 8, 9, 13, 12 | ||
2, 5, 6, 9, 8, 17, 18, 21, 20 | ||
3, 7, 8, 12, 11, 19, 20, 24, 23 | ||
4, 8, 9, 13, 12, 20, 21, 25, 24 | ||
5, 9, 10, 14, 13, 21, 22, 26, 25 | ||
6, 12, 13, 16, 15, 24, 25, 28, 27 | ||
7, 20, 21, 25, 24, 29, 30, 32, 31 | ||
** | ||
*SOLID SECTION, ELSET=EB1, MATERIAL=Default-Steel |
Binary file not shown.
Oops, something went wrong.