From ee08b9fb260d74fa1764f8c69567c895a3027312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rostislav=20L=C3=A1n?= Date: Mon, 9 Jan 2023 02:13:38 +0100 Subject: [PATCH] Fixed some scaling issues --- src/main.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main.py b/src/main.py index 4dd899b..06f6f6e 100644 --- a/src/main.py +++ b/src/main.py @@ -75,8 +75,8 @@ class apply_filters: self.height = self.img.shape[0] self.print_size(self.img.shape) print(self.dpi) - fig = plt.figure(figsize=(self.width/100, self.height/100), - frameon=False, dpi=self.dpi) + fig = plt.figure(figsize=(self.width, self.height), + frameon=False, dpi=1) ax = plt.Axes(fig, [0., 0., 1., 1.]) ax.set_axis_off() @@ -244,9 +244,10 @@ class apply_filters: self.img[1:-1:1, 1:-1:1] = rescaled # Create meshgrid for 3D model - verticesX = np.around(np.linspace(0, self.width / 10, self.width), 3) - verticesY = np.around(np.linspace(0, self.height / 10, self.height), 3) - self.meshgrid = np.meshgrid(verticesX, verticesY) + # This sets the scale of stl model + x = np.linspace(0, 25.4 * self.width/self.dpi, self.width) + y = np.linspace(0, 25.4 * self.height/self.dpi, self.height) + self.meshgrid = np.meshgrid(x, y) def make_mesh(self): ''' 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 z = (self.img / 10).reshape(-1, 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) count = 0 @@ -309,12 +310,11 @@ class apply_filters: faces = np.array(faces) vertices = np.array(vertices) - # Create the mesh - self.stl_mesh = mesh.Mesh(np.zeros(len(faces), dtype=mesh.Mesh.dtype)) + # Create the mesh - vertices.shape (no_faces, 3, 3) + self.stl_mesh = mesh.Mesh(np.zeros(faces.shape[0], dtype=mesh.Mesh.dtype)) for i, face in enumerate(faces): for j in range(3): self.stl_mesh.vectors[i][j] = vertices[face[j], :] - self.stl_mesh.vectors[i][j] /= 2.54 # convert to inches def save_mesh(self): ''' Save final mesh to stl file.