Commit 355f5f36 authored by Simone Mastrogiovanni's avatar Simone Mastrogiovanni
Browse files

first push

parent 08dd932b
File added
*.stl filter=lfs diff=lfs merge=lfs -text
This diff is collapsed.
This diff is collapsed.
#!/usr/bin/env python
import sys
import numpy
import matplotlib
import matplotlib.pyplot as plt
import stl_tools
import skimage.transform
# Radius of region to cut out in middle
cut_size = 180
# Load raw data
X, Y, Z = numpy.loadtxt(sys.argv[1], usecols=(0,1,2), unpack=True)
# Reduce the max value of Z to the 2nd highest value, as the max value is in
# fact junk, and skews the entire visual scale.
#z_newmax, z_max = numpy.sort(numpy.unique(Z))[-2:]
z_median = numpy.median(Z)
#z_min = numpy.min(Z)
#Z[Z==z_max] = z_newmax
#Z[Z==z_max] = z_min
# Determine grid values of x and y
x_uniq = numpy.sort(numpy.unique(X))
y_uniq = numpy.sort(numpy.unique(Y))
# Build a rectangular grid in z by grabbing the values corresponding to each
# x,y pair.
z_grid = numpy.empty((len(x_uniq), len(y_uniq)), dtype=numpy.float64)
for i, x in enumerate(x_uniq):
for j, y in enumerate(y_uniq):
if (x*x + y*y) <= cut_size:
z_grid[i,j] = z_median
z_grid[i,j] = Z[(X==x)&(Y==y)][0]
fig, ax = plt.subplots()
ax.contourf(x_uniq, y_uniq, z_grid)
# Scale image
z_grid = skimage.transform.resize(
z_grid, (200, 200),
mode="constant", preserve_range=True,
z_min, z_max = numpy.min(z_grid), numpy.max(z_grid)
z_range = z_max - z_min
z_grid -= z_min
z_grid /= z_range
stl_tools.numpy2stl(z_grid, sys.argv[1][:-3:]+'.stl', scale=50, solid=True)
from pylab import imread
from scipy.ndimage import gaussian_filter
from stl_tools import numpy2stl
import sys
A = 256 * imread(sys.argv[1])
A = A[:, :, 2] + 1.0*A[:,:, 0] # Compose RGBA channels to give depth
A = gaussian_filter(A, 1) # smoothing
numpy2stl(A,sys.argv[1][:-3:]+'.stl', scale=0.05, mask_val=5., solid=True)
File added
File added
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment