import medcoupling as mc
import numpy as np
+def patchVTKArr( arrLi ):
+ i = 0
+ nbFaces = arrLi[i] ; i += 1
+ ret = [None for elt in range(nbFaces)]
+ for iFace in range(nbFaces):
+ nbPtsInFace = arrLi[i] ; i += 1
+ if iFace > 0:
+ ret[iFace] = [-1]
+ else:
+ ret[iFace] = []
+ ret[iFace] += arrLi[i:i+nbPtsInFace] ; i += nbPtsInFace
+ ret = [ mc.NORM_POLYHED] + sum( ret, [] )
+ return mc.DataArrayInt( ret )
+
+def patchForPolyedra(polyhedCellIds, ug, mesh):
+ """
+ Method in charge to change the connectivity of polyedra contained in mesh using ug vtkUnstructuredGrid.
+
+ :param in polyhedCellIds: mc.DataArrayInt of cells ids in mesh to be patched
+ :param in ug: vtkUnstructuredGrid containing polyhedra
+ :param in-out mesh: mc.MEDCouplingUMesh. 3D Mesh whose polyedra cells connectivity will be modified
+ """
+ c, ci = mesh.getNodalConnectivity(), mesh.getNodalConnectivityIndex()
+ facesLoc = mc.DataArrayInt( numpy_support.vtk_to_numpy( ug.GetFaceLocations() ) )
+ faces = mc.DataArrayInt( numpy_support.vtk_to_numpy( ug.GetFaces() ) )
+ facesLoc = mc.DataArrayInt.Aggregate( [ facesLoc, mc.DataArrayInt([ len(faces) ]) ] )
+ connForPoly = mc.DataArrayInt.Aggregate( [patchVTKArr( ( faces[facesLoc[i]:facesLoc[i+1]] ).getValues() ) for i in range(ug.GetNumberOfCells()) ] )
+ tmpDa = mc.DataArrayInt( len(facesLoc) ) ; tmpDa.iota()
+ facesLoc -= tmpDa
+ meshPoly = mc.MEDCouplingUMesh( mesh.getName(), 3) ; meshPoly.setCoords( mesh.getCoords() ) ; meshPoly.setConnectivity(connForPoly,facesLoc,True)
+ mesh[polyhedCellIds] = meshPoly
+ pass
+
def mesh_convertor(fileName):
#vtk.vtkDataSetReader()
reader = vtk.vtkXMLUnstructuredGridReader()
m.setConnectivity(c,ci,True)
m.checkConsistencyLight()
#
+ if m.getMeshDimension() == 3:
+ polyhedCellIds = ct.findIdsEqual(mc.NORM_POLYHED)
+ if not polyhedCellIds.empty():
+ patchForPolyedra(polyhedCellIds, ug, m)
+ #
return m