def plot(self, loc): # Orient the object to the origin and scale to fit the print bed dimensions self.model.geometry = orient.to_origin(self.model.geometry) self.model.geometry = orient.fit_bed(self.model.geometry, xdim.get(), ydim.get(), zdim.get()) # Apply isometric perspective to the geometry plot_geometry, camera = gtransform.perspective(self.model.geometry) # Draw lines between points of the geometry faces plot_geometry = draw_lines(plot_geometry, self.model.normal, camera, view.get()) # Clear pixel array to white and then change each pixel color based on the XY pixel map self.pxarray = pygame.PixelArray(loc) self.pxarray[:][:] = (255, 255, 255) for point in range(0, plot_geometry.shape[0]): x = int(embed_w/2 + plot_geometry[point, 0]) # X coordinate (0,0 of screen is top left) y = int(embed_h/2 + plot_geometry[point, 1]) # Y coordinate (0,0 of screen is top left) # Plot all front facing lines and back facing when wireplot is selected if plot_geometry[point, 2] == 1 or view.get() == 'wire': self.pxarray[x][y] = (0, 0, 0) # Color = black # Plot grey lines only if grey lines are selected and the line is not already plotted black elif plot_geometry[point, 2] == 0 and view.get() == 'grey' and self.pxarray[x][y] != 0: self.pxarray[x][y] = (210, 210, 210) # Color = grey # Plot pixel array to screen and refresh window/GUI pygame.surfarray.blit_array(loc, self.pxarray) pygame.display.flip() window.update()
def plot_transform(self, loc, transtype, data): if transtype == 'ortho': # Transform the original geometry according to the selected orthographic view new_geometry, new_normals = gtransform.transform( self.model.geometry, self.model.normal, transtype, data) # Draw lines between points and clip to viewing window based on window height and width new_geometry = draw_lines(new_geometry, new_normals, [0, 0, 1], view.get(), embed_w, embed_h) else: # Transform geometry based on the selected transformation self.model.coordinates, self.model.normals = gtransform.transform( self.model.coordinates, self.model.normals, transtype, data) # Apply selected perspective with appropriate settings of fz, phi, and theta new_geometry, camera = gtransform.perspective( persp.get(), self.model.coordinates, fz.get(), phi.get(), theta.get()) # Draw lines between points and clip to viewing window new_geometry = draw_lines(new_geometry, self.model.normals, camera, view.get(), embed_w, embed_h) # Clear pixel array to white and then change each pixel color based on the XY pixel map self.pxarray[:][:] = (255, 255, 255) for point in range(0, new_geometry.shape[0]): x = int( embed_w / 2 + new_geometry[point, 0]) # X coordinate (0,0 of screen is top left) y = int( embed_h / 2 + new_geometry[point, 1]) # Y coordinate (0,0 of screen is top left) # Plot all front facing lines and back facing when wireplot is selected if new_geometry[point, 2] == 1 or view.get() == 'wire': self.pxarray[x][y] = (0, 0, 0) # Color = black # Plot grey lines only if grey lines are selected and the line is not already plotted black elif new_geometry[point, 2] == 0 and view.get( ) == 'grey' and self.pxarray[x][y] != 0: self.pxarray[x][y] = (210, 210, 210) # Color = grey # Plot pixel array to screen and refresh window/GUI pygame.surfarray.blit_array(loc, self.pxarray) pygame.display.flip() window.update()
def orient(geometry, width, height): # Compute object dimensions and distance from the origin max_size = np.max(geometry, axis=0) # Max X,Y,Z values of the object min_size = np.min(geometry, axis=0) # Min X,Y,Z values of the object x_trans = 0 - 0.5*(max_size[0]+min_size[0]) # Avg X distance from the origin (center of the object) y_trans = 0 - 0.5*(max_size[1]+min_size[1]) # Avg Y distance from the origin (center of the object) z_trans = 0 - 0.5*(max_size[2]+min_size[2]) # Avg Z distance from the origin (center of the object) geometry = gtransform.translate(geometry, x_trans, y_trans, z_trans) # Translate object accordingly to origin # Compute scaling to center object in the screen geometry_scale, _ = gtransform.perspective('iso', geometry, None, None, None) # Apply isometric perspective max_size = np.max(geometry_scale, axis=0) # Max X and Y values of projected point cloud on display (Z = 0) scale = 1 # Based on whether the object is larger in width or height when projected, apply a scaling factor # that will fit the object entirely within the space of the pixel array/clipping region if max_size[0] >= max_size[1]: scale = (0.5*width)/(2*max_size[0]) if max_size[0] < max_size[1]: scale = (0.5*height)/(2*max_size[1]) geometry = gtransform.scale(geometry, 1/scale) # Apply global scaling with appropriate factor return geometry
def initial_plot(self, loc): # Copy original geometry to new internal variable to be used for transformations (keep original # geometry unchanged for use in displaying the orthographic views of the object) self.model.coordinates, self.model.normals = self.model.geometry, self.model.normal # Apply selected perspective with appropriate settings of fz, phi, and theta plot_geometry, camera = gtransform.perspective(persp.get(), self.model.coordinates, fz.get(), phi.get(), theta.get()) # Draw lines between points and clip to viewing window based on window height and width plot_geometry = draw_lines(plot_geometry, self.model.normals, camera, view.get(), embed_w, embed_h) # Clear pixel array to white and then change each pixel color based on the XY pixel map self.pxarray = pygame.PixelArray(loc) self.pxarray[:][:] = (255, 255, 255) for point in range(0, plot_geometry.shape[0]): x = int( embed_w / 2 + plot_geometry[point, 0]) # X coordinate (0,0 of screen is top left) y = int( embed_h / 2 + plot_geometry[point, 1]) # Y coordinate (0,0 of screen is top left) # Plot all front facing lines and back facing when wireplot is selected if plot_geometry[point, 2] == 1 or view.get() == 'wire': self.pxarray[x][y] = (0, 0, 0) # Color = black # Plot grey lines only if grey lines are selected and the line is not already plotted black elif plot_geometry[point, 2] == 0 and view.get( ) == 'grey' and self.pxarray[x][y] != 0: self.pxarray[x][y] = (210, 210, 210) # Color = grey # Plot pixel array to screen and refresh window/GUI pygame.surfarray.blit_array(loc, self.pxarray) pygame.display.flip() window.update()