Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1a57322
wip
jafranc Sep 16, 2025
84c0ba8
PoC
jafranc Sep 30, 2025
f32fe2e
decorator and precommit recipe
jafranc Oct 2, 2025
6f6e652
clean up
jafranc Oct 2, 2025
5437cc0
yapf uncommited
jafranc Oct 2, 2025
1f65fe7
n+ attempts
jafranc Oct 2, 2025
adaa26b
wip - need Protocol
jafranc Oct 3, 2025
2ec2a52
Crash but closer
jafranc Oct 3, 2025
9992917
safe path
jafranc Oct 10, 2025
f08e059
ordering filter and others to avoid segfault
jafranc Oct 10, 2025
9ed4ec4
some inheritance
jafranc Oct 10, 2025
4e4b704
copied inherited
jafranc Oct 10, 2025
4919f5d
Even more refactored
jafranc Oct 10, 2025
ee309ff
make it a class !!
jafranc Oct 14, 2025
827fa23
mypy/ruff/yapf
jafranc Oct 14, 2025
4b468e8
stay generic in Protocol
jafranc Oct 14, 2025
39c2b2f
fix
jafranc Oct 14, 2025
82e8996
expanding
jafranc Oct 14, 2025
840dcca
some adj
jafranc Oct 15, 2025
0fdc32a
Merge branch 'main' into jafranc/refact/testSISO
jafranc Oct 15, 2025
8ca7bf6
revert changes from logger PR
jafranc Oct 15, 2025
731421c
Merge branch 'main' into jafranc/refact/testSISO
jafranc Oct 15, 2025
ecd13f7
SISOFilter for all
jafranc Oct 15, 2025
a149214
revert logger's branch change
jafranc Oct 15, 2025
c68f4b1
addressing all comments
jafranc Oct 21, 2025
e943d4c
mypy
jafranc Oct 21, 2025
358a45f
some more constraints
jafranc Oct 21, 2025
08bd8e2
Fix for PVPythonViewConfigurator to handle new MultiblockDataSet inpu…
alexbenedicto Oct 23, 2025
da3aab5
Merge remote-tracking branch 'origin/main' into jafranc/refact/testSISO
jafranc Oct 27, 2025
6694540
few fixes
jafranc Oct 27, 2025
984273f
ending dots
jafranc Oct 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .hooks/pre-commit.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash -e

function run_precommit_checks
{
echo "running mypy"
python -m mypy --config-file ./.mypy.ini --check-untyped-defs $1
echo "running ruff"
python -m ruff check --unsafe-fixes --config .ruff.toml $1
echo "running yapf"
python -m yapf -r -i --style .style.yapf $1

return 0
}


source ${ENV_PYTHON}/bin/activate

#sphinx-build -b html docs/ docs/_build -W
for file in $(git diff --name-only --cached | grep -e "modified\|added" | grep py)
do
run_precommit_checks $file
done

68 changes: 11 additions & 57 deletions geos-pv/src/geos/pv/plugins/PVClipToMainFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,16 @@
# ruff: noqa: E402 # disable Module level import not at top of file
import sys
from pathlib import Path
from typing import Union

from paraview.util.vtkAlgorithm import ( # type: ignore[import-not-found]
VTKPythonAlgorithmBase, smdomain, smhint, smproperty, smproxy,
VTKPythonAlgorithmBase,
) # source: https://github.com/Kitware/ParaView/blob/master/Wrapping/Python/paraview/util/vtkAlgorithm.py
from paraview.detail.loghandler import ( # type: ignore[import-not-found]
VTKHandler,
) # source: https://github.com/Kitware/ParaView/blob/master/Wrapping/Python/paraview/detail/loghandler.py

from vtkmodules.vtkCommonDataModel import (
vtkMultiBlockDataSet,
vtkUnstructuredGrid,
)

from vtkmodules.vtkCommonCore import (
vtkInformation,
vtkInformationVector,
)
vtkMultiBlockDataSet, )

# update sys.path to load all GEOS Python Package dependencies
geos_pv_path: Path = Path( __file__ ).parent.parent.parent.parent.parent
Expand All @@ -30,6 +22,7 @@

update_paths()

from geos.pv.utils.details import SISOFilter, FilterCategory
from geos.mesh.processing.ClipToMainFrame import ClipToMainFrame

__doc__ = """
Expand All @@ -43,67 +36,28 @@
"""


@smproxy.filter( name="PVClipToMainFrame", label="Clip to the main frame" )
@smhint.xml( '<ShowInMenu category="4- Geos Utils"/>' )
@smproperty.input( name="Input", port_index=0 )
@smdomain.datatype(
dataTypes=[ "vtkMultiBlockDataSet", "vtkUnstructuredGrid" ],
composite_data_supported=True,
)
@SISOFilter( category=FilterCategory.GEOS_UTILS,
decoratedLabel="Clip to the main frame",
decoratedType=[ "vtkMultiBlockDataSet", "vtkDataSet" ] )
class PVClipToMainFrame( VTKPythonAlgorithmBase ):

def __init__( self ) -> None:
"""Init motherclass, filter and logger."""
VTKPythonAlgorithmBase.__init__( self,
nInputPorts=1,
nOutputPorts=1,
inputType="vtkDataObject",
outputType="vtkDataObject" )

self._realFilter = ClipToMainFrame( speHandler=True )
if not self._realFilter.logger.hasHandlers():
self._realFilter.SetLoggerHandler( VTKHandler() )

#ensure I/O consistency
def RequestDataObject( self, request: vtkInformation, inInfoVec: list[ vtkInformationVector ],
outInfoVec: vtkInformationVector ) -> int:
"""Inherited from VTKPythonAlgorithmBase::RequestDataObject.
def Filter( self, inputMesh: vtkMultiBlockDataSet, outputMesh: vtkMultiBlockDataSet ) -> None:
"""Is applying CreateConstantAttributePerRegion filter.

Args:
request (vtkInformation): request
inInfoVec (list[vtkInformationVector]): input objects
outInfoVec (vtkInformationVector): output objects

Returns:
int: 1 if calculation successfully ended, 0 otherwise.
inputMesh : A mesh to transform.
outputMesh : A mesh transformed.
"""
inData = self.GetInputData( inInfoVec, 0, 0 )
outData = self.GetOutputData( outInfoVec, 0 )
assert inData is not None
if outData is None or ( not outData.IsA( inData.GetClassName() ) ):
outData = inData.NewInstance()
outInfoVec.GetInformationObject( 0 ).Set( outData.DATA_OBJECT(), outData )
return super().RequestDataObject( request, inInfoVec, outInfoVec ) # type: ignore[no-any-return]

def RequestData( self, request: vtkInformation, inInfo: list[ vtkInformationVector ],
outInfo: vtkInformationVector ) -> int:
"""Inherited from VTKPythonAlgorithmBase::RequestData. Apply ClipToMainFrame filter.

Args:
request (vtkInformation): Request
inInfo (list[vtkInformationVector]): Input objects
outInfo (vtkInformationVector): Output objects

Returns:
int: 1 if calculation successfully ended, 0 otherwise.
"""
inputMesh: Union[ vtkMultiBlockDataSet, vtkUnstructuredGrid ] = self.GetInputData( inInfo, 0, 0 )
outputMesh: Union[ vtkMultiBlockDataSet, vtkUnstructuredGrid ] = self.GetOutputData( outInfo, 0 )

# struct
self._realFilter.SetInputData( inputMesh )
self._realFilter.ComputeTransform()
self._realFilter.Update()
outputMesh.ShallowCopy( self._realFilter.GetOutputDataObject( 0 ) )

return 1
return
106 changes: 26 additions & 80 deletions geos-pv/src/geos/pv/plugins/PVCreateConstantAttributePerRegion.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,31 @@
# SPDX-FileContributor: Martin Lemay, Romain Baville
# ruff: noqa: E402 # disable Module level import not at top of file
import sys
import numpy as np
from pathlib import Path

from typing import Union, Any
from typing import Any
from typing_extensions import Self

from paraview.util.vtkAlgorithm import ( # type: ignore[import-not-found]
smdomain, smhint, smproperty, smproxy,
VTKPythonAlgorithmBase, smdomain, smproperty,
) # source: https://github.com/Kitware/ParaView/blob/master/Wrapping/Python/paraview/util/vtkAlgorithm.py
from paraview.detail.loghandler import ( # type: ignore[import-not-found]
VTKHandler,
) # source: https://github.com/Kitware/ParaView/blob/master/Wrapping/Python/paraview/detail/loghandler.py

from vtkmodules.util.vtkAlgorithm import VTKPythonAlgorithmBase
from vtkmodules.vtkCommonCore import (
vtkInformation,
vtkInformationVector,
)
import vtkmodules.util.numpy_support as vnp

from vtkmodules.vtkCommonDataModel import (
vtkMultiBlockDataSet,
vtkDataSet,
)
vtkDataSet, )

# update sys.path to load all GEOS Python Package dependencies
geos_pv_path: Path = Path( __file__ ).parent.parent.parent.parent.parent
sys.path.insert( 0, str( geos_pv_path / "src" ) )
from geos.pv.utils.config import update_paths

update_paths()
from geos.mesh.processing.CreateConstantAttributePerRegion import ( CreateConstantAttributePerRegion )

from geos.mesh.processing.CreateConstantAttributePerRegion import CreateConstantAttributePerRegion, vnp, np
from geos.pv.utils.details import SISOFilter, FilterCategory

__doc__ = """
PVCreateConstantAttributePerRegion is a Paraview plugin that allows to create an attribute
Expand All @@ -42,7 +37,7 @@
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.

.. Warning::
.. Warning::
The input mesh should contain an attribute corresponding to the regions.

To use it:
Expand All @@ -56,22 +51,13 @@
"""


@smproxy.filter(
name="PVCreateConstantAttributePerRegion",
label="Create Constant Attribute Per Region",
)
@smhint.xml( """<ShowInMenu category="0- Geos Pre-processing"/>""" )
@smproperty.input( name="Input", port_index=0 )
@smdomain.datatype(
dataTypes=[ "vtkMultiBlockDataSet", "vtkDataSet" ],
composite_data_supported=True,
)
@SISOFilter( category=FilterCategory.GEOS_PROP,
decoratedLabel="Create Constant Attribute Per Region",
decoratedType=[ "vtkMultiBlockDataSet", "vtkDataSet" ] )
class PVCreateConstantAttributePerRegion( VTKPythonAlgorithmBase ):

def __init__( self: Self ) -> None:
"""Create an attribute with constant value per region."""
super().__init__( nInputPorts=1, nOutputPorts=1, inputType="vtkDataObject", outputType="vtkDataObject" )

self.clearDictRegionValues: bool = True

# Region attribute settings.
Expand Down Expand Up @@ -111,7 +97,7 @@ def __init__( self: Self ) -> None:
<NoDefault />
</Hints>
""" )
def _setRegionAttributeName( self: Self, regionName: str ) -> None:
def setRegionAttributeName( self: Self, regionName: str ) -> None:
"""Set region attribute name.

Args:
Expand All @@ -124,7 +110,7 @@ def _setRegionAttributeName( self: Self, regionName: str ) -> None:
<StringVectorProperty
name="SetDictRegionValues"
number_of_elements="2"
command="_setDictRegionValues"
command="setDictRegionValues"
repeat_command="1"
number_of_elements_per_command="2">
<Documentation>
Expand All @@ -142,7 +128,7 @@ def _setRegionAttributeName( self: Self, regionName: str ) -> None:
</Hints>
</StringVectorProperty>
""" )
def _setDictRegionValues( self: Self, regionIndex: str, value: str ) -> None:
def setDictRegionValues( self: Self, regionIndex: str, value: str ) -> None:
"""Set the dictionary with the region indexes and its corresponding list of values for each components.

Args:
Expand All @@ -166,7 +152,7 @@ def _setDictRegionValues( self: Self, regionIndex: str, value: str ) -> None:
<Property name="SetDictRegionValues"/>
</PropertyGroup>
""" )
def _groupRegionAttributeSettingsWidgets( self: Self ) -> None:
def groupRegionAttributeSettingsWidgets( self: Self ) -> None:
"""Group the widgets to set the settings of the region attribute."""
self.Modified()

Expand All @@ -183,7 +169,7 @@ def _groupRegionAttributeSettingsWidgets( self: Self ) -> None:
</Documentation>
</StringVectorProperty>
""" )
def _setAttributeName( self: Self, newAttributeName: str ) -> None:
def setAttributeName( self: Self, newAttributeName: str ) -> None:
"""Set attribute name.

Args:
Expand Down Expand Up @@ -216,7 +202,7 @@ def _setAttributeName( self: Self, newAttributeName: str ) -> None:
The requested numpy scalar type for values of the new attribute.
</Documentation>
""" )
def _setValueType( self: Self, valueType: int ) -> None:
def setValueType( self: Self, valueType: int ) -> None:
"""Set the type for the value used to create the new attribute.

Args:
Expand All @@ -238,7 +224,7 @@ def _setValueType( self: Self, valueType: int ) -> None:
The number of components for the new attribute to create.
</Documentation>
""" )
def _setNbComponent( self: Self, nbComponents: int ) -> None:
def setNbComponent( self: Self, nbComponents: int ) -> None:
"""Set the number of components of the attribute to create.

Args:
Expand All @@ -261,7 +247,7 @@ def _setNbComponent( self: Self, nbComponents: int ) -> None:
Names of components: X, Y, Z
</Documentation>
""" )
def _setComponentNames( self: Self, componentNames: str ) -> None:
def setComponentNames( self: Self, componentNames: str ) -> None:
"""Set the names of the components of the attribute to create.

Args:
Expand All @@ -283,57 +269,17 @@ def _setComponentNames( self: Self, componentNames: str ) -> None:
<Property name="NumberOfComponents"/>
<Property name="ComponentNames"/>
</PropertyGroup>""" )
def _groupNewAttributeSettingsWidgets( self: Self ) -> None:
def groupNewAttributeSettingsWidgets( self: Self ) -> None:
"""Group the widgets to set the settings of the new attribute."""
self.Modified()

def RequestDataObject(
self: Self,
request: vtkInformation,
inInfoVec: list[ vtkInformationVector ],
outInfoVec: vtkInformationVector,
) -> int:
"""Inherited from VTKPythonAlgorithmBase::RequestDataObject.
def Filter( self, inputMesh: vtkDataSet, outputMesh: vtkDataSet ) -> None:
"""Is applying CreateConstantAttributePerRegion filter.

Args:
request (vtkInformation): request
inInfoVec (list[vtkInformationVector]): input objects
outInfoVec (vtkInformationVector): output objects

Returns:
int: 1 if calculation successfully ended, 0 otherwise.
inputMesh : A mesh to transform
outputMesh : A mesh transformed.
"""
inData = self.GetInputData( inInfoVec, 0, 0 )
outData = self.GetOutputData( outInfoVec, 0 )
assert inData is not None
if outData is None or ( not outData.IsA( inData.GetClassName() ) ):
outData = inData.NewInstance()
outInfoVec.GetInformationObject( 0 ).Set( outData.DATA_OBJECT(), outData )
return super().RequestDataObject( request, inInfoVec, outInfoVec ) # type: ignore[no-any-return]

def RequestData(
self: Self,
request: vtkInformation, # noqa: F841
inInfoVec: list[ vtkInformationVector ], # noqa: F841
outInfoVec: vtkInformationVector, # noqa: F841
) -> int:
"""Inherited from VTKPythonAlgorithmBase::RequestData.

Args:
request (vtkInformation): Request.
inInfoVec (list[vtkInformationVector]): Input objects.
outInfoVec (vtkInformationVector): Output objects.

Returns:
int: 1 if calculation successfully ended, 0 otherwise.
"""
inputMesh: Union[ vtkDataSet, vtkMultiBlockDataSet ] = self.GetInputData( inInfoVec, 0, 0 )
outputMesh: Union[ vtkDataSet, vtkMultiBlockDataSet ] = self.GetOutputData( outInfoVec, 0 )

assert inputMesh is not None, "Input mesh is null."
assert outputMesh is not None, "Output pipeline is null."

outputMesh.ShallowCopy( inputMesh )
filter: CreateConstantAttributePerRegion = CreateConstantAttributePerRegion(
outputMesh,
self.regionName,
Expand All @@ -352,4 +298,4 @@ def RequestData(

self.clearDictRegion = True

return 1
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you use a return here and after but not in PVClipToMainFrame ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

Loading