Ejemplo n.º 1
0
 def getVert(self,icell):
     if self.data.GetCell(icell).GetCellType() == 8 :
         pts=ah.vtk2array(self.data.GetCell(icell).GetPoints().GetData())
         return np.array((pts[0][0:2],pts[1][0:2],pts[3][0:2],pts[2][0:2]))
     if self.data.GetCell(icell).GetCellType() == 3 :
         pts=ah.vtk2array(self.data.GetCell(icell).GetPoints().GetData())
         return np.array((pts[0][0],pts[1][0]))
     else: 
         if (self.silent == 0): print  "Can handle only type 3 or type 8"
Ejemplo n.º 2
0
def get_pointdata(offset,filenameout='data',type='pvtu',attribute_mode='cell'):

    if type == 'vtu':
        filename=''.join([filenameout,repr(offset).zfill(4),'.vtu'])
        datareader = v.vtkXMLUnstructuredGridReader()
    elif type == 'pvtu':
        filename=''.join([filenameout,repr(offset).zfill(4),'.pvtu'])
        datareader = v.vtkXMLPUnstructuredGridReader()
        
    print '=== Reading ',filename,' ==='
        
    datareader.SetFileName(filename)
    datareader.Update()
    data = datareader.GetOutput()

    if attribute_mode == 'cell':
        c2p = v.vtkCellDataToPointData()
        c2p.SetInput(data)
        pointdata=c2p.GetOutput()
        pointdata.Update()
    else:
        pointdata = data 


    vtk_points=data.GetPoints().GetData()
    points=ah.vtk2array(vtk_points)
 
    print '=== Done with reading data! ==='
    return {'pointdata': pointdata, 'points': points}
Ejemplo n.º 3
0
 def getPoints(self):
     try:
         self.data
     except AttributeError:
         self.getData()
     try:
         self.points
     except AttributeError:
         vtk_points=self.data.GetPoints().GetData()
         self.points=ah.vtk2array(vtk_points)
     return self.points
Ejemplo n.º 4
0
def vtk_points(offset,filenameout='data'):

    filename=''.join([filenameout,repr(offset),'.vtk'])

    datareader = v.vtkDataSetReader()
    datareader.SetFileName(filename)
    datareader.Update()
    data = datareader.GetOutput()
    
    vtk_points=data.GetPoints().GetData()
    points=ah.vtk2array(vtk_points)
    return points
Ejemplo n.º 5
0
def vtu_points(offset,filenameout='data',):

    filename=''.join([filenameout,repr(offset).zfill(4),'.vtu'])

    datareader = v.vtkXMLUnstructuredGridReader()
    datareader.SetFileName(filename)
    datareader.Update()
    data = datareader.GetOutput()
    
    vtk_points=data.GetPoints().GetData()
    points=ah.vtk2array(vtk_points)
    return points
Ejemplo n.º 6
0
def vtk_points(offset, filenameout='data'):

    filename = ''.join([filenameout, repr(offset), '.vtk'])

    datareader = v.vtkDataSetReader()
    datareader.SetFileName(filename)
    datareader.Update()
    data = datareader.GetOutput()

    vtk_points = data.GetPoints().GetData()
    points = ah.vtk2array(vtk_points)
    return points
Ejemplo n.º 7
0
def vtu_points(
    offset,
    filenameout='data',
):

    filename = ''.join([filenameout, repr(offset).zfill(4), '.vtu'])

    datareader = v.vtkXMLUnstructuredGridReader()
    datareader.SetFileName(filename)
    datareader.Update()
    data = datareader.GetOutput()

    vtk_points = data.GetPoints().GetData()
    points = ah.vtk2array(vtk_points)
    return points
Ejemplo n.º 8
0
def vtu_values(offset, varname, filenameout='data', attribute_mode='cell'):

    filename = ''.join([filenameout, repr(offset).zfill(4), '.vtu'])

    datareader = v.vtkXMLUnstructuredGridReader()
    datareader.SetFileName(filename)
    datareader.Update()
    data = datareader.GetOutput()

    if attribute_mode == 'cell':
        vtk_values = data.GetCellData().GetArray(varname)
    elif attribute_mode == 'point':
        vtk_values = data.GetPointData().GetArray(varname)
    else:
        print "attribute_mode is either 'cell' or 'point'"

# this is convenient to convert vtkarrays to numpy arrays
    value = ah.vtk2array(vtk_values)
    return value
Ejemplo n.º 9
0
def vtu_values(offset,varname,filenameout='data',attribute_mode='cell'):

    filename=''.join([filenameout,repr(offset).zfill(4),'.vtu'])

    datareader = v.vtkXMLUnstructuredGridReader()
    datareader.SetFileName(filename)
    datareader.Update()
    data = datareader.GetOutput()
    
    if attribute_mode == 'cell':
        vtk_values = data.GetCellData().GetArray(varname)
    elif attribute_mode == 'point':
        vtk_values = data.GetPointData().GetArray(varname)
    else:
        print "attribute_mode is either 'cell' or 'point'"
        
# this is convenient to convert vtkarrays to numpy arrays
    value = ah.vtk2array(vtk_values)
    return value
Ejemplo n.º 10
0
def vtk_values(offset,varname,filenameout='data',attribute_mode='point'):
    # This can be used for the legacy vtk data generated by paraview filters.  
    
    filename=''.join([filenameout,repr(offset),'.vtk'])

    datareader = v.vtkDataSetReader()
    datareader.SetFileName(filename)
    datareader.Update()
    data = datareader.GetOutput()
    
    if attribute_mode == 'cell':
        vtk_values = data.GetCellData().GetArray(varname)
    elif attribute_mode == 'point':
        vtk_values = data.GetPointData().GetArray(varname)
    else:
        print "attribute_mode is either 'cell' or 'point'"
        
# this is convenient to convert vtkarrays to numpy arrays
    value = ah.vtk2array(vtk_values)
    return value
Ejemplo n.º 11
0
def vtk_values(offset, varname, filenameout='data', attribute_mode='point'):
    # This can be used for the legacy vtk data generated by paraview filters.

    filename = ''.join([filenameout, repr(offset), '.vtk'])

    datareader = v.vtkDataSetReader()
    datareader.SetFileName(filename)
    datareader.Update()
    data = datareader.GetOutput()

    if attribute_mode == 'cell':
        vtk_values = data.GetCellData().GetArray(varname)
    elif attribute_mode == 'point':
        vtk_values = data.GetPointData().GetArray(varname)
    else:
        print "attribute_mode is either 'cell' or 'point'"

# this is convenient to convert vtkarrays to numpy arrays
    value = ah.vtk2array(vtk_values)
    return value
Ejemplo n.º 12
0
 def getPointList(self):
     tstart = default_timer()
     try:
         self.data
     except AttributeError:
         self.getData()
     try:
         [self.xlist,self.ylist]
     except AttributeError:
         if self.data.GetCell(0).GetCellType() != 8 :
             if (self.silent == 0): print  "Can handle pixel types only"
             pass
         self.xlist = []
         self.ylist = []
         for icell in range(self.ncells):
             pts=ah.vtk2array(self.data.GetCell(icell).GetPoints().GetData())
             self.xlist.extend((pts[0][0],pts[1][0],pts[3][0],pts[2][0],None))
             self.ylist.extend((pts[0][1],pts[1][1],pts[3][1],pts[2][1],None))
     tend = default_timer()
     if (self.silent == 0): print  'Getting formatted pointlist time=%f sec' % (tend-tstart)
     return [self.xlist,self.ylist]        
Ejemplo n.º 13
0
def get_pointdata(offset,filenameout='data',type='pvtu'):

    if type == 'vtu':
        filename=''.join([filenameout,repr(offset).zfill(4),'.vtu'])
        datareader = v.vtkXMLUnstructuredGridReader()
    elif type == 'pvtu':
        filename=''.join([filenameout,repr(offset).zfill(4),'.pvtu'])
        datareader = v.vtkXMLPUnstructuredGridReader()
        
    print '=== Reading ',filename,' ==='
        
    datareader.SetFileName(filename)
    datareader.Update()
    data = datareader.GetOutput()
    c2p = v.vtkCellDataToPointData()
    c2p.SetInput(data)
    pointdata=c2p.GetOutput()
    pointdata.Update()
 
    vtk_points=data.GetPoints().GetData()
    points=ah.vtk2array(vtk_points)
 
    print '=== Done with reading data! ==='
    return {'pointdata': pointdata, 'points': points}
Ejemplo n.º 14
0
def extract(data,varname,attribute_mode='cell'):
    '''Extracts variable "varname" from vtk datastructure "data"'''
    if attribute_mode == 'cell':
        vtk_values = data.GetCellData().GetArray(varname)
    elif attribute_mode == 'point':
        if data.GetPointData().GetNumberOfArrays() > 0:
            vtk_values = data.GetPointData().GetArray(varname)
        else:
            # Convert to pointdata first
            c2p = v.vtkCellDataToPointData()
            c2p.SetInput(data)
            pointdata=c2p.GetOutput()
            pointdata.Update()
            vtk_values = pointdata.GetPointData().GetScalars(varname)
    elif attribute_mode == 'topoint':
        c2p = v.vtkCellDataToPointData()
        c2p.SetInput(data)
        pointdata=c2p.GetOutput()
        pointdata.Update()
    	vtk_values = pointdata.GetPointData().GetScalars(varname)
    else:
        print "attribute_mode is either 'cell' or 'point'"
    
    return (ah.vtk2array(vtk_values)).astype(np.float64)
Ejemplo n.º 15
0
 def getTime(self):
     try:
         self.time=ah.vtk2array(self.data.GetFieldData().GetArray(0))[0]
     except AttributeError:
         self.time = np.nan
     return self.time