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 get_ipython() 235 self.default_backend = "2d" 236 except NameError: 237 pass 238 239 self.default_font = "Normografo" 240 241 self.enable_pipeline = True 242 self.progressbar_delay = 0.5 243 self.palette = 0 244 self.remember_last_figure_format = False 245 246 self.cache_directory = ".cache" # "/vedo" is added automatically 247 248 self.screenshot_transparent_background = False 249 self.screeshot_large_image = False 250 251 self.enable_default_mouse_callbacks = True 252 self.enable_default_keyboard_callbacks = True 253 self.immediate_rendering = True 254 255 self.renderer_frame_color = None 256 self.renderer_frame_alpha = 0.5 257 self.renderer_frame_width = 0.5 258 self.renderer_frame_padding = 0.0001 259 self.background_gradient_orientation = 0 260 261 self.point_smoothing = False 262 self.line_smoothing = False 263 self.polygon_smoothing = False 264 265 self.light_follows_camera = False 266 self.two_sided_lighting = True 267 268 self.use_depth_peeling = False 269 self.multi_samples = 8 270 self.alpha_bit_planes = 1 271 self.max_number_of_peels = 4 272 self.occlusion_ratio = 0.1 273 274 self.use_fxaa = False 275 276 self.preserve_depth_buffer = False 277 278 self.use_polygon_offset = True 279 self.polygon_offset_factor = 0.1 280 self.polygon_offset_units = 0.1 281 282 self.interpolate_scalars_before_mapping = True 283 284 self.use_parallel_projection = False 285 286 self.window_splitting_position = None 287 288 self.tiff_orientation_type = 1 289 290 self.annotated_cube_color = (0.75, 0.75, 0.75) 291 self.annotated_cube_text_color = None 292 self.annotated_cube_text_scale = 0.2 293 self.annotated_cube_texts = ["right", "left ", "front", "back ", " top ", "bttom"] 294 295 self.enable_print_color = True 296 297 self.backend_autoclose = True 298 299 self.k3d_menu_visibility = True 300 self.k3d_plot_height = 512 301 self.k3d_antialias = True 302 self.k3d_lighting = 1.5 303 self.k3d_camera_autofit = True 304 self.k3d_grid_autofit= True 305 self.k3d_axes_color = "k4" 306 self.k3d_axes_helper = 1.0 307 self.k3d_point_shader= "mesh" 308 self.k3d_line_shader = "thick" 309 310 self.font_parameters = dict( 311 Normografo=dict( 312 mono=False, 313 fscale=0.75, 314 hspacing=1, 315 lspacing=0.2, 316 dotsep="~×", 317 islocal=True, 318 ), 319 Bongas=dict( 320 mono=False, 321 fscale=0.875, 322 hspacing=0.52, 323 lspacing=0.25, 324 dotsep="·", 325 islocal=True, 326 ), 327 Calco=dict( 328 mono=True, 329 fscale=0.8, 330 hspacing=1, 331 lspacing=0.1, 332 dotsep="×", 333 islocal=True, 334 ), 335 Comae=dict( 336 mono=False, 337 fscale=0.75, 338 lspacing=0.2, 339 hspacing=1, 340 dotsep="~×", 341 islocal=True, 342 ), 343 ComicMono=dict( 344 mono=True, 345 fscale=0.8, 346 hspacing=1, 347 lspacing=0.1, 348 dotsep="x", 349 islocal=False, 350 ), 351 Edo=dict( 352 mono=False, 353 fscale=0.75, 354 hspacing=1, 355 lspacing=0.2, 356 dotsep="~x ", 357 islocal=False, 358 ), 359 FiraMonoMedium=dict( 360 mono=True, 361 fscale=0.8, 362 hspacing=1, 363 lspacing=0.1, 364 dotsep="×", 365 islocal=False, 366 ), 367 FiraMonoBold=dict( 368 mono=True, 369 fscale=0.8, 370 hspacing=1, 371 lspacing=0.1, 372 dotsep="×", 373 islocal=False, 374 ), 375 Glasgo=dict( 376 mono=True, 377 fscale=0.75, 378 lspacing=0.1, 379 hspacing=1, 380 dotsep="~×", 381 islocal=True, 382 ), 383 Kanopus=dict( 384 mono=False, 385 fscale=0.75, 386 lspacing=0.15, 387 hspacing=0.75, 388 dotsep="~×", 389 islocal=True, 390 ), 391 LogoType=dict( 392 mono=False, 393 fscale=0.75, 394 hspacing=1, 395 lspacing=0.2, 396 dotsep="~×", 397 islocal=False, 398 ), 399 Quikhand=dict( 400 mono=False, 401 fscale=0.8, 402 hspacing=0.6, 403 lspacing=0.15, 404 dotsep="~~×~", 405 islocal=True, 406 ), 407 SmartCouric=dict( 408 mono=True, 409 fscale=0.8, 410 hspacing=1.05, 411 lspacing=0.1, 412 dotsep="×", 413 islocal=True, 414 ), 415 Spears=dict( 416 mono=False, 417 fscale=0.8, 418 hspacing=0.5, 419 lspacing=0.2, 420 dotsep="~×", 421 islocal=False, 422 ), 423 Theemim=dict( 424 mono=False, 425 fscale=0.825, 426 hspacing=0.52, 427 lspacing=0.3, 428 dotsep="~~×", 429 islocal=True, 430 ), 431 VictorMono=dict( 432 mono=True, 433 fscale=0.725, 434 hspacing=1, 435 lspacing=0.1, 436 dotsep="×", 437 islocal=True, 438 ), 439 Justino1=dict( 440 mono=True, 441 fscale=0.725, 442 hspacing=1, 443 lspacing=0.1, 444 dotsep="×", 445 islocal=False, 446 ), 447 Justino2=dict( 448 mono=True, 449 fscale=0.725, 450 hspacing=1, 451 lspacing=0.1, 452 dotsep="×", 453 islocal=False, 454 ), 455 Justino3=dict( 456 mono=True, 457 fscale=0.725, 458 hspacing=1, 459 lspacing=0.1, 460 dotsep="×", 461 islocal=False, 462 ), 463 Calibri=dict( 464 mono=False, 465 fscale=0.75, 466 hspacing=1, 467 lspacing=0.2, 468 dotsep="~×", 469 islocal=False, 470 ), 471 Capsmall=dict( 472 mono=False, 473 fscale=0.8, 474 hspacing=0.75, 475 lspacing=0.15, 476 dotsep="~×", 477 islocal=False, 478 ), 479 Cartoons123=dict( 480 mono=False, 481 fscale=0.8, 482 hspacing=0.75, 483 lspacing=0.15, 484 dotsep="x", 485 islocal=False, 486 ), 487 Vega=dict( 488 mono=False, 489 fscale=0.8, 490 hspacing=0.75, 491 lspacing=0.15, 492 dotsep="×", 493 islocal=False, 494 ), 495 Meson=dict( 496 mono=False, 497 fscale=0.8, 498 hspacing=0.9, 499 lspacing=0.225, 500 dotsep="~×", 501 islocal=False, 502 ), 503 Komika=dict( 504 mono=False, 505 fscale=0.7, 506 hspacing=0.75, 507 lspacing=0.225, 508 dotsep="~×", 509 islocal=False, 510 ), 511 Brachium=dict( 512 mono=True, 513 fscale=0.8, 514 hspacing=1, 515 lspacing=0.1, 516 dotsep="x", 517 islocal=False, 518 ), 519 Dalim=dict( 520 mono=False, 521 fscale=0.75, 522 lspacing=0.2, 523 hspacing=1, 524 dotsep="~×", 525 islocal=False, 526 ), 527 Miro=dict( 528 mono=False, 529 fscale=0.75, 530 lspacing=0.2, 531 hspacing=1, 532 dotsep="~×", 533 islocal=False, 534 ), 535 Ubuntu=dict( 536 mono=False, 537 fscale=0.75, 538 lspacing=0.2, 539 hspacing=1, 540 dotsep="~×", 541 islocal=False, 542 ), 543 Mizar=dict( 544 mono=False, 545 fscale=0.75, 546 lspacing=0.2, 547 hspacing=0.75, 548 dotsep="~×", 549 islocal=False, 550 ), 551 LiberationSans=dict( 552 mono=False, 553 fscale=0.75, 554 lspacing=0.2, 555 hspacing=1, 556 dotsep="~×", 557 islocal=False, 558 ), 559 DejavuSansMono=dict( 560 mono=True, 561 fscale=0.725, 562 hspacing=1, 563 lspacing=0.1, 564 dotsep="~×", 565 islocal=False, 566 ), 567 SunflowerHighway=dict( 568 mono=False, 569 fscale=0.75, 570 lspacing=0.2, 571 hspacing=1, 572 dotsep="~×", 573 islocal=False, 574 ), 575 Swansea=dict( 576 mono=False, 577 fscale=0.75, 578 lspacing=0.2, 579 hspacing=1, 580 dotsep="~×", 581 islocal=False, 582 ), 583 Housekeeper=dict( # supports chinese glyphs 584 mono=False, 585 fscale=0.75, 586 hspacing=1, 587 lspacing=0.2, 588 dotsep="~×", 589 islocal=False, 590 ), 591 Wananti=dict( # supports chinese glyphs 592 mono=False, 593 fscale=0.75, 594 hspacing=1, 595 lspacing=0.2, 596 dotsep="~x", 597 islocal=False, 598 ), 599 AnimeAce=dict( 600 mono=False, 601 fscale=0.75, 602 hspacing=1, 603 lspacing=0.2, 604 dotsep="~x", 605 islocal=False, 606 ), 607 Antares=dict( 608 mono=True, 609 fscale=0.8, 610 hspacing=1, 611 lspacing=0.1, 612 dotsep="×", 613 islocal=False, 614 ), 615 Archistico=dict( 616 mono=False, 617 fscale=0.75, 618 lspacing=0.2, 619 hspacing=0.75, 620 dotsep="~×", 621 islocal=False, 622 ), 623 KazyCase=dict( 624 mono=True, 625 fscale=0.8, 626 hspacing=1.2, 627 lspacing=0.1, 628 dotsep="×", 629 islocal=False, 630 ), 631 Roboto=dict( 632 mono=True, 633 fscale=0.8, 634 hspacing=1, 635 lspacing=0.1, 636 dotsep="×", 637 islocal=False, 638 ), 639 ) 640 641 #################################################################################### 642 def __getitem__(self, key): 643 """Make the class work like a dictionary too""" 644 return getattr(self, key) 645 646 def __setitem__(self, key, value): 647 """Make the class work like a dictionary too""" 648 setattr(self, key, value) 649 650 def __str__(self) -> str: 651 """Return a string representation of the object""" 652 s = Settings.__doc__.replace(" ", "") 653 s = s.replace(".. code-block:: python\n", "") 654 s = s.replace("```python\n", "") 655 s = s.replace("```\n", "") 656 s = s.replace("\n\n", "\n #------------------------------------------------------\n") 657 s = s.replace("\n ", "\n") 658 s = s.replace("\n ", "\n") 659 s = s.replace(" from", "from") 660 try: 661 from pygments import highlight 662 from pygments.lexers import Python3Lexer 663 from pygments.formatters import Terminal256Formatter 664 s = highlight(s, Python3Lexer(), Terminal256Formatter(style="zenburn")) 665 except (ModuleNotFoundError, ImportError): 666 pass 667 668 module = self.__class__.__module__ 669 name = self.__class__.__name__ 670 header = f"{module}.{name} at ({hex(id(self))})".ljust(75) 671 s = f"\x1b[1m\x1b[7m{header}\x1b[0m\n" + s 672 return s.strip() 673 674 ############################################################ 675 def keys(self) -> list: 676 """Return all keys""" 677 return self.__slots__ 678 679 def values(self) -> list: 680 """Return all values""" 681 return [getattr(self, key) for key in self.__slots__] 682 683 def items(self) -> list: 684 """Return all items""" 685 return [(key, getattr(self, key)) for key in self.__slots__] 686 687 def reset(self) -> None: 688 """Reset all settings to their default status.""" 689 self.__init__() 690 691 ############################################################ 692 def init_colab(self, enable_k3d=True) -> None: 693 """ 694 Initialize colab environment 695 """ 696 print("setting up colab environment (can take a minute) ...", end="") 697 698 res = os.system("which Xvfb") 699 if res: 700 os.system("apt-get install xvfb") 701 702 os.system("pip install pyvirtualdisplay") 703 704 from pyvirtualdisplay import Display 705 Display(visible=0).start() 706 707 if enable_k3d: 708 os.system("pip install k3d") 709 710 from google.colab import output 711 output.enable_custom_widget_manager() 712 713 if enable_k3d: 714 import k3d 715 try: 716 print("installing k3d...", end="") 717 os.system("jupyter nbextension install --py --user k3d") 718 os.system("jupyter nbextension enable --py --user k3d") 719 k3d.switch_to_text_protocol() 720 self.default_backend = "k3d" 721 self.backend_autoclose = False 722 except: 723 print("(FAILED) ... ", end="") 724 725 print(" setup completed.") 726 727 ############################################################ 728 def start_xvfb(self) -> None: 729 """ 730 Start xvfb. 731 732 Xvfb or X virtual framebuffer is a display server implementing 733 the X11 display server protocol. In contrast to other display servers, 734 Xvfb performs all graphical operations in virtual memory 735 without showing any screen output. 736 """ 737 print("starting xvfb (can take a minute) ...", end="") 738 res = os.system("which Xvfb") 739 if res: 740 os.system("apt-get install xvfb") 741 os.system("set -x") 742 os.system("export DISPLAY=:99.0") 743 os.system("Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &") 744 os.system("sleep 3") 745 os.system("set +x") 746 os.system('exec "$@"') 747 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 get_ipython() 236 self.default_backend = "2d" 237 except NameError: 238 pass 239 240 self.default_font = "Normografo" 241 242 self.enable_pipeline = True 243 self.progressbar_delay = 0.5 244 self.palette = 0 245 self.remember_last_figure_format = False 246 247 self.cache_directory = ".cache" # "/vedo" is added automatically 248 249 self.screenshot_transparent_background = False 250 self.screeshot_large_image = False 251 252 self.enable_default_mouse_callbacks = True 253 self.enable_default_keyboard_callbacks = True 254 self.immediate_rendering = True 255 256 self.renderer_frame_color = None 257 self.renderer_frame_alpha = 0.5 258 self.renderer_frame_width = 0.5 259 self.renderer_frame_padding = 0.0001 260 self.background_gradient_orientation = 0 261 262 self.point_smoothing = False 263 self.line_smoothing = False 264 self.polygon_smoothing = False 265 266 self.light_follows_camera = False 267 self.two_sided_lighting = True 268 269 self.use_depth_peeling = False 270 self.multi_samples = 8 271 self.alpha_bit_planes = 1 272 self.max_number_of_peels = 4 273 self.occlusion_ratio = 0.1 274 275 self.use_fxaa = False 276 277 self.preserve_depth_buffer = False 278 279 self.use_polygon_offset = True 280 self.polygon_offset_factor = 0.1 281 self.polygon_offset_units = 0.1 282 283 self.interpolate_scalars_before_mapping = True 284 285 self.use_parallel_projection = False 286 287 self.window_splitting_position = None 288 289 self.tiff_orientation_type = 1 290 291 self.annotated_cube_color = (0.75, 0.75, 0.75) 292 self.annotated_cube_text_color = None 293 self.annotated_cube_text_scale = 0.2 294 self.annotated_cube_texts = ["right", "left ", "front", "back ", " top ", "bttom"] 295 296 self.enable_print_color = True 297 298 self.backend_autoclose = True 299 300 self.k3d_menu_visibility = True 301 self.k3d_plot_height = 512 302 self.k3d_antialias = True 303 self.k3d_lighting = 1.5 304 self.k3d_camera_autofit = True 305 self.k3d_grid_autofit= True 306 self.k3d_axes_color = "k4" 307 self.k3d_axes_helper = 1.0 308 self.k3d_point_shader= "mesh" 309 self.k3d_line_shader = "thick" 310 311 self.font_parameters = dict( 312 Normografo=dict( 313 mono=False, 314 fscale=0.75, 315 hspacing=1, 316 lspacing=0.2, 317 dotsep="~×", 318 islocal=True, 319 ), 320 Bongas=dict( 321 mono=False, 322 fscale=0.875, 323 hspacing=0.52, 324 lspacing=0.25, 325 dotsep="·", 326 islocal=True, 327 ), 328 Calco=dict( 329 mono=True, 330 fscale=0.8, 331 hspacing=1, 332 lspacing=0.1, 333 dotsep="×", 334 islocal=True, 335 ), 336 Comae=dict( 337 mono=False, 338 fscale=0.75, 339 lspacing=0.2, 340 hspacing=1, 341 dotsep="~×", 342 islocal=True, 343 ), 344 ComicMono=dict( 345 mono=True, 346 fscale=0.8, 347 hspacing=1, 348 lspacing=0.1, 349 dotsep="x", 350 islocal=False, 351 ), 352 Edo=dict( 353 mono=False, 354 fscale=0.75, 355 hspacing=1, 356 lspacing=0.2, 357 dotsep="~x ", 358 islocal=False, 359 ), 360 FiraMonoMedium=dict( 361 mono=True, 362 fscale=0.8, 363 hspacing=1, 364 lspacing=0.1, 365 dotsep="×", 366 islocal=False, 367 ), 368 FiraMonoBold=dict( 369 mono=True, 370 fscale=0.8, 371 hspacing=1, 372 lspacing=0.1, 373 dotsep="×", 374 islocal=False, 375 ), 376 Glasgo=dict( 377 mono=True, 378 fscale=0.75, 379 lspacing=0.1, 380 hspacing=1, 381 dotsep="~×", 382 islocal=True, 383 ), 384 Kanopus=dict( 385 mono=False, 386 fscale=0.75, 387 lspacing=0.15, 388 hspacing=0.75, 389 dotsep="~×", 390 islocal=True, 391 ), 392 LogoType=dict( 393 mono=False, 394 fscale=0.75, 395 hspacing=1, 396 lspacing=0.2, 397 dotsep="~×", 398 islocal=False, 399 ), 400 Quikhand=dict( 401 mono=False, 402 fscale=0.8, 403 hspacing=0.6, 404 lspacing=0.15, 405 dotsep="~~×~", 406 islocal=True, 407 ), 408 SmartCouric=dict( 409 mono=True, 410 fscale=0.8, 411 hspacing=1.05, 412 lspacing=0.1, 413 dotsep="×", 414 islocal=True, 415 ), 416 Spears=dict( 417 mono=False, 418 fscale=0.8, 419 hspacing=0.5, 420 lspacing=0.2, 421 dotsep="~×", 422 islocal=False, 423 ), 424 Theemim=dict( 425 mono=False, 426 fscale=0.825, 427 hspacing=0.52, 428 lspacing=0.3, 429 dotsep="~~×", 430 islocal=True, 431 ), 432 VictorMono=dict( 433 mono=True, 434 fscale=0.725, 435 hspacing=1, 436 lspacing=0.1, 437 dotsep="×", 438 islocal=True, 439 ), 440 Justino1=dict( 441 mono=True, 442 fscale=0.725, 443 hspacing=1, 444 lspacing=0.1, 445 dotsep="×", 446 islocal=False, 447 ), 448 Justino2=dict( 449 mono=True, 450 fscale=0.725, 451 hspacing=1, 452 lspacing=0.1, 453 dotsep="×", 454 islocal=False, 455 ), 456 Justino3=dict( 457 mono=True, 458 fscale=0.725, 459 hspacing=1, 460 lspacing=0.1, 461 dotsep="×", 462 islocal=False, 463 ), 464 Calibri=dict( 465 mono=False, 466 fscale=0.75, 467 hspacing=1, 468 lspacing=0.2, 469 dotsep="~×", 470 islocal=False, 471 ), 472 Capsmall=dict( 473 mono=False, 474 fscale=0.8, 475 hspacing=0.75, 476 lspacing=0.15, 477 dotsep="~×", 478 islocal=False, 479 ), 480 Cartoons123=dict( 481 mono=False, 482 fscale=0.8, 483 hspacing=0.75, 484 lspacing=0.15, 485 dotsep="x", 486 islocal=False, 487 ), 488 Vega=dict( 489 mono=False, 490 fscale=0.8, 491 hspacing=0.75, 492 lspacing=0.15, 493 dotsep="×", 494 islocal=False, 495 ), 496 Meson=dict( 497 mono=False, 498 fscale=0.8, 499 hspacing=0.9, 500 lspacing=0.225, 501 dotsep="~×", 502 islocal=False, 503 ), 504 Komika=dict( 505 mono=False, 506 fscale=0.7, 507 hspacing=0.75, 508 lspacing=0.225, 509 dotsep="~×", 510 islocal=False, 511 ), 512 Brachium=dict( 513 mono=True, 514 fscale=0.8, 515 hspacing=1, 516 lspacing=0.1, 517 dotsep="x", 518 islocal=False, 519 ), 520 Dalim=dict( 521 mono=False, 522 fscale=0.75, 523 lspacing=0.2, 524 hspacing=1, 525 dotsep="~×", 526 islocal=False, 527 ), 528 Miro=dict( 529 mono=False, 530 fscale=0.75, 531 lspacing=0.2, 532 hspacing=1, 533 dotsep="~×", 534 islocal=False, 535 ), 536 Ubuntu=dict( 537 mono=False, 538 fscale=0.75, 539 lspacing=0.2, 540 hspacing=1, 541 dotsep="~×", 542 islocal=False, 543 ), 544 Mizar=dict( 545 mono=False, 546 fscale=0.75, 547 lspacing=0.2, 548 hspacing=0.75, 549 dotsep="~×", 550 islocal=False, 551 ), 552 LiberationSans=dict( 553 mono=False, 554 fscale=0.75, 555 lspacing=0.2, 556 hspacing=1, 557 dotsep="~×", 558 islocal=False, 559 ), 560 DejavuSansMono=dict( 561 mono=True, 562 fscale=0.725, 563 hspacing=1, 564 lspacing=0.1, 565 dotsep="~×", 566 islocal=False, 567 ), 568 SunflowerHighway=dict( 569 mono=False, 570 fscale=0.75, 571 lspacing=0.2, 572 hspacing=1, 573 dotsep="~×", 574 islocal=False, 575 ), 576 Swansea=dict( 577 mono=False, 578 fscale=0.75, 579 lspacing=0.2, 580 hspacing=1, 581 dotsep="~×", 582 islocal=False, 583 ), 584 Housekeeper=dict( # supports chinese glyphs 585 mono=False, 586 fscale=0.75, 587 hspacing=1, 588 lspacing=0.2, 589 dotsep="~×", 590 islocal=False, 591 ), 592 Wananti=dict( # supports chinese glyphs 593 mono=False, 594 fscale=0.75, 595 hspacing=1, 596 lspacing=0.2, 597 dotsep="~x", 598 islocal=False, 599 ), 600 AnimeAce=dict( 601 mono=False, 602 fscale=0.75, 603 hspacing=1, 604 lspacing=0.2, 605 dotsep="~x", 606 islocal=False, 607 ), 608 Antares=dict( 609 mono=True, 610 fscale=0.8, 611 hspacing=1, 612 lspacing=0.1, 613 dotsep="×", 614 islocal=False, 615 ), 616 Archistico=dict( 617 mono=False, 618 fscale=0.75, 619 lspacing=0.2, 620 hspacing=0.75, 621 dotsep="~×", 622 islocal=False, 623 ), 624 KazyCase=dict( 625 mono=True, 626 fscale=0.8, 627 hspacing=1.2, 628 lspacing=0.1, 629 dotsep="×", 630 islocal=False, 631 ), 632 Roboto=dict( 633 mono=True, 634 fscale=0.8, 635 hspacing=1, 636 lspacing=0.1, 637 dotsep="×", 638 islocal=False, 639 ), 640 ) 641 642 #################################################################################### 643 def __getitem__(self, key): 644 """Make the class work like a dictionary too""" 645 return getattr(self, key) 646 647 def __setitem__(self, key, value): 648 """Make the class work like a dictionary too""" 649 setattr(self, key, value) 650 651 def __str__(self) -> str: 652 """Return a string representation of the object""" 653 s = Settings.__doc__.replace(" ", "") 654 s = s.replace(".. code-block:: python\n", "") 655 s = s.replace("```python\n", "") 656 s = s.replace("```\n", "") 657 s = s.replace("\n\n", "\n #------------------------------------------------------\n") 658 s = s.replace("\n ", "\n") 659 s = s.replace("\n ", "\n") 660 s = s.replace(" from", "from") 661 try: 662 from pygments import highlight 663 from pygments.lexers import Python3Lexer 664 from pygments.formatters import Terminal256Formatter 665 s = highlight(s, Python3Lexer(), Terminal256Formatter(style="zenburn")) 666 except (ModuleNotFoundError, ImportError): 667 pass 668 669 module = self.__class__.__module__ 670 name = self.__class__.__name__ 671 header = f"{module}.{name} at ({hex(id(self))})".ljust(75) 672 s = f"\x1b[1m\x1b[7m{header}\x1b[0m\n" + s 673 return s.strip() 674 675 ############################################################ 676 def keys(self) -> list: 677 """Return all keys""" 678 return self.__slots__ 679 680 def values(self) -> list: 681 """Return all values""" 682 return [getattr(self, key) for key in self.__slots__] 683 684 def items(self) -> list: 685 """Return all items""" 686 return [(key, getattr(self, key)) for key in self.__slots__] 687 688 def reset(self) -> None: 689 """Reset all settings to their default status.""" 690 self.__init__() 691 692 ############################################################ 693 def init_colab(self, enable_k3d=True) -> None: 694 """ 695 Initialize colab environment 696 """ 697 print("setting up colab environment (can take a minute) ...", end="") 698 699 res = os.system("which Xvfb") 700 if res: 701 os.system("apt-get install xvfb") 702 703 os.system("pip install pyvirtualdisplay") 704 705 from pyvirtualdisplay import Display 706 Display(visible=0).start() 707 708 if enable_k3d: 709 os.system("pip install k3d") 710 711 from google.colab import output 712 output.enable_custom_widget_manager() 713 714 if enable_k3d: 715 import k3d 716 try: 717 print("installing k3d...", end="") 718 os.system("jupyter nbextension install --py --user k3d") 719 os.system("jupyter nbextension enable --py --user k3d") 720 k3d.switch_to_text_protocol() 721 self.default_backend = "k3d" 722 self.backend_autoclose = False 723 except: 724 print("(FAILED) ... ", end="") 725 726 print(" setup completed.") 727 728 ############################################################ 729 def start_xvfb(self) -> None: 730 """ 731 Start xvfb. 732 733 Xvfb or X virtual framebuffer is a display server implementing 734 the X11 display server protocol. In contrast to other display servers, 735 Xvfb performs all graphical operations in virtual memory 736 without showing any screen output. 737 """ 738 print("starting xvfb (can take a minute) ...", end="") 739 res = os.system("which Xvfb") 740 if res: 741 os.system("apt-get install xvfb") 742 os.system("set -x") 743 os.system("export DISPLAY=:99.0") 744 os.system("Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &") 745 os.system("sleep 3") 746 os.system("set +x") 747 os.system('exec "$@"') 748 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 get_ipython() 236 self.default_backend = "2d" 237 except NameError: 238 pass 239 240 self.default_font = "Normografo" 241 242 self.enable_pipeline = True 243 self.progressbar_delay = 0.5 244 self.palette = 0 245 self.remember_last_figure_format = False 246 247 self.cache_directory = ".cache" # "/vedo" is added automatically 248 249 self.screenshot_transparent_background = False 250 self.screeshot_large_image = False 251 252 self.enable_default_mouse_callbacks = True 253 self.enable_default_keyboard_callbacks = True 254 self.immediate_rendering = True 255 256 self.renderer_frame_color = None 257 self.renderer_frame_alpha = 0.5 258 self.renderer_frame_width = 0.5 259 self.renderer_frame_padding = 0.0001 260 self.background_gradient_orientation = 0 261 262 self.point_smoothing = False 263 self.line_smoothing = False 264 self.polygon_smoothing = False 265 266 self.light_follows_camera = False 267 self.two_sided_lighting = True 268 269 self.use_depth_peeling = False 270 self.multi_samples = 8 271 self.alpha_bit_planes = 1 272 self.max_number_of_peels = 4 273 self.occlusion_ratio = 0.1 274 275 self.use_fxaa = False 276 277 self.preserve_depth_buffer = False 278 279 self.use_polygon_offset = True 280 self.polygon_offset_factor = 0.1 281 self.polygon_offset_units = 0.1 282 283 self.interpolate_scalars_before_mapping = True 284 285 self.use_parallel_projection = False 286 287 self.window_splitting_position = None 288 289 self.tiff_orientation_type = 1 290 291 self.annotated_cube_color = (0.75, 0.75, 0.75) 292 self.annotated_cube_text_color = None 293 self.annotated_cube_text_scale = 0.2 294 self.annotated_cube_texts = ["right", "left ", "front", "back ", " top ", "bttom"] 295 296 self.enable_print_color = True 297 298 self.backend_autoclose = True 299 300 self.k3d_menu_visibility = True 301 self.k3d_plot_height = 512 302 self.k3d_antialias = True 303 self.k3d_lighting = 1.5 304 self.k3d_camera_autofit = True 305 self.k3d_grid_autofit= True 306 self.k3d_axes_color = "k4" 307 self.k3d_axes_helper = 1.0 308 self.k3d_point_shader= "mesh" 309 self.k3d_line_shader = "thick" 310 311 self.font_parameters = dict( 312 Normografo=dict( 313 mono=False, 314 fscale=0.75, 315 hspacing=1, 316 lspacing=0.2, 317 dotsep="~×", 318 islocal=True, 319 ), 320 Bongas=dict( 321 mono=False, 322 fscale=0.875, 323 hspacing=0.52, 324 lspacing=0.25, 325 dotsep="·", 326 islocal=True, 327 ), 328 Calco=dict( 329 mono=True, 330 fscale=0.8, 331 hspacing=1, 332 lspacing=0.1, 333 dotsep="×", 334 islocal=True, 335 ), 336 Comae=dict( 337 mono=False, 338 fscale=0.75, 339 lspacing=0.2, 340 hspacing=1, 341 dotsep="~×", 342 islocal=True, 343 ), 344 ComicMono=dict( 345 mono=True, 346 fscale=0.8, 347 hspacing=1, 348 lspacing=0.1, 349 dotsep="x", 350 islocal=False, 351 ), 352 Edo=dict( 353 mono=False, 354 fscale=0.75, 355 hspacing=1, 356 lspacing=0.2, 357 dotsep="~x ", 358 islocal=False, 359 ), 360 FiraMonoMedium=dict( 361 mono=True, 362 fscale=0.8, 363 hspacing=1, 364 lspacing=0.1, 365 dotsep="×", 366 islocal=False, 367 ), 368 FiraMonoBold=dict( 369 mono=True, 370 fscale=0.8, 371 hspacing=1, 372 lspacing=0.1, 373 dotsep="×", 374 islocal=False, 375 ), 376 Glasgo=dict( 377 mono=True, 378 fscale=0.75, 379 lspacing=0.1, 380 hspacing=1, 381 dotsep="~×", 382 islocal=True, 383 ), 384 Kanopus=dict( 385 mono=False, 386 fscale=0.75, 387 lspacing=0.15, 388 hspacing=0.75, 389 dotsep="~×", 390 islocal=True, 391 ), 392 LogoType=dict( 393 mono=False, 394 fscale=0.75, 395 hspacing=1, 396 lspacing=0.2, 397 dotsep="~×", 398 islocal=False, 399 ), 400 Quikhand=dict( 401 mono=False, 402 fscale=0.8, 403 hspacing=0.6, 404 lspacing=0.15, 405 dotsep="~~×~", 406 islocal=True, 407 ), 408 SmartCouric=dict( 409 mono=True, 410 fscale=0.8, 411 hspacing=1.05, 412 lspacing=0.1, 413 dotsep="×", 414 islocal=True, 415 ), 416 Spears=dict( 417 mono=False, 418 fscale=0.8, 419 hspacing=0.5, 420 lspacing=0.2, 421 dotsep="~×", 422 islocal=False, 423 ), 424 Theemim=dict( 425 mono=False, 426 fscale=0.825, 427 hspacing=0.52, 428 lspacing=0.3, 429 dotsep="~~×", 430 islocal=True, 431 ), 432 VictorMono=dict( 433 mono=True, 434 fscale=0.725, 435 hspacing=1, 436 lspacing=0.1, 437 dotsep="×", 438 islocal=True, 439 ), 440 Justino1=dict( 441 mono=True, 442 fscale=0.725, 443 hspacing=1, 444 lspacing=0.1, 445 dotsep="×", 446 islocal=False, 447 ), 448 Justino2=dict( 449 mono=True, 450 fscale=0.725, 451 hspacing=1, 452 lspacing=0.1, 453 dotsep="×", 454 islocal=False, 455 ), 456 Justino3=dict( 457 mono=True, 458 fscale=0.725, 459 hspacing=1, 460 lspacing=0.1, 461 dotsep="×", 462 islocal=False, 463 ), 464 Calibri=dict( 465 mono=False, 466 fscale=0.75, 467 hspacing=1, 468 lspacing=0.2, 469 dotsep="~×", 470 islocal=False, 471 ), 472 Capsmall=dict( 473 mono=False, 474 fscale=0.8, 475 hspacing=0.75, 476 lspacing=0.15, 477 dotsep="~×", 478 islocal=False, 479 ), 480 Cartoons123=dict( 481 mono=False, 482 fscale=0.8, 483 hspacing=0.75, 484 lspacing=0.15, 485 dotsep="x", 486 islocal=False, 487 ), 488 Vega=dict( 489 mono=False, 490 fscale=0.8, 491 hspacing=0.75, 492 lspacing=0.15, 493 dotsep="×", 494 islocal=False, 495 ), 496 Meson=dict( 497 mono=False, 498 fscale=0.8, 499 hspacing=0.9, 500 lspacing=0.225, 501 dotsep="~×", 502 islocal=False, 503 ), 504 Komika=dict( 505 mono=False, 506 fscale=0.7, 507 hspacing=0.75, 508 lspacing=0.225, 509 dotsep="~×", 510 islocal=False, 511 ), 512 Brachium=dict( 513 mono=True, 514 fscale=0.8, 515 hspacing=1, 516 lspacing=0.1, 517 dotsep="x", 518 islocal=False, 519 ), 520 Dalim=dict( 521 mono=False, 522 fscale=0.75, 523 lspacing=0.2, 524 hspacing=1, 525 dotsep="~×", 526 islocal=False, 527 ), 528 Miro=dict( 529 mono=False, 530 fscale=0.75, 531 lspacing=0.2, 532 hspacing=1, 533 dotsep="~×", 534 islocal=False, 535 ), 536 Ubuntu=dict( 537 mono=False, 538 fscale=0.75, 539 lspacing=0.2, 540 hspacing=1, 541 dotsep="~×", 542 islocal=False, 543 ), 544 Mizar=dict( 545 mono=False, 546 fscale=0.75, 547 lspacing=0.2, 548 hspacing=0.75, 549 dotsep="~×", 550 islocal=False, 551 ), 552 LiberationSans=dict( 553 mono=False, 554 fscale=0.75, 555 lspacing=0.2, 556 hspacing=1, 557 dotsep="~×", 558 islocal=False, 559 ), 560 DejavuSansMono=dict( 561 mono=True, 562 fscale=0.725, 563 hspacing=1, 564 lspacing=0.1, 565 dotsep="~×", 566 islocal=False, 567 ), 568 SunflowerHighway=dict( 569 mono=False, 570 fscale=0.75, 571 lspacing=0.2, 572 hspacing=1, 573 dotsep="~×", 574 islocal=False, 575 ), 576 Swansea=dict( 577 mono=False, 578 fscale=0.75, 579 lspacing=0.2, 580 hspacing=1, 581 dotsep="~×", 582 islocal=False, 583 ), 584 Housekeeper=dict( # supports chinese glyphs 585 mono=False, 586 fscale=0.75, 587 hspacing=1, 588 lspacing=0.2, 589 dotsep="~×", 590 islocal=False, 591 ), 592 Wananti=dict( # supports chinese glyphs 593 mono=False, 594 fscale=0.75, 595 hspacing=1, 596 lspacing=0.2, 597 dotsep="~x", 598 islocal=False, 599 ), 600 AnimeAce=dict( 601 mono=False, 602 fscale=0.75, 603 hspacing=1, 604 lspacing=0.2, 605 dotsep="~x", 606 islocal=False, 607 ), 608 Antares=dict( 609 mono=True, 610 fscale=0.8, 611 hspacing=1, 612 lspacing=0.1, 613 dotsep="×", 614 islocal=False, 615 ), 616 Archistico=dict( 617 mono=False, 618 fscale=0.75, 619 lspacing=0.2, 620 hspacing=0.75, 621 dotsep="~×", 622 islocal=False, 623 ), 624 KazyCase=dict( 625 mono=True, 626 fscale=0.8, 627 hspacing=1.2, 628 lspacing=0.1, 629 dotsep="×", 630 islocal=False, 631 ), 632 Roboto=dict( 633 mono=True, 634 fscale=0.8, 635 hspacing=1, 636 lspacing=0.1, 637 dotsep="×", 638 islocal=False, 639 ), 640 )
def
values(self) -> list:
680 def values(self) -> list: 681 """Return all values""" 682 return [getattr(self, key) for key in self.__slots__]
Return all values
def
items(self) -> list:
684 def items(self) -> list: 685 """Return all items""" 686 return [(key, getattr(self, key)) for key in self.__slots__]
Return all items
def
reset(self) -> None:
688 def reset(self) -> None: 689 """Reset all settings to their default status.""" 690 self.__init__()
Reset all settings to their default status.
def
init_colab(self, enable_k3d=True) -> None:
693 def init_colab(self, enable_k3d=True) -> None: 694 """ 695 Initialize colab environment 696 """ 697 print("setting up colab environment (can take a minute) ...", end="") 698 699 res = os.system("which Xvfb") 700 if res: 701 os.system("apt-get install xvfb") 702 703 os.system("pip install pyvirtualdisplay") 704 705 from pyvirtualdisplay import Display 706 Display(visible=0).start() 707 708 if enable_k3d: 709 os.system("pip install k3d") 710 711 from google.colab import output 712 output.enable_custom_widget_manager() 713 714 if enable_k3d: 715 import k3d 716 try: 717 print("installing k3d...", end="") 718 os.system("jupyter nbextension install --py --user k3d") 719 os.system("jupyter nbextension enable --py --user k3d") 720 k3d.switch_to_text_protocol() 721 self.default_backend = "k3d" 722 self.backend_autoclose = False 723 except: 724 print("(FAILED) ... ", end="") 725 726 print(" setup completed.")
Initialize colab environment
def
start_xvfb(self) -> None:
729 def start_xvfb(self) -> None: 730 """ 731 Start xvfb. 732 733 Xvfb or X virtual framebuffer is a display server implementing 734 the X11 display server protocol. In contrast to other display servers, 735 Xvfb performs all graphical operations in virtual memory 736 without showing any screen output. 737 """ 738 print("starting xvfb (can take a minute) ...", end="") 739 res = os.system("which Xvfb") 740 if res: 741 os.system("apt-get install xvfb") 742 os.system("set -x") 743 os.system("export DISPLAY=:99.0") 744 os.system("Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &") 745 os.system("sleep 3") 746 os.system("set +x") 747 os.system('exec "$@"') 748 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.