-
Notifications
You must be signed in to change notification settings - Fork 0
feat: adding SISO decorator #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1a57322
84c0ba8
f32fe2e
6f6e652
5437cc0
1f65fe7
adaa26b
2ec2a52
9992917
f08e059
9ed4ec4
4e4b704
4919f5d
ee309ff
827fa23
4b468e8
39c2b2f
82e8996
840dcca
0fdc32a
8ca7bf6
731421c
ecd13f7
a149214
c68f4b1
e943d4c
358a45f
08bd8e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||
|
|
||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 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 | ||||||
|
|
@@ -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: | ||||||
|
|
@@ -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. | ||||||
|
|
@@ -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: | ||||||
|
|
@@ -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> | ||||||
|
|
@@ -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: | ||||||
|
|
@@ -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() | ||||||
|
|
||||||
|
|
@@ -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: | ||||||
|
|
@@ -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: | ||||||
|
|
@@ -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: | ||||||
|
|
@@ -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: | ||||||
|
|
@@ -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, | ||||||
|
|
@@ -352,4 +298,4 @@ def RequestData( | |||||
|
|
||||||
| self.clearDictRegion = True | ||||||
|
|
||||||
| return 1 | ||||||
| return | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch |
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.