Skip to content

Commit a35eb2c

Browse files
committed
ci fix
1 parent 7adc08b commit a35eb2c

File tree

11 files changed

+865
-765
lines changed

11 files changed

+865
-765
lines changed

geos-mesh/src/geos/mesh/model/CellTypeCounts.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@
44
import numpy as np
55
import numpy.typing as npt
66
from typing_extensions import Self
7-
from vtkmodules.vtkCommonDataModel import (
8-
vtkCellTypes,
9-
VTK_TRIANGLE, VTK_QUAD, VTK_TETRA, VTK_VERTEX, VTK_POLYHEDRON, VTK_POLYGON, VTK_PYRAMID, VTK_HEXAHEDRON, VTK_WEDGE, VTK_NUMBER_OF_CELL_TYPES
10-
)
11-
7+
from vtkmodules.vtkCommonDataModel import ( vtkCellTypes, VTK_TRIANGLE, VTK_QUAD, VTK_TETRA, VTK_VERTEX, VTK_POLYHEDRON,
8+
VTK_POLYGON, VTK_PYRAMID, VTK_HEXAHEDRON, VTK_WEDGE,
9+
VTK_NUMBER_OF_CELL_TYPES )
1210

1311
__doc__ = """
1412
CellTypeCounts stores the number of elements of each type.
1513
"""
1614

15+
1716
class CellTypeCounts():
18-
def __init__(self: Self ) ->None:
17+
18+
def __init__( self: Self ) -> None:
1919
"""CellTypeCounts stores the number of cells of each type."""
20-
self._counts: npt.NDArray[np.int64] = np.zeros(VTK_NUMBER_OF_CELL_TYPES, dtype=float)
20+
self._counts: npt.NDArray[ np.int64 ] = np.zeros( VTK_NUMBER_OF_CELL_TYPES, dtype=float )
2121

22-
def __str__(self: Self) ->str:
22+
def __str__( self: Self ) -> str:
2323
"""Overload __str__ method.
2424
2525
Returns:
2626
str: counts as string.
2727
"""
2828
return self.print()
2929

30-
def __add__(self: Self, other :Self) ->Self:
30+
def __add__( self: Self, other: Self ) -> Self:
3131
"""Addition operator.
3232
3333
CellTypeCounts addition consists in suming counts.
@@ -38,32 +38,32 @@ def __add__(self: Self, other :Self) ->Self:
3838
Returns:
3939
Self: new CellTypeCounts object
4040
"""
41-
assert isinstance(other, CellTypeCounts), "Other object must be a CellTypeCounts."
41+
assert isinstance( other, CellTypeCounts ), "Other object must be a CellTypeCounts."
4242
newCounts: CellTypeCounts = CellTypeCounts()
4343
newCounts._counts = self._counts + other._counts
4444
return newCounts
4545

46-
def addType(self: Self, cellType: int) ->None:
46+
def addType( self: Self, cellType: int ) -> None:
4747
"""Increment the number of cell of input type.
4848
4949
Args:
5050
cellType (int): cell type
5151
"""
52-
self._counts[cellType] += 1
53-
self._updateGeneralCounts(cellType, 1)
52+
self._counts[ cellType ] += 1
53+
self._updateGeneralCounts( cellType, 1 )
5454

55-
def setTypeCount(self: Self, cellType: int, count: int) ->None:
55+
def setTypeCount( self: Self, cellType: int, count: int ) -> None:
5656
"""Set the number of cells of input type.
5757
5858
Args:
5959
cellType (int): cell type
6060
count (int): number of cells
6161
"""
62-
prevCount = self._counts[cellType]
63-
self._counts[cellType] = count
64-
self._updateGeneralCounts(cellType, count - prevCount)
62+
prevCount = self._counts[ cellType ]
63+
self._counts[ cellType ] = count
64+
self._updateGeneralCounts( cellType, count - prevCount )
6565

66-
def getTypeCount(self: Self, cellType: int)->int:
66+
def getTypeCount( self: Self, cellType: int ) -> int:
6767
"""Get the number of cells of input type.
6868
6969
Args:
@@ -72,36 +72,36 @@ def getTypeCount(self: Self, cellType: int)->int:
7272
Returns:
7373
int: number of cells
7474
"""
75-
return int(self._counts[cellType])
75+
return int( self._counts[ cellType ] )
7676

77-
def _updateGeneralCounts(self: Self, cellType: int, count: int) ->None:
77+
def _updateGeneralCounts( self: Self, cellType: int, count: int ) -> None:
7878
"""Update generic type counters.
7979
8080
Args:
8181
cellType (int): cell type
8282
count (int): count increment
8383
"""
84-
if (cellType != VTK_POLYGON) and (vtkCellTypes.GetDimension(cellType) == 2):
85-
self._counts[VTK_POLYGON] += count
86-
if (cellType != VTK_POLYHEDRON) and (vtkCellTypes.GetDimension(cellType) == 3):
87-
self._counts[VTK_POLYHEDRON] += count
84+
if ( cellType != VTK_POLYGON ) and ( vtkCellTypes.GetDimension( cellType ) == 2 ):
85+
self._counts[ VTK_POLYGON ] += count
86+
if ( cellType != VTK_POLYHEDRON ) and ( vtkCellTypes.GetDimension( cellType ) == 3 ):
87+
self._counts[ VTK_POLYHEDRON ] += count
8888

89-
def print(self: Self) ->str:
89+
def print( self: Self ) -> str:
9090
"""Print counts string.
9191
9292
Returns:
9393
str: counts string.
9494
"""
9595
card: str = ""
96-
card += "| | |\n"
97-
card += "| - | - |\n"
96+
card += "| | |\n"
97+
card += "| - | - |\n"
9898
card += f"| **Total Number of Vertices** | {int(self._counts[VTK_VERTEX]):12} |\n"
9999
card += f"| **Total Number of Polygon** | {int(self._counts[VTK_POLYGON]):12} |\n"
100100
card += f"| **Total Number of Polyhedron** | {int(self._counts[VTK_POLYHEDRON]):12} |\n"
101101
card += f"| **Total Number of Cells** | {int(self._counts[VTK_POLYHEDRON]+self._counts[VTK_POLYGON]):12} |\n"
102-
card += "| - | - |\n"
103-
for cellType in (VTK_TRIANGLE, VTK_QUAD):
102+
card += "| - | - |\n"
103+
for cellType in ( VTK_TRIANGLE, VTK_QUAD ):
104104
card += f"| **Total Number of {vtkCellTypes.GetClassNameFromTypeId(cellType):<13}** | {int(self._counts[cellType]):12} |\n"
105-
for cellType in (VTK_TETRA, VTK_PYRAMID, VTK_WEDGE, VTK_HEXAHEDRON):
105+
for cellType in ( VTK_TETRA, VTK_PYRAMID, VTK_WEDGE, VTK_HEXAHEDRON ):
106106
card += f"| **Total Number of {vtkCellTypes.GetClassNameFromTypeId(cellType):<13}** | {int(self._counts[cellType]):12} |\n"
107107
return card

geos-mesh/src/geos/mesh/processing/MergeColocatedPoints.py

Lines changed: 55 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
vtkCell,
2020
)
2121

22-
2322
__doc__ = """
2423
MergeColocatedPoints module is a vtk filter that merges colocated points from input mesh.
2524
@@ -47,10 +46,12 @@
4746
output :vtkUnstructuredGrid = filter.GetOutputDataObject(0)
4847
"""
4948

50-
class MergeColocatedPoints(VTKPythonAlgorithmBase):
51-
def __init__(self: Self ) ->None:
49+
50+
class MergeColocatedPoints( VTKPythonAlgorithmBase ):
51+
52+
def __init__( self: Self ) -> None:
5253
"""MergeColocatedPoints filter merges duplacted points of the input mesh."""
53-
super().__init__(nInputPorts=1, nOutputPorts=1, outputType="vtkUnstructuredGrid")
54+
super().__init__( nInputPorts=1, nOutputPorts=1, outputType="vtkUnstructuredGrid" )
5455

5556
def FillInputPortInformation( self: Self, port: int, info: vtkInformation ) -> int:
5657
"""Inherited from VTKPythonAlgorithmBase::RequestInformation.
@@ -63,13 +64,14 @@ def FillInputPortInformation( self: Self, port: int, info: vtkInformation ) -> i
6364
int: 1 if calculation successfully ended, 0 otherwise.
6465
"""
6566
if port == 0:
66-
info.Set(self.INPUT_REQUIRED_DATA_TYPE(), "vtkUnstructuredGrid")
67-
68-
def RequestDataObject(self: Self,
69-
request: vtkInformation, # noqa: F841
70-
inInfoVec: list[ vtkInformationVector ], # noqa: F841
71-
outInfoVec: vtkInformationVector,
72-
) -> int:
67+
info.Set( self.INPUT_REQUIRED_DATA_TYPE(), "vtkUnstructuredGrid" )
68+
69+
def RequestDataObject(
70+
self: Self,
71+
request: vtkInformation, # noqa: F841
72+
inInfoVec: list[ vtkInformationVector ], # noqa: F841
73+
outInfoVec: vtkInformationVector,
74+
) -> int:
7375
"""Inherited from VTKPythonAlgorithmBase::RequestDataObject.
7476
7577
Args:
@@ -80,19 +82,20 @@ def RequestDataObject(self: Self,
8082
Returns:
8183
int: 1 if calculation successfully ended, 0 otherwise.
8284
"""
83-
inData = self.GetInputData(inInfoVec, 0, 0)
84-
outData = self.GetOutputData(outInfoVec, 0)
85+
inData = self.GetInputData( inInfoVec, 0, 0 )
86+
outData = self.GetOutputData( outInfoVec, 0 )
8587
assert inData is not None
86-
if outData is None or (not outData.IsA(inData.GetClassName())):
88+
if outData is None or ( not outData.IsA( inData.GetClassName() ) ):
8789
outData = inData.NewInstance()
88-
outInfoVec.GetInformationObject(0).Set(outData.DATA_OBJECT(), outData)
89-
return super().RequestDataObject(request, inInfoVec, outInfoVec)
90-
91-
def RequestData(self: Self,
92-
request: vtkInformation, # noqa: F841
93-
inInfoVec: list[ vtkInformationVector ], # noqa: F841
94-
outInfoVec: vtkInformationVector,
95-
) -> int:
90+
outInfoVec.GetInformationObject( 0 ).Set( outData.DATA_OBJECT(), outData )
91+
return super().RequestDataObject( request, inInfoVec, outInfoVec )
92+
93+
def RequestData(
94+
self: Self,
95+
request: vtkInformation, # noqa: F841
96+
inInfoVec: list[ vtkInformationVector ], # noqa: F841
97+
outInfoVec: vtkInformationVector,
98+
) -> int:
9699
"""Inherited from VTKPythonAlgorithmBase::RequestData.
97100
98101
Args:
@@ -104,17 +107,14 @@ def RequestData(self: Self,
104107
int: 1 if calculation successfully ended, 0 otherwise.
105108
"""
106109
inData: vtkUnstructuredGrid = vtkUnstructuredGrid.GetData( inInfoVec[ 0 ] )
107-
output: vtkUnstructuredGrid = self.GetOutputData(outInfoVec, 0)
110+
output: vtkUnstructuredGrid = self.GetOutputData( outInfoVec, 0 )
108111
assert inData is not None, "Input mesh is undefined."
109112
assert output is not None, "Output mesh is undefined."
110-
vertexMap: list[int] = self.setMergePoints(inData, output)
111-
self.setCells(inData, output, vertexMap)
113+
vertexMap: list[ int ] = self.setMergePoints( inData, output )
114+
self.setCells( inData, output, vertexMap )
112115
return 1
113116

114-
def setMergePoints(self :Self,
115-
input: vtkUnstructuredGrid,
116-
output: vtkUnstructuredGrid
117-
) ->list[int]:
117+
def setMergePoints( self: Self, input: vtkUnstructuredGrid, output: vtkUnstructuredGrid ) -> list[ int ]:
118118
"""Merge duplicated points and set new points and attributes to output mesh.
119119
120120
Args:
@@ -124,36 +124,33 @@ def setMergePoints(self :Self,
124124
Returns:
125125
list[int]: list containing new point ids.
126126
"""
127-
vertexMap: list[int] = []
127+
vertexMap: list[ int ] = []
128128
newPoints: vtkPoints = vtkPoints()
129129
# use point locator to check for colocated points
130130
pointsLocator = vtkIncrementalOctreePointLocator()
131-
pointsLocator.InitPointInsertion(newPoints,input.GetBounds())
131+
pointsLocator.InitPointInsertion( newPoints, input.GetBounds() )
132132
# create an array to count the number of colocated points
133133
vertexCount: vtkIntArray = vtkIntArray()
134-
vertexCount.SetName("Count")
135-
ptId = reference(0)
136-
countD: int = 0 # total number of colocated points
137-
for v in range(input.GetNumberOfPoints()):
138-
inserted: bool = pointsLocator.InsertUniquePoint( input.GetPoints().GetPoint(v), ptId)
134+
vertexCount.SetName( "Count" )
135+
ptId = reference( 0 )
136+
countD: int = 0 # total number of colocated points
137+
for v in range( input.GetNumberOfPoints() ):
138+
inserted: bool = pointsLocator.InsertUniquePoint( input.GetPoints().GetPoint( v ), ptId )
139139
if inserted:
140-
vertexCount.InsertNextValue(1)
140+
vertexCount.InsertNextValue( 1 )
141141
else:
142-
vertexCount.SetValue( ptId, vertexCount.GetValue(ptId) + 1)
142+
vertexCount.SetValue( ptId, vertexCount.GetValue( ptId ) + 1 )
143143
countD = countD + 1
144-
vertexMap += [ptId.get()]
144+
vertexMap += [ ptId.get() ]
145145

146-
output.SetPoints(pointsLocator.GetLocatorPoints())
146+
output.SetPoints( pointsLocator.GetLocatorPoints() )
147147
# copy point attributes
148-
output.GetPointData().DeepCopy(input.GetPointData())
148+
output.GetPointData().DeepCopy( input.GetPointData() )
149149
# add the array to points data
150-
output.GetPointData().AddArray(vertexCount)
150+
output.GetPointData().AddArray( vertexCount )
151151
return vertexMap
152152

153-
def setCells(self :Self,
154-
input: vtkUnstructuredGrid,
155-
output: vtkUnstructuredGrid,
156-
vertexMap: list[int]) ->bool:
153+
def setCells( self: Self, input: vtkUnstructuredGrid, output: vtkUnstructuredGrid, vertexMap: list[ int ] ) -> bool:
157154
"""Set cell point ids and attributes to output mesh.
158155
159156
Args:
@@ -166,21 +163,22 @@ def setCells(self :Self,
166163
"""
167164
nbCells: int = input.GetNumberOfCells()
168165
nbPoints: int = output.GetNumberOfPoints()
169-
assert np.unique(vertexMap).size == nbPoints, "The size of the list of point ids must be equal to the number of points."
166+
assert np.unique(
167+
vertexMap ).size == nbPoints, "The size of the list of point ids must be equal to the number of points."
170168
cellTypes: vtkCellTypes = vtkCellTypes()
171-
input.GetCellTypes(cellTypes)
172-
output.Allocate(nbCells)
169+
input.GetCellTypes( cellTypes )
170+
output.Allocate( nbCells )
173171
# create mesh cells
174-
for cellId in range(nbCells):
175-
cell: vtkCell = input.GetCell(cellId)
172+
for cellId in range( nbCells ):
173+
cell: vtkCell = input.GetCell( cellId )
176174
# create cells from point ids
177175
cellsID: vtkIdList = vtkIdList()
178-
for ptId in range(cell.GetNumberOfPoints()):
179-
ptIdOld: int = cell.GetPointId(ptId)
180-
ptIdNew: int = vertexMap[ptIdOld]
181-
cellsID.InsertNextId(ptIdNew)
182-
output.InsertNextCell(cell.GetCellType(), cellsID)
176+
for ptId in range( cell.GetNumberOfPoints() ):
177+
ptIdOld: int = cell.GetPointId( ptId )
178+
ptIdNew: int = vertexMap[ ptIdOld ]
179+
cellsID.InsertNextId( ptIdNew )
180+
output.InsertNextCell( cell.GetCellType(), cellsID )
183181
# copy cell attributes
184182
assert output.GetNumberOfCells() == nbCells, "Output and input mesh must have the same number of cells."
185-
output.GetCellData().DeepCopy(input.GetCellData())
183+
output.GetCellData().DeepCopy( input.GetCellData() )
186184
return True

0 commit comments

Comments
 (0)