Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
4671570
First working version + some debug
jacquesn7 Sep 5, 2025
f70a9be
get rid of np.matrix
jacquesn7 Sep 5, 2025
faeb6a4
Using PV Transform filter
jacquesn7 Sep 5, 2025
dcea142
style
jacquesn7 Sep 5, 2025
0635ef1
more testing
jacquesn7 Sep 5, 2025
652dd7e
lint and style
jacquesn7 Sep 5, 2025
a801816
yapf-ing
jacquesn7 Sep 5, 2025
5b051e8
name conv
jafranc Sep 8, 2025
fa66f4b
change for full vtkTransform inheritance
jafranc Sep 8, 2025
8db4114
loglevel changes and clean up
jafranc Sep 8, 2025
29d549f
file's header
jafranc Sep 8, 2025
0a2f1cb
using vtkLandmarkTransform and vtkOBBTree
jafranc Sep 9, 2025
9be24e9
some doc and accessible tests
jafranc Sep 9, 2025
29ba247
ruff and yapf
jafranc Sep 10, 2025
e46b174
docs
jafranc Sep 10, 2025
9493451
fix doc and rename module
jafranc Sep 10, 2025
43d7e25
Fix test and all quadrant
jafranc Sep 12, 2025
6a5d546
Adressing Romain's comments
jafranc Sep 12, 2025
ce7b9b5
Some MaJ + conftest use
jafranc Sep 12, 2025
8439b24
minors
jafranc Sep 12, 2025
e7afe9c
Merge branch 'main' into jafranc/feat/translateAndRotate
jafranc Sep 12, 2025
20eec19
Logger
jafranc Sep 12, 2025
633e810
placeholders
jafranc Sep 12, 2025
a75723f
yapf
jafranc Sep 12, 2025
7f7fea6
stars not good for docs
jafranc Sep 12, 2025
3b27c66
first working version for input: VTU
jafranc Sep 15, 2025
e30a4a4
first working version with MBDS
jafranc Sep 15, 2025
b8ffc41
last corr before PR
jafranc Sep 16, 2025
af9f31f
apply Romain's comments
jafranc Sep 17, 2025
4cdf4d9
fin comm test + mypy/ruff/yapf
jafranc Sep 17, 2025
3d4d09c
wip
jafranc Sep 17, 2025
0fcb633
Merge branch 'jafranc/feat/translateAndRotate' into jafranc/feat/PVTr…
jafranc Sep 17, 2025
f6c3834
Romain's trick to get both Unstructured and MBDS
jafranc Sep 17, 2025
5f65ffa
few fixes
jafranc Sep 18, 2025
1f34cd3
Merge branch 'main' into jafranc/feat/PVTranslateAndRotate
jafranc Sep 18, 2025
a470718
typo
jafranc Sep 18, 2025
8099917
infortunate duplication removed
jafranc Sep 18, 2025
37a82f7
Merge branch 'jafranc/feat/PVTranslateAndRotate' of https://github.co…
jafranc Sep 18, 2025
02598c7
yapf
jafranc Sep 18, 2025
a684fb1
Ensure compat w PV12.X and python <3.10
jafranc Sep 19, 2025
9c08276
Merge branch 'jafranc/feat/PVTranslateAndRotate' of https://github.co…
jafranc Sep 19, 2025
2d2f762
Romain's comments
jafranc Sep 19, 2025
7f5076a
Message from Romain
jafranc Sep 24, 2025
ff8260d
Update ClipToMainFrame.py
jafranc Sep 24, 2025
7fa7bde
yapfing
jafranc Sep 25, 2025
0a232ec
Merge branch 'jafranc/feat/PVTranslateAndRotate' of https://github.co…
jafranc Sep 25, 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
6 changes: 6 additions & 0 deletions docs/geos_pv_docs/processing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ PVSplitMesh
----------------------------------

.. automodule:: geos.pv.plugins.PVSplitMesh


PVClipToMainFrame
----------------------------------

.. automodule:: geos.pv.plugins.PVClipToMainFrame
17 changes: 10 additions & 7 deletions geos-mesh/src/geos/mesh/processing/ClipToMainFrame.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# SPDX-License-Identifier: Apache 2.0
# SPDX-FileCopyrightText: Copyright 2023-2025 TotalEnergies
# SPDX-FileContributor: Jacques Franc
from typing import Tuple
import logging

import numpy as np
import numpy.typing as npt

from vtkmodules.numpy_interface import dataset_adapter as dsa
from vtkmodules.vtkCommonCore import vtkPoints
Expand All @@ -11,15 +16,9 @@
from vtkmodules.vtkCommonTransforms import vtkLandmarkTransform
from vtkmodules.vtkFiltersGeneral import vtkTransformFilter

from geos.utils.Logger import logging, Logger, getLogger

from geos.utils.Logger import ( Logger, getLogger )
from geos.mesh.utils.genericHelpers import getMultiBlockBounds

import numpy as np
import numpy.typing as npt

from typing import Tuple

__doc__ = """
Module to clip a mesh to the main frame using rigid body transformation.

Expand Down Expand Up @@ -241,13 +240,17 @@ def ComputeTransform( self ) -> None:
# dispatch to ClipToMainFrame depending on input type
if isinstance( self.GetInput(), vtkMultiBlockDataSet ):
#locate reference point
self.logger.info(
"Processing MultiblockDataSet.\n Please make sure your MultiblockDataSet is owning a vtkUnstructured grid as a leaf."
)
try:
idBlock = self.__locate_reference_point( self.GetInput() )
except IndexError:
self.logger.error( "Reference point is not in the domain" )

clip = ClipToMainFrameElement( self.GetInput().GetDataSet( idBlock ) )
else:
self.logger.info( "Processing untructuredGrid" )
clip = ClipToMainFrameElement( self.GetInput() )

clip.Update()
Expand Down
2 changes: 1 addition & 1 deletion geos-mesh/src/geos/mesh/utils/genericHelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def to_vtk_id_list( data: List[ int ] ) -> vtkIdList:
return result


def vtk_iter( vtkContainer: vtkIdList | vtkCellTypes ) -> Iterator[ Any ]:
def vtk_iter( vtkContainer: Union[ vtkIdList, vtkCellTypes ] ) -> Iterator[ Any ]:
"""Utility function transforming a vtk "container" into an iterable.

Args:
Expand Down
16 changes: 9 additions & 7 deletions geos-mesh/tests/test_clipToMainFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
import pytest
import itertools
from dataclasses import dataclass
from typing import Generator, Tuple
from typing import Generator, Tuple, List
from vtkmodules.vtkCommonCore import vtkIdList, vtkPoints
from vtkmodules.vtkCommonDataModel import vtkUnstructuredGrid, vtkHexahedron, vtkMultiBlockDataSet
from vtkmodules.numpy_interface import dataset_adapter as dsa
import numpy as np
import numpy.typing as npt
from vtkmodules.util.vtkConstants import VTK_HEXAHEDRON

from typing import List

from geos.mesh.processing.ClipToMainFrame import ClipToMainFrame

Lx, Ly, Lz = 5, 2, 8
Expand Down Expand Up @@ -76,8 +74,9 @@ def __build_test_mesh( mxx: Tuple[ int, ...] ) -> Generator[ Expected, None, Non

# Creating multiple meshes, each time with a different angles
mesh = vtkUnstructuredGrid()
( vtps := vtkPoints() ).SetData( dsa.numpy_support.numpy_to_vtk( pts ) )
mesh.SetPoints( vtps )
vpts = vtkPoints()
vpts.SetData( dsa.numpy_support.numpy_to_vtk( pts ) )
mesh.SetPoints( vpts )

ids = vtkIdList()
for i in range( nx - 1 ):
Expand All @@ -103,7 +102,8 @@ def __build_test_mesh( mxx: Tuple[ int, ...] ) -> Generator[ Expected, None, Non
"expected", [ item for t in list( itertools.product( [ -1, 1 ], repeat=3 ) ) for item in __build_test_mesh( t ) ] )
def test_clipToMainFrame_polyhedron( expected: Expected ) -> None:
"""Test the ClipToMainFrameFilter on a rotated and translated box hexa mesh."""
( filter := ClipToMainFrame() ).SetInputData( expected.mesh )
filter = ClipToMainFrame()
filter.SetInputData( expected.mesh )
filter.ComputeTransform()
filter.Update()
output_mesh: vtkUnstructuredGrid = filter.GetOutput()
Expand Down Expand Up @@ -133,10 +133,12 @@ def test_clipToMainFrame_polyhedron( expected: Expected ) -> None:
def test_clipToMainFrame_generic( dataSetTest: vtkMultiBlockDataSet ) -> None:
"""Test the ClipToMainFrameFilter on a MultiBlockDataSet."""
multiBlockDataSet: vtkMultiBlockDataSet = dataSetTest( "multiblock" )
( filter := ClipToMainFrame() ).SetInputData( multiBlockDataSet )
filter = ClipToMainFrame()
filter.SetInputData( multiBlockDataSet )
filter.ComputeTransform()
filter.Update()
print( filter.GetTransform() )
output_mesh: vtkMultiBlockDataSet = filter.GetOutputDataObject( 0 )
assert output_mesh.GetNumberOfPoints() == multiBlockDataSet.GetNumberOfPoints()
assert output_mesh.GetNumberOfCells() == multiBlockDataSet.GetNumberOfCells()
assert output_mesh.IsA( 'vtkMultiBlockDataSet' )
109 changes: 109 additions & 0 deletions geos-pv/src/geos/pv/plugins/PVClipToMainFrame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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