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

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"
# Alternatively set the environment variable VEDO_CACHE_DIR
# to change the cache directory for all vedo scripts.
# Note that "/vedo" is appended automatically to the path.

# Palette number when using an integer to choose a color
palette = 0

# Options for saving window screenshots:
screenshot_transparent_background = False
screeshot_large_image = False # sometimes setting this to True gives better results

# Enable tracking pipeline functionality:
# allows to show a graph with the pipeline of action which let to a final object
# this is achieved by calling "myobj.pipeline.show()" (a new window will pop up)
self.enable_pipeline = True

# Remember the last format used when creating new figures in vedo.pyplot
# this is useful when creating multiple figures of the same kind
# and avoid to specify the format each time in plot(..., like=...)
remember_last_figure_format = False

# Set up default mouse and keyboard callbacks
enable_default_mouse_callbacks = True
enable_default_keyboard_callbacks = True

# Force single precsion of points coordinates.
# Useful for very large point clouds and meshes. Default is True.
force_single_precision_points = True

# Progress bar delay before showing up [sec]
progressbar_delay = 0.5

# If False, when multiple renderers are present, render only once at the end
immediate_rendering = True

# In multirendering mode, show a grey frame margin (set width=0 to disable)
renderer_frame_color = None
renderer_frame_alpha = 0.5
renderer_frame_width = 0.5
renderer_frame_padding = 0.001

# 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_visible  = None    # None (default behavior) or True, False
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()
241    def __init__(self) -> None:
242
243        self.default_backend = "vtk"
244        try:
245            # adapted from: https://stackoverflow.com/a/39662359/2912349
246            shell = get_ipython().__class__.__name__ # type: ignore
247            if shell == 'ZMQInteractiveShell':
248                self.default_backend = "2d"
249        except NameError:
250            pass
251
252        self.default_font = "Normografo"
253
254        self.enable_pipeline = True
255        self.progressbar_delay = 0.5
256        self.palette = 0
257        self.remember_last_figure_format = False
258
259        self.force_single_precision_points = True
260
261        # check if environment variable VEDO_CACHE_DIR is set
262        if "VEDO_CACHE_DIR" in os.environ:
263            self.cache_directory = os.environ["VEDO_CACHE_DIR"]
264        else:
265            self.cache_directory = ".cache"  # "/vedo" is appended automatically
266
267        self.screenshot_transparent_background = False
268        self.screeshot_large_image = False
269
270        self.enable_default_mouse_callbacks = True
271        self.enable_default_keyboard_callbacks = True
272        self.immediate_rendering = True
273
274        self.renderer_frame_color = None
275        self.renderer_frame_alpha = 0.5
276        self.renderer_frame_width = 0.5
277        self.renderer_frame_padding = 0.0001
278        self.background_gradient_orientation = 0
279
280        self.point_smoothing = False
281        self.line_smoothing = False
282        self.polygon_smoothing = False
283
284        self.light_follows_camera = False
285        self.two_sided_lighting = True
286
287        self.use_depth_peeling = False
288        self.multi_samples = 8
289        self.alpha_bit_planes = 1
290        self.max_number_of_peels = 4
291        self.occlusion_ratio = 0.1
292
293        self.use_fxaa = False
294
295        self.preserve_depth_buffer = False
296
297        self.use_polygon_offset = True
298        self.polygon_offset_factor = 0.1
299        self.polygon_offset_units = 0.1
300
301        self.interpolate_scalars_before_mapping = True
302
303        self.use_parallel_projection = False
304
305        self.window_splitting_position = None
306
307        self.tiff_orientation_type = 1
308
309        self.annotated_cube_color = (0.75, 0.75, 0.75)
310        self.annotated_cube_text_color = None
311        self.annotated_cube_text_scale = 0.2
312        self.annotated_cube_texts = ["right", "left ", "front", "back ", " top ", "bttom"]
313
314        self.enable_print_color = True
315
316        self.backend_autoclose = True
317
318        self.k3d_menu_visibility = True
319        self.k3d_plot_height = 512
320        self.k3d_antialias   = True
321        self.k3d_lighting    = 1.5
322        self.k3d_camera_autofit = True
323        self.k3d_grid_visible = None
324        self.k3d_grid_autofit= True
325        self.k3d_axes_color  = "k4"
326        self.k3d_axes_helper = 1.0
327        self.k3d_point_shader= "mesh"
328        self.k3d_line_shader = "thick"
329
330        self.font_parameters = dict(
331
332            Normografo=dict(
333                mono=False,
334                fscale=0.75,
335                hspacing=1,
336                lspacing=0.2,
337                dotsep="~×",
338                islocal=True,
339            ),
340            Bongas=dict(
341                mono=False,
342                fscale=0.875,
343                hspacing=0.52,
344                lspacing=0.25,
345                dotsep="·",
346                islocal=True,
347            ),
348            Calco=dict(
349                mono=True,
350                fscale=0.8,
351                hspacing=1,
352                lspacing=0.1,
353                dotsep="×",
354                islocal=True,
355            ),
356            Comae=dict(
357                mono=False,
358                fscale=0.75,
359                lspacing=0.2,
360                hspacing=1,
361                dotsep="~×",
362                islocal=True,
363            ),
364            ComicMono=dict(
365                mono=True,
366                fscale=0.8,
367                hspacing=1,
368                lspacing=0.1,
369                dotsep="x",
370                islocal=False,
371            ),
372            Edo=dict(
373                mono=False,
374                fscale=0.75,
375                hspacing=1,
376                lspacing=0.2,
377                dotsep="~x ",
378                islocal=False,
379            ),
380            FiraMonoMedium=dict(
381                mono=True,
382                fscale=0.8,
383                hspacing=1,
384                lspacing=0.1,
385                dotsep="×",
386                islocal=False,
387            ),
388            FiraMonoBold=dict(
389                mono=True,
390                fscale=0.8,
391                hspacing=1,
392                lspacing=0.1,
393                dotsep="×",
394                islocal=False,
395            ),
396            Glasgo=dict(
397                mono=True,
398                fscale=0.75,
399                lspacing=0.1,
400                hspacing=1,
401                dotsep="~×",
402                islocal=True,
403            ),
404            Kanopus=dict(
405                mono=False,
406                fscale=0.75,
407                lspacing=0.15,
408                hspacing=0.75,
409                dotsep="~×",
410                islocal=True,
411            ),
412            LogoType=dict(
413                mono=False,
414                fscale=0.75,
415                hspacing=1,
416                lspacing=0.2,
417                dotsep="~×",
418                islocal=False,
419            ),
420            Quikhand=dict(
421                mono=False,
422                fscale=0.8,
423                hspacing=0.6,
424                lspacing=0.15,
425                dotsep="~~×~",
426                islocal=True,
427            ),
428            SmartCouric=dict(
429                mono=True,
430                fscale=0.8,
431                hspacing=1.05,
432                lspacing=0.1,
433                dotsep="×",
434                islocal=True,
435            ),
436            Spears=dict(
437                mono=False,
438                fscale=0.8,
439                hspacing=0.5,
440                lspacing=0.2,
441                dotsep="~×",
442                islocal=False,
443            ),
444            Theemim=dict(
445                mono=False,
446                fscale=0.825,
447                hspacing=0.52,
448                lspacing=0.3,
449                dotsep="~~×",
450                islocal=True,
451            ),
452            VictorMono=dict(
453                mono=True,
454                fscale=0.725,
455                hspacing=1,
456                lspacing=0.1,
457                dotsep="×",
458                islocal=True,
459            ),
460            Justino1=dict(
461                mono=True,
462                fscale=0.725,
463                hspacing=1,
464                lspacing=0.1,
465                dotsep="×",
466                islocal=False,
467            ),
468            Justino2=dict(
469                mono=True,
470                fscale=0.725,
471                hspacing=1,
472                lspacing=0.1,
473                dotsep="×",
474                islocal=False,
475            ),
476            Justino3=dict(
477                mono=True,
478                fscale=0.725,
479                hspacing=1,
480                lspacing=0.1,
481                dotsep="×",
482                islocal=False,
483            ),
484            Calibri=dict(
485                mono=False,
486                fscale=0.75,
487                hspacing=1,
488                lspacing=0.2,
489                dotsep="~×",
490                islocal=False,
491            ),
492            Capsmall=dict(
493                mono=False,
494                fscale=0.8,
495                hspacing=0.75,
496                lspacing=0.15,
497                dotsep="~×",
498                islocal=False,
499            ),
500            Cartoons123=dict(
501                mono=False,
502                fscale=0.8,
503                hspacing=0.75,
504                lspacing=0.15,
505                dotsep="x",
506                islocal=False,
507            ),
508            Darwin=dict(
509                mono=False,
510                fscale=0.8,
511                hspacing=0.75,
512                lspacing=0.15,
513                dotsep="x",
514                islocal=False,
515            ),
516            Vega=dict(
517                mono=False,
518                fscale=0.8,
519                hspacing=0.75,
520                lspacing=0.15,
521                dotsep="×",
522                islocal=False,
523            ),
524            Meson=dict(
525                mono=False,
526                fscale=0.8,
527                hspacing=0.9,
528                lspacing=0.225,
529                dotsep="~×",
530                islocal=False,
531            ),
532            Komika=dict(
533                mono=False,
534                fscale=0.7,
535                hspacing=0.75,
536                lspacing=0.225,
537                dotsep="~×",
538                islocal=False,
539            ),
540            Brachium=dict(
541                mono=True,
542                fscale=0.8,
543                hspacing=1,
544                lspacing=0.1,
545                dotsep="x",
546                islocal=False,
547            ),
548            Dalim=dict(
549                mono=False,
550                fscale=0.75,
551                lspacing=0.2,
552                hspacing=1,
553                dotsep="~×",
554                islocal=False,
555            ),
556            Miro=dict(
557                mono=False,
558                fscale=0.75,
559                lspacing=0.2,
560                hspacing=1,
561                dotsep="~×",
562                islocal=False,
563            ),
564            Ubuntu=dict(
565                mono=False,
566                fscale=0.75,
567                lspacing=0.2,
568                hspacing=1,
569                dotsep="~×",
570                islocal=False,
571            ),
572            Mizar=dict(
573                mono=False,
574                fscale=0.75,
575                lspacing=0.2,
576                hspacing=0.75,
577                dotsep="~×",
578                islocal=False,
579            ),
580            LiberationSans=dict(
581                mono=False,
582                fscale=0.75,
583                lspacing=0.2,
584                hspacing=1,
585                dotsep="~×",
586                islocal=False,
587            ),
588            DejavuSansMono=dict(
589                mono=True,
590                fscale=0.725,
591                hspacing=1,
592                lspacing=0.1,
593                dotsep="~×",
594                islocal=False,
595            ),
596            SunflowerHighway=dict(
597                mono=False,
598                fscale=0.75,
599                lspacing=0.2,
600                hspacing=1,
601                dotsep="~×",
602                islocal=False,
603            ),
604            Swansea=dict(
605                mono=False,
606                fscale=0.75,
607                lspacing=0.2,
608                hspacing=1,
609                dotsep="~×",
610                islocal=False,
611            ),
612            Housekeeper=dict(  # supports chinese glyphs
613                mono=False,
614                fscale=0.75,
615                hspacing=1,
616                lspacing=0.2,
617                dotsep="~×",
618                islocal=False,
619            ),
620            Wananti=dict(  # supports chinese glyphs
621                mono=False,
622                fscale=0.75,
623                hspacing=1,
624                lspacing=0.2,
625                dotsep="~x",
626                islocal=False,
627            ),
628            AnimeAce=dict(
629                mono=False,
630                fscale=0.75,
631                hspacing=1,
632                lspacing=0.2,
633                dotsep="~x",
634                islocal=False,
635            ),
636            Antares=dict(
637                mono=True,
638                fscale=0.8,
639                hspacing=1,
640                lspacing=0.1,
641                dotsep="×",
642                islocal=False,
643            ),
644            Archistico=dict(
645                mono=False,
646                fscale=0.75,
647                lspacing=0.2,
648                hspacing=0.75,
649                dotsep="~×",
650                islocal=False,
651            ),
652            KazyCase=dict(
653                mono=True,
654                fscale=0.8,
655                hspacing=1.2,
656                lspacing=0.1,
657                dotsep="×",
658                islocal=False,
659            ),
660            Roboto=dict(
661                mono=True,
662                fscale=0.8,
663                hspacing=1,
664                lspacing=0.1,
665                dotsep="×",
666                islocal=False,
667            ),
668        )
def keys(self) -> list:
704    def keys(self) -> list:
705        """Return all keys"""
706        return self.__slots__

Return all keys

def values(self) -> list:
708    def values(self) -> list:
709        """Return all values"""
710        return [getattr(self, key) for key in self.__slots__]

Return all values

def items(self) -> list:
712    def items(self) -> list:
713        """Return all items"""
714        return [(key, getattr(self, key)) for key in self.__slots__]

Return all items

def reset(self) -> None:
716    def reset(self) -> None:
717        """Reset all settings to their default status."""
718        self.__init__()

Reset all settings to their default status.

def init_colab(self, enable_k3d=True) -> None:
721    def init_colab(self, enable_k3d=True) -> None:
722        """
723        Initialize colab environment
724        """
725        print("setting up colab environment (can take a minute) ...", end="")
726
727        res = os.system("which Xvfb")
728        if res:
729            os.system("apt-get install xvfb")
730
731        os.system("pip install pyvirtualdisplay")
732
733        from pyvirtualdisplay import Display # type: ignore
734        Display(visible=0).start()
735
736        if enable_k3d:
737            os.system("pip install k3d")
738
739        from google.colab import output # type: ignore
740        output.enable_custom_widget_manager()
741
742        if enable_k3d:
743            import k3d
744            try:
745                print("installing k3d...", end="")
746                os.system("jupyter nbextension install --py --user k3d")
747                os.system("jupyter nbextension enable  --py --user k3d")
748                k3d.switch_to_text_protocol()
749                self.default_backend = "k3d"
750                self.backend_autoclose = False
751            except:
752                print("(FAILED) ... ", end="")
753
754        print(" setup completed.")

Initialize colab environment

@staticmethod
def start_xvfb() -> None:
757    @staticmethod
758    def start_xvfb() -> None:
759        """
760        Start xvfb.
761
762        Xvfb or X virtual framebuffer is a display server implementing
763        the X11 display server protocol. In contrast to other display servers,
764        Xvfb performs all graphical operations in virtual memory
765        without showing any screen output.
766        """
767        print("starting xvfb (can take a minute) ...", end="")
768        res = os.system("which Xvfb")
769        if res:
770            os.system("apt-get install xvfb")
771        os.system("set -x")
772        os.system("export DISPLAY=:99.0")
773        os.system("Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &")
774        os.system("sleep 3")
775        os.system("set +x")
776        os.system('exec "$@"')
777        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.

def clear_cache(self) -> None:
780    def clear_cache(self) -> None:
781        """Clear the cache directory."""
782        import shutil
783        try:
784            home_directory = os.path.expanduser("~")
785            cachedir = os.path.join(home_directory, self.cache_directory, "vedo")
786            shutil.rmtree(cachedir)
787            print(f"Cache directory '{cachedir}' cleared.")
788        except FileNotFoundError:
789            print(f"Cache directory '{cachedir}' not found.")
790            pass

Clear the cache directory.

def set_vtk_verbosity(self, level: int) -> None:
793    def set_vtk_verbosity(self, level: int) -> None:
794        """Set the verbosity level of VTK."""
795        from vtkmodules.vtkCommonCore import vtkLogger
796
797        levels = {
798            0: vtkLogger.VERBOSITY_ERROR,
799            1: vtkLogger.VERBOSITY_WARNING,
800            2: vtkLogger.VERBOSITY_INFO,
801        }
802        vtkLogger.SetStderrVerbosity(levels[level])

Set the verbosity level of VTK.