Basic Scene¶
This example shows the smallest scene with a point visual.
Preview¶
Run And Adapt¶
Commands below assume a Datoviz source checkout and start at the repository root. Use your configured build environment; Python routes additionally require local bindings.
| Route | Availability | Command or action |
|---|---|---|
| C | Canonical native source | just example-c features/basic_scene (build and run), or rerun ./build/examples/c/features/basic_scene |
| Python | Available; manually maintained direct-engine example | python3 -m examples.python.gallery.features.basic_scene |
| Browser | Live WebGPU route | Open live example |
This example is approved as a starting point for user code and coding agents. Keep the object lifetimes and data shapes intact while adapting the data and styling.
What To Look For¶
A scene owns one figure, one full panel, and one point visual. The point visual uploads position, color, and diameter_px arrays for three markers, then disables depth testing for a flat 2D preview. This is the baseline pattern for beginner examples: create the scene objects, upload attribute arrays, style the visual, and attach it to a panel.
Source¶
#!/usr/bin/env python3
"""Smallest retained scene with one point visual."""
from __future__ import annotations
import numpy as np
import datoviz as dvz
from examples.python.gallery import common as ex
def main() -> None:
scene, figure, panel = ex.scene_panel()
point = dvz.dvz_point(scene, 0)
if not point:
raise RuntimeError("dvz_point() failed")
positions = np.array(
[[-0.45, -0.25, 0.0], [0.00, 0.34, 0.0], [0.45, -0.25, 0.0]],
dtype=np.float32,
)
colors = ex.color_array(ex.CYAN, ex.GREEN, ex.YELLOW)
diameters = np.array([42.0, 58.0, 42.0], dtype=np.float32)
dvz.dvz_visual_set_data_many(
point,
{
"position": positions,
"color": colors,
"diameter_px": diameters,
},
)
ex.set_filled_point_style(point)
dvz.dvz_visual_set_depth_test(point, False)
ex.add_visual(panel, point)
ex.run(scene, figure, "Basic Scene")
if __name__ == "__main__":
main()
/*
* Copyright (c) 2021 Cyrille Rossant and contributors. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project root for details.
* SPDX-License-Identifier: MIT
*/
/* basic_scene - This example shows the smallest retained scene with a point visual.
*
* Scenario: features_basic_scene
* Style: features, graphite_cyan, 1280x720 window target
*
* Build: just example-c features/basic_scene
* Run: ./build/examples/c/features/basic_scene --live
* Smoke: ./build/examples/c/features/basic_scene --png
*
* What to look for: a scene owns one figure, one full panel, and one point visual. The point visual
* uploads position, color, and diameter_px arrays for three markers, then disables depth testing
* for a flat 2D preview. This is the baseline pattern for beginner examples: create the scene
* objects, upload attribute arrays, style the visual, and attach it to a panel.
*/
/*************************************************************************************************/
/* Includes */
/*************************************************************************************************/
#include <stdbool.h>
#include <stdint.h>
#include "datoviz/scene.h"
#include "example_style.h"
#include "runner/scenario_runner.h"
DvzScenarioSpec dvz_example_basic_scene_scenario(void);
/*************************************************************************************************/
/* Constants */
/*************************************************************************************************/
#define WIDTH EXAMPLE_WINDOW_WIDTH
#define HEIGHT EXAMPLE_WINDOW_HEIGHT
#define POINT_COUNT 3u
/*************************************************************************************************/
/* Scenario callbacks */
/*************************************************************************************************/
/**
* Initialize the smallest retained scene scenario.
*
* @param ctx scenario context
* @param out_user scenario state output
* @return true on success
*/
static bool _scenario_init(DvzScenarioContext* ctx, void** out_user)
{
if (ctx == NULL)
return false;
if (out_user != NULL)
*out_user = NULL;
const vec3 positions[POINT_COUNT] = {
{-0.45f, -0.25f, 0.0f},
{+0.00f, +0.34f, 0.0f},
{+0.45f, -0.25f, 0.0f},
};
DvzColor colors[POINT_COUNT] = {
example_graphite_cyan_color(EXAMPLE_STYLE_COLOR_ACCENT_PRIMARY),
example_graphite_cyan_color(EXAMPLE_STYLE_COLOR_ACCENT_SECONDARY),
example_graphite_cyan_color(EXAMPLE_STYLE_COLOR_WARNING),
};
const float diameters[POINT_COUNT] = {42.0f, 58.0f, 42.0f};
ctx->figure = dvz_figure(ctx->scene, ctx->width, ctx->height, 0);
if (ctx->figure == NULL)
return false;
DvzPanel* panel = dvz_panel_full(ctx->figure);
if (panel == NULL)
return false;
example_graphite_cyan_set_panel_background(panel);
DvzVisual* point = dvz_point(ctx->scene, 0);
if (point == NULL)
return false;
DvzVisualDataUpdate updates[] = {
{.attr_name = "position", .data = positions, .item_count = POINT_COUNT},
{.attr_name = "color", .data = colors, .item_count = POINT_COUNT},
{.attr_name = "diameter_px", .data = diameters, .item_count = POINT_COUNT},
};
if (dvz_visual_set_data_many(point, updates, 3) != 0)
return false;
DvzPointStyleDesc style = dvz_point_style_desc();
style.aspect = DVZ_SHAPE_ASPECT_FILLED;
style.stroke_width_px = 0.0f;
if (dvz_point_set_style(point, &style) != 0)
return false;
if (dvz_visual_set_depth_test(point, false) != 0)
return false;
return dvz_panel_add_visual(panel, point, NULL) == 0;
}
/**
* Return the scene-basic scenario specification.
*
* @return scenario specification
*/
DvzScenarioSpec dvz_example_basic_scene_scenario(void)
{
return (DvzScenarioSpec){
.id = "features_basic_scene",
.title = "Basic Scene",
.width = WIDTH,
.height = HEIGHT,
.fps = 60.0,
.requirements = DVZ_SCENARIO_REQ_POINT_VISUAL,
.init = _scenario_init,
};
}
/*************************************************************************************************/
/* Functions */
/*************************************************************************************************/
/**
* Run the smallest retained scene feature example through the native scenario runner.
*
* @param argc command-line argument count
* @param argv command-line argument vector
* @return process exit code
*/
#ifndef DVZ_EXAMPLE_NO_MAIN
int main(int argc, char** argv)
{
DvzScenarioSpec spec = dvz_example_basic_scene_scenario();
return dvz_scenario_run_native_cli(&spec, argc, argv) == 0 ? 0 : 1;
}
#endif
Example details
- ID:
features_basic_scene - Category:
feature - Lane:
features - Status:
supported - Source:
examples/c/features/basic_scene.c - Approved adaptation starter:
yes - Python source:
examples/python/gallery/features/basic_scene.py - Python adaptation: Available; manually maintained direct-engine example
- Browser support: Live in browser
- WebGPU live route:
examples/webgpu/live.html?id=features_basic_scene - Browser capability tags:
point - Validation:
smoke+screenshot
Data
| Field | Value |
|---|---|
kind |
synthetic |
