Skip to content

Commit

Permalink
reduced scale of examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan committed Oct 11, 2013
1 parent a21338b commit 4ac55d0
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 28 deletions.
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,20 @@ Automatic tests can be performed by running `stl_tools/test/test_stl.py`.
Run the file `examples.py` to produce a few sample STL files from images included in `examples/example_data`.

The first example converts the commonly-used [Lena test image](http://en.wikipedia.org/wiki/Lenna) to an STL file

The "solid" keyword argument sets whether to create a solid geometry (with sides and a bottom) or not.
The algorithm used to generate the sides and bottom have not yet been optimized, so may double the file size
at the moment. We'll generate this example without a bottom.
```python
from stl_tools import numpy2stl

from scipy.misc import lena, imresize
from scipy.ndimage import gaussian_filter

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

numpy2stl(A, "examples/Lena.stl", scale=0.1)
A = imresize(lena(), (256, 256)) # load Lena image, shrink in half
A = gaussian_filter(A, 1) # smoothing

numpy2stl(A, "examples/Lena.stl", scale=0.1, solid=False)
```

Source image vs. output geometry:
Expand All @@ -72,17 +75,18 @@ Source image vs. output geometry:

---

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

Python code:

```python
from pylab import imread

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

```python
A = 256.*imread("examples/example_data/openmdao.png") # 0 - 256 (8 bit) scale
A = A[:,:,0] + 1.*A[:,:,3] # Compose elements from RGBA channels to give depth
A = gaussian_filter(A, 2) # smoothing

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

Equivalent command-line syntax:
Expand Down
16 changes: 6 additions & 10 deletions examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@

A = imresize(lena(), (256, 256)) # load Lena image, shrink in half
A = gaussian_filter(A, 1) # smoothing
numpy2stl(A, "examples/Lena.stl", scale=0.1)

from scipy.misc import lena, imresize
A = imresize(lena(), (256, 256))
A = gaussian_filter(A, 1) # smoothing
numpy2stl(A, "examples/Lena.stl", scale=0.1)
numpy2stl(A, "examples/Lena.stl", scale=0.1, solid=False)

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

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

text = ("$\oint_{\Gamma} (A\, dx + B\, dy) = \iint_{U} \left(\\frac{\partial "
"B}{\partial x} - \\frac{\partial A}{\partial y}\\right)\ dxdy$ \n\n "
Expand Down
Binary file modified examples/Lena.stl
Binary file not shown.
Binary file modified examples/OpenMDAO-logo.stl
Binary file not shown.
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages

setup(name='stl_tools',
version='0.2',
version='0.2.2',
install_requires=['numpy', 'scipy', 'matplotlib'],
description="Generate STL files from numpy arrays and text",
author='Tristan Hearn',
Expand All @@ -10,7 +10,7 @@
license='Apache 2.0',
packages=['stl_tools'],
entry_points={
'console_scripts':
['image2stl=stl_tools.image2stl:image2stl']
'console_scripts':
['image2stl=stl_tools.image2stl:image2stl']
}
)
4 changes: 2 additions & 2 deletions stl_tools/numpy2stl.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def numpy2stl(A, fn, scale=0.1, mask_val=-np.inf, ascii=False,
max_width=235.,
max_depth=140.,
max_height=150.,
solid=True,
solid=False,
min_thickness_percent=0.1):
"""
Reads a numpy array, and outputs an STL file
Expand Down Expand Up @@ -105,8 +105,8 @@ def numpy2stl(A, fn, scale=0.1, mask_val=-np.inf, ascii=False,

facets = []
mask = np.zeros((m, n))
print("Creating top mesh...")
for i, k in product(range(m - 1), range(n - 1)):
print("Creating top mesh...")

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

0 comments on commit 4ac55d0

Please sign in to comment.