1111import vtkmodules .util .numpy_support as vnp
1212from vtkmodules .vtkCommonDataModel import vtkMultiBlockDataSet , vtkDataSet
1313
14+ from geos .utils .pieceEnum import Piece
1415from geos .utils .Logger import ( getLogger , Logger , CountWarningHandler )
1516from geos .mesh .utils .arrayHelpers import ( getArrayInObject , getComponentNames , getNumberOfComponents ,
1617 getVtkDataTypeInObject , isAttributeGlobal , getAttributePieceInfo ,
@@ -116,9 +117,7 @@ def __init__(
116117 # Region attribute settings.
117118 self .regionName : str = regionName
118119 self .dictRegionValues : dict [ Any , Any ] = dictRegionValues
119- self .onPoints : Union [ None , bool ]
120- self .onBoth : bool
121- self .onPoints , self .onBoth = getAttributePieceInfo ( self .mesh , self .regionName )
120+ self .piece : Piece = getAttributePieceInfo ( self .mesh , self .regionName )
122121
123122 # Check if the new component have default values (information for the output message).
124123 self .useDefaultValue : bool = False
@@ -165,15 +164,15 @@ def applyFilter( self: Self ) -> None:
165164 self .logger .addHandler ( self .counter )
166165
167166 # Check the validity of the attribute region.
168- if self .onPoints is None :
167+ if self .piece == Piece . NONE :
169168 raise AttributeError ( f"The attribute { self .regionName } is not in the mesh." )
170169
171- if self .onBoth :
170+ if self .piece == Piece . BOTH :
172171 raise AttributeError (
173172 f"There are two attributes named { self .regionName } , one on points and the other on cells. The region attribute must be unique."
174173 )
175174
176- nbComponentsRegion : int = getNumberOfComponents ( self .mesh , self .regionName , self .onPoints )
175+ nbComponentsRegion : int = getNumberOfComponents ( self .mesh , self .regionName , self .piece )
177176 if nbComponentsRegion != 1 :
178177 raise AttributeError ( f"The region attribute { self .regionName } has to many components, one is requires." )
179178
@@ -192,11 +191,11 @@ def applyFilter( self: Self ) -> None:
192191 newArray : npt .NDArray [ Any ]
193192 if isinstance ( self .mesh , vtkMultiBlockDataSet ):
194193 # Check if the attribute region is global.
195- if not isAttributeGlobal ( self .mesh , self .regionName , self .onPoints ):
194+ if not isAttributeGlobal ( self .mesh , self .regionName , self .piece ):
196195 raise AttributeError ( f"The region attribute { self .regionName } has to be global." )
197196
198197 validIndexes , invalidIndexes = checkValidValuesInMultiBlock ( self .mesh , self .regionName , listIndexes ,
199- self .onPoints )
198+ self .piece )
200199 if len ( validIndexes ) == 0 :
201200 if len ( self .dictRegionValues ) == 0 :
202201 self .logger .warning ( "No region index entered." )
@@ -208,7 +207,7 @@ def applyFilter( self: Self ) -> None:
208207 self .defaultValue ,
209208 self .newAttributeName ,
210209 componentNames = self .componentNames ,
211- onPoints = self .onPoints ,
210+ piece = self .piece ,
212211 logger = self .logger ):
213212 raise ValueError (
214213 f"Something went wrong with the creation of the attribute { self .newAttributeName } ." )
@@ -223,20 +222,20 @@ def applyFilter( self: Self ) -> None:
223222 for flatIdDataSet in listFlatIdDataSet :
224223 dataSet : vtkDataSet = vtkDataSet .SafeDownCast ( self .mesh .GetDataSet ( flatIdDataSet ) )
225224
226- regionArray = getArrayInObject ( dataSet , self .regionName , self .onPoints )
225+ regionArray = getArrayInObject ( dataSet , self .regionName , self .piece )
227226 newArray = self ._createArrayFromRegionArrayWithValueMap ( regionArray )
228227 if not createAttribute ( dataSet ,
229228 newArray ,
230229 self .newAttributeName ,
231230 componentNames = self .componentNames ,
232- onPoints = self .onPoints ,
231+ piece = self .piece ,
233232 logger = self .logger ):
234233 raise ValueError (
235234 f"Something went wrong with the creation of the attribute { self .newAttributeName } ." )
236235
237236 else :
238237 validIndexes , invalidIndexes = checkValidValuesInDataSet ( self .mesh , self .regionName , listIndexes ,
239- self .onPoints )
238+ self .piece )
240239 if len ( validIndexes ) == 0 :
241240 if len ( self .dictRegionValues ) == 0 :
242241 self .logger .warning ( "No region index entered." )
@@ -248,7 +247,7 @@ def applyFilter( self: Self ) -> None:
248247 self .defaultValue ,
249248 self .newAttributeName ,
250249 componentNames = self .componentNames ,
251- onPoints = self .onPoints ,
250+ piece = self .piece ,
252251 logger = self .logger ):
253252 raise ValueError (
254253 f"Something went wrong with the creation of the attribute { self .newAttributeName } ." )
@@ -258,13 +257,13 @@ def applyFilter( self: Self ) -> None:
258257 self .logger .warning (
259258 f"The region indexes { invalidIndexes } are not in the region attribute { self .regionName } ." )
260259
261- regionArray = getArrayInObject ( self .mesh , self .regionName , self .onPoints )
260+ regionArray = getArrayInObject ( self .mesh , self .regionName , self .piece )
262261 newArray = self ._createArrayFromRegionArrayWithValueMap ( regionArray )
263262 if not createAttribute ( self .mesh ,
264263 newArray ,
265264 self .newAttributeName ,
266265 componentNames = self .componentNames ,
267- onPoints = self .onPoints ,
266+ piece = self .piece ,
268267 logger = self .logger ):
269268 raise ValueError (
270269 f"Something went wrong with the creation of the attribute { self .newAttributeName } ." )
@@ -282,7 +281,7 @@ def _setInfoRegion( self: Self ) -> None:
282281 """
283282 # Get the numpy type from the vtk typecode.
284283 dictType : dict [ int , Any ] = vnp .get_vtk_to_numpy_typemap ()
285- regionVtkType : int = getVtkDataTypeInObject ( self .mesh , self .regionName , self .onPoints )
284+ regionVtkType : int = getVtkDataTypeInObject ( self .mesh , self .regionName , self .piece )
286285 regionNpType : type = dictType [ regionVtkType ]
287286
288287 # Set the correct type of values and region index.
@@ -356,11 +355,10 @@ def _logOutputMessage( self: Self, trueIndexes: list[ Any ] ) -> None:
356355
357356 # Info about the created attribute.
358357 # The piece where the attribute is created.
359- piece : str = "points" if self .onPoints else "cells"
360- self .logger .info ( f"The new attribute { self .newAttributeName } is created on { piece } ." )
358+ self .logger .info ( f"The new attribute { self .newAttributeName } is created on { self .piece .value } ." )
361359
362360 # The number of component and they names if multiple.
363- componentNamesCreated : tuple [ str , ...] = getComponentNames ( self .mesh , self .newAttributeName , self .onPoints )
361+ componentNamesCreated : tuple [ str , ...] = getComponentNames ( self .mesh , self .newAttributeName , self .piece )
364362 if self .nbComponents > 1 :
365363 messComponent : str = ( f"The new attribute { self .newAttributeName } has { self .nbComponents } components"
366364 f" named { componentNamesCreated } ." )
0 commit comments