[vtkusers] height field from point data

boyeggplant110 boyeggplant110 at gmail.com
Wed Dec 5 19:02:17 EST 2012


Hi all,

I try to construct a height field with VTK. My data is point data stored in
csv files. I read the data and use vtkDelaunay2D to triangulate the dataset
and vtkGeometryFilter to extract geometry . But my result just show a plane.
Does anyone know how to add the height?

I attach my code:

First part --read data: the data read from csv file  and is stored in
vtkpoints object ([x,y,0]) and the height  is stored in vtkFloatarray. Both
objects are imported to vtkploydata object

Second part ----heightfield: use vtkDelaunay2D and vtkGeometryFilter

 

 

def readdata(filename):

    dataset1=vtkPolyData()

    newpoints=vtkPoints()

    newscalars=vtkFloatArray()

    l=len(filename)

    for j in range(1,l) :

        data_csv=csv.reader(open(filename[j]))

        data_csv.next()

        data_array_temp=[0,0,0]

        index=1

        for row in data_csv:

            data_array_temp[0]=j*5

            data_array_temp[1]=index

            #data_array_temp[2]=float(row[4])

            newpoints.InsertNextPoint(data_array_temp)

            newscalars.InsertNextValue (float(row[4]))

            index=index+1

    dataset1.SetPoints(newpoints)

    dataset1.GetPointData().SetScalars(newscalars)

    return dataset1

ef heightfield(dataset):

    del2=vtkDelaunay2D()

    #del2.SetTolerance(0.01)

    del2.SetAlpha(0)

    del2.SetInput(dataset)

    print('1')

    #hf=vtkGreedyTerrainDecimation()

    #hf.SetInput(del2.GetOutput())

    geometry=vtkGeometryFilter()

    geometry.SetInput(del2.GetOutput())

    warp=vtkWarpScalar()

    warp.SetInput(geometry.GetOutput())

    warp.SetScaleFactor(1)

    warp.XYPlaneOn()

    warp.UseNormalOn()

    warp.SetNormal(0,0,2)

    lut =vtkLookupTable()

    lut.SetNumberOfColors(100)

    lut.SetHueRange(0.2, 0.97)

    lut.SetSaturationRange(-1, 1)

    lut.Build()

    merge=vtkMergeFilter()

    merge.SetGeometry(warp.GetOutput())

    merge.SetScalars(dataset)

    mapper=vtkPolyDataMapper()

    mapper.SetLookupTable(lut)

    mapper.SetInput(merge.GetOutput())

    actor=vtkActor()

    actor.SetMapper(mapper)

    renderer=vtkRenderer()

    renderer.AddActor(actor)

    renderwindow=vtkRenderWindow()

    renderwindow.AddRenderer(renderer)

    renderwindow.SetSize(200,200)

    interactor=vtkRenderWindowInteractor()

    interactor.SetRenderWindow(renderwindow)

    interactor.Initialize()

    renderwindow.Render()

    interactor.Start()

return

 

thanks in advance!

 

JIE 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20121205/eabaf03c/attachment.htm>


More information about the vtkusers mailing list