1919 vtkCell ,
2020)
2121
22-
2322__doc__ = """
2423MergeColocatedPoints module is a vtk filter that merges colocated points from input mesh.
2524
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