Skip to content

Data Containers

mouette is architectured around the concept of data containers, which are containers dedicated to the storage of one type of elements in a mesh and all of its attributes. Data structures in mouette are then defined as collections of specific data containers:

  • A PointCloud object only has one container named vertices such that object.vertices[i] is a 3D vector containing the position of vertex i in space.

  • In addition to the vertices container, a Polyline object also defines an edges container, which stores pairs of vertex indices.

  • A SurfaceMesh object adds the faces and face_corners containers.

  • Finally, a VolumeMesh objects adds a cells container and two corner containers: cell_corners and cell_faces.

The DataContainer class

Bases: _BaseDataContainer

A DataContainer is a container class for all elements of the same type in an instance (for example, vertices, edges or faces). It stores relevant information about the combinatorics (in the _data field) as well as various attributes onto the elements (in the _attr field)

size property

The container size. Alias for len(container)

Returns:

Name Type Description
int int

number of elements in the container

__iadd__(other)

Performs several appends for a list of elements

Parameters:

Name Type Description Default
other Iterable | DataContainer

a collection of elements to append to the container

required

Raises:

Type Description
Exception

fails if other is not an iterable

Returns:

Name Type Description
self

self

append(val)

Adds the value 'val' at the end of the container. Also expands all attributes to be able to receive a value for 'val'

Parameters:

Name Type Description Default
val Any

value to append to the container

required

clear()

Empty the container

create_attribute(name, data_type, elem_size=1, dense=False, default_value=None, size=None)

Creates an attribute with name name

Parameters:

Name Type Description Default
name str

attribute's name. If 'name' already exists in the attribute dict, the corresponding attribute will be overridden. The override warning can be disabled in the config.

required
data_type type

The type of data stored in the attribute.

required
elem_size int

The number of data per elements. Defaults to 1.

1
dense bool

Whether to create an Attribute object (dictionnary storage) or an ArrayAttribute object (numpy array storage). Defaults to False (dictionnary mode).

False
default_value Any

The default value to fill the attribute with. If not provided, will be taken as the default value of the type data_type. Defaults to None.

None
size int

Current size of the DataContainer to be passed. Defaults to None.

None

Returns:

Name Type Description
Attribute Attribute

delete_attribute(name)

Deletes the attribute associated with name name if it exists.

Parameters:

Name Type Description Default
name str

the attribute's name.

required

empty()

Returns:

Name Type Description
bool bool

whether the container is empty

get_attribute(name)

Returns the attribute with name name. Fails if the attribute does not exist

Parameters:

Name Type Description Default
name str

the attribute's name

required

Raises:

Type Description
Exception

no attribute has name name inside this data container.

Returns:

Name Type Description
Attribute Attribute

the attribute

has_attribute(name)

Returns True is an attribute with name name is defined for this container.

Parameters:

Name Type Description Default
name str

the attribute's name

required

Returns:

Name Type Description
bool bool

register_array_as_attribute(name, data, default_value=None)

Converts a numpy array as an attribute.

Parameters:

Name Type Description Default
name str

attribute's name. If 'name' already exists in the attribute dict, the corresponding attribute will be overridden. The override warning can be disabled in the config.

required
data ndarray

the data array. Type of the attribute will be extrapolated from data.dtype.

required
default_value Any

The default value to fill the attribute with. If not provided, will be taken as the default value of the type data_type. Defaults to None.

None

Bases: ABC

Base class for a data container. A container encapsulate all elements of the same type in a mesh as well as attributes defined on them.

create_attribute(name, data_type, elem_size=1, dense=False, default_value=None, size=None)

Creates an attribute with name name

Parameters:

Name Type Description Default
name str

attribute's name. If 'name' already exists in the attribute dict, the corresponding attribute will be overridden. The override warning can be disabled in the config.

required
data_type type

The type of data stored in the attribute.

required
elem_size int

The number of data per elements. Defaults to 1.

1
dense bool

Whether to create an Attribute object (dictionnary storage) or an ArrayAttribute object (numpy array storage). Defaults to False (dictionnary mode).

False
default_value Any

The default value to fill the attribute with. If not provided, will be taken as the default value of the type data_type. Defaults to None.

None
size int

Current size of the DataContainer to be passed. Defaults to None.

None

Returns:

Name Type Description
Attribute Attribute

delete_attribute(name)

Deletes the attribute associated with name name if it exists.

Parameters:

Name Type Description Default
name str

the attribute's name.

required

get_attribute(name)

Returns the attribute with name name. Fails if the attribute does not exist

Parameters:

Name Type Description Default
name str

the attribute's name

required

Raises:

Type Description
Exception

no attribute has name name inside this data container.

Returns:

Name Type Description
Attribute Attribute

the attribute

has_attribute(name)

Returns True is an attribute with name name is defined for this container.

Parameters:

Name Type Description Default
name str

the attribute's name

required

Returns:

Name Type Description
bool bool

register_array_as_attribute(name, data, default_value=None)

Converts a numpy array as an attribute.

Parameters:

Name Type Description Default
name str

attribute's name. If 'name' already exists in the attribute dict, the corresponding attribute will be overridden. The override warning can be disabled in the config.

required
data ndarray

the data array. Type of the attribute will be extrapolated from data.dtype.

required
default_value Any

The default value to fill the attribute with. If not provided, will be taken as the default value of the type data_type. Defaults to None.

None

The special case of corner containers

Bases: _BaseDataContainer

A CornerDataContainer is a variant of a DataContainer for corner elements. It is used for face corners, cell corners and cell faces.

Unlike a regular data container that stores a list of simplicial elements, a corner container stores two pieces of information: the associated vertex/face of the corner and the face/cell it belongs to.

size property

The container size. Alias for len(container)

Returns:

Name Type Description
int

number of elements in the container

__getitem__(key)

Shortcut for self.elem(key)

Parameters:

Name Type Description Default
key int

corner identifier

required

Returns:

Name Type Description
int int

the vertex or the face this corner points to

adj(key)

Returns the mesh element (either face or cell) from which the corner 'key' belongs to

Parameters:

Name Type Description Default
key int

identifier of a corner

required

Returns:

Name Type Description
int int

identifier of a face or a cell

clear()

Empty the container

create_attribute(name, data_type, elem_size=1, dense=False, default_value=None, size=None)

Creates an attribute with name name

Parameters:

Name Type Description Default
name str

attribute's name. If 'name' already exists in the attribute dict, the corresponding attribute will be overridden. The override warning can be disabled in the config.

required
data_type type

The type of data stored in the attribute.

required
elem_size int

The number of data per elements. Defaults to 1.

1
dense bool

Whether to create an Attribute object (dictionnary storage) or an ArrayAttribute object (numpy array storage). Defaults to False (dictionnary mode).

False
default_value Any

The default value to fill the attribute with. If not provided, will be taken as the default value of the type data_type. Defaults to None.

None
size int

Current size of the DataContainer to be passed. Defaults to None.

None

Returns:

Name Type Description
Attribute Attribute

delete_attribute(name)

Deletes the attribute associated with name name if it exists.

Parameters:

Name Type Description Default
name str

the attribute's name.

required

element(key)

Returns the mesh element (vertex or face) associated with the corner 'key'

Parameters:

Name Type Description Default
key int

identifier of a corner

required

Returns:

Name Type Description
int int

identifier of a vertex or face

empty()

Returns:

Name Type Description
bool

whether the container is empty

get_attribute(name)

Returns the attribute with name name. Fails if the attribute does not exist

Parameters:

Name Type Description Default
name str

the attribute's name

required

Raises:

Type Description
Exception

no attribute has name name inside this data container.

Returns:

Name Type Description
Attribute Attribute

the attribute

has_attribute(name)

Returns True is an attribute with name name is defined for this container.

Parameters:

Name Type Description Default
name str

the attribute's name

required

Returns:

Name Type Description
bool bool

register_array_as_attribute(name, data, default_value=None)

Converts a numpy array as an attribute.

Parameters:

Name Type Description Default
name str

attribute's name. If 'name' already exists in the attribute dict, the corresponding attribute will be overridden. The override warning can be disabled in the config.

required
data ndarray

the data array. Type of the attribute will be extrapolated from data.dtype.

required
default_value Any

The default value to fill the attribute with. If not provided, will be taken as the default value of the type data_type. Defaults to None.

None

Attributes

ArrayAttribute(elem_type, n_elem, elem_size=1, default_value=None)

Bases: _BaseAttribute

init method and the whole Attribute class are not supposed to be manipulated outside of the DataContainer class. An ArrayAttribute stores its values in a numpy array. This is a less flexible but safer approach than Attribute.

Parameters:

Name Type Description Default
elem_type

the type of the attribute (bool, int, float, complex, string)

required
n_elem int

Total number of elements in the container. Should match the size of the DataContainer the attribute is stored in.

required
elem_size int

Number of elem_type objects to be stored per element. Defaults to 1.

1
dense bool

description. Defaults to False.

required
default_value optional)

the default value of the attribute is n_elem is not specified. If it is not specified either, it will correspond to the default value of the type provided in elem_type.

None

__iter__()

Sparse attributes allow to iterate only over non-default elements

clear()

Empties the attribute. Frees the memory and ensures that all access return default value

empty()

Check if an attribute is empty. For an attribute to be empty, its number of elements should not be fixed, and the dictionnary should be empty

Attribute(elem_type, elem_size=1, default_value=None)

Bases: _BaseAttribute

init method and the whole Attribute class are not supposed to be manipulated outside of the DataContainer class

Parameters:

Name Type Description Default
elem_type

the type of the attribute (bool, int, float, complex, string)

required
elem_size int

Number of elem_type objects to be stored per element. Defaults to 1.

1
default_value optional)

the default value of the attribute is n_elem is not specified. If it is not specified either, it will correspond to the default value of the type provided in elem_type.

None

__iter__()

Sparse attributes allow to iterate only over non-default elements

clear()

Empties the attribute. Frees the memory and ensures that all access return default value

empty()

Check if an attribute is empty. For an attribute to be empty, its number of elements should not be fixed, and the dictionnary should be empty