Generic processing filters

The generic_processing_tools module of geos-processing package contains filters to process meshes.

geos.processing.generic_processing_tools.AttributeMapping filter

AttributeMapping is a vtk filter that transfers global attributes from a source mesh to a final mesh with same point/cell coordinates. The final mesh is updated directly, without creation of a copy.

Input meshes can be vtkDataSet or vtkMultiBlockDataSet.

Warning

For one application of the filter, the attributes to transfer should all be located on the same piece (all on points or all on cells).

Note

For cell, the coordinates of the points in the cell are compared. If one of the two meshes is a surface and the other a volume, all the points of the surface must be points of the volume.

To use a logger handler of yours, set the variable ‘speHandler’ to True and add it using the member function setLoggerHandler.

To use the filter:

from geos.processing.generic_processing_tools.AttributeMapping import AttributeMapping

# Filter inputs.
meshFrom: Union[ vtkDataSet, vtkMultiBlockDataSet ]
meshTo: Union[ vtkDataSet, vtkMultiBlockDataSet ]
attributeNames: set[ str ]
# Optional inputs.
onPoints: bool  # defaults to False
speHandler: bool  # defaults to False

# Instantiate the filter
attributeMappingFilter: AttributeMapping = AttributeMapping(
    meshFrom,
    meshTo,
    attributeNames,
    onPoints,
    speHandler,
)

# Set the handler of yours (only if speHandler is True).
yourHandler: logging.Handler
attributeMappingFilter.setLoggerHandler( yourHandler )

# Do calculations.
attributeMappingFilter.applyFilter()
class geos.processing.generic_processing_tools.AttributeMapping.AttributeMapping(meshFrom, meshTo, attributeNames, onPoints=False, speHandler=False)[source]

Bases: object

Transfer global attributes from a source mesh to a final mesh.

Mapping the piece of the attributes to transfer.

Parameters:
  • meshFrom (Union[vtkDataSet, vtkMultiBlockDataSet]) – The source mesh with attributes to transfer.

  • meshTo (Union[vtkDataSet, vtkMultiBlockDataSet]) – The final mesh where to transfer attributes.

  • attributeNames (set[str]) – Names of the attributes to transfer.

  • onPoints (bool) – True if attributes are on points, False if they are on cells. Defaults to False.

  • speHandler (bool, optional) – True to use a specific handler, False to use the internal handler. Defaults to False.

applyFilter()[source]

Transfer global attributes from a source mesh to a final mesh.

Mapping the piece of the attributes to transfer.

Returns:

True if calculation successfully ended, False otherwise.

Return type:

boolean (bool)

getElementMap()[source]

Getter of the element mapping dictionary.

If attribute to transfer are on points it will be a pointMap, else it will be a cellMap.

Returns:

The element mapping dictionary.

Return type:

self.elementMap (dict[int, npt.NDArray[np.int64]])

setLoggerHandler(handler)[source]

Set a specific handler for the filter logger.

In this filter 4 log levels are use, .info, .error, .warning and .critical, be sure to have at least the same 4 levels.

Parameters:

handler (logging.Handler) – The handler to add.

geos.processing.generic_processing_tools.CreateConstantAttributePerRegion filter

CreateConstantAttributePerRegion is a vtk filter that allows to create an attribute with constant values per components for each chosen indexes of a reference/region attribute. If other region indexes exist values are set to nan for float type, -1 for int type or 0 for uint type.

Input mesh is either vtkMultiBlockDataSet or vtkDataSet and the region attribute must have one component. The relation index/values is given by a dictionary. Its keys are the indexes and its items are the list of values for each component. To use a handler of yours, set the variable ‘speHandler’ to True and add it using the member function addLoggerHandler.

By default, the value type is set to float32, their is one component and no name and the logger use an intern handler.

To use it:

from geos.processing.generic_processing_tools.CreateConstantAttributePerRegion import CreateConstantAttributePerRegion

# Filter inputs.
mesh: Union[vtkMultiBlockDataSet, vtkDataSet]
regionName: str
dictRegionValues: dict[ Any, Any ]
newAttributeName: str

# Optional inputs.
valueNpType: type
nbComponents: int
componentNames: tuple[ str, ... ]
speHandler: bool

# Instantiate the filter
createConstantAttributePerRegionFilter: CreateConstantAttributePerRegion = CreateConstantAttributePerRegion(
    mesh,
    regionName,
    dictRegionValues,
    newAttributeName,
    valueNpType,
    nbComponents,
    componentNames,
    speHandler,
)

# Set your handler (only if speHandler is True).
yourHandler: logging.Handler
createConstantAttributePerRegionFilter.addLoggerHandler( yourHandler )

# Do calculations.
createConstantAttributePerRegionFilter.applyFilter()
class geos.processing.generic_processing_tools.CreateConstantAttributePerRegion.CreateConstantAttributePerRegion(mesh, regionName, dictRegionValues, newAttributeName, valueNpType=<class 'numpy.float32'>, nbComponents=1, componentNames=(), speHandler=False)[source]

Bases: object

Create an attribute with constant value per region.

Parameters:
  • mesh (Union[ vtkDataSet, vtkMultiBlockDataSet ]) – Mesh where to create the constant attribute per region.

  • regionName (str) – Name of the attribute with the region indexes.

  • dictRegionValues (dict[ Any, Any ]) – Dictionary with the region ids as keys and the list of values as items.

  • newAttributeName (str) – Name of the new attribute to create.

  • valueNpType (type, optional) – Numpy scalar type for values. Defaults to numpy.float32.

  • nbComponents (int, optional) – Number of components for the new attribute. Defaults to 1.

  • componentNames (tuple[str,...], optional) – Name of the components for vectorial attributes. If one component, gives an empty tuple. Defaults to an empty tuple.

  • speHandler (bool, optional) – True to use a specific handler, False to use the internal handler. Defaults to False.

applyFilter()[source]

Create a constant attribute per region in the mesh.

Returns:

True if calculation successfully ended, False otherwise.

Return type:

boolean (bool)

setLoggerHandler(handler)[source]

Set a specific handler for the filter logger.

In this filter 4 log levels are use, .info, .error, .warning and .critical, be sure to have at least the same 4 levels.

Parameters:

handler (logging.Handler) – The handler to add.

geos.processing.generic_processing_tools.FillPartialArrays filter

Fill partial attributes of the input mesh with constant values per component.

Input mesh is vtkMultiBlockDataSet and attributes to fill must be partial.

The list of filling values per attribute is given by a dictionary. Its keys are the attribute names and its items are the list of filling values for each component.

If the list of filling value is None, attributes are filled with the same constant value for each component: 0 for uint data, -1 for int data and nan for float data.

To use a handler of yours for the logger, set the variable ‘speHandler’ to True and add it to the filter with the member function setLoggerHandler.

To use it:

from geos.processing.generic_processing_tools.FillPartialArrays import FillPartialArrays

# Filter inputs.
multiBlockDataSet: vtkMultiBlockDataSet
dictAttributesValues: dict[ str, Union[ list[ Any ], None ] ]
# Optional inputs.
speHandler: bool

# Instantiate the filter.
fillPartialArraysFilter: FillPartialArrays = FillPartialArrays(
    multiBlockDataSet,
    dictAttributesValues,
    speHandler
)

# Set the handler of yours (only if speHandler is True).
yourHandler: logging.Handler
fillPartialArraysFilter.setLoggerHandler( yourHandler )

# Do calculations.
fillPartialArraysFilter.applyFilter()
class geos.processing.generic_processing_tools.FillPartialArrays.FillPartialArrays(multiBlockDataSet, dictAttributesValues, speHandler=False)[source]

Bases: object

Fill partial attributes with constant value per component.

If the list of filling values for an attribute is None, it will be filled with the default value for each component:

  • 0 for uint data.

  • -1 for int data.

  • nan for float data.

Parameters:
  • multiBlockDataSet (vtkMultiBlockDataSet) – The mesh where to fill the attribute.

  • dictAttributesValues (dict[str, Any]) – The dictionary with the attribute to fill as keys and the list of filling values as values.

  • speHandler (bool, optional) – True to use a specific handler, False to use the internal handler. Defaults to False.

applyFilter()[source]

Create a constant attribute per region in the mesh.

Returns:

True if calculation successfully ended, False otherwise.

Return type:

boolean (bool)

setLoggerHandler(handler)[source]

Set a specific handler for the filter logger.

In this filter 4 log levels are use, .info, .error, .warning and .critical, be sure to have at least the same 4 levels.

Parameters:

handler (logging.Handler) – The handler to add.

geos.processing.generic_processing_tools.SplitMesh filter

SplitMesh module is a vtk filter that split cells of a mesh composed of Tetrahedra, pyramids, and hexahedra.

Filter input and output types are vtkUnstructuredGrid.

To use the filter:

from geos.processing.generic_processing_tools.SplitMesh import SplitMesh

# Filter inputs
input: vtkUnstructuredGrid

# Instantiate the filter
splitMeshFilter: SplitMesh = SplitMesh()

# Set input data object
splitMeshFilter.SetInputDataObject( input )

# Do calculations
splitMeshFilter.Update()

# Get output object
output :vtkUnstructuredGrid = splitMeshFilter.GetOutputDataObject( 0 )
class geos.processing.generic_processing_tools.SplitMesh.SplitMesh[source]

Bases: VTKPythonAlgorithmBase

SplitMesh filter splits each cell using edge centers.

FillInputPortInformation(port, info)[source]

Inherited from VTKPythonAlgorithmBase::RequestInformation.

Parameters:
  • port (int) – input port

  • info (vtkInformationVector) – info

Returns:

1 if calculation successfully ended, 0 otherwise.

Return type:

int

RequestData(request, inInfoVec, outInfoVec)[source]

Inherited from VTKPythonAlgorithmBase::RequestData.

Parameters:
  • request (vtkInformation) – request

  • inInfoVec (list[vtkInformationVector]) – input objects

  • outInfoVec (vtkInformationVector) – output objects

Returns:

1 if calculation successfully ended, 0 otherwise.

Return type:

int

RequestDataObject(request, inInfoVec, outInfoVec)[source]

Inherited from VTKPythonAlgorithmBase::RequestDataObject.

Parameters:
  • request (vtkInformation) – request

  • inInfoVec (list[vtkInformationVector]) – input objects

  • outInfoVec (vtkInformationVector) – output objects

Returns:

1 if calculation successfully ended, 0 otherwise.

Return type:

int

geos.processing.generic_processing_tools.MergeBlockEnhanced filter

Merge Blocks Keeping Partial Attributes is a filter that allows to merge blocks from a multiblock dataset while keeping partial attributes.

Input is a vtkMultiBlockDataSet and output is a vtkUnstructuredGrid.

Note

  • You may encounter issues if two datasets of the input multiblock dataset have duplicated cell IDs.

  • Partial attributes are filled with default values depending on their types.
    • 0 for uint data.

    • -1 for int data.

    • nan for float data.

To use it:

from geos.processing.generic_processing_tools.MergeBlockEnhanced import MergeBlockEnhanced
import logging
from geos.utils.Errors import VTKError

# Define filter inputs
multiblockdataset: vtkMultiblockDataSet
speHandler: bool # optional

# Instantiate the filter
mergeBlockEnhancedFilter: MergeBlockEnhanced = MergeBlockEnhanced( multiblockdataset, speHandler )

# Use your own handler (if speHandler is True)
yourHandler: logging.Handler
mergeBlockEnhancedFilter.setLoggerHandler( yourHandler )

# Do calculations
try:
    mergeBlockEnhancedFilter.applyFilter()
except VTKError:
    logging.error("Something went wrong in VTK")

# Get the merged mesh
mergeBlockEnhancedFilter.getOutput()
class geos.processing.generic_processing_tools.MergeBlockEnhanced.MergeBlockEnhanced(inputMesh, speHandler=False)[source]

Bases: object

Merge a multiblock dataset and keep the partial attributes in the output mesh.

Partial attributes are filled with default values depending on the data type such that:
  • 0 for uint data.

  • -1 for int data.

  • nan for float data.

Parameters:
  • inputMesh (vtkMultiBlockDataSet) – The input multiblock dataset to merge.

  • speHandler (bool, optional) – True to use a specific handler, False to use the internal handler.

  • False. (Defaults to)

applyFilter()[source]

Merge the blocks of a multiblock dataset mesh.

Returns:

True if the blocks were successfully merged, False otherwise.

Return type:

bool

Raises:

VTKError (geos.utils.Errors) – error captured if any from the VTK log

getOutput()[source]

Get the merged mesh.

Returns:

The merged mesh.

Return type:

vtkUnstructuredGrid

setLoggerHandler(handler)[source]

Set a specific handler for the filter logger.

In this filter 4 log levels are use, .info, .error, .warning and .critical, be sure to have at least the same 4 levels.

Parameters:

handler (logging.Handler) – The handler to add.

geos.processing.generic_processing_tools.ClipToMainFrame filter

Module to clip a mesh to the main frame using rigid body transformation.

Methods include:
  • ClipToMainFrameElement class to compute the transformation

  • ClipToMainFrame class to apply the transformation to a mesh

To use it:

from geos.processing.generic_processing_tools.ClipToMainFrame import ClipToMainFrame

# Filter inputs.
multiBlockDataSet: vtkMultiBlockDataSet
# Optional Inputs
speHandler : bool

# Instantiate the filter.
clipToMainFrameFilter: ClipToMainFrame = ClipToMainFrame()
clipToMainFrameFilter.SetInputData( multiBlockDataSet )

# Set the handler of yours (only if speHandler is True).
yourHandler: logging.Handler
clipToMainFrameFilter.setLoggerHandler( yourHandler )

# Do calculations.
clipToMainFrameFilter.ComputeTransform()
clipToMainFrameFilter.Update()
output: vtkMultiBlockDataSet = clipToMainFrameFilter.GetOutput()
class geos.processing.generic_processing_tools.ClipToMainFrame.ClipToMainFrame(speHandler=False, **properties)[source]

Bases: vtkTransformFilter

Filter to clip a mesh to the main frame using ClipToMainFrame class.

Initialize the ClipToMainFrame Filter with optional speHandler args and forwarding properties to main class.

Parameters:
  • speHandler (bool, optional) – True to use a specific handler, False to use the internal handler.

  • False. (Defaults to)

  • properties (kwargs) – kwargs forwarded to vtkTransformFilter.

ComputeTransform()[source]

Update the transformation.

SetLoggerHandler(handler)[source]

Set a specific handler for the filter logger.

In this filter 4 log levels are use, .info, .error, .warning and .critical, be sure to have at least the same 4 levels.

Parameters:

handler (logging.Handler) – The handler to add.

class geos.processing.generic_processing_tools.ClipToMainFrame.ClipToMainFrameElement(mesh)[source]

Bases: vtkLandmarkTransform

Clip mesh to main frame.

Parameters:

mesh (vtkUnstructuredGrid) – Mesh to clip.

Update()[source]

Update the transformation.

mesh
sourcePts
targetPts