Fixed some scaling issues

master
Rostislav Lán 2 years ago
parent 71771d0217
commit ee08b9fb26

@ -75,8 +75,8 @@ class apply_filters:
self.height = self.img.shape[0] self.height = self.img.shape[0]
self.print_size(self.img.shape) self.print_size(self.img.shape)
print(self.dpi) print(self.dpi)
fig = plt.figure(figsize=(self.width/100, self.height/100), fig = plt.figure(figsize=(self.width, self.height),
frameon=False, dpi=self.dpi) frameon=False, dpi=1)
ax = plt.Axes(fig, [0., 0., 1., 1.]) ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off() ax.set_axis_off()
@ -244,9 +244,10 @@ class apply_filters:
self.img[1:-1:1, 1:-1:1] = rescaled self.img[1:-1:1, 1:-1:1] = rescaled
# Create meshgrid for 3D model # Create meshgrid for 3D model
verticesX = np.around(np.linspace(0, self.width / 10, self.width), 3) # This sets the scale of stl model
verticesY = np.around(np.linspace(0, self.height / 10, self.height), 3) x = np.linspace(0, 25.4 * self.width/self.dpi, self.width)
self.meshgrid = np.meshgrid(verticesX, verticesY) y = np.linspace(0, 25.4 * self.height/self.dpi, self.height)
self.meshgrid = np.meshgrid(x, y)
def make_mesh(self): def make_mesh(self):
''' Create mesh from image. ''' Create mesh from image.
@ -266,12 +267,12 @@ class apply_filters:
''' '''
# Convert meshgrid and image matrix to array of 3D points # Add the image matrix to the 2D meshgrid and create 1D array of 3D points
vertice_arr = np.vstack(list(map(np.ravel, self.meshgrid))).T vertice_arr = np.vstack(list(map(np.ravel, self.meshgrid))).T
z = (self.img / 10).reshape(-1, 1) z = (self.img / 10).reshape(-1, 1)
vertice_arr = np.concatenate((vertice_arr, z), axis=1) vertice_arr = np.concatenate((vertice_arr, z), axis=1)
# Convert back to matrix of 3D points # Convert 1D array back to matrix of 3D points
vertice_arr = vertice_arr.reshape(self.height, self.width, 3) vertice_arr = vertice_arr.reshape(self.height, self.width, 3)
count = 0 count = 0
@ -309,12 +310,11 @@ class apply_filters:
faces = np.array(faces) faces = np.array(faces)
vertices = np.array(vertices) vertices = np.array(vertices)
# Create the mesh # Create the mesh - vertices.shape (no_faces, 3, 3)
self.stl_mesh = mesh.Mesh(np.zeros(len(faces), dtype=mesh.Mesh.dtype)) self.stl_mesh = mesh.Mesh(np.zeros(faces.shape[0], dtype=mesh.Mesh.dtype))
for i, face in enumerate(faces): for i, face in enumerate(faces):
for j in range(3): for j in range(3):
self.stl_mesh.vectors[i][j] = vertices[face[j], :] self.stl_mesh.vectors[i][j] = vertices[face[j], :]
self.stl_mesh.vectors[i][j] /= 2.54 # convert to inches
def save_mesh(self): def save_mesh(self):
''' Save final mesh to stl file. ''' Save final mesh to stl file.

Loading…
Cancel
Save