Factory

Creating a Factory

The Factory is an easy user interface to create and update visual objects such as meshes, point-clouds, etc. The Factory will also automatically store each object in a dedicated Table of a Database. Thus, it requires a Database to connect to (by default, a new Database is created, but an exiting one can be specified):

from SSD.Core import UserAPI

factory = UserAPI(database_dir='my_directory',
                  database_name='my_database',
                  remove_existing=True)

Adding an object to the Factory

The Factory provides a specific method to create each of the available objects with add_<object>. These methods allow to highly customize the objects rendering style. Each object will have a unique identifier in the factory, following the order of creation:

# Adding a mesh
idx = factory.add_mesh(positions=position_array,
                       cells=cells_array)
print(idx)
"""
>> 0
"""

# Adding a point-cloud
idx = factory.add_points(positions=position_array)
print(idx)
"""
>> 1
"""

Updating an object in the Factory

The Factory also provides a specific method to update each of the available objects with update_<object>. Object state and some rendering options can be updated depending on the object. It is important to specify the right identifier in the factory (identifiers follow the order of creation):

# Updating a mesh
factory.update_mesh(object_id=0,
                    positions=updated_position_array)

# Updating a point-cloud
factory.update_points(object_id=1,
                      positions=updated_position_array)

Note

You can update a single object several times per time step, meaning that the same raw of data in the Table will be modified. A call to render will synchronize Tables and a new row will be edited next (see Visualizer).

Available objects

The Factory allows to create several visual object types. The visualization data to provide does not depend on the Visualizer you will use.

Mesh

Field

Type

Init

Update

Description

positions

ndarray

Required

Optional

List of vertices. Updated position vector must always have the same size.

cells

ndarray

Required

Disabled

List of connections between vertices.

at

int

Optional

Disabled

Sub-window in which the Mesh will be rendered.

alpha

float

Optional

Optional

Opacity of the Mesh between 0 and 1.

c

str

Optional

Optional

Uniform color of the Mesh.

colormap

str

Optional

Disabled

Name of the color palette that maps a color to a scalar value.

scalar_field

ndarray

Optional

Optional

List of scalar values to define color based on the colormap.

wireframe

bool

Optional

Optional

Specifies if the Mesh should be rendered as wireframe.

line_width

float

Optional

Optional

Width of the edges.

Example

factory.add_mesh(positions=pos_array,
                 cells=cells_array,
                 color_map='jet',
                 scalar_field=pos_array[:, 1],
                 wireframe=True,
                 line_width=1.)
vedo_visualizer_mesh.png

Points

Field

Type

Init

Update

Description

positions

ndarray

Required

Optional

List of vertices. Updated position vector must always have the same size.

at

int

Optional

Disabled

Sub-window in which the Points will be rendered.

alpha

float

Optional

Optional

Opacity of the Points between 0 and 1.

c

str

Optional

Optional

Uniform color of the Points.

colormap

str

Optional

Disabled

Name of the color palette that maps a color to a scalar value.

scalar_field

ndarray

Optional

Optional

List of scalar values to define color based on the colormap.

point_size

float

Optional

Optional

Size of the Points.

Example

factory.add_points(positions=pos_array,
                   color_map='jet',
                   scalar_field=pos_array[:, 1],
                   point_size=5)
vedo_visualizer_points.png

Arrows

Field

Type

Init

Update

Description

positions

ndarray

Required

Optional

List of starting positions of the Arrows.

vectors

ndarray

Required

Optional

List of vectors defining the Arrows.

at

int

Optional

Disabled

Sub-window in which the Arrows will be rendered.

alpha

float

Optional

Optional

Opacity of the Arrows between 0 and 1.

c

str

Optional

Optional

Uniform color of the Arrows.

colormap

str

Optional

Disabled

Name of the color palette that maps a color to a scalar value.

scalar_field

ndarray

Optional

Optional

List of scalar values to define color based on the colormap.

res

int

Optional

Disabled

Circular resolution of the Arrows.

Example

factory.add_arrows(positions=pos_array,
                   vectors=vec_array,
                   c='green',
                   res=15)
vedo_visualizer_arrows.png

Markers

Field

Type

Init

Update

Description

normal_to

int

Required

Optional

Index of the object in the Factory on which the Markers will be rendered (Mesh or Points).

indices

ndarray

Required

Optional

Indices of the vertices on which the Markers will be rendered.

at

int

Optional

Disabled

Sub-window in which the Markers will be rendered.

alpha

float

Optional

Optional

Opacity of the Markers between 0 and 1.

c

str

Optional

Optional

Uniform color of the Markers.

colormap

str

Optional

Disabled

Name of the color palette that maps a color to a scalar value.

scalar_field

ndarray

Optional

Optional

List of scalar values to define color based on the colormap.

symbol

str

Optional

Optional

Symbol of the Markers.

size

float

Optional

Optional

Size of the Markers.

filled

bool

Optional

Optional

Specifies whether the symbols should be filled or not.

Example

factory.add_markers(normal_to=0,
                    indices=[0, 15, 35],
                    c='red',
                    symbol='0')
vedo_visualizer_markers.png

Text

Field

Type

Init

Update

Description

content

str

Required

Optional

Content of the Text.

at

int

Optional

Disabled

Sub-window in which the Text will be rendered.

corner

str

Optional

Disabled

Horizontal and vertical positions of the Text between T (top), M (middle), B (bottom), R (right), L (left).

c

str

Optional

Optional

Uniform color of the Text.

font

str

Optional

Disabled

Font of the Text.

size

int

Optional

Disabled

Size of the Text.

bold

bool

Optional

Optional

Apply bold style to the Text.

italic

bool

Optional

Optional

Apply italic style to the Text.

Example

factory.add_text(content='SSD',
                 corner='TM',
                 c='black',
                 bold=True)