-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPVClipToMainFrame.py
More file actions
109 lines (87 loc) · 4.22 KB
/
PVClipToMainFrame.py
File metadata and controls
109 lines (87 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright 2023-2024 TotalEnergies.
# SPDX-FileContributor: Jacques Franc
# 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,
) # 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,
)
# 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.ClipToMainFrame import ClipToMainFrame
__doc__ = """
Clip the input mesh to the main frame applying the correct LandmarkTransform
To use it:
* Load the module in Paraview: Tools>Manage Plugins...>Load new>PVClipToMainFrame.
* Apply.
"""
@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,
)
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.
Args:
request (vtkInformation): request
inInfoVec (list[vtkInformationVector]): input objects
outInfoVec (vtkInformationVector): output objects
Returns:
int: 1 if calculation successfully ended, 0 otherwise.
"""
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