コード例 #1
0
 def readFromHdf5(cls,
                  hdf5Parser,
                  varName,
                  triSurfaceMesh,
                  key,
                  projectedField=False):
     '''
     '''
     time = hdf5Parser[key]['time'].value
     stensSrc = hdf5Parser[key][varName].value
     stensTgt = np.zeros((stensSrc.shape[0],stensSrc.shape[1]))
     if projectedField==True:
         for i in range(stensSrc.shape[0]):
             stenAsMat = TriSurface.mat(stensSrc[i,:])
             stensTgt[i,:] = triSurfaceMesh.linTrans.srcToTgt(stenAsMat)
     else:
         stensTgt = stensSrc
     
     # update class member variables
     return cls(txx=stensTgt[:,0],
                txy=stensTgt[:,1],
                txz=stensTgt[:,2],
                tyy=stensTgt[:,3],
                tyz=stensTgt[:,4],
                tzz=stensTgt[:,5],
                time=float(time),
                triSurfaceMesh=triSurfaceMesh,
                projectedField=projectedField,
                interpolation=None,
                kind=None) 
コード例 #2
0
    def readFromHdf5(cls,
                     hdf5Parser,
                     varName,
                     triSurfaceMesh,
                     key,
                     projectedField=False):
        '''
        '''
        time = hdf5Parser[key]['time'].value
        stensSrc = hdf5Parser[key][varName].value
        stensTgt = np.zeros((stensSrc.shape[0], stensSrc.shape[1]))
        if projectedField == True:
            for i in range(stensSrc.shape[0]):
                stenAsMat = TriSurface.mat(stensSrc[i, :])
                stensTgt[i, :] = triSurfaceMesh.linTrans.srcToTgt(stenAsMat)
        else:
            stensTgt = stensSrc

        # update class member variables
        return cls(txx=stensTgt[:, 0],
                   txy=stensTgt[:, 1],
                   txz=stensTgt[:, 2],
                   tyy=stensTgt[:, 3],
                   tyz=stensTgt[:, 4],
                   tzz=stensTgt[:, 5],
                   time=float(time),
                   triSurfaceMesh=triSurfaceMesh,
                   projectedField=projectedField,
                   interpolation=None,
                   kind=None)
コード例 #3
0
    def readFromVTK(cls,
                    vtkFile,
                    viewAnchor,
                    xViewBasis,
                    yViewBasis,
                    srcBasisSrc=[[1,0,0],[0,1,0],[0,0,1]]):
        '''
        Construct from a surface saved by OpenFOAM in VTK format.
        '''
        afftrans, lintrans = TriSurface.getTransformation(viewAnchor,
                                                          xViewBasis,
                                                          yViewBasis,
                                                          srcBasisSrc)
       
        # read VTK file
        ptsSrc, triangles, vecsSrc = ParserFunctions.parseVTK_ugly_sampledSurface(vtkFile)
        
        # Transform the points
        ptsTgt = np.zeros((ptsSrc.shape[0],ptsSrc.shape[1]))
        for i in range(ptsSrc.shape[0]):
            ptsTgt[i,:] = afftrans.srcToTgt(ptsSrc[i,:])

        # update class member variables
        return cls(x=ptsTgt[:,0],
                   y=ptsTgt[:,1],
                   z=ptsTgt[:,2],
                   triangles=triangles,
                   mask=None,
                   affTrans=afftrans,
                   linTrans=lintrans)
コード例 #4
0
    def readFromVTK(cls,
                    vtkFile,
                    viewAnchor,
                    xViewBasis,
                    yViewBasis,
                    srcBasisSrc=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]):
        '''
        Construct from a surface saved by OpenFOAM in VTK format.
        '''
        afftrans, lintrans = TriSurface.getTransformation(
            viewAnchor, xViewBasis, yViewBasis, srcBasisSrc)

        # read VTK file
        ptsSrc, triangles, vecsSrc = ParserFunctions.parseVTK_ugly_sampledSurface(
            vtkFile)

        # Transform the points
        ptsTgt = np.zeros((ptsSrc.shape[0], ptsSrc.shape[1]))
        for i in range(ptsSrc.shape[0]):
            ptsTgt[i, :] = afftrans.srcToTgt(ptsSrc[i, :])

        # update class member variables
        return cls(x=ptsTgt[:, 0],
                   y=ptsTgt[:, 1],
                   z=ptsTgt[:, 2],
                   triangles=triangles,
                   mask=None,
                   affTrans=afftrans,
                   linTrans=lintrans)
コード例 #5
0
    def readFromFoamFile(cls,
                         varsFile,
                         triSurfaceMesh,
                         time,
                         projectedField=False):
        '''
        Construct from a surface saved  by OpenFOAM in foamFile format.
        
        Arguments:
            *varsFile*: python string.
             Path to the file holding the scalar field.
             
            *time*: python float
             timestep of the surface. If this information does not matter,
             use 0.
             
            *triSurfaceMesh* :  TriSurfaceMesh object.
             TriSurfaceMesh object, which holds the mesh information.
             
            *projectedField* python bool (default=False)
             Unused for the scalar field, but might be used for the fields
             added with the methods "addField", "addFieldFromFoamFile" and
             "addFieldFromVtk"
        '''

        #get scalars
        stensSrc = ParserFunctions.parseFoamFile_sampledSurface(varsFile)
        stensTgt = np.zeros((stensSrc.shape[0],stensSrc.shape[1]))
        if projectedField==True:
            for i in range(stensSrc.shape[0]):
                stenAsMat = TriSurface.mat(stensSrc[i,:])
                stensTgt[i,:] = triSurfaceMesh.linTrans.srcToTgt(stenAsMat)
        else:
            stensTgt = stensSrc

        # update class member variables
        return cls(txx=stensTgt[:,0],
                   txy=stensTgt[:,1],
                   txz=stensTgt[:,2],
                   tyy=stensTgt[:,3],
                   tyz=stensTgt[:,4],
                   tzz=stensTgt[:,5],
                   time=time,
                   triSurfaceMesh=triSurfaceMesh,
                   projectedField=projectedField,
                   interpolation=None,
                   kind=None)
コード例 #6
0
    def readFromFoamFile(cls,
                         varsFile,
                         triSurfaceMesh,
                         time,
                         projectedField=False):
        '''
        Construct from a surface saved  by OpenFOAM in foamFile format.
        
        Arguments:
            *varsFile*: python string.
             Path to the file holding the scalar field.
             
            *time*: python float
             timestep of the surface. If this information does not matter,
             use 0.
             
            *triSurfaceMesh* :  TriSurfaceMesh object.
             TriSurfaceMesh object, which holds the mesh information.
             
            *projectedField* python bool (default=False)
             Unused for the scalar field, but might be used for the fields
             added with the methods "addField", "addFieldFromFoamFile" and
             "addFieldFromVtk"
        '''

        #get scalars
        stensSrc = ParserFunctions.parseFoamFile_sampledSurface(varsFile)
        stensTgt = np.zeros((stensSrc.shape[0], stensSrc.shape[1]))
        if projectedField == True:
            for i in range(stensSrc.shape[0]):
                stenAsMat = TriSurface.mat(stensSrc[i, :])
                stensTgt[i, :] = triSurfaceMesh.linTrans.srcToTgt(stenAsMat)
        else:
            stensTgt = stensSrc

        # update class member variables
        return cls(txx=stensTgt[:, 0],
                   txy=stensTgt[:, 1],
                   txz=stensTgt[:, 2],
                   tyy=stensTgt[:, 3],
                   tyz=stensTgt[:, 4],
                   tzz=stensTgt[:, 5],
                   time=time,
                   triSurfaceMesh=triSurfaceMesh,
                   projectedField=projectedField,
                   interpolation=None,
                   kind=None)
コード例 #7
0
def transformPoints(ptsSrc,
                    xViewBasis,
                    yViewBasis=None,
                    viewAnchor=(0, 0, 0),
                    srcBasisSrc=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]):
    '''
    '''
    # create basis vectors if missing
    if not yViewBasis:
        n = getN(ptsSrc)
        yViewBasis = getYBasis(n, xViewBasis)

    # create the transformation objects
    afftrans, lintrans = TriSurface.getTransformation(viewAnchor, xViewBasis,
                                                      yViewBasis, srcBasisSrc)

    # transform the points from the source basis to the target basis
    ptsTgt = np.zeros((ptsSrc.shape[0], ptsSrc.shape[1]))
    for i in range(ptsSrc.shape[0]):
        ptsTgt[i, :] = afftrans.srcToTgt(ptsSrc[i, :])

    return ptsTgt, afftrans, lintrans
コード例 #8
0
def transformPoints(ptsSrc,
                     xViewBasis,
                     yViewBasis=None,
                     viewAnchor=(0,0,0),
                     srcBasisSrc=[[1,0,0],[0,1,0],[0,0,1]]):
    '''
    '''
    # create basis vectors if missing
    if not yViewBasis:
        n=getN(ptsSrc)
        yViewBasis=getYBasis(n,xViewBasis)
    
    # create the transformation objects    
    afftrans, lintrans = TriSurface.getTransformation(viewAnchor,
                                          xViewBasis,
                                          yViewBasis,
                                          srcBasisSrc)
    
    # transform the points from the source basis to the target basis
    ptsTgt = np.zeros((ptsSrc.shape[0],ptsSrc.shape[1]))
    for i in range(ptsSrc.shape[0]):
        ptsTgt[i,:] = afftrans.srcToTgt(ptsSrc[i,:])
        
    return ptsTgt,afftrans,lintrans