vedo.settings
1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3import os 4 5__docformat__ = "google" 6 7 8class Settings: 9 """ 10 General settings to modify the global behavior and style. 11 12 Example: 13 ```python 14 from vedo import settings, Cube 15 settings.use_parallel_projection = True 16 # settings["use_parallel_projection"] = True # this is equivalent! 17 Cube().color('g').show().close() 18 ``` 19 20 List of available properties: 21 22 ```python 23 # Set the default font to be used for axes, comments etc. 24 # Check out the available fonts at http://vedo.embl.es/fonts 25 # For example: 26 default_font = 'Normografo' 27 # To customize the font parameters use: 28 settings.font_parameters["Normografo"] = dict( 29 mono=False, 30 fscale=0.75, 31 hspacing=1, 32 lspacing=0.2, 33 dotsep="~×", 34 islocal=True, 35 ) 36 # Where 37 # mono : if True all letters occupy the same space slot horizontally 38 # fscale : sets the general scaling factor for the size of the font 39 # hspacing: horizontal stretching factor (affects both letters and words) 40 # lspacing: horizontal spacing inbetween letters (not words) 41 # dotsep : a string of characters to be interpreted as dot separator 42 # islocal : if locally stored in /fonts, otherwise it's on vedo.embl.es/fonts 43 # 44 # To run a demo try: 45 # vedo --run fonts 46 47 # Use this local folder to store downloaded files (default is ~/.cache/vedo) 48 cache_directory = ".cache" 49 50 # Palette number when using an integer to choose a color 51 palette = 0 52 53 # Options for saving window screenshots: 54 screenshot_transparent_background = False 55 screeshot_large_image = False # sometimes setting this to True gives better results 56 57 # Enable tracking pipeline functionality: 58 # allows to show a graph with the pipeline of action which let to a final object 59 # this is achieved by calling "myobj.pipeline.show()" (a new window will pop up) 60 self.enable_pipeline = True 61 62 # Remember the last format used when creating new figures in vedo.pyplot 63 # this is useful when creating multiple figures of the same kind 64 # and avoid to specify the format each time in plot(..., like=...) 65 remember_last_figure_format = False 66 67 # Set up default mouse and keyboard callbacks 68 enable_default_mouse_callbacks = True 69 enable_default_keyboard_callbacks = True 70 71 # Force single precsion of points coordinates. 72 # Useful for very large point clouds and meshes. Default is True. 73 force_single_precision_points = True 74 75 # Progress bar delay before showing up [sec] 76 progressbar_delay = 0.5 77 78 # If False, when multiple renderers are present, render only once at the end 79 immediate_rendering = True 80 81 # In multirendering mode, show a grey frame margin (set width=0 to disable) 82 renderer_frame_color = None 83 renderer_frame_alpha = 0.5 84 renderer_frame_width = 0.5 85 renderer_frame_padding = 0.0001 86 87 # In multirendering mode, set the position of the horizontal of vertical splitting [0,1] 88 window_splitting_position = None 89 90 # Gradient orientation mode for background window color 91 # 0 = Vertical 92 # 1 = Horizontal 93 # 2 = Radial viewport farthest side 94 # 3 = Radial viewport farthest corner 95 background_gradient_orientation = 0 96 97 # Enable / disable color printing by printc() 98 enable_print_color = True 99 100 # Smoothing options for points, lines and polygons 101 point_smoothing = False 102 line_smoothing = False 103 polygon_smoothing = False 104 105 # Turn on/off the automatic repositioning of lights as the camera moves 106 light_follows_camera = False 107 two_sided_lighting = True 108 109 # Turn on/off rendering of translucent material with depth peeling technique 110 use_depth_peeling = False 111 alpha_bit_planes = True # options only active if useDepthPeeling=True 112 multi_samples = 8 # antialiasing multisample buffer 113 max_number_of_peels= 4 # maximum number of rendering passes 114 occlusion_ratio = 0.0 # occlusion ratio, 0 = exact image. 115 116 # Turn on/off nvidia FXAA post-process anti-aliasing, if supported 117 use_fxaa = False # either True or False 118 119 # By default, the depth buffer is reset for each renderer 120 # If True, use the existing depth buffer 121 preserve_depth_buffer = False 122 123 # Use a polygon/edges offset to possibly resolve conflicts in rendering 124 use_polygon_offset = False 125 polygon_offset_factor = 0.1 126 polygon_offset_units = 0.1 127 128 # Interpolate scalars to render them smoothly 129 interpolate_scalars_before_mapping = True 130 131 # Set parallel projection On or Off (place camera to infinity, no perspective effects) 132 use_parallel_projection = False 133 134 # Set orientation type when reading TIFF files: 135 # TOPLEFT 1 (row 0 top, col 0 lhs) TOPRIGHT 2 (row 0 top, col 0 rhs) 136 # BOTRIGHT 3 (row 0 bottom, col 0 rhs) BOTLEFT 4 (row 0 bottom, col 0 lhs) 137 # LEFTTOP 5 (row 0 lhs, col 0 top) RIGHTTOP 6 (row 0 rhs, col 0 top) 138 # RIGHTBOT 7 (row 0 rhs, col 0 bottom) LEFTBOT 8 (row 0 lhs, col 0 bottom) 139 tiff_orientation_type = 1 140 141 # Annotated cube axis type nr. 5 options: 142 annotated_cube_color = (0.75, 0.75, 0.75) 143 annotated_cube_text_color = None # use default, otherwise specify a single color 144 annotated_cube_text_scale = 0.2 145 annotated_cube_texts = ["right","left ", "front","back ", " top ", "bttom"] 146 147 # Set the default backend for plotting in jupyter notebooks. 148 # If a jupyter environment is detected, the default is automatically switched to "2d" 149 default_backend = "vtk" 150 151 # Automatically close the Plotter instance after show() in jupyter sessions 152 # setting it to False will keep the current Plotter instance active 153 backend_autoclose = True 154 155 # Settings specific to the K3D backend in jupyter notebooks 156 k3d_menu_visibility = True 157 k3d_plot_height = 512 158 k3d_antialias = True 159 k3d_lighting = 1.5 160 k3d_camera_autofit= True 161 k3d_grid_autofit = True 162 k3d_axes_color = "gray4" 163 k3d_axes_helper = 1.0 # size of the small triad of axes on the bottom right 164 k3d_point_shader = "mesh" # others are '3d', '3dSpecular', 'dot', 'flat' 165 k3d_line_shader = "thick" # others are 'flat', 'mesh' 166 ``` 167 """ 168 169 # Restrict the attributes so accidental typos will generate an AttributeError exception 170 __slots__ = [ 171 "default_font", 172 "default_backend", 173 "cache_directory", 174 "palette", 175 "remember_last_figure_format", 176 "screenshot_transparent_background", 177 "screeshot_large_image", 178 "enable_default_mouse_callbacks", 179 "enable_default_keyboard_callbacks", 180 "enable_pipeline", 181 "progressbar_delay", 182 "immediate_rendering", 183 "renderer_frame_color", 184 "renderer_frame_alpha", 185 "renderer_frame_width", 186 "renderer_frame_padding", 187 "force_single_precision_points", 188 "point_smoothing", 189 "line_smoothing", 190 "polygon_smoothing", 191 "light_follows_camera", 192 "two_sided_lighting", 193 "use_depth_peeling", 194 "multi_samples", 195 "alpha_bit_planes", 196 "max_number_of_peels", 197 "occlusion_ratio", 198 "use_fxaa", 199 "preserve_depth_buffer", 200 "use_polygon_offset", 201 "polygon_offset_factor", 202 "polygon_offset_units", 203 "interpolate_scalars_before_mapping", 204 "use_parallel_projection", 205 "background_gradient_orientation", 206 "window_splitting_position", 207 "tiff_orientation_type", 208 "annotated_cube_color", 209 "annotated_cube_text_color", 210 "annotated_cube_text_scale", 211 "annotated_cube_texts", 212 "enable_print_color", 213 "backend_autoclose", 214 "k3d_menu_visibility", 215 "k3d_plot_height", 216 "k3d_antialias", 217 "k3d_lighting", 218 "k3d_camera_autofit", 219 "k3d_grid_autofit", 220 "k3d_axes_color", 221 "k3d_axes_helper", 222 "k3d_point_shader", 223 "k3d_line_shader", 224 "font_parameters", 225 ] 226 227 ############################################################ 228 # Dry run mode (for test purposes only) 229 # 0 = normal 230 # 1 = do not hold execution 231 # 2 = do not hold execution and do not show any window 232 dry_run_mode = 0 233 234 ############################################################ 235 def __init__(self) -> None: 236 237 self.default_backend = "vtk" 238 try: 239 # adapted from: https://stackoverflow.com/a/39662359/2912349 240 shell = get_ipython().__class__.__name__ 241 if shell == 'ZMQInteractiveShell': 242 self.default_backend = "2d" 243 except NameError: 244 pass 245 246 self.default_font = "Normografo" 247 248 self.enable_pipeline = True 249 self.progressbar_delay = 0.5 250 self.palette = 0 251 self.remember_last_figure_format = False 252 253 self.force_single_precision_points = True 254 255 self.cache_directory = ".cache" # "/vedo" is added automatically 256 257 self.screenshot_transparent_background = False 258 self.screeshot_large_image = False 259 260 self.enable_default_mouse_callbacks = True 261 self.enable_default_keyboard_callbacks = True 262 self.immediate_rendering = True 263 264 self.renderer_frame_color = None 265 self.renderer_frame_alpha = 0.5 266 self.renderer_frame_width = 0.5 267 self.renderer_frame_padding = 0.0001 268 self.background_gradient_orientation = 0 269 270 self.point_smoothing = False 271 self.line_smoothing = False 272 self.polygon_smoothing = False 273 274 self.light_follows_camera = False 275 self.two_sided_lighting = True 276 277 self.use_depth_peeling = False 278 self.multi_samples = 8 279 self.alpha_bit_planes = 1 280 self.max_number_of_peels = 4 281 self.occlusion_ratio = 0.1 282 283 self.use_fxaa = False 284 285 self.preserve_depth_buffer = False 286 287 self.use_polygon_offset = True 288 self.polygon_offset_factor = 0.1 289 self.polygon_offset_units = 0.1 290 291 self.interpolate_scalars_before_mapping = True 292 293 self.use_parallel_projection = False 294 295 self.window_splitting_position = None 296 297 self.tiff_orientation_type = 1 298 299 self.annotated_cube_color = (0.75, 0.75, 0.75) 300 self.annotated_cube_text_color = None 301 self.annotated_cube_text_scale = 0.2 302 self.annotated_cube_texts = ["right", "left ", "front", "back ", " top ", "bttom"] 303 304 self.enable_print_color = True 305 306 self.backend_autoclose = True 307 308 self.k3d_menu_visibility = True 309 self.k3d_plot_height = 512 310 self.k3d_antialias = True 311 self.k3d_lighting = 1.5 312 self.k3d_camera_autofit = True 313 self.k3d_grid_autofit= True 314 self.k3d_axes_color = "k4" 315 self.k3d_axes_helper = 1.0 316 self.k3d_point_shader= "mesh" 317 self.k3d_line_shader = "thick" 318 319 self.font_parameters = dict( 320 321 Normografo=dict( 322 mono=False, 323 fscale=0.75, 324 hspacing=1, 325 lspacing=0.2, 326 dotsep="~×", 327 islocal=True, 328 ), 329 Bongas=dict( 330 mono=False, 331 fscale=0.875, 332 hspacing=0.52, 333 lspacing=0.25, 334 dotsep="·", 335 islocal=True, 336 ), 337 Calco=dict( 338 mono=True, 339 fscale=0.8, 340 hspacing=1, 341 lspacing=0.1, 342 dotsep="×", 343 islocal=True, 344 ), 345 Comae=dict( 346 mono=False, 347 fscale=0.75, 348 lspacing=0.2, 349 hspacing=1, 350 dotsep="~×", 351 islocal=True, 352 ), 353 ComicMono=dict( 354 mono=True, 355 fscale=0.8, 356 hspacing=1, 357 lspacing=0.1, 358 dotsep="x", 359 islocal=False, 360 ), 361 Edo=dict( 362 mono=False, 363 fscale=0.75, 364 hspacing=1, 365 lspacing=0.2, 366 dotsep="~x ", 367 islocal=False, 368 ), 369 FiraMonoMedium=dict( 370 mono=True, 371 fscale=0.8, 372 hspacing=1, 373 lspacing=0.1, 374 dotsep="×", 375 islocal=False, 376 ), 377 FiraMonoBold=dict( 378 mono=True, 379 fscale=0.8, 380 hspacing=1, 381 lspacing=0.1, 382 dotsep="×", 383 islocal=False, 384 ), 385 Glasgo=dict( 386 mono=True, 387 fscale=0.75, 388 lspacing=0.1, 389 hspacing=1, 390 dotsep="~×", 391 islocal=True, 392 ), 393 Kanopus=dict( 394 mono=False, 395 fscale=0.75, 396 lspacing=0.15, 397 hspacing=0.75, 398 dotsep="~×", 399 islocal=True, 400 ), 401 LogoType=dict( 402 mono=False, 403 fscale=0.75, 404 hspacing=1, 405 lspacing=0.2, 406 dotsep="~×", 407 islocal=False, 408 ), 409 Quikhand=dict( 410 mono=False, 411 fscale=0.8, 412 hspacing=0.6, 413 lspacing=0.15, 414 dotsep="~~×~", 415 islocal=True, 416 ), 417 SmartCouric=dict( 418 mono=True, 419 fscale=0.8, 420 hspacing=1.05, 421 lspacing=0.1, 422 dotsep="×", 423 islocal=True, 424 ), 425 Spears=dict( 426 mono=False, 427 fscale=0.8, 428 hspacing=0.5, 429 lspacing=0.2, 430 dotsep="~×", 431 islocal=False, 432 ), 433 Theemim=dict( 434 mono=False, 435 fscale=0.825, 436 hspacing=0.52, 437 lspacing=0.3, 438 dotsep="~~×", 439 islocal=True, 440 ), 441 VictorMono=dict( 442 mono=True, 443 fscale=0.725, 444 hspacing=1, 445 lspacing=0.1, 446 dotsep="×", 447 islocal=True, 448 ), 449 Justino1=dict( 450 mono=True, 451 fscale=0.725, 452 hspacing=1, 453 lspacing=0.1, 454 dotsep="×", 455 islocal=False, 456 ), 457 Justino2=dict( 458 mono=True, 459 fscale=0.725, 460 hspacing=1, 461 lspacing=0.1, 462 dotsep="×", 463 islocal=False, 464 ), 465 Justino3=dict( 466 mono=True, 467 fscale=0.725, 468 hspacing=1, 469 lspacing=0.1, 470 dotsep="×", 471 islocal=False, 472 ), 473 Calibri=dict( 474 mono=False, 475 fscale=0.75, 476 hspacing=1, 477 lspacing=0.2, 478 dotsep="~×", 479 islocal=False, 480 ), 481 Capsmall=dict( 482 mono=False, 483 fscale=0.8, 484 hspacing=0.75, 485 lspacing=0.15, 486 dotsep="~×", 487 islocal=False, 488 ), 489 Cartoons123=dict( 490 mono=False, 491 fscale=0.8, 492 hspacing=0.75, 493 lspacing=0.15, 494 dotsep="x", 495 islocal=False, 496 ), 497 Darwin=dict( 498 mono=False, 499 fscale=0.8, 500 hspacing=0.75, 501 lspacing=0.15, 502 dotsep="x", 503 islocal=False, 504 ), 505 Vega=dict( 506 mono=False, 507 fscale=0.8, 508 hspacing=0.75, 509 lspacing=0.15, 510 dotsep="×", 511 islocal=False, 512 ), 513 Meson=dict( 514 mono=False, 515 fscale=0.8, 516 hspacing=0.9, 517 lspacing=0.225, 518 dotsep="~×", 519 islocal=False, 520 ), 521 Komika=dict( 522 mono=False, 523 fscale=0.7, 524 hspacing=0.75, 525 lspacing=0.225, 526 dotsep="~×", 527 islocal=False, 528 ), 529 Brachium=dict( 530 mono=True, 531 fscale=0.8, 532 hspacing=1, 533 lspacing=0.1, 534 dotsep="x", 535 islocal=False, 536 ), 537 Dalim=dict( 538 mono=False, 539 fscale=0.75, 540 lspacing=0.2, 541 hspacing=1, 542 dotsep="~×", 543 islocal=False, 544 ), 545 Miro=dict( 546 mono=False, 547 fscale=0.75, 548 lspacing=0.2, 549 hspacing=1, 550 dotsep="~×", 551 islocal=False, 552 ), 553 Ubuntu=dict( 554 mono=False, 555 fscale=0.75, 556 lspacing=0.2, 557 hspacing=1, 558 dotsep="~×", 559 islocal=False, 560 ), 561 Mizar=dict( 562 mono=False, 563 fscale=0.75, 564 lspacing=0.2, 565 hspacing=0.75, 566 dotsep="~×", 567 islocal=False, 568 ), 569 LiberationSans=dict( 570 mono=False, 571 fscale=0.75, 572 lspacing=0.2, 573 hspacing=1, 574 dotsep="~×", 575 islocal=False, 576 ), 577 DejavuSansMono=dict( 578 mono=True, 579 fscale=0.725, 580 hspacing=1, 581 lspacing=0.1, 582 dotsep="~×", 583 islocal=False, 584 ), 585 SunflowerHighway=dict( 586 mono=False, 587 fscale=0.75, 588 lspacing=0.2, 589 hspacing=1, 590 dotsep="~×", 591 islocal=False, 592 ), 593 Swansea=dict( 594 mono=False, 595 fscale=0.75, 596 lspacing=0.2, 597 hspacing=1, 598 dotsep="~×", 599 islocal=False, 600 ), 601 Housekeeper=dict( # supports chinese glyphs 602 mono=False, 603 fscale=0.75, 604 hspacing=1, 605 lspacing=0.2, 606 dotsep="~×", 607 islocal=False, 608 ), 609 Wananti=dict( # supports chinese glyphs 610 mono=False, 611 fscale=0.75, 612 hspacing=1, 613 lspacing=0.2, 614 dotsep="~x", 615 islocal=False, 616 ), 617 AnimeAce=dict( 618 mono=False, 619 fscale=0.75, 620 hspacing=1, 621 lspacing=0.2, 622 dotsep="~x", 623 islocal=False, 624 ), 625 Antares=dict( 626 mono=True, 627 fscale=0.8, 628 hspacing=1, 629 lspacing=0.1, 630 dotsep="×", 631 islocal=False, 632 ), 633 Archistico=dict( 634 mono=False, 635 fscale=0.75, 636 lspacing=0.2, 637 hspacing=0.75, 638 dotsep="~×", 639 islocal=False, 640 ), 641 KazyCase=dict( 642 mono=True, 643 fscale=0.8, 644 hspacing=1.2, 645 lspacing=0.1, 646 dotsep="×", 647 islocal=False, 648 ), 649 Roboto=dict( 650 mono=True, 651 fscale=0.8, 652 hspacing=1, 653 lspacing=0.1, 654 dotsep="×", 655 islocal=False, 656 ), 657 ) 658 659 #################################################################################### 660 def __getitem__(self, key): 661 """Make the class work like a dictionary too""" 662 return getattr(self, key) 663 664 def __setitem__(self, key, value): 665 """Make the class work like a dictionary too""" 666 setattr(self, key, value) 667 668 def __str__(self) -> str: 669 """Return a string representation of the object""" 670 s = Settings.__doc__.replace(" ", "") 671 s = s.replace(".. code-block:: python\n", "") 672 s = s.replace("```python\n", "") 673 s = s.replace("```\n", "") 674 s = s.replace("\n\n", "\n #------------------------------------------------------\n") 675 s = s.replace("\n ", "\n") 676 s = s.replace("\n ", "\n") 677 s = s.replace(" from", "from") 678 try: 679 from pygments import highlight 680 from pygments.lexers import Python3Lexer 681 from pygments.formatters import Terminal256Formatter 682 s = highlight(s, Python3Lexer(), Terminal256Formatter(style="zenburn")) 683 except (ModuleNotFoundError, ImportError): 684 pass 685 686 module = self.__class__.__module__ 687 name = self.__class__.__name__ 688 header = f"{module}.{name} at ({hex(id(self))})".ljust(75) 689 s = f"\x1b[1m\x1b[7m{header}\x1b[0m\n" + s 690 return s.strip() 691 692 ############################################################ 693 def keys(self) -> list: 694 """Return all keys""" 695 return self.__slots__ 696 697 def values(self) -> list: 698 """Return all values""" 699 return [getattr(self, key) for key in self.__slots__] 700 701 def items(self) -> list: 702 """Return all items""" 703 return [(key, getattr(self, key)) for key in self.__slots__] 704 705 def reset(self) -> None: 706 """Reset all settings to their default status.""" 707 self.__init__() 708 709 ############################################################ 710 def init_colab(self, enable_k3d=True) -> None: 711 """ 712 Initialize colab environment 713 """ 714 print("setting up colab environment (can take a minute) ...", end="") 715 716 res = os.system("which Xvfb") 717 if res: 718 os.system("apt-get install xvfb") 719 720 os.system("pip install pyvirtualdisplay") 721 722 from pyvirtualdisplay import Display 723 Display(visible=0).start() 724 725 if enable_k3d: 726 os.system("pip install k3d") 727 728 from google.colab import output 729 output.enable_custom_widget_manager() 730 731 if enable_k3d: 732 import k3d 733 try: 734 print("installing k3d...", end="") 735 os.system("jupyter nbextension install --py --user k3d") 736 os.system("jupyter nbextension enable --py --user k3d") 737 k3d.switch_to_text_protocol() 738 self.default_backend = "k3d" 739 self.backend_autoclose = False 740 except: 741 print("(FAILED) ... ", end="") 742 743 print(" setup completed.") 744 745 ############################################################ 746 def start_xvfb(self) -> None: 747 """ 748 Start xvfb. 749 750 Xvfb or X virtual framebuffer is a display server implementing 751 the X11 display server protocol. In contrast to other display servers, 752 Xvfb performs all graphical operations in virtual memory 753 without showing any screen output. 754 """ 755 print("starting xvfb (can take a minute) ...", end="") 756 res = os.system("which Xvfb") 757 if res: 758 os.system("apt-get install xvfb") 759 os.system("set -x") 760 os.system("export DISPLAY=:99.0") 761 os.system("Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &") 762 os.system("sleep 3") 763 os.system("set +x") 764 os.system('exec "$@"') 765 print(" xvfb started.")
class
Settings:
9class Settings: 10 """ 11 General settings to modify the global behavior and style. 12 13 Example: 14 ```python 15 from vedo import settings, Cube 16 settings.use_parallel_projection = True 17 # settings["use_parallel_projection"] = True # this is equivalent! 18 Cube().color('g').show().close() 19 ``` 20 21 List of available properties: 22 23 ```python 24 # Set the default font to be used for axes, comments etc. 25 # Check out the available fonts at http://vedo.embl.es/fonts 26 # For example: 27 default_font = 'Normografo' 28 # To customize the font parameters use: 29 settings.font_parameters["Normografo"] = dict( 30 mono=False, 31 fscale=0.75, 32 hspacing=1, 33 lspacing=0.2, 34 dotsep="~×", 35 islocal=True, 36 ) 37 # Where 38 # mono : if True all letters occupy the same space slot horizontally 39 # fscale : sets the general scaling factor for the size of the font 40 # hspacing: horizontal stretching factor (affects both letters and words) 41 # lspacing: horizontal spacing inbetween letters (not words) 42 # dotsep : a string of characters to be interpreted as dot separator 43 # islocal : if locally stored in /fonts, otherwise it's on vedo.embl.es/fonts 44 # 45 # To run a demo try: 46 # vedo --run fonts 47 48 # Use this local folder to store downloaded files (default is ~/.cache/vedo) 49 cache_directory = ".cache" 50 51 # Palette number when using an integer to choose a color 52 palette = 0 53 54 # Options for saving window screenshots: 55 screenshot_transparent_background = False 56 screeshot_large_image = False # sometimes setting this to True gives better results 57 58 # Enable tracking pipeline functionality: 59 # allows to show a graph with the pipeline of action which let to a final object 60 # this is achieved by calling "myobj.pipeline.show()" (a new window will pop up) 61 self.enable_pipeline = True 62 63 # Remember the last format used when creating new figures in vedo.pyplot 64 # this is useful when creating multiple figures of the same kind 65 # and avoid to specify the format each time in plot(..., like=...) 66 remember_last_figure_format = False 67 68 # Set up default mouse and keyboard callbacks 69 enable_default_mouse_callbacks = True 70 enable_default_keyboard_callbacks = True 71 72 # Force single precsion of points coordinates. 73 # Useful for very large point clouds and meshes. Default is True. 74 force_single_precision_points = True 75 76 # Progress bar delay before showing up [sec] 77 progressbar_delay = 0.5 78 79 # If False, when multiple renderers are present, render only once at the end 80 immediate_rendering = True 81 82 # In multirendering mode, show a grey frame margin (set width=0 to disable) 83 renderer_frame_color = None 84 renderer_frame_alpha = 0.5 85 renderer_frame_width = 0.5 86 renderer_frame_padding = 0.0001 87 88 # In multirendering mode, set the position of the horizontal of vertical splitting [0,1] 89 window_splitting_position = None 90 91 # Gradient orientation mode for background window color 92 # 0 = Vertical 93 # 1 = Horizontal 94 # 2 = Radial viewport farthest side 95 # 3 = Radial viewport farthest corner 96 background_gradient_orientation = 0 97 98 # Enable / disable color printing by printc() 99 enable_print_color = True 100 101 # Smoothing options for points, lines and polygons 102 point_smoothing = False 103 line_smoothing = False 104 polygon_smoothing = False 105 106 # Turn on/off the automatic repositioning of lights as the camera moves 107 light_follows_camera = False 108 two_sided_lighting = True 109 110 # Turn on/off rendering of translucent material with depth peeling technique 111 use_depth_peeling = False 112 alpha_bit_planes = True # options only active if useDepthPeeling=True 113 multi_samples = 8 # antialiasing multisample buffer 114 max_number_of_peels= 4 # maximum number of rendering passes 115 occlusion_ratio = 0.0 # occlusion ratio, 0 = exact image. 116 117 # Turn on/off nvidia FXAA post-process anti-aliasing, if supported 118 use_fxaa = False # either True or False 119 120 # By default, the depth buffer is reset for each renderer 121 # If True, use the existing depth buffer 122 preserve_depth_buffer = False 123 124 # Use a polygon/edges offset to possibly resolve conflicts in rendering 125 use_polygon_offset = False 126 polygon_offset_factor = 0.1 127 polygon_offset_units = 0.1 128 129 # Interpolate scalars to render them smoothly 130 interpolate_scalars_before_mapping = True 131 132 # Set parallel projection On or Off (place camera to infinity, no perspective effects) 133 use_parallel_projection = False 134 135 # Set orientation type when reading TIFF files: 136 # TOPLEFT 1 (row 0 top, col 0 lhs) TOPRIGHT 2 (row 0 top, col 0 rhs) 137 # BOTRIGHT 3 (row 0 bottom, col 0 rhs) BOTLEFT 4 (row 0 bottom, col 0 lhs) 138 # LEFTTOP 5 (row 0 lhs, col 0 top) RIGHTTOP 6 (row 0 rhs, col 0 top) 139 # RIGHTBOT 7 (row 0 rhs, col 0 bottom) LEFTBOT 8 (row 0 lhs, col 0 bottom) 140 tiff_orientation_type = 1 141 142 # Annotated cube axis type nr. 5 options: 143 annotated_cube_color = (0.75, 0.75, 0.75) 144 annotated_cube_text_color = None # use default, otherwise specify a single color 145 annotated_cube_text_scale = 0.2 146 annotated_cube_texts = ["right","left ", "front","back ", " top ", "bttom"] 147 148 # Set the default backend for plotting in jupyter notebooks. 149 # If a jupyter environment is detected, the default is automatically switched to "2d" 150 default_backend = "vtk" 151 152 # Automatically close the Plotter instance after show() in jupyter sessions 153 # setting it to False will keep the current Plotter instance active 154 backend_autoclose = True 155 156 # Settings specific to the K3D backend in jupyter notebooks 157 k3d_menu_visibility = True 158 k3d_plot_height = 512 159 k3d_antialias = True 160 k3d_lighting = 1.5 161 k3d_camera_autofit= True 162 k3d_grid_autofit = True 163 k3d_axes_color = "gray4" 164 k3d_axes_helper = 1.0 # size of the small triad of axes on the bottom right 165 k3d_point_shader = "mesh" # others are '3d', '3dSpecular', 'dot', 'flat' 166 k3d_line_shader = "thick" # others are 'flat', 'mesh' 167 ``` 168 """ 169 170 # Restrict the attributes so accidental typos will generate an AttributeError exception 171 __slots__ = [ 172 "default_font", 173 "default_backend", 174 "cache_directory", 175 "palette", 176 "remember_last_figure_format", 177 "screenshot_transparent_background", 178 "screeshot_large_image", 179 "enable_default_mouse_callbacks", 180 "enable_default_keyboard_callbacks", 181 "enable_pipeline", 182 "progressbar_delay", 183 "immediate_rendering", 184 "renderer_frame_color", 185 "renderer_frame_alpha", 186 "renderer_frame_width", 187 "renderer_frame_padding", 188 "force_single_precision_points", 189 "point_smoothing", 190 "line_smoothing", 191 "polygon_smoothing", 192 "light_follows_camera", 193 "two_sided_lighting", 194 "use_depth_peeling", 195 "multi_samples", 196 "alpha_bit_planes", 197 "max_number_of_peels", 198 "occlusion_ratio", 199 "use_fxaa", 200 "preserve_depth_buffer", 201 "use_polygon_offset", 202 "polygon_offset_factor", 203 "polygon_offset_units", 204 "interpolate_scalars_before_mapping", 205 "use_parallel_projection", 206 "background_gradient_orientation", 207 "window_splitting_position", 208 "tiff_orientation_type", 209 "annotated_cube_color", 210 "annotated_cube_text_color", 211 "annotated_cube_text_scale", 212 "annotated_cube_texts", 213 "enable_print_color", 214 "backend_autoclose", 215 "k3d_menu_visibility", 216 "k3d_plot_height", 217 "k3d_antialias", 218 "k3d_lighting", 219 "k3d_camera_autofit", 220 "k3d_grid_autofit", 221 "k3d_axes_color", 222 "k3d_axes_helper", 223 "k3d_point_shader", 224 "k3d_line_shader", 225 "font_parameters", 226 ] 227 228 ############################################################ 229 # Dry run mode (for test purposes only) 230 # 0 = normal 231 # 1 = do not hold execution 232 # 2 = do not hold execution and do not show any window 233 dry_run_mode = 0 234 235 ############################################################ 236 def __init__(self) -> None: 237 238 self.default_backend = "vtk" 239 try: 240 # adapted from: https://stackoverflow.com/a/39662359/2912349 241 shell = get_ipython().__class__.__name__ 242 if shell == 'ZMQInteractiveShell': 243 self.default_backend = "2d" 244 except NameError: 245 pass 246 247 self.default_font = "Normografo" 248 249 self.enable_pipeline = True 250 self.progressbar_delay = 0.5 251 self.palette = 0 252 self.remember_last_figure_format = False 253 254 self.force_single_precision_points = True 255 256 self.cache_directory = ".cache" # "/vedo" is added automatically 257 258 self.screenshot_transparent_background = False 259 self.screeshot_large_image = False 260 261 self.enable_default_mouse_callbacks = True 262 self.enable_default_keyboard_callbacks = True 263 self.immediate_rendering = True 264 265 self.renderer_frame_color = None 266 self.renderer_frame_alpha = 0.5 267 self.renderer_frame_width = 0.5 268 self.renderer_frame_padding = 0.0001 269 self.background_gradient_orientation = 0 270 271 self.point_smoothing = False 272 self.line_smoothing = False 273 self.polygon_smoothing = False 274 275 self.light_follows_camera = False 276 self.two_sided_lighting = True 277 278 self.use_depth_peeling = False 279 self.multi_samples = 8 280 self.alpha_bit_planes = 1 281 self.max_number_of_peels = 4 282 self.occlusion_ratio = 0.1 283 284 self.use_fxaa = False 285 286 self.preserve_depth_buffer = False 287 288 self.use_polygon_offset = True 289 self.polygon_offset_factor = 0.1 290 self.polygon_offset_units = 0.1 291 292 self.interpolate_scalars_before_mapping = True 293 294 self.use_parallel_projection = False 295 296 self.window_splitting_position = None 297 298 self.tiff_orientation_type = 1 299 300 self.annotated_cube_color = (0.75, 0.75, 0.75) 301 self.annotated_cube_text_color = None 302 self.annotated_cube_text_scale = 0.2 303 self.annotated_cube_texts = ["right", "left ", "front", "back ", " top ", "bttom"] 304 305 self.enable_print_color = True 306 307 self.backend_autoclose = True 308 309 self.k3d_menu_visibility = True 310 self.k3d_plot_height = 512 311 self.k3d_antialias = True 312 self.k3d_lighting = 1.5 313 self.k3d_camera_autofit = True 314 self.k3d_grid_autofit= True 315 self.k3d_axes_color = "k4" 316 self.k3d_axes_helper = 1.0 317 self.k3d_point_shader= "mesh" 318 self.k3d_line_shader = "thick" 319 320 self.font_parameters = dict( 321 322 Normografo=dict( 323 mono=False, 324 fscale=0.75, 325 hspacing=1, 326 lspacing=0.2, 327 dotsep="~×", 328 islocal=True, 329 ), 330 Bongas=dict( 331 mono=False, 332 fscale=0.875, 333 hspacing=0.52, 334 lspacing=0.25, 335 dotsep="·", 336 islocal=True, 337 ), 338 Calco=dict( 339 mono=True, 340 fscale=0.8, 341 hspacing=1, 342 lspacing=0.1, 343 dotsep="×", 344 islocal=True, 345 ), 346 Comae=dict( 347 mono=False, 348 fscale=0.75, 349 lspacing=0.2, 350 hspacing=1, 351 dotsep="~×", 352 islocal=True, 353 ), 354 ComicMono=dict( 355 mono=True, 356 fscale=0.8, 357 hspacing=1, 358 lspacing=0.1, 359 dotsep="x", 360 islocal=False, 361 ), 362 Edo=dict( 363 mono=False, 364 fscale=0.75, 365 hspacing=1, 366 lspacing=0.2, 367 dotsep="~x ", 368 islocal=False, 369 ), 370 FiraMonoMedium=dict( 371 mono=True, 372 fscale=0.8, 373 hspacing=1, 374 lspacing=0.1, 375 dotsep="×", 376 islocal=False, 377 ), 378 FiraMonoBold=dict( 379 mono=True, 380 fscale=0.8, 381 hspacing=1, 382 lspacing=0.1, 383 dotsep="×", 384 islocal=False, 385 ), 386 Glasgo=dict( 387 mono=True, 388 fscale=0.75, 389 lspacing=0.1, 390 hspacing=1, 391 dotsep="~×", 392 islocal=True, 393 ), 394 Kanopus=dict( 395 mono=False, 396 fscale=0.75, 397 lspacing=0.15, 398 hspacing=0.75, 399 dotsep="~×", 400 islocal=True, 401 ), 402 LogoType=dict( 403 mono=False, 404 fscale=0.75, 405 hspacing=1, 406 lspacing=0.2, 407 dotsep="~×", 408 islocal=False, 409 ), 410 Quikhand=dict( 411 mono=False, 412 fscale=0.8, 413 hspacing=0.6, 414 lspacing=0.15, 415 dotsep="~~×~", 416 islocal=True, 417 ), 418 SmartCouric=dict( 419 mono=True, 420 fscale=0.8, 421 hspacing=1.05, 422 lspacing=0.1, 423 dotsep="×", 424 islocal=True, 425 ), 426 Spears=dict( 427 mono=False, 428 fscale=0.8, 429 hspacing=0.5, 430 lspacing=0.2, 431 dotsep="~×", 432 islocal=False, 433 ), 434 Theemim=dict( 435 mono=False, 436 fscale=0.825, 437 hspacing=0.52, 438 lspacing=0.3, 439 dotsep="~~×", 440 islocal=True, 441 ), 442 VictorMono=dict( 443 mono=True, 444 fscale=0.725, 445 hspacing=1, 446 lspacing=0.1, 447 dotsep="×", 448 islocal=True, 449 ), 450 Justino1=dict( 451 mono=True, 452 fscale=0.725, 453 hspacing=1, 454 lspacing=0.1, 455 dotsep="×", 456 islocal=False, 457 ), 458 Justino2=dict( 459 mono=True, 460 fscale=0.725, 461 hspacing=1, 462 lspacing=0.1, 463 dotsep="×", 464 islocal=False, 465 ), 466 Justino3=dict( 467 mono=True, 468 fscale=0.725, 469 hspacing=1, 470 lspacing=0.1, 471 dotsep="×", 472 islocal=False, 473 ), 474 Calibri=dict( 475 mono=False, 476 fscale=0.75, 477 hspacing=1, 478 lspacing=0.2, 479 dotsep="~×", 480 islocal=False, 481 ), 482 Capsmall=dict( 483 mono=False, 484 fscale=0.8, 485 hspacing=0.75, 486 lspacing=0.15, 487 dotsep="~×", 488 islocal=False, 489 ), 490 Cartoons123=dict( 491 mono=False, 492 fscale=0.8, 493 hspacing=0.75, 494 lspacing=0.15, 495 dotsep="x", 496 islocal=False, 497 ), 498 Darwin=dict( 499 mono=False, 500 fscale=0.8, 501 hspacing=0.75, 502 lspacing=0.15, 503 dotsep="x", 504 islocal=False, 505 ), 506 Vega=dict( 507 mono=False, 508 fscale=0.8, 509 hspacing=0.75, 510 lspacing=0.15, 511 dotsep="×", 512 islocal=False, 513 ), 514 Meson=dict( 515 mono=False, 516 fscale=0.8, 517 hspacing=0.9, 518 lspacing=0.225, 519 dotsep="~×", 520 islocal=False, 521 ), 522 Komika=dict( 523 mono=False, 524 fscale=0.7, 525 hspacing=0.75, 526 lspacing=0.225, 527 dotsep="~×", 528 islocal=False, 529 ), 530 Brachium=dict( 531 mono=True, 532 fscale=0.8, 533 hspacing=1, 534 lspacing=0.1, 535 dotsep="x", 536 islocal=False, 537 ), 538 Dalim=dict( 539 mono=False, 540 fscale=0.75, 541 lspacing=0.2, 542 hspacing=1, 543 dotsep="~×", 544 islocal=False, 545 ), 546 Miro=dict( 547 mono=False, 548 fscale=0.75, 549 lspacing=0.2, 550 hspacing=1, 551 dotsep="~×", 552 islocal=False, 553 ), 554 Ubuntu=dict( 555 mono=False, 556 fscale=0.75, 557 lspacing=0.2, 558 hspacing=1, 559 dotsep="~×", 560 islocal=False, 561 ), 562 Mizar=dict( 563 mono=False, 564 fscale=0.75, 565 lspacing=0.2, 566 hspacing=0.75, 567 dotsep="~×", 568 islocal=False, 569 ), 570 LiberationSans=dict( 571 mono=False, 572 fscale=0.75, 573 lspacing=0.2, 574 hspacing=1, 575 dotsep="~×", 576 islocal=False, 577 ), 578 DejavuSansMono=dict( 579 mono=True, 580 fscale=0.725, 581 hspacing=1, 582 lspacing=0.1, 583 dotsep="~×", 584 islocal=False, 585 ), 586 SunflowerHighway=dict( 587 mono=False, 588 fscale=0.75, 589 lspacing=0.2, 590 hspacing=1, 591 dotsep="~×", 592 islocal=False, 593 ), 594 Swansea=dict( 595 mono=False, 596 fscale=0.75, 597 lspacing=0.2, 598 hspacing=1, 599 dotsep="~×", 600 islocal=False, 601 ), 602 Housekeeper=dict( # supports chinese glyphs 603 mono=False, 604 fscale=0.75, 605 hspacing=1, 606 lspacing=0.2, 607 dotsep="~×", 608 islocal=False, 609 ), 610 Wananti=dict( # supports chinese glyphs 611 mono=False, 612 fscale=0.75, 613 hspacing=1, 614 lspacing=0.2, 615 dotsep="~x", 616 islocal=False, 617 ), 618 AnimeAce=dict( 619 mono=False, 620 fscale=0.75, 621 hspacing=1, 622 lspacing=0.2, 623 dotsep="~x", 624 islocal=False, 625 ), 626 Antares=dict( 627 mono=True, 628 fscale=0.8, 629 hspacing=1, 630 lspacing=0.1, 631 dotsep="×", 632 islocal=False, 633 ), 634 Archistico=dict( 635 mono=False, 636 fscale=0.75, 637 lspacing=0.2, 638 hspacing=0.75, 639 dotsep="~×", 640 islocal=False, 641 ), 642 KazyCase=dict( 643 mono=True, 644 fscale=0.8, 645 hspacing=1.2, 646 lspacing=0.1, 647 dotsep="×", 648 islocal=False, 649 ), 650 Roboto=dict( 651 mono=True, 652 fscale=0.8, 653 hspacing=1, 654 lspacing=0.1, 655 dotsep="×", 656 islocal=False, 657 ), 658 ) 659 660 #################################################################################### 661 def __getitem__(self, key): 662 """Make the class work like a dictionary too""" 663 return getattr(self, key) 664 665 def __setitem__(self, key, value): 666 """Make the class work like a dictionary too""" 667 setattr(self, key, value) 668 669 def __str__(self) -> str: 670 """Return a string representation of the object""" 671 s = Settings.__doc__.replace(" ", "") 672 s = s.replace(".. code-block:: python\n", "") 673 s = s.replace("```python\n", "") 674 s = s.replace("```\n", "") 675 s = s.replace("\n\n", "\n #------------------------------------------------------\n") 676 s = s.replace("\n ", "\n") 677 s = s.replace("\n ", "\n") 678 s = s.replace(" from", "from") 679 try: 680 from pygments import highlight 681 from pygments.lexers import Python3Lexer 682 from pygments.formatters import Terminal256Formatter 683 s = highlight(s, Python3Lexer(), Terminal256Formatter(style="zenburn")) 684 except (ModuleNotFoundError, ImportError): 685 pass 686 687 module = self.__class__.__module__ 688 name = self.__class__.__name__ 689 header = f"{module}.{name} at ({hex(id(self))})".ljust(75) 690 s = f"\x1b[1m\x1b[7m{header}\x1b[0m\n" + s 691 return s.strip() 692 693 ############################################################ 694 def keys(self) -> list: 695 """Return all keys""" 696 return self.__slots__ 697 698 def values(self) -> list: 699 """Return all values""" 700 return [getattr(self, key) for key in self.__slots__] 701 702 def items(self) -> list: 703 """Return all items""" 704 return [(key, getattr(self, key)) for key in self.__slots__] 705 706 def reset(self) -> None: 707 """Reset all settings to their default status.""" 708 self.__init__() 709 710 ############################################################ 711 def init_colab(self, enable_k3d=True) -> None: 712 """ 713 Initialize colab environment 714 """ 715 print("setting up colab environment (can take a minute) ...", end="") 716 717 res = os.system("which Xvfb") 718 if res: 719 os.system("apt-get install xvfb") 720 721 os.system("pip install pyvirtualdisplay") 722 723 from pyvirtualdisplay import Display 724 Display(visible=0).start() 725 726 if enable_k3d: 727 os.system("pip install k3d") 728 729 from google.colab import output 730 output.enable_custom_widget_manager() 731 732 if enable_k3d: 733 import k3d 734 try: 735 print("installing k3d...", end="") 736 os.system("jupyter nbextension install --py --user k3d") 737 os.system("jupyter nbextension enable --py --user k3d") 738 k3d.switch_to_text_protocol() 739 self.default_backend = "k3d" 740 self.backend_autoclose = False 741 except: 742 print("(FAILED) ... ", end="") 743 744 print(" setup completed.") 745 746 ############################################################ 747 def start_xvfb(self) -> None: 748 """ 749 Start xvfb. 750 751 Xvfb or X virtual framebuffer is a display server implementing 752 the X11 display server protocol. In contrast to other display servers, 753 Xvfb performs all graphical operations in virtual memory 754 without showing any screen output. 755 """ 756 print("starting xvfb (can take a minute) ...", end="") 757 res = os.system("which Xvfb") 758 if res: 759 os.system("apt-get install xvfb") 760 os.system("set -x") 761 os.system("export DISPLAY=:99.0") 762 os.system("Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &") 763 os.system("sleep 3") 764 os.system("set +x") 765 os.system('exec "$@"') 766 print(" xvfb started.")
General settings to modify the global behavior and style.
Example:
from vedo import settings, Cube settings.use_parallel_projection = True # settings["use_parallel_projection"] = True # this is equivalent! Cube().color('g').show().close()
List of available properties:
# Set the default font to be used for axes, comments etc.
# Check out the available fonts at http://vedo.embl.es/fonts
# For example:
default_font = 'Normografo'
# To customize the font parameters use:
settings.font_parameters["Normografo"] = dict(
mono=False,
fscale=0.75,
hspacing=1,
lspacing=0.2,
dotsep="~×",
islocal=True,
)
# Where
# mono : if True all letters occupy the same space slot horizontally
# fscale : sets the general scaling factor for the size of the font
# hspacing: horizontal stretching factor (affects both letters and words)
# lspacing: horizontal spacing inbetween letters (not words)
# dotsep : a string of characters to be interpreted as dot separator
# islocal : if locally stored in /fonts, otherwise it's on vedo.embl.es/fonts
#
# To run a demo try:
# vedo --run fonts
# Use this local folder to store downloaded files (default is ~/.cache/vedo)
cache_directory = ".cache"
# Palette number when using an integer to choose a color
palette = 0
# Options for saving window screenshots:
screenshot_transparent_background = False
screeshot_large_image = False # sometimes setting this to True gives better results
# Enable tracking pipeline functionality:
# allows to show a graph with the pipeline of action which let to a final object
# this is achieved by calling "myobj.pipeline.show()" (a new window will pop up)
self.enable_pipeline = True
# Remember the last format used when creating new figures in vedo.pyplot
# this is useful when creating multiple figures of the same kind
# and avoid to specify the format each time in plot(..., like=...)
remember_last_figure_format = False
# Set up default mouse and keyboard callbacks
enable_default_mouse_callbacks = True
enable_default_keyboard_callbacks = True
# Force single precsion of points coordinates.
# Useful for very large point clouds and meshes. Default is True.
force_single_precision_points = True
# Progress bar delay before showing up [sec]
progressbar_delay = 0.5
# If False, when multiple renderers are present, render only once at the end
immediate_rendering = True
# In multirendering mode, show a grey frame margin (set width=0 to disable)
renderer_frame_color = None
renderer_frame_alpha = 0.5
renderer_frame_width = 0.5
renderer_frame_padding = 0.0001
# In multirendering mode, set the position of the horizontal of vertical splitting [0,1]
window_splitting_position = None
# Gradient orientation mode for background window color
# 0 = Vertical
# 1 = Horizontal
# 2 = Radial viewport farthest side
# 3 = Radial viewport farthest corner
background_gradient_orientation = 0
# Enable / disable color printing by printc()
enable_print_color = True
# Smoothing options for points, lines and polygons
point_smoothing = False
line_smoothing = False
polygon_smoothing = False
# Turn on/off the automatic repositioning of lights as the camera moves
light_follows_camera = False
two_sided_lighting = True
# Turn on/off rendering of translucent material with depth peeling technique
use_depth_peeling = False
alpha_bit_planes = True # options only active if useDepthPeeling=True
multi_samples = 8 # antialiasing multisample buffer
max_number_of_peels= 4 # maximum number of rendering passes
occlusion_ratio = 0.0 # occlusion ratio, 0 = exact image.
# Turn on/off nvidia FXAA post-process anti-aliasing, if supported
use_fxaa = False # either True or False
# By default, the depth buffer is reset for each renderer
# If True, use the existing depth buffer
preserve_depth_buffer = False
# Use a polygon/edges offset to possibly resolve conflicts in rendering
use_polygon_offset = False
polygon_offset_factor = 0.1
polygon_offset_units = 0.1
# Interpolate scalars to render them smoothly
interpolate_scalars_before_mapping = True
# Set parallel projection On or Off (place camera to infinity, no perspective effects)
use_parallel_projection = False
# Set orientation type when reading TIFF files:
# TOPLEFT 1 (row 0 top, col 0 lhs) TOPRIGHT 2 (row 0 top, col 0 rhs)
# BOTRIGHT 3 (row 0 bottom, col 0 rhs) BOTLEFT 4 (row 0 bottom, col 0 lhs)
# LEFTTOP 5 (row 0 lhs, col 0 top) RIGHTTOP 6 (row 0 rhs, col 0 top)
# RIGHTBOT 7 (row 0 rhs, col 0 bottom) LEFTBOT 8 (row 0 lhs, col 0 bottom)
tiff_orientation_type = 1
# Annotated cube axis type nr. 5 options:
annotated_cube_color = (0.75, 0.75, 0.75)
annotated_cube_text_color = None # use default, otherwise specify a single color
annotated_cube_text_scale = 0.2
annotated_cube_texts = ["right","left ", "front","back ", " top ", "bttom"]
# Set the default backend for plotting in jupyter notebooks.
# If a jupyter environment is detected, the default is automatically switched to "2d"
default_backend = "vtk"
# Automatically close the Plotter instance after show() in jupyter sessions
# setting it to False will keep the current Plotter instance active
backend_autoclose = True
# Settings specific to the K3D backend in jupyter notebooks
k3d_menu_visibility = True
k3d_plot_height = 512
k3d_antialias = True
k3d_lighting = 1.5
k3d_camera_autofit= True
k3d_grid_autofit = True
k3d_axes_color = "gray4"
k3d_axes_helper = 1.0 # size of the small triad of axes on the bottom right
k3d_point_shader = "mesh" # others are '3d', '3dSpecular', 'dot', 'flat'
k3d_line_shader = "thick" # others are 'flat', 'mesh'
Settings()
236 def __init__(self) -> None: 237 238 self.default_backend = "vtk" 239 try: 240 # adapted from: https://stackoverflow.com/a/39662359/2912349 241 shell = get_ipython().__class__.__name__ 242 if shell == 'ZMQInteractiveShell': 243 self.default_backend = "2d" 244 except NameError: 245 pass 246 247 self.default_font = "Normografo" 248 249 self.enable_pipeline = True 250 self.progressbar_delay = 0.5 251 self.palette = 0 252 self.remember_last_figure_format = False 253 254 self.force_single_precision_points = True 255 256 self.cache_directory = ".cache" # "/vedo" is added automatically 257 258 self.screenshot_transparent_background = False 259 self.screeshot_large_image = False 260 261 self.enable_default_mouse_callbacks = True 262 self.enable_default_keyboard_callbacks = True 263 self.immediate_rendering = True 264 265 self.renderer_frame_color = None 266 self.renderer_frame_alpha = 0.5 267 self.renderer_frame_width = 0.5 268 self.renderer_frame_padding = 0.0001 269 self.background_gradient_orientation = 0 270 271 self.point_smoothing = False 272 self.line_smoothing = False 273 self.polygon_smoothing = False 274 275 self.light_follows_camera = False 276 self.two_sided_lighting = True 277 278 self.use_depth_peeling = False 279 self.multi_samples = 8 280 self.alpha_bit_planes = 1 281 self.max_number_of_peels = 4 282 self.occlusion_ratio = 0.1 283 284 self.use_fxaa = False 285 286 self.preserve_depth_buffer = False 287 288 self.use_polygon_offset = True 289 self.polygon_offset_factor = 0.1 290 self.polygon_offset_units = 0.1 291 292 self.interpolate_scalars_before_mapping = True 293 294 self.use_parallel_projection = False 295 296 self.window_splitting_position = None 297 298 self.tiff_orientation_type = 1 299 300 self.annotated_cube_color = (0.75, 0.75, 0.75) 301 self.annotated_cube_text_color = None 302 self.annotated_cube_text_scale = 0.2 303 self.annotated_cube_texts = ["right", "left ", "front", "back ", " top ", "bttom"] 304 305 self.enable_print_color = True 306 307 self.backend_autoclose = True 308 309 self.k3d_menu_visibility = True 310 self.k3d_plot_height = 512 311 self.k3d_antialias = True 312 self.k3d_lighting = 1.5 313 self.k3d_camera_autofit = True 314 self.k3d_grid_autofit= True 315 self.k3d_axes_color = "k4" 316 self.k3d_axes_helper = 1.0 317 self.k3d_point_shader= "mesh" 318 self.k3d_line_shader = "thick" 319 320 self.font_parameters = dict( 321 322 Normografo=dict( 323 mono=False, 324 fscale=0.75, 325 hspacing=1, 326 lspacing=0.2, 327 dotsep="~×", 328 islocal=True, 329 ), 330 Bongas=dict( 331 mono=False, 332 fscale=0.875, 333 hspacing=0.52, 334 lspacing=0.25, 335 dotsep="·", 336 islocal=True, 337 ), 338 Calco=dict( 339 mono=True, 340 fscale=0.8, 341 hspacing=1, 342 lspacing=0.1, 343 dotsep="×", 344 islocal=True, 345 ), 346 Comae=dict( 347 mono=False, 348 fscale=0.75, 349 lspacing=0.2, 350 hspacing=1, 351 dotsep="~×", 352 islocal=True, 353 ), 354 ComicMono=dict( 355 mono=True, 356 fscale=0.8, 357 hspacing=1, 358 lspacing=0.1, 359 dotsep="x", 360 islocal=False, 361 ), 362 Edo=dict( 363 mono=False, 364 fscale=0.75, 365 hspacing=1, 366 lspacing=0.2, 367 dotsep="~x ", 368 islocal=False, 369 ), 370 FiraMonoMedium=dict( 371 mono=True, 372 fscale=0.8, 373 hspacing=1, 374 lspacing=0.1, 375 dotsep="×", 376 islocal=False, 377 ), 378 FiraMonoBold=dict( 379 mono=True, 380 fscale=0.8, 381 hspacing=1, 382 lspacing=0.1, 383 dotsep="×", 384 islocal=False, 385 ), 386 Glasgo=dict( 387 mono=True, 388 fscale=0.75, 389 lspacing=0.1, 390 hspacing=1, 391 dotsep="~×", 392 islocal=True, 393 ), 394 Kanopus=dict( 395 mono=False, 396 fscale=0.75, 397 lspacing=0.15, 398 hspacing=0.75, 399 dotsep="~×", 400 islocal=True, 401 ), 402 LogoType=dict( 403 mono=False, 404 fscale=0.75, 405 hspacing=1, 406 lspacing=0.2, 407 dotsep="~×", 408 islocal=False, 409 ), 410 Quikhand=dict( 411 mono=False, 412 fscale=0.8, 413 hspacing=0.6, 414 lspacing=0.15, 415 dotsep="~~×~", 416 islocal=True, 417 ), 418 SmartCouric=dict( 419 mono=True, 420 fscale=0.8, 421 hspacing=1.05, 422 lspacing=0.1, 423 dotsep="×", 424 islocal=True, 425 ), 426 Spears=dict( 427 mono=False, 428 fscale=0.8, 429 hspacing=0.5, 430 lspacing=0.2, 431 dotsep="~×", 432 islocal=False, 433 ), 434 Theemim=dict( 435 mono=False, 436 fscale=0.825, 437 hspacing=0.52, 438 lspacing=0.3, 439 dotsep="~~×", 440 islocal=True, 441 ), 442 VictorMono=dict( 443 mono=True, 444 fscale=0.725, 445 hspacing=1, 446 lspacing=0.1, 447 dotsep="×", 448 islocal=True, 449 ), 450 Justino1=dict( 451 mono=True, 452 fscale=0.725, 453 hspacing=1, 454 lspacing=0.1, 455 dotsep="×", 456 islocal=False, 457 ), 458 Justino2=dict( 459 mono=True, 460 fscale=0.725, 461 hspacing=1, 462 lspacing=0.1, 463 dotsep="×", 464 islocal=False, 465 ), 466 Justino3=dict( 467 mono=True, 468 fscale=0.725, 469 hspacing=1, 470 lspacing=0.1, 471 dotsep="×", 472 islocal=False, 473 ), 474 Calibri=dict( 475 mono=False, 476 fscale=0.75, 477 hspacing=1, 478 lspacing=0.2, 479 dotsep="~×", 480 islocal=False, 481 ), 482 Capsmall=dict( 483 mono=False, 484 fscale=0.8, 485 hspacing=0.75, 486 lspacing=0.15, 487 dotsep="~×", 488 islocal=False, 489 ), 490 Cartoons123=dict( 491 mono=False, 492 fscale=0.8, 493 hspacing=0.75, 494 lspacing=0.15, 495 dotsep="x", 496 islocal=False, 497 ), 498 Darwin=dict( 499 mono=False, 500 fscale=0.8, 501 hspacing=0.75, 502 lspacing=0.15, 503 dotsep="x", 504 islocal=False, 505 ), 506 Vega=dict( 507 mono=False, 508 fscale=0.8, 509 hspacing=0.75, 510 lspacing=0.15, 511 dotsep="×", 512 islocal=False, 513 ), 514 Meson=dict( 515 mono=False, 516 fscale=0.8, 517 hspacing=0.9, 518 lspacing=0.225, 519 dotsep="~×", 520 islocal=False, 521 ), 522 Komika=dict( 523 mono=False, 524 fscale=0.7, 525 hspacing=0.75, 526 lspacing=0.225, 527 dotsep="~×", 528 islocal=False, 529 ), 530 Brachium=dict( 531 mono=True, 532 fscale=0.8, 533 hspacing=1, 534 lspacing=0.1, 535 dotsep="x", 536 islocal=False, 537 ), 538 Dalim=dict( 539 mono=False, 540 fscale=0.75, 541 lspacing=0.2, 542 hspacing=1, 543 dotsep="~×", 544 islocal=False, 545 ), 546 Miro=dict( 547 mono=False, 548 fscale=0.75, 549 lspacing=0.2, 550 hspacing=1, 551 dotsep="~×", 552 islocal=False, 553 ), 554 Ubuntu=dict( 555 mono=False, 556 fscale=0.75, 557 lspacing=0.2, 558 hspacing=1, 559 dotsep="~×", 560 islocal=False, 561 ), 562 Mizar=dict( 563 mono=False, 564 fscale=0.75, 565 lspacing=0.2, 566 hspacing=0.75, 567 dotsep="~×", 568 islocal=False, 569 ), 570 LiberationSans=dict( 571 mono=False, 572 fscale=0.75, 573 lspacing=0.2, 574 hspacing=1, 575 dotsep="~×", 576 islocal=False, 577 ), 578 DejavuSansMono=dict( 579 mono=True, 580 fscale=0.725, 581 hspacing=1, 582 lspacing=0.1, 583 dotsep="~×", 584 islocal=False, 585 ), 586 SunflowerHighway=dict( 587 mono=False, 588 fscale=0.75, 589 lspacing=0.2, 590 hspacing=1, 591 dotsep="~×", 592 islocal=False, 593 ), 594 Swansea=dict( 595 mono=False, 596 fscale=0.75, 597 lspacing=0.2, 598 hspacing=1, 599 dotsep="~×", 600 islocal=False, 601 ), 602 Housekeeper=dict( # supports chinese glyphs 603 mono=False, 604 fscale=0.75, 605 hspacing=1, 606 lspacing=0.2, 607 dotsep="~×", 608 islocal=False, 609 ), 610 Wananti=dict( # supports chinese glyphs 611 mono=False, 612 fscale=0.75, 613 hspacing=1, 614 lspacing=0.2, 615 dotsep="~x", 616 islocal=False, 617 ), 618 AnimeAce=dict( 619 mono=False, 620 fscale=0.75, 621 hspacing=1, 622 lspacing=0.2, 623 dotsep="~x", 624 islocal=False, 625 ), 626 Antares=dict( 627 mono=True, 628 fscale=0.8, 629 hspacing=1, 630 lspacing=0.1, 631 dotsep="×", 632 islocal=False, 633 ), 634 Archistico=dict( 635 mono=False, 636 fscale=0.75, 637 lspacing=0.2, 638 hspacing=0.75, 639 dotsep="~×", 640 islocal=False, 641 ), 642 KazyCase=dict( 643 mono=True, 644 fscale=0.8, 645 hspacing=1.2, 646 lspacing=0.1, 647 dotsep="×", 648 islocal=False, 649 ), 650 Roboto=dict( 651 mono=True, 652 fscale=0.8, 653 hspacing=1, 654 lspacing=0.1, 655 dotsep="×", 656 islocal=False, 657 ), 658 )
def
values(self) -> list:
698 def values(self) -> list: 699 """Return all values""" 700 return [getattr(self, key) for key in self.__slots__]
Return all values
def
items(self) -> list:
702 def items(self) -> list: 703 """Return all items""" 704 return [(key, getattr(self, key)) for key in self.__slots__]
Return all items
def
reset(self) -> None:
706 def reset(self) -> None: 707 """Reset all settings to their default status.""" 708 self.__init__()
Reset all settings to their default status.
def
init_colab(self, enable_k3d=True) -> None:
711 def init_colab(self, enable_k3d=True) -> None: 712 """ 713 Initialize colab environment 714 """ 715 print("setting up colab environment (can take a minute) ...", end="") 716 717 res = os.system("which Xvfb") 718 if res: 719 os.system("apt-get install xvfb") 720 721 os.system("pip install pyvirtualdisplay") 722 723 from pyvirtualdisplay import Display 724 Display(visible=0).start() 725 726 if enable_k3d: 727 os.system("pip install k3d") 728 729 from google.colab import output 730 output.enable_custom_widget_manager() 731 732 if enable_k3d: 733 import k3d 734 try: 735 print("installing k3d...", end="") 736 os.system("jupyter nbextension install --py --user k3d") 737 os.system("jupyter nbextension enable --py --user k3d") 738 k3d.switch_to_text_protocol() 739 self.default_backend = "k3d" 740 self.backend_autoclose = False 741 except: 742 print("(FAILED) ... ", end="") 743 744 print(" setup completed.")
Initialize colab environment
def
start_xvfb(self) -> None:
747 def start_xvfb(self) -> None: 748 """ 749 Start xvfb. 750 751 Xvfb or X virtual framebuffer is a display server implementing 752 the X11 display server protocol. In contrast to other display servers, 753 Xvfb performs all graphical operations in virtual memory 754 without showing any screen output. 755 """ 756 print("starting xvfb (can take a minute) ...", end="") 757 res = os.system("which Xvfb") 758 if res: 759 os.system("apt-get install xvfb") 760 os.system("set -x") 761 os.system("export DISPLAY=:99.0") 762 os.system("Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &") 763 os.system("sleep 3") 764 os.system("set +x") 765 os.system('exec "$@"') 766 print(" xvfb started.")
Start xvfb.
Xvfb or X virtual framebuffer is a display server implementing the X11 display server protocol. In contrast to other display servers, Xvfb performs all graphical operations in virtual memory without showing any screen output.