Skip to content

Commit 4ac55d0

Browse files
author
Tristan
committed
reduced scale of examples
1 parent a21338b commit 4ac55d0

File tree

6 files changed

+27
-28
lines changed

6 files changed

+27
-28
lines changed

README.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,20 @@ Automatic tests can be performed by running `stl_tools/test/test_stl.py`.
5252
Run the file `examples.py` to produce a few sample STL files from images included in `examples/example_data`.
5353

5454
The first example converts the commonly-used [Lena test image](http://en.wikipedia.org/wiki/Lenna) to an STL file
55-
55+
The "solid" keyword argument sets whether to create a solid geometry (with sides and a bottom) or not.
56+
The algorithm used to generate the sides and bottom have not yet been optimized, so may double the file size
57+
at the moment. We'll generate this example without a bottom.
5658
```python
5759
from stl_tools import numpy2stl
5860

5961
from scipy.misc import lena, imresize
6062
from scipy.ndimage import gaussian_filter
6163

62-
A = imresize(lena(), (256,256)) # load Lena image, shrink in half
63-
A = gaussian_filter(A, 1) # smoothing
6464

65-
numpy2stl(A, "examples/Lena.stl", scale=0.1)
65+
A = imresize(lena(), (256, 256)) # load Lena image, shrink in half
66+
A = gaussian_filter(A, 1) # smoothing
67+
68+
numpy2stl(A, "examples/Lena.stl", scale=0.1, solid=False)
6669
```
6770

6871
Source image vs. output geometry:
@@ -72,17 +75,18 @@ Source image vs. output geometry:
7275

7376
---
7477

75-
The next three examples convert logos to STL, using color information to achieve appropriate 3D layering
78+
The next two examples convert logos to STL, using color information to achieve appropriate 3D layering.
79+
For this example, we'll generate a solid geometry (solid=True), for comparison to the first example.
7680

7781
Python code:
7882

7983
```python
8084
from pylab import imread
8185

82-
A = 256 * imread("examples/example_data/NASA.png") # 0 - 256 (8 bit) scale
83-
A = A[:,:, 2] + 1.0*A[:,:, 0] # Compose RGBA channels to give depth
86+
A = 256 * imread("examples/example_data/NASA.png")
87+
A = A[:, :, 2] + 1.0*A[:,:, 0] # Compose RGBA channels to give depth
8488
A = gaussian_filter(A, 1) # smoothing
85-
numpy2stl(A, "examples/NASA.stl", scale=0.05, mask_val=5.)
89+
numpy2stl(A, "examples/NASA.stl", scale=0.05, mask_val=5., solid=True)
8690
```
8791
Equivalent command-line syntax:
8892
```bash
@@ -97,11 +101,10 @@ Equivalent command-line syntax:
97101
Python code:
98102

99103
```python
100-
A = 256.*imread("examples/example_data/openmdao.png") # 0 - 256 (8 bit) scale
101-
A = A[:,:,0] + 1.*A[:,:,3] # Compose elements from RGBA channels to give depth
102-
A = gaussian_filter(A, 2) # smoothing
103-
104-
numpy2stl(A, "examples/OpenMDAO-logo.stl", scale=0.05, mask_val = 1.)
104+
A = 256 * imread("examples/example_data/openmdao.png")
105+
A = A[:, :, 0] + 1.*A[:,:, 3] # Compose some elements from RGBA to give depth
106+
A = gaussian_filter(A, 2) # smoothing
107+
numpy2stl(A, "examples/OpenMDAO-logo.stl", scale=0.05, mask_val=1., solid=False)
105108
```
106109

107110
Equivalent command-line syntax:

examples.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,18 @@
1010

1111
A = imresize(lena(), (256, 256)) # load Lena image, shrink in half
1212
A = gaussian_filter(A, 1) # smoothing
13-
numpy2stl(A, "examples/Lena.stl", scale=0.1)
14-
15-
from scipy.misc import lena, imresize
16-
A = imresize(lena(), (256, 256))
17-
A = gaussian_filter(A, 1) # smoothing
18-
numpy2stl(A, "examples/Lena.stl", scale=0.1)
13+
numpy2stl(A, "examples/Lena.stl", scale=0.1, solid=False)
1914

2015
A = 256 * imread("examples/example_data/NASA.png")
21-
A = A[:,:, 2] + 1.0*A[:,:, 0] # Compose RGBA channels to give depth
16+
A = A[:, :, 2] + 1.0*A[:,:, 0] # Compose RGBA channels to give depth
2217
A = gaussian_filter(A, 1) # smoothing
23-
numpy2stl(A, "examples/NASA.stl", scale=0.05, mask_val=5.)
18+
numpy2stl(A, "examples/NASA.stl", scale=0.05, mask_val=5., solid=True)
2419

2520
A = 256 * imread("examples/example_data/openmdao.png")
26-
A = A[:,:, 0] + 1.*A[:,:, 3] # Compose some elements from RGBA to give depth
21+
A = A[:, :, 0] + 1.*A[:,:, 3] # Compose some elements from RGBA to give depth
2722
A = gaussian_filter(A, 2) # smoothing
28-
numpy2stl(A, "examples/OpenMDAO-logo.stl", scale=0.05, mask_val=1.)
23+
numpy2stl(A, "examples/OpenMDAO-logo.stl",
24+
scale=0.05, mask_val=1., solid=False)
2925

3026
text = ("$\oint_{\Gamma} (A\, dx + B\, dy) = \iint_{U} \left(\\frac{\partial "
3127
"B}{\partial x} - \\frac{\partial A}{\partial y}\\right)\ dxdy$ \n\n "

examples/Lena.stl

-6.2 MB
Binary file not shown.

examples/OpenMDAO-logo.stl

-5.13 MB
Binary file not shown.

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup, find_packages
22

33
setup(name='stl_tools',
4-
version='0.2',
4+
version='0.2.2',
55
install_requires=['numpy', 'scipy', 'matplotlib'],
66
description="Generate STL files from numpy arrays and text",
77
author='Tristan Hearn',
@@ -10,7 +10,7 @@
1010
license='Apache 2.0',
1111
packages=['stl_tools'],
1212
entry_points={
13-
'console_scripts':
14-
['image2stl=stl_tools.image2stl:image2stl']
13+
'console_scripts':
14+
['image2stl=stl_tools.image2stl:image2stl']
1515
}
1616
)

stl_tools/numpy2stl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def numpy2stl(A, fn, scale=0.1, mask_val=-np.inf, ascii=False,
6262
max_width=235.,
6363
max_depth=140.,
6464
max_height=150.,
65-
solid=True,
65+
solid=False,
6666
min_thickness_percent=0.1):
6767
"""
6868
Reads a numpy array, and outputs an STL file
@@ -105,8 +105,8 @@ def numpy2stl(A, fn, scale=0.1, mask_val=-np.inf, ascii=False,
105105

106106
facets = []
107107
mask = np.zeros((m, n))
108+
print("Creating top mesh...")
108109
for i, k in product(range(m - 1), range(n - 1)):
109-
print("Creating top mesh...")
110110

111111
this_pt = np.array([i - m / 2., k - n / 2., A[i, k]])
112112
top_right = np.array([i - m / 2., k + 1 - n / 2., A[i, k + 1]])

0 commit comments

Comments
 (0)