spateo.tdr.models.utilities#

Submodules#

Package Contents#

Functions#

read_model(filename)

Read any file type supported by vtk or meshio.

save_model(model, filename[, binary, texture])

Save the pvvista/vtk model to vtk/vtm file.

add_model_labels(...)

Add rgba color to each point of model based on labels.

center_to_zero(model[, inplace])

Translate the center point of the model to the (0, 0, 0).

collect_models(→ pyvista.MultiBlock)

A composite class to hold many data sets which can be iterated over.

merge_models(→ PolyData or UnstructuredGrid)

Merge all models in the models list. The format of all models must be the same.

multiblock2model(model[, message])

Merge all models in MultiBlock into one model

rotate_model(, rotate_center, tuple] = None, inplace, ...)

Rotate the model around the rotate_center.

scale_model(→ Union[pyvista.PolyData, ...)

Scale the model around the center of the model.

split_model(→ pyvista.MultiBlock)

Find, label, and split connected bodies/volumes.

translate_model(, inplace, pyvista.UnstructuredGrid, None])

Translate the mesh.

spateo.tdr.models.utilities.read_model(filename: str)[source]#

Read any file type supported by vtk or meshio. :param filename: The string path to the file to read.

Returns:

Wrapped PyVista dataset.

spateo.tdr.models.utilities.save_model(model: pyvista.DataSet | pyvista.MultiBlock, filename: str, binary: bool = True, texture: str | numpy.ndarray = None)[source]#

Save the pvvista/vtk model to vtk/vtm file. :param model: A reconstructed model. :param filename: Filename of output file. Writer type is inferred from the extension of the filename.

If model is a pyvista.MultiBlock object, please enter a filename ending with .vtm; else please enter a filename ending with .vtk.

Parameters:
binary

If True, write as binary. Otherwise, write as ASCII. Binary files write much faster than ASCII and have a smaller file size.

texture

Write a single texture array to file when using a PLY file.

Texture array must be a 3 or 4 component array with the datatype np.uint8. Array may be a cell array or a point array, and may also be a string if the array already exists in the PolyData.

If a string is provided, the texture array will be saved to disk as that name. If an array is provided, the texture array will be saved as ‘RGBA’

spateo.tdr.models.utilities.add_model_labels(model: pyvista.PolyData | pyvista.UnstructuredGrid, labels: numpy.ndarray, key_added: str = 'groups', where: Literal[point_data, cell_data] = 'cell_data', colormap: str | list | dict | numpy.ndarray = 'rainbow', alphamap: float | list | dict | numpy.ndarray = 1.0, mask_color: str | None = 'gainsboro', mask_alpha: float | None = 0.0, inplace: bool = False) Tuple[Optional[PolyData or UnstructuredGrid], Optional[Union[str]]][source]#

Add rgba color to each point of model based on labels.

Parameters:
model

A reconstructed model.

labels

An array of labels of interest.

key_added

The key under which to add the labels.

where

The location where the label information is recorded in the model.

colormap

Colors to use for plotting data.

alphamap

The opacity of the color to use for plotting data.

mask_color

Color to use for plotting mask information.

mask_alpha

The opacity of the color to use for plotting mask information.

inplace

Updates model in-place.

Returns:

model.cell_data[key_added] or model.point_data[key_added], the labels array;

model.cell_data[f'{key_added}_rgba'] or model.point_data[f'{key_added}_rgba'], the rgba colors of the labels.

plot_cmap: Recommended colormap parameter values for plotting.

Return type:

A model, which contains the following properties

spateo.tdr.models.utilities.center_to_zero(model: pyvista.PolyData | pyvista.UnstructuredGrid, inplace: bool = False)[source]#

Translate the center point of the model to the (0, 0, 0).

Parameters:
model

A 3D reconstructed model.

inplace

Updates model in-place.

Returns:

Model with center point at (0, 0, 0).

Return type:

model_z

spateo.tdr.models.utilities.collect_models(models: List[PolyData or UnstructuredGrid or DataSet], models_name: List[str] | None = None) pyvista.MultiBlock[source]#

A composite class to hold many data sets which can be iterated over. You can think of MultiBlock like lists or dictionaries as we can iterate over this data structure by index and we can also access blocks by their string name. If the input is a dictionary, it can be iterated in the following ways:

>>> blocks = collect_models(models, models_name)
>>> for name in blocks.keys():
...     print(blocks[name])
If the input is a list, it can be iterated in the following ways:
>>> blocks = collect_models(models)
>>> for block in blocks:
...    print(block)
spateo.tdr.models.utilities.merge_models(models: List[PolyData or UnstructuredGrid or DataSet]) PolyData or UnstructuredGrid[source]#

Merge all models in the models list. The format of all models must be the same.

spateo.tdr.models.utilities.multiblock2model(model, message=None)[source]#

Merge all models in MultiBlock into one model

spateo.tdr.models.utilities.rotate_model(model: pyvista.PolyData | pyvista.UnstructuredGrid, angle: list | tuple = (0, 0, 0), rotate_center: list | tuple = None, inplace: bool = False) pyvista.PolyData | pyvista.UnstructuredGrid | None[source]#

Rotate the model around the rotate_center.

Parameters:
model

A 3D reconstructed model.

angle

Angles in degrees to rotate about the x-axis, y-axis, z-axis. Length 3 list or tuple.

rotate_center

Rotation center point. The default is the center of the model. Length 3 list or tuple.

inplace

Updates model in-place.

Returns:

The rotated model.

Return type:

model_r

spateo.tdr.models.utilities.scale_model(model: pyvista.PolyData | pyvista.UnstructuredGrid, distance: float | int | list | tuple = None, scale_factor: float | int | list | tuple = 1, scale_center: list | tuple = None, inplace: bool = False) pyvista.PolyData | pyvista.UnstructuredGrid | None[source]#

Scale the model around the center of the model.

Parameters:
model

A 3D reconstructed model.

distance

The distance by which the model is scaled. If distance is float, the model is scaled same distance along the xyz axis; when the scale factor is list, the model is scaled along the xyz axis at different distance. If distance is None, there will be no scaling based on distance.

scale_factor

The scale by which the model is scaled. If scale factor is float, the model is scaled along the xyz axis at the same scale; when the scale factor is list, the model is scaled along the xyz axis at different scales. If scale_factor is None, there will be no scaling based on scale factor.

scale_center

Scaling center. If scale factor is None, the scale_center will default to the center of the model.

inplace

Updates model in-place.

Returns:

The scaled model.

Return type:

model_s

spateo.tdr.models.utilities.split_model(model: pyvista.PolyData | pyvista.UnstructuredGrid | pyvista.DataSet, label: bool | None = False) pyvista.MultiBlock[source]#

Find, label, and split connected bodies/volumes. This splits different connected bodies into blocks in a pyvista.MultiBlock dataset.

spateo.tdr.models.utilities.translate_model(model: pyvista.PolyData | pyvista.UnstructuredGrid, distance: list | tuple = (0, 0, 0), inplace: bool = False) pyvista.PolyData | pyvista.UnstructuredGrid | None[source]#

Translate the mesh.

Parameters:
model

A 3D reconstructed model.

distance

Distance to translate about the x-axis, y-axis, z-axis. Length 3 list or tuple.

inplace

Updates model in-place.

Returns:

The translated model.

Return type:

model_t