• System

Wrapper helpers

By: SKY ENGINE AI
scroll down ↓to find out morewrapper-helpers_3_resourcesTutorial

Wrapper Helpers

In this example you are going to learn the use of wrapper functions that wrap up frequently repeated code.
In SkyRenderer tutorials these activities are handled under the hood inside SceneComposer class.
In this tutorial we will handle them explicitly.

Agenda:

  • Logging in SkyRenderer
  • Obtaining root paths
  • Display Configuration
  • Renders Visualization

Logging in SkyRenderer

SkyRenderer contains a wrapper function configure_logger that returns a preconfigured logger object suited for
rendering environment. The default log level is set to INFO.

    from skyrenderer.core.logger_config import configure_logger
    logger = configure_logger()
    logger.info("Logging in SkyRenderer")
2025-01-29 13:56:05,626 | skyrenderer |  INFO: Logging in SkyRenderer

Obtaining root paths

Root paths config is a dictionary containing information about the root directories of assets and cache.
We can access the default paths used in SkyEngine Platform environment by invoking get_skyengine_root_paths wrapper.
The returned config must be passed to the RendererContext constructor.

    from skyrenderer.utils.tutorial_config import get_skyengine_root_paths
    from skyrenderer.scene.renderer_context import RendererContext
    root_paths_config = {
        "assets_root": "/dli/mount/assets",
        "cache_root": "/dli/mount/cache",
        "gpu_sources_root": None,
        "config_root": None,
    }
    root_paths_config = get_skyengine_root_paths()
    renderer_context = RendererContext(root_paths_config)
2025-01-29 13:56:10,219 | skyrenderer.scene.renderer_context |  INFO: Root paths:
- root path: /dli/skyenvironment/skyrenderer/skyrenderer
- assets path: /dli/mount/assets
- config path: /dli/skyenvironment/skyrenderer/skyrenderer/config
- gpu sources path: /dli/skyenvironment/skyrenderer/skyrenderer/optix_sources/sources
- cache path: /dli/mount/cache
- ptx cache path: compiled_ptx/ptx
- ocio path: ocio_configs/aces_1.2/config.ocio

Display Config

In order to specify Display Config in an explicit way, we should specify a number of parameters.

    from skyrenderer.example_assistant.display_config import DisplayConfig
    from skyrenderer.example_assistant.visualization_settings import (
        VisualizationDestination,
        VisualizedOutput,
        PictureFileFormat,
        MovieFileFormat,
    )
    display_config = DisplayConfig(
        visualization_destination=VisualizationDestination.DISPLAY,
        visualized_outputs=(VisualizedOutput.RENDER,),
        picture_file_format=PictureFileFormat.PNG,
        movie_file_format=MovieFileFormat.MP4,
        output_files_path="visualization_files",
        output_files_subdirs=None,
        output_files_name=None,
        fps=1,
        cv_waitkey=0,
    )

We can also use create_display_config wrapper to get the same config. There are other wrappers
for getting default configs for other Visualization Destinations:

  • create_display_config,
  • create_display_config,
  • create_movie_config.
    display_config = DisplayConfig.create_display_config()

Renders Visualization

ExampleAssistant is a class that provides wrappers for render visualization. Let's pass renderer_context and
display_config to create its instance. Firstly we will demonstrate the explicit setup of the scene using
the renderer context and visualization.

We can do the same actions using a wrapper - visualize function.
visualize function takes 2 arguments: example assistant and render output.
We can obtain render output using 2 wrappers: generate_renders and generate_renders_with_setup.
generate_renders_with_setup performs the same operations as generate_renders, additionally it calls the setup
function of the renderer_context before the rendering process.

    from skyrenderer.example_assistant.example_assistant import ExampleAssistant
    from skyrenderer.utils.visualization_helper import visualize, generate_renders_with_setup, generate_renders
    example_assistant = ExampleAssistant(context=renderer_context, display_config=display_config)
    renderer_context.setup()
    logger.info(f"Scene\n{str(renderer_context)}")
    with example_assistant.get_visualizer() as visualizer:
        visualizer(renderer_context.render_to_numpy())
wrapper-helpers_1_resourcesTutorial
2025-01-29 13:56:10,394 | skyrenderer.scene.renderer_context |  WARNING: Scene layout "user_defined" is empty - using default

2025-01-29 13:56:10,404 | skyrenderer.websocket_service.websocket_event_loop |  INFO: Websocket connection with backend opened

2025-01-29 13:56:10,845 | skyrenderer.utils.time_measurement |  INFO: Setup time: 566 ms

2025-01-29 13:56:10,847 | skyrenderer |  INFO: Scene

scene_tree: 
top_node (NO_CLASS; count: 1)
|-- sphere_GEO (NO_CLASS; count: 1)
|-- camera_CAM (NO_CLASS; count: 1)
|-- camera_target_NUL (NO_CLASS; count: 1)
+-- light_LIGHT_NUL (NO_CLASS; count: 1)


2025-01-29 13:56:10,952 | skyrenderer.utils.time_measurement |  INFO: Context update time: 104 ms

2025-01-29 13:56:14,519 | skyrenderer.utils.time_measurement |  INFO: Key points calculation time: 0 ms

2025-01-29 13:56:14,520 | skyrenderer.utils.time_measurement |  INFO: Render time: 3.57 seconds

    visualize(example_assistant, generate_renders(renderer_context))
wrapper-helpers_2_resourcesTutorial
2025-01-29 13:56:14,794 | skyrenderer.utils.time_measurement |  INFO: Context update time: 6 ms

2025-01-29 13:56:15,253 | skyrenderer.utils.time_measurement |  INFO: Key points calculation time: 0 ms

2025-01-29 13:56:15,255 | skyrenderer.utils.time_measurement |  INFO: Render time: 458 ms

    renderer_context.clear()
    visualize(example_assistant, generate_renders_with_setup(renderer_context, logger=logger))
wrapper-helpers_3_resourcesTutorial
2025-01-29 13:56:30,647 | skyrenderer.scene.renderer_context |  WARNING: Scene layout "user_defined" is empty - using default

2025-01-29 13:56:30,661 | skyrenderer.websocket_service.websocket_event_loop |  INFO: Websocket connection with backend opened

2025-01-29 13:56:30,722 | skyrenderer.utils.time_measurement |  INFO: Setup time: 195 ms

2025-01-29 13:56:30,722 | skyrenderer |  INFO: Scene

scene_tree: 
top_node (NO_CLASS; count: 1)
|-- sphere_GEO (NO_CLASS; count: 1)
|-- camera_CAM (NO_CLASS; count: 1)
|-- camera_target_NUL (NO_CLASS; count: 1)
+-- light_LIGHT_NUL (NO_CLASS; count: 1)


2025-01-29 13:56:30,812 | skyrenderer.utils.time_measurement |  INFO: Context update time: 89 ms

2025-01-29 13:56:31,253 | skyrenderer.utils.time_measurement |  INFO: Key points calculation time: 0 ms

2025-01-29 13:56:31,255 | skyrenderer.utils.time_measurement |  INFO: Render time: 443 ms

Summary

In this section you have learnt:

  • You can simplify many repetitive operations using wrapper helpers.
  • In the tutorial code, activities such as setting root paths, display config or visualizing are handled in
    SceneComposer class. In production code we will have to do them either by specifying them explicitly, or by
    using wrappers.