[vtkusers] Problem clamping 2D line to surface

Guillaume Dumont dumont.guillaume at gmail.com
Thu Feb 20 12:17:15 EST 2014


Ok solved my problem by myself.

I was all wrong. I found how to do this with vtkProjectedTerrainPath. I
posted another message to the mailing list about this. Here it is for
reference:

In case someone else is interested in this I found an example (more
precisely a test) at:
http://vtk.org/gitweb?p=VTK.git;a=blob;f=Filters/Hybrid/Testing/Python/TestProjectedTerrainPath.py

which I was able to modify to suit my needs.

In the ends it boils down to:

- Load the STL file and create a vtkImageData containing the the elevation
of the points. In my case I used an image that encompasses all the points
in the STL and a vtkCellLocator to get the elevation for each "pixel" in
the image.

- Create polylines with default elevation.

- Use vtkProjectedTerrainPath with the vtkImageData and the vtkPolyData of
the polylines

- Render as usual.

the gotchas I found is that it seems that only the Hug projection mode
worked for me. Also, I had some trouble figuring at the origin of the
vtkImageData should be: in my case the min x and min y of the STL surface
and 0 for z so that the polylines and surface line up properly.

Guillaume


On Thu, Feb 13, 2014 at 11:55 AM, Guillaume Dumont <
dumont.guillaume at gmail.com> wrote:

> Hi,
>
> I have an elevation map stored in a STL file. I can successfully load this
> as a vtkPolyData instance and display it. Now, I have several 2D polylines
> that I want to display as paths on this surface. From the documentation (
> http://www.vtk.org/doc/nightly/html/classvtkProjectedTerrainPath.html#details)
> I understand that I can use vtkProjectedTerrainPath for that. However, I
> cannot find any examples of its usage.
>
> Can anyone give me C++, Python or pseudo-code that would get me started?
>
> From what I understand I need to convert my vtkPolyData to vtkImageData.
> How can I do that?
>
> Many thanks.
>
> Guillaume
>


On Fri, Jan 17, 2014 at 4:37 PM, Guillaume Dumont <
dumont.guillaume at gmail.com> wrote:

> 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
>



-- 
Guillaume Dumont
=========================
dumont.guillaume at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140220/7c2df1d9/attachment.html>


More information about the vtkusers mailing list