Domanda

I read through a PYTHON script an unstructuredGrid which format is vtk. I'd like to offset every points of this UGrid. I mean i have a x, y and z offset which I would like to apply to the UGrid so that I can obtain the same origin for two different mesh. I can't directly assign this offset since the coordinates are tuples. Any advice welcolmed.

Thx,

Arnaud

È stato utile?

Soluzione

What I use quite often is the following function to read an ascii vtk file, process the points and write it again to a new file.

def offsetVTK(infilename, outfilename, offset):
    outfil = open(outfilename,'w')
    with open(infilename,'r') as infil:
        lin = 1
        while lin:
            lin = infil.readline()
            if lin.lower().startswith('points'):
                numpt = int(lin.split()[1])
                outfil.write(lin)
                for i in xrange(numpt):
                    outfil.write('{0[0]} {0[1]} {0[2]}\n'.format(
                       np.array(infil.readline().split(),dtype=float) + offset))
            else:
                outfil.write(lin)
    outfil.close()

offsetVTK('ray.vtk','ray_off.vtk', np.array([100,0,0]))

Originally, I used it to rotate and shear the grid, however applying an offset is even easier.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top