-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPVTetQualityAnalysis.py
More file actions
119 lines (96 loc) · 4.56 KB
/
PVTetQualityAnalysis.py
File metadata and controls
119 lines (96 loc) · 4.56 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
110
111
112
113
114
115
116
117
118
119
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright 2023-2024 TotalEnergies.
# SPDX-FileContributor: Paloma Martinez
# ruff: noqa: E402 # disable Module level import not at top of file
import sys
import logging
from pathlib import Path
from typing_extensions import Self, Optional
from vtkmodules.vtkCommonCore import vtkInformation, vtkInformationVector
from vtkmodules.vtkCommonDataModel import vtkUnstructuredGrid
# update sys.path to load all GEOS Python Package dependencies
geos_pv_path: Path = Path( __file__ ).parent.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 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 VTKHandler # type: ignore[import-not-found]
# source: https://github.com/Kitware/ParaView/blob/master/Wrapping/Python/paraview/detail/loghandler.py
from geos.processing.pre_processing.TetQualityAnalysis import TetQualityAnalysis
from geos.pv.utils.details import FilterCategory
from geos.utils.Logger import isHandlerInLogger
__doc__ = f"""
Tetrahedra QC is a ParaView plugin filter that analyzes and compares the tetrahedras of two given vtkUnstructured grid datasets.
A figure with relevant quality metrics is saved at the end of the process for a visual comparison.
To use it:
* Load the plugin in ParaView: Tools > Manage Plugins ... > Load New ... > .../geosPythonPackages/geos-pv/src/geos/pv/plugins/qc/PVTetQualityAnalysis
* Select the first dataset
* Select the filter: Filters > { FilterCategory.QC.value } > Tetrahedras QC
* In the dialog box, select the `mesh 1` and the `mesh 2`
* Change the output filename if needed
* Apply
"""
HANDLER: logging.Handler = VTKHandler()
@smproxy.filter( name="PVTetQualityAnalysis", label="Tetrahedra QC" )
@smhint.xml( f'<ShowInMenu category="{ FilterCategory.QC.value }"/>' )
@smproperty.input( name="inputMesh", port_index=0, label="mesh 1" )
@smdomain.datatype(
dataTypes=[ "vtkUnstructuredGrid" ],
composite_data_supported=True,
)
@smproperty.input( name="inputMesh2", port_index=1, label="mesh 2" )
@smdomain.datatype(
dataTypes=[ "vtkUnstructuredGrid" ],
composite_data_supported=True,
)
class PVTetQualityAnalysis( VTKPythonAlgorithmBase ):
def __init__( self: Self ) -> None:
"""QC analysis of the tetrahedras from two meshes."""
super().__init__( nInputPorts=2, inputType="vtkObject" )
self._filename: Optional[ str ] = None
self._meshes: dict[ str, vtkUnstructuredGrid ] = {}
self._outputFilename: bool = True
@smproperty.stringvector( name="FilePath", label="File Path" )
@smdomain.xml( """
<FileListDomain name="files" />
<Documentation>Output file path.</Documentation>
<Hints>
<FileChooser extensions="png" file_description="Output plot file." />
<AcceptAnyFile/>
</Hints>
""" )
def SetFileName( self: Self, fname: str ) -> None:
"""Specify filename for the output figure.
Args:
fname (str): File path
"""
if self._filename != fname:
self._filename = fname
self.Modified()
def RequestData(
self: Self,
request: vtkInformation, #noqa: F841
inInfoVec: list[ vtkInformationVector ],
outInfoVec: vtkInformationVector,
) -> 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.
"""
for n in range( 2 ):
self._meshes[ str( n ) ] = self.GetInputData( inInfoVec, n, 0 )
tetQualityAnalysisFilter: TetQualityAnalysis = TetQualityAnalysis( self._meshes, True )
if not isHandlerInLogger( HANDLER, tetQualityAnalysisFilter.logger ):
tetQualityAnalysisFilter.setLoggerHandler( HANDLER )
try:
tetQualityAnalysisFilter.setFilename( self._filename )
tetQualityAnalysisFilter.applyFilter()
except Exception as e:
tetQualityAnalysisFilter.logger.error( f' FATAL ERROR due to:\n{e}' )
return 1