You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+40-32Lines changed: 40 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,17 +5,17 @@ stl_tools
5
5
Python code to generate STL geometry files from plain text, LaTeX code, and 2D numpy arrays (matrices).
6
6
7
7
This allows for rapid 3D printing of text, rendered equations, or simple digital images.
8
-
Use them for product prototyping, art, cookie cutters, ice cube trays, chocolate molds, (see [this](http://www.makerbot.com/tutorials/making-chocolate-molds/)
8
+
Use them for product prototyping, art, cookie cutters, ice cube trays, chocolate molds, (see [this](http://www.makerbot.com/tutorials/making-chocolate-molds/)
9
9
to learn how to make a printed object food-safe) or whatever else you can think of.
10
10
11
-
Some modification may be needed to the STL or printer settings to get certain shapes to print cleanly (ie. thicker base,
11
+
Some modification may be needed to the STL or printer settings to get certain shapes to print cleanly (ie. thicker base,
12
12
support structures, etc).
13
13
14
-
Besides printing, these can also be merged into other 3D meshes for many other
14
+
Besides printing, these can also be merged into other 3D meshes for many other
15
15
possible uses, using programs such as [Blender](http://www.blender.org/).
16
16
17
17
Also included is a function that can convert raw LaTeX expressions to high
18
-
quality .png images, which allows for simple inclusion of LaTeX equations into
18
+
quality .png images, which allows for simple inclusion of LaTeX equations into
19
19
non-LaTeX document editors.
20
20
21
21
A command-line script for converting images to STL (no text yet) is included in the installation for those who do not
@@ -24,14 +24,14 @@ want to write Python code directly.
24
24
## Requirements:
25
25
-[Python](http://python.org/) 2.7 or higher (Python 3.x not yet tested, but would probably work)
26
26
-[Numpy](http://www.numpy.org/) 1.7 or higher (for array manipulation)
27
-
-[Scipy](http://www.scipy.org/) 0.12 or higher and [PIL](http://www.pythonware.com/products/pil/)(for image reading and filtering functions)
27
+
-[Scipy](http://www.scipy.org/) 0.12 or higher (for resizing and filtering functions)
28
28
-[Matplotlib](http://matplotlib.org/) 1.2.1 or higher (for rendering text and LaTeX to image data)
29
29
30
30
## Installation:
31
-
Run `python setup.py build install` to install.
31
+
Run `python setup.py build install` to install.
32
32
33
33
This will check for the 3rd party
34
-
dependencies above and install the library.
34
+
dependencies above and install the library.
35
35
36
36
This will also install the
37
37
command line script `image2stl` into the `Python/Scripts` directory.
@@ -68,13 +68,12 @@ The next three examples convert logos to STL, using color information to achieve
68
68
Python code:
69
69
70
70
```python
71
-
fromscipy.miscimport imread
71
+
frompylabimport imread
72
72
73
-
A = imread("examples/example_data/NASA.png")
74
-
A = A[:,:,2] +1.0*A[:,:,0] # Compose elements from RGBA channels to give depth
@@ -151,7 +150,7 @@ There are 3 principal functions (no classes) to import and use from stl_tools:
151
150
fn (string) - filename to use for STL file
152
151
153
152
Optional input:
154
-
scale (float) - scales the height (surface) of the
153
+
scale (float) - scales the height (surface) of the
155
154
resulting STL mesh. Tune to match needs
156
155
157
156
mask_val (float) - any element of the inputted array that is less
@@ -164,14 +163,14 @@ There are 3 principal functions (no classes) to import and use from stl_tools:
164
163
165
164
max_width, max_depth, max_height (floats) - maximum size of the stl
166
165
object (in mm). Match this to
167
-
the dimensions of a 3D printer platform
166
+
the dimensions of a 3D printer platform
168
167
169
168
Returns: (None)
170
169
171
-
`numpy2stl()` is the main function of this repository.
170
+
`numpy2stl()` is the main function of this repository.
172
171
173
172
It takes a 2D numpy array and output filename
174
-
as input, and writes an STL file.
173
+
as input, and writes an STL file.
175
174
176
175
Each element of the array is tesselated to its neighbors to produce 2 triangular faces for
177
176
every 4 contiguous elements. The depth axis of any vertex is taken to be the value of the array corresponding to that point.
@@ -183,7 +182,7 @@ Array elements which are less than this value will not be included as vertices.
183
182
It takes a bit of trial-and-error to get these just right. Plotting the intermediate arrays
184
183
with a colorbar (to show scaling) helps in finding decent values.
185
184
186
-
The `max_width`, `max_height`, and `max_depth` values are measurements (in mm) used to scale the final output to
185
+
The `max_width`, `max_height`, and `max_depth` values are measurements (in mm) used to scale the final output to
187
186
the largest size that can fit onto your 3D printer platform. Default values are for the MakerBot Replicator.
188
187
189
188
@@ -201,7 +200,7 @@ the largest size that can fit onto your 3D printer platform. Default values are
201
200
Returns: (None)
202
201
203
202
`text2png()` was written as an intermediate helper function to render text to pngs, to then be imported, filtered, and meshed.
204
-
However, it may be useful in it's own right. For example, it can be used alone to render LaTeX expressions into images, to be imported into WYSIWYG document editors like MS Word or LibreOffice Writer.
203
+
However, it may be useful in it's own right. For example, it can be used alone to render LaTeX expressions into images, to be imported into WYSIWYG document editors like MS Word or LibreOffice Writer.
205
204
206
205
### `stl_tools.text2array`
207
206
text2array(text)
@@ -211,7 +210,7 @@ However, it may be useful in it's own right. For example, it can be used alone t
211
210
text (string) - text to render
212
211
213
212
Returns: A (ndarray) - 2D numpy array of rendered text
214
-
213
+
215
214
216
215
`text2array()` renders inputted text using `text2png()`, but imports the resulting png as an ndarray and deletes the intermediate file.
217
216
There may be a direct way to render the matplotlib figure as an array without using an intermediate file, but I could not seem to find a simple
@@ -231,10 +230,10 @@ arguments. See the examples above for usage.
231
230
For images of standard sizes for modern cameras, the resulting STL filesize can be pretty large.
232
231
233
232
- Just like was shown in the examples, applying a simple filtering function to smooth
234
-
sharp edges results in an STL geometry that is likely to be more easily printable. Fine tuning in a
233
+
sharp edges results in an STL geometry that is likely to be more easily printable. Fine tuning in a
235
234
program like Photoshop or Gimp can also help prevent spikes/jagged edges in the geometry.
236
235
237
-
- To make a proper mold, scale up the edges of the source image to match the maximum pixel value of the image (or higher), to form a lip.
236
+
- To make a proper mold, scale up the edges of the source image to match the maximum pixel value of the image (or higher), to form a lip.
238
237
For example:
239
238
```python
240
239
m, n = A.shape
@@ -244,13 +243,22 @@ A[:, 0::n-1] = border_val # make left and right lip
244
243
```
245
244
In practice, the border may need to be thicker than 1 pixel.
246
245
246
+
## Known bugs:
247
+
248
+
-`scipy.misc.imread` has some odd behavior for me on my Linux box (64-bit
249
+
Mint 15). When an image is read, an empty 0-dim array is returned. This is
250
+
supposedly due to a versioning issue with PIL, which I can't seem to work
251
+
around successfully. `pylab.imread` works fine, and seems consistent
252
+
across platforms.
253
+
254
+
247
255
## Todo/future features:
248
256
249
-
- Photos of actual printed models.
257
+
- Photos of actual printed models.
250
258
251
259
- I'm looking into writing a utility function to refine STL meshes by removing redundant vertices (so that wide flat spaces aren't packed with dense tessellations)
252
260
253
-
- It's possible to apply various warping functions to the resulting
254
-
meshes. So you could load an image, warp the result into a cylinder, and have a
261
+
- It's possible to apply various warping functions to the resulting
262
+
meshes. So you could load an image, warp the result into a cylinder, and have a
0 commit comments