Skip to content

3. Set or alter the object properties

Full example code: examples/visualization/visualization_step_3.py

To get a full overview of all possible attributes and setter methods of an object, you can print out the __setters__ attribute.

# Overview of all surface properties we can set.
print(SurfaceBuilder.__setters__)
[
    'set_polydata',
    'set_properties',
    'set_edges',
    'set_opacity',
    'set_scale',
    'set_scalars',
    'set_scalar_min',
    'set_scalar_max',
    'set_scalar_range',
    'set_cell_scalars'
]

On top of our previously defined vertices and elements of our cube, we now add an array of scalars as value for each vertex.

import numpy as np

scalars = np.array([1, 2, 3, 4, 8, 7, 6, 5])
from dgmr.visualization.renderer import Plot, Subplots
from dgmr.visualization import SurfaceBuilder

# Create our cube object
cube_color = (
    SurfaceBuilder(vertices, quads)
    .set_scalars(scalars, cmap="hsv")
    .set_opacity(.9)
    .set_scale(.95)
    .set_edges(True, line_width=3)
)

plot = Plot(640, 480)
plot.renderer.add_object(cube_color)
plot.start()

Syntax

Depending on personal preference, you have several options to call methods and set object properties.

Chained methods

cube_color = (
    SurfaceBuilder(vertices, quads)
    .set_scalars(scalars, cmap="hsv")
    .set_opacity(.9)
    .set_scale(.95)
)

Verbose

cube_color = SurfaceBuilder(vertices, quads)
cube_color.set_scalars(scalars, cmap="hsv")
cube_color.set_opacity(.9)
cube_color.set_scale(.95)

Using property dictionary

cube_properties = {
    "scalars": scalars,
    "opacity": .9,
    "scale": .95
}
cube_color = SurfaceBuilder(vertices, quads).set_properties(cube_properties)

← Previous: Add an object to your plot Next: Object overview →