def generateImages(self, mesh, path): axisName = 'w' for axis in self.axes: if axisName == 'w': axisName = 'x' elif axisName == 'x': mesh.rotate(np.array([1, 0, 0]), math.radians(45), None) axisName = 'y' elif axisName == 'y': mesh.rotate(np.array([0, 1, 0]), math.radians(45), None) axisName = 'z' elif axisName == 'z': mesh.rotate(np.array([0.5, 0.866, 0]), math.radians(45), None) axisName = 'zy' for x in range(math.floor(self.fullRotation / self.rotationAngle)): if axisName == 'z': mesh.rotate(np.array([0, 1, 0]), math.radians(5), None) # dual rotation for extra variation # rotate(axis, theta=0, point=None) mesh.rotate(axis, math.radians(self.rotationAngle), None) # Plot the mesh vtkplotlib.mesh_plot(mesh, color="blue") vtkplotlib.save_fig( os.path.normpath(path + '/_' + axisName + str(x) + '.png')) #saves the figure as an image vtkplotlib.figure.close(vtkplotlib.gcf())
def generate_thumbnail(infile, outfile, size=None): """Generate a thumbnail or previewfile into 'outfile' using the design file in 'infile'""" mesh = Mesh.from_file(infile) vpl.mesh_plot(mesh) # Front of design and slightly up vpl.view(camera_position=[0, -1, 0.5]) vpl.save_fig(outfile, pixels=size or [1280, 1280], off_screen=True)
def create_figure(path_dict, figure_path, path_dict2=None, pair_mapping=None, transp_backg=False): assert ((path_dict2 is None) + (pair_mapping is None)) != 1, \ 'please specify all kwargs or none of them' if pair_mapping is not None: # for k in tqdm(pair_mapping): # mesh= Mesh.from_file(path_dict[k[0]]) # mesh2 = Mesh.from_file(path_dict2[k[1]]) for k, values in tqdm(pair_mapping.items()): mesh = Mesh.from_file(path_dict[k]) mesh = _add_normalizing_vector_point(mesh, 300, -300) fig = vpl.figure() fig.background_color = 'black' vpl.mesh_plot(mesh, color='pink', opacity=0.3) #make dendrite translucent for v in values: # add second, third,.. .stl to same plot mesh2 = Mesh.from_file(path_dict2[str(v)]) vpl.mesh_plot(mesh2) save_path = figure_path + str(k) + '.png' vpl.save_fig( save_path, magnification=5, off_screen=True, ) if transp_backg == True: #make black background transparent _transparent_background(save_path) fig.close() else: for k in tqdm(path_dict): # Read the STL using numpy-stl mesh = Mesh.from_file(path_dict[k]) if debug == True: mesh = _add_normalizing_vector_point(mesh, 300, -300) fig = vpl.figure() fig.background_color = 'black' vpl.mesh_plot(mesh) save_path = figure_path + str(k) + '.png' vpl.save_fig( save_path, magnification=5, off_screen=True, ) if transp_backg == True: #make black background transparent _transparent_background(save_path) fig.close()
def test_save(self): plots = vpl.scatter(np.random.uniform(-10, 10, (30, 3))) # I can't get python2 to cooperate with unicode here. # The os functions just don't like them. if sys.version[0] == "3": path = Path.cwd() / u"ҢघԝઌƔࢳܢˀા\\Հએࡓ\u061cཪЈतயଯ\u0886.png" try: os.mkdir(str(path.parent)) vpl.save_fig(path) self.assertTrue(path.exists()) os.remove(str(path)) finally: if path.parent.exists(): os.rmdir(str(path.parent)) else: path = Path.cwd() / "image.png" vpl.save_fig(path) os.remove(str(path)) array = vpl.screenshot_fig(2) self.assertEqual(array.shape, tuple(i * 2 for i in vpl.gcf().render_size) + (3, )) plt.imshow(array) plt.show() shape = tuple(i * j for (i, j) in zip(vpl.gcf().render_size, (2, 3))) vpl.screenshot_fig(pixels=shape).shape # The following will fail depending on VTK version # self.assertEqual(vpl.screenshot_fig(pixels=shape).shape, # shape[::-1] + (3,)) vpl.close() fig = vpl.figure() for plot in plots: fig += plot vpl.show()
def test_save(): plots = vpl.scatter(np.random.uniform(-10, 10, (30, 3))) path = TEST_DIR / "name.png" if path.exists(): os.remove(str(path)) vpl.save_fig(path) assert path.exists() array = vpl.screenshot_fig(magnification=2) assert array.shape == tuple(i * 2 for i in vpl.gcf().render_size) + (3, ) shape = tuple(i * j for (i, j) in zip(vpl.gcf().render_size, (2, 3))) vpl.screenshot_fig(pixels=shape).shape # The following will fail depending on VTK version # .assertEqual(vpl.screenshot_fig(pixels=shape).shape, # shape[::-1] + (3,)) vpl.close() return array
def renderimage(tread,options): reifenflanke = 'rimAndShoulder/reifenflanke.stl' modulfelge = 'rimAndShoulder/modulfelge.stl' # Read the STL using numpy-stl geom = mesh.Mesh.from_file(tread) shoulder = mesh.Mesh.from_file(reifenflanke) rim = mesh.Mesh.from_file(modulfelge) # Plot the mesh vpl.mesh_plot(geom,color=[76,76,76]) if options == 'full': vpl.mesh_plot(shoulder,color=[76,76,76]) vpl.mesh_plot(rim,color=[1,1,1]) # Show the figure vpl.view(camera_direction = [0.8,0.5,0],up_view=[0,0,1]) #fig = vpl.gcf() #fig.background_color = "transparent" #vpl.show() #name = 'render.png' vpl.save_fig('render/render.png',off_screen=True,magnification=2) vpl.close()