<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi<div><br></div><div>I am trying to smooth a meshgrid to get a nice terrain map like this :</div><div><br></div><div><a href="http://i18.photobucket.com/albums/b117/666villa/RCT3/Landscape004.jpg">http://i18.photobucket.com/albums/b117/666villa/RCT3/Landscape004.jpg</a></div><div><a href="http://marc.jacquier.free.fr/tuts/trace_while/h_f.gif">http://marc.jacquier.free.fr/tuts/trace_while/h_f.gif</a></div><div><a href="http://research.microsoft.com/~hoppe/proj/svdlod/">http://research.microsoft.com/~hoppe/proj/svdlod/</a></div><div><br></div><div>So with a roundish/smoothed aspect.</div><div><br></div><div>I am building my terrain with triangles for the moment, from a dataset of x, y, z coordinates.</div><div><br></div><div>I tried the vtkSmoothPolyDataFilter but no smoothing is done. Is this the right filter to use ? What other filters could I use on my meshgrid to obtain the wanted aspect ?</div><div><br></div><div>I added a screenshot of the original terrain and the smoothed one (which in this case is not) at the end.</div><div><br></div><div>Any help would be appreciated :)</div><div><br></div><div>Michka</div><div><br></div><div><br></div><div><br></div><div><br></div><div>#!/usr/bin/env python</div><div><br></div><div>import vtk</div><div>import random</div><div>import numpy</div><div><br></div><div>colors = vtk.vtkUnsignedCharArray()</div><div>colors.SetNumberOfComponents(3)</div><div><br></div><div>size = 32</div><div><br></div><div>topography = numpy.zeros([size, size])</div><div>for i in range(size):</div><div> for j in range(size):</div><div> topography[i][j] = random.randrange(0, 100)</div><div><br></div><div>points = vtk.vtkPoints()</div><div><br></div><div>triangles = vtk.vtkCellArray()</div><div>mult = 100.0</div><div><br></div><div>count = 0</div><div><br></div><div>for i in range(size-1):</div><div> for j in range(size-1):</div><div> </div><div> z1 = topography[i][j]</div><div> z2 = topography[i][j+1]</div><div> z3 = topography[i+1][j]</div><div> </div><div> # Triangle 1</div><div> points.InsertNextPoint(i*mult, j*mult, z1)</div><div> points.InsertNextPoint(i*mult, (j+1)*mult, z2)</div><div> points.InsertNextPoint((i+1)*mult, j*mult, z3)</div><div> </div><div> triangle = vtk.vtkTriangle()</div><div> triangle.GetPointIds().SetId ( 0, count )</div><div> triangle.GetPointIds().SetId ( 1, count + 1 )</div><div> triangle.GetPointIds().SetId ( 2, count + 2 )</div><div> </div><div> triangles.InsertNextCell ( triangle )</div><div> </div><div> z1 = topography[i][j+1]</div><div> z2 = topography[i+1][j+1]</div><div> z3 = topography[i+1][j]</div><div> </div><div> # Triangle 2</div><div> points.InsertNextPoint(i*mult, (j+1)*mult, z1)</div><div> points.InsertNextPoint((i+1)*mult, (j+1)*mult, z2)</div><div> points.InsertNextPoint((i+1)*mult, j*mult, z3)</div><div> </div><div> triangle = vtk.vtkTriangle()</div><div> triangle.GetPointIds().SetId ( 0, count + 3)</div><div> triangle.GetPointIds().SetId ( 1, count + 4 )</div><div> triangle.GetPointIds().SetId ( 2, count + 5 )</div><div> </div><div> count += 6</div><div> </div><div> triangles.InsertNextCell ( triangle )</div><div> </div><div> # Add some color</div><div> r = [int(i/float(size)*255),int(j/float(size)*255),0]</div><div> colors.InsertNextTupleValue(r)</div><div> colors.InsertNextTupleValue(r)</div><div> colors.InsertNextTupleValue(r)</div><div> colors.InsertNextTupleValue(r)</div><div> colors.InsertNextTupleValue(r)</div><div> colors.InsertNextTupleValue(r)</div><div><br></div><div># Create a polydata object</div><div>trianglePolyData = vtk.vtkPolyData()</div><div><br></div><div># Add the geometry and topology to the polydata</div><div>trianglePolyData.SetPoints (points)</div><div>trianglePolyData.GetPointData().SetScalars(colors)</div><div>trianglePolyData.SetPolys (triangles)</div><div><br></div><div># Try to smooth the meshgrid<b> (Does nothing ?)</b></div><div>smooth = vtk.vtkSmoothPolyDataFilter()</div><div>smooth.SetInputData(trianglePolyData)</div><div>smooth.SetRelaxationFactor(0.001)</div><div>smooth.SetNumberOfIterations(20)</div><div><br></div><div># Create a mapper and actor for normal dataset</div><div>mapper = vtk.vtkPolyDataMapper()</div><div>mapper.SetInputData(trianglePolyData)</div><div>actor = vtk.vtkActor()</div><div>actor.SetMapper(mapper)</div><div><br></div><div># Create a mapper and actor for smoothed dataset</div><div>mapper = vtk.vtkPolyDataMapper()</div><div>mapper.SetInputConnection(smooth.GetOutputPort())</div><div>actor_filtered = vtk.vtkActor()</div><div>actor_filtered.SetMapper(mapper)</div><div>actor_filtered.SetPosition(4000, 0, 0)</div><div><br></div><div># Visualize</div><div>renderer = vtk.vtkRenderer()</div><div>renderWindow = vtk.vtkRenderWindow()</div><div>renderWindow.AddRenderer(renderer)</div><div>renderWindowInteractor = vtk.vtkRenderWindowInteractor()</div><div>renderWindowInteractor.SetRenderWindow(renderWindow)</div><div><br></div><div>renderer.AddActor(actor)</div><div>renderer.AddActor(actor_filtered)</div><div>renderer.SetBackground(0,0,0) # Background color white</div><div><br></div><div>renderWindow.SetSize(800, 800)</div><div>renderWindow.Render()</div><div>renderWindowInteractor.Start() </div><div><br></div><div><img apple-inline="yes" id="AD16B95D-7F8B-42FA-BD5F-B49F6968B37F" height="512" width="645" apple-width="yes" apple-height="yes" src="cid:F80D2D19-E0D7-40EB-B0A1-82C9BBDF58D7"></div></body></html>