[vtkusers] Problem clamping 2D line to surface

Guillaume Dumont dumont.guillaume at gmail.com
Fri Jan 17 16:37:09 EST 2014


Hi,

I am new to vtk and I am trying to clamp a 2D line to 3D surface. By clamp
I mean that I want the z coordinates of the line to follow as close as
possible the z coordinates of the surface. I figured that would apply thin
plate spline transform to the line but I might have configured things wrong
because I can't get it to work. What's the best way to accomplish this in
VTK? Is this even possible?

Below is my python code for reference, and attached a screenshot of the
rendering window.

Any help is appreciated.

Thanks

Guillaume

import sysimport vtk

filename = sys.argv[1]

renderer = vtk.vtkRenderer()

window = vtk.vtkRenderWindow()
window.AddRenderer(renderer)

interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(window)

style = vtk.vtkInteractorStyleTrackballCamera()
interactor.SetInteractorStyle(style)

reader = vtk.vtkSTLReader()
reader.SetFileName(filename)
reader.Update()

transform = vtk.vtkTransform()
transform.Scale(1,1,20)

filter = vtk.vtkTransformFilter()
filter.SetTransform(transform)
filter.SetInput(reader.GetOutput())

mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(filter.GetOutput() )

actor = vtk.vtkActor()
actor.SetMapper(mapper)

renderer.AddActor(actor)
 ## create source
source = vtk.vtkLineSource()
source.SetPoint1(800,800,2800)
source.SetPoint2(2000,2000,2800)

transform2 = vtk.vtkThinPlateSplineTransform()
transform2.SetSourceLandmarks( filter.GetOutput().GetPoints() )
transform2.SetTargetLandmarks( filter.GetOutput().GetPoints() )

filter2 = vtk.vtkTransformFilter()
filter2.SetTransform(transform2)
filter2.SetInput(source.GetOutput())
 # mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(filter2.GetOutput())
 # actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
 # color actor
actor.GetProperty().SetColor(1,0,1)
 # assign actor to the renderer
renderer.AddActor(actor)

window.Render()
interactor.Start()





-- 
Guillaume Dumont
=========================
dumont.guillaume at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140117/5a0d5bfb/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtk.png
Type: image/png
Size: 121691 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140117/5a0d5bfb/attachment-0001.png>


More information about the vtkusers mailing list