-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
1a57322
wip
jafranc 84c0ba8
PoC
jafranc f32fe2e
decorator and precommit recipe
jafranc 6f6e652
clean up
jafranc 5437cc0
yapf uncommited
jafranc 1f65fe7
n+ attempts
jafranc adaa26b
wip - need Protocol
jafranc 2ec2a52
Crash but closer
jafranc 9992917
safe path
jafranc f08e059
ordering filter and others to avoid segfault
jafranc 9ed4ec4
some inheritance
jafranc 4e4b704
copied inherited
jafranc 4919f5d
Even more refactored
jafranc ee309ff
make it a class !!
jafranc 827fa23
mypy/ruff/yapf
jafranc 4b468e8
stay generic in Protocol
jafranc 39c2b2f
fix
jafranc 82e8996
expanding
jafranc 840dcca
some adj
jafranc 0fdc32a
Merge branch 'main' into jafranc/refact/testSISO
jafranc 8ca7bf6
revert changes from logger PR
jafranc 731421c
Merge branch 'main' into jafranc/refact/testSISO
jafranc ecd13f7
SISOFilter for all
jafranc a149214
revert logger's branch change
jafranc c68f4b1
addressing all comments
jafranc e943d4c
mypy
jafranc 358a45f
some more constraints
jafranc 08bd8e2
Fix for PVPythonViewConfigurator to handle new MultiblockDataSet inpu…
alexbenedicto da3aab5
Merge remote-tracking branch 'origin/main' into jafranc/refact/testSISO
jafranc 6694540
few fixes
jafranc 984273f
ending dots
jafranc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
RomainBaville marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 |
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.