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