Fixed curved model volume issue, fxed name engraving on the bottom, added base height param for curved model.

master
Rostislav Lán 2 years ago
parent 52e1a31897
commit 77e0fc4b8a

@ -91,22 +91,22 @@ class app:
else:
self.mode = "3d"
if len(self.args.stl_file) < 4:
if len(self.args.stl_file) < 5:
self.height_line = 2
self.height_base = 10
self.curv_rate_x = 0.5
self.curv_rate_y = 0.5
print(
"Warning: Too few arguments, using default values (2mm lines, curvature 0.5 on x, 0.5 on y)")
else:
self.height_line = float(self.args.stl_file[1])
self.height_base = float(self.args.stl_file[2])
self.curv_rate_x = float(
self.args.stl_file[2]) # finger depth
self.curv_rate_y = float(
self.args.stl_file[3]) # finger depth
# self.curv_rate_x = float(self.args.stl_file[2]) # excentricity x
# self.curv_rate_y = float(self.args.stl_file[3]) # excentricity y
print("Line height:", self.height_line,"mm, x axis curvature:", self.curv_rate_x,
", y axis curvature:", self.curv_rate_y)
self.curv_rate_y = float(
self.args.stl_file[4]) # finger depth
print("Line height:", self.height_line, "mm, base height: ", self.height_base,
"mm, x axis curvature: ", self.curv_rate_x, ", y axis curvature:", self.curv_rate_y)
print(self.mode, "mode selected")
self.run_stl()
@ -241,20 +241,21 @@ class app:
In case none were given, pass and save original image to the output file.
'''
if len(self.filters) == 0:
pass
else:
if len(self.filters) != 0:
# Apply all filters
for i, filter_name in enumerate(self.filters):
# Get filter class from filter.py, use the apply method
filter = getattr(flt, filter_name)
filter.apply(self, self.params[i+1])
else:
pass
def save_image(self, fig, ax):
'''Save processed image to the output file.
'''
print("Saving image to", self.output_file, file=sys.stderr)
# Colormap must be set to grayscale to avoid color mismatch.
ax.imshow(self.img, cmap="gray")
fig.savefig(fname=self.output_file, dpi=self.dpi)
@ -268,6 +269,7 @@ class app:
self.prepare_heightmap()
self.get_ID()
# Create a mesh using one of two modes
if self.mode == "2d":
self.make_stl_planar()
@ -343,7 +345,7 @@ class app:
# paint the background black
ax.plot([0, 1], [0, 1], c="black", lw=self.width)
# extract text from filename
# extract filename
text = self.stl_file.split("/")[-1].split(".")[0] + self.id
fontsize = 20
@ -369,9 +371,14 @@ class app:
plt.close()
# TODO: maybe don't use nested for loops, use numpy?
for i in range(self.height):
for j in range(self.width):
bottom_vert_arr[i][j][2] = data[i][j][0]
if self.mode == "2d":
for i in range(self.height):
for j in range(self.width):
bottom_vert_arr[i][j][2] = data[i][j][0]
elif self.mode == "3d":
for i in range(self.height):
for j in range(self.width):
bottom_vert_arr[i][j][2] += data[i][j][0] - self.height_base
return bottom_vert_arr
@ -498,29 +505,23 @@ class app:
* (self.curv_rate_y**2))
z[y] = z[y] + new
# TODO: clip responsivelly to save material used to print the model
#bottom = z[0][math.floor(self.width/2)]
z = z.reshape(-1, 1)
z_cpy = np.copy(z)
self.img = (self.img / 10).reshape(-1, 1)
z += self.img
top_vert_arr = np.vstack(list(map(np.ravel, self.meshgrid))).T
top_vert_arr = np.concatenate((top_vert_arr, z), axis=1)
vert_arr_tmp = np.vstack(list(map(np.ravel, self.meshgrid))).T
# for top side
top_vert_arr = np.concatenate((vert_arr_tmp, z), axis=1)
top_vert_arr = top_vert_arr.reshape(self.height, self.width, 3)
# for bottom side
bottom_vert_arr = np.concatenate((vert_arr_tmp, z_cpy), axis=1)
bottom_vert_arr = bottom_vert_arr.reshape(self.height, self.width, 3)
count = 0
vertices = []
faces = []
#min_point = 0
#for i in range(self.height - 1):
# if top_vert_arr[i][0][2] <= bottom:
# min_point = i
# Add faces for the backside of the lithophane
#vec_side = (top_vert_arr[self.height-1][0][2] -
# top_vert_arr[min_point][0][2]) / (self.height - min_point)
bottom_vert_arr = np.copy(top_vert_arr)
self.engrave_text(bottom_vert_arr)
# TODO: code bellow is duplicate of the code in planar generation
@ -556,8 +557,6 @@ class app:
# Horizontal side faces
for i in range(self.height - 1): # right
#if (top_vert_arr[i][0][2] < bottom_vert_arr[i][0][2]):
# continue
vertices.append([top_vert_arr[i][0]])
vertices.append([top_vert_arr[i+1][0]])
@ -565,11 +564,7 @@ class app:
vertices.append([bottom_vert_arr[i+1][0]])
count = self.append_faces(faces, count)
for i in range(self.height - 1): # left
max = self.width - 1
#if (top_vert_arr[i][max][2] < bottom_vert_arr[i][max][2]):
# continue
vertices.append([top_vert_arr[i+1][max]])
vertices.append([top_vert_arr[i][max]])
@ -579,9 +574,7 @@ class app:
count = self.append_faces(faces, count)
# Vertical side faces
for j in range(self.width - 1): # top
#if (top_vert_arr[0][j][2] < bottom_vert_arr[0][j][2]):
# continue
for j in range(self.width - 1):
vertices.append([top_vert_arr[0][j+1]])
vertices.append([top_vert_arr[0][j]])
@ -589,11 +582,7 @@ class app:
vertices.append([bottom_vert_arr[0][j]])
count = self.append_faces(faces, count)
for j in range(self.width - 1): # bottom
max = self.height - 1
#if (top_vert_arr[max][j][2] < bottom_vert_arr[max][j][2]):
# continue
vertices.append([top_vert_arr[max][j]])
vertices.append([top_vert_arr[max][j+1]])

Loading…
Cancel
Save