<html><div style='background-color:'><DIV>
<P>Hello!! I have just started using vtk and it seems that I have run into some nasty errors. I have a problem with the memory, as I get a segmentation fault when i try to run my program. The program first reads a .vtk file and after some smoothing I am able to plot an image (bathymetry map). When I try to overlay the coastline i get the segmentation fault. The coastline is made of a number of vertices, stored in the cell array. Cant find the bug(s).</P>
<P>I am also wondering on how to write the cell, scalar and vertices data to one big .vtk file. I was only able to write the point data to file.</P>
<P>I am grateful for any help. The program is attached to the bottom of this email. Sincerely, Trond Kristiansen. </P><FONT size=1>
<P>from Numeric import *</P>
<P>from vtk import *</P>
<P>import string</P>
<P>reader=vtkStructuredGridReader()</P>
<P>reader.SetFileName('../Sandwell/w.vtk')</P>
<P>mapper=vtkDataSetMapper()</P>
<P>mapper.SetInput(reader.GetOutput())</P>
<P>data=reader.GetOutput()</P>
<P>delaunay = vtkDelaunay2D()</P>
<P>delaunay.SetInput(data)</P>
<P>delaunay.SetTolerance(0.0001)</P>
<P>delaunay.Update()</P>
<P>delaunayData =delaunay.GetOutput()</P>
<P>print 'Number Of Points ', delaunayData.GetNumberOfPoints()</P>
<P>print 'Number Of Polygons Created ', delaunayData.GetNumberOfPolys()</P>
<P>smooth = vtkSmoothPolyDataFilter()</P>
<P>smooth.SetNumberOfIterations(20)</P>
<P>smooth.SetRelaxationFactor(0.1)</P>
<P>smooth.SetFeatureAngle(30.0)</P>
<P>smooth.SetEdgeAngle(10.0)</P>
<P>smooth.SetInput(delaunayData)</P>
<P>smooth.Update()</P>
<P>smoothData=smooth.GetOutput()</P>
<P>polys=vtkDataSetMapper()</P>
<P>polys.SetInput(smoothData)</P>
<P># Start overlay of high res coastline</P>
<P>coast = open('coastline.dat','r')</P>
<P>coastXY = coast.readline()</P>
<P>XY = string.split(coastXY)</P>
<P> </P>
<P>poly = vtkPolyData()</P>
<P>point = vtkPoints()</P>
<P>cell = vtkCellArray()</P>
<P>cell.Squeeze()</P>
<P>while coastXY:</P>
<P></P>
<P>if XY[0] =='nan': name='nan'</P>
<P>else:</P>
<P>coastlineX=string.atof(XY[0])*1000</P>
<P>coastlineY=string.atof(XY[1])*1000</P>
<P>coastlineZ=0.1</P>
<P>if (55000 < coastlineY < 61000) and (5000 < coastlineX < 11000):</P>
<P>pointID=point.InsertNextPoint(coastlineX,coastlineY,coastlineZ)</P>
<P>cell.InsertNextCell(pointID)</P>
<P></P>
<P>coastXY = coast.readline()</P>
<P>XY = string.split(coastXY)</P>
<P></P>
<P>coast.close()</P>
<P>poly.SetPoints(point)</P>
<P>poly.SetVerts(cell)</P>
<P>poly.Update()</P>
<P>actor=vtkActor()</P>
<P>actor.SetMapper(polys)</P>
<P>glMapper=vtkPolyDataMapper()</P>
<P>glMapper.SetInput(poly)</P>
<P> </P>
<P>Coastactor=vtkActor()</P>
<P>Coastactor.SetMapper(glMapper)</P>
<P>#Coastactor.GetProperty().SetColor(0,0,0)</P>
<P>#Coastactor.GetProperty().SetPointSize(0.1)</P>
<P>ren=vtkRenderer()</P>
<P>ren.AddActor(actor)</P>
<P># !!!! BUG , unless not used!!</P>
<P>#ren.AddActor(Coastactor)</P>
<P>win=vtkRenderWindow()</P>
<P>win.AddRenderer(ren)</P>
<P>win.SetSize(1000,1000)</P>
<P> </P>
<P>iren=vtkRenderWindowInteractor()</P>
<P>iren.SetRenderWindow(win)</P>
<P> </P>
<P> </P>
<P>iren.Initialize()</P>
<P>iren.Start()</P>
<P>polys=None</P>
<P>actor=None</P>
<P>ren=None</P>
<P>mapper=None</P>
<P>reader=None</P>
<P>delaunay=None</P>
<P></FONT><BR><BR> </P></DIV>
<DIV></DIV><BR>
<DIV></DIV></div><br clear=all><hr>MSN Photos is the easiest way to share and print your photos: <a href='http://g.msn.com/1HM1ENNO/c156??PI=44351'>Click Here</a><br></html>