[vtkusers] Mesh from contours using vtkRuledSurfaceFilter
Paul Kibet Korir
pkorir at ebi.ac.uk
Thu Jun 9 12:00:37 EDT 2016
In case someone finds this useful...
Source:
http://www.paraview.org/Wiki/VTK/Examples/Python/PolyData/RuledSurfaceFilter
Trick: vtkRuledSurfaceFilter requires the vtkPolyData it works on to
have Lines (set with SetLines(cells) method) NOT Polygons
---
import vtk
# create a rendering window and renderer
ren = vtk.vtkRenderer()
ren.SetBackground(0.1, 0.2, 0.4)
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.FullScreenOn()
# create a renderwindowinteractor
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
#Create the points fot the lines.
points = vtk.vtkPoints()
points.InsertPoint(0, 0, 0, 1)
points.InsertPoint(1, 0, 0, 0)
points.InsertPoint(2, 1, 0, 0)
points.InsertPoint(3, 0, 1, 1)
points.InsertPoint(4, 1, 1, 1)
points.InsertPoint(5, 1, 1, 0)
line1 = vtk.vtkPolyLine()
line1.GetPointIds().SetNumberOfIds(3)
line1.GetPointIds().SetId(0, 0)
line1.GetPointIds().SetId(1, 1)
line1.GetPointIds().SetId(2, 2)
line2 = vtk.vtkPolyLine()
line2.GetPointIds().SetNumberOfIds(3)
line2.GetPointIds().SetId(0, 3)
line2.GetPointIds().SetId(1, 4)
line2.GetPointIds().SetId(2, 5)
#Create a cellArray containing the lines
lines =vtk.vtkCellArray()
lines.InsertNextCell(line1)
lines.InsertNextCell(line2)
#Create the vtkPolyData to contain the points and cellArray with the lines
polydata = vtk.vtkPolyData()
polydata.SetPoints(points)
polydata.SetLines(lines)
print polydata
#Create the ruledSurfaceFilter from the polydata containing the lines
ruledSurfaceFilter = vtk.vtkRuledSurfaceFilter()
ruledSurfaceFilter.SetInputData(polydata)
ruledSurfaceFilter.SetResolution(21, 21)
ruledSurfaceFilter.SetRuledModeToResample()
ruledSurfaceFilter.Update()
#Create the mapper with the ruledSufaceFilter as input
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(ruledSurfaceFilter.GetOutput())
mapper.Update()
#create the actor with the mapper
actor = vtk.vtkActor()
actor.SetMapper(mapper)
#add the actor to the display
ren.AddActor(actor)
# enable user interface interactor
iren.Initialize()
renWin.Render()
iren.Start()
---
Regards,
Paul
On 08/06/2016 16:00, Paul Kibet Korir wrote:
>
> Hellos,
>
> The vtkRuledSurfaceFilter documentation
> <http://www.vtk.org/doc/release/7.0/html/classvtkRuledSurfaceFilter.html#a68bd60190bef5e8d9b15f79c0576e189>
> states that this filter "...can also be used to create surfaces from
> contours".
>
> Can someone please share an example on how this can be achieved? I've
> tried many things to no avail.
>
>
> --
> With kind regards,
>
> *Dr. Paul K Korir, PhD*
> /Scientific Programmer/
> EMBL-EBI
> Main Building, A2-35,
> WTGC, Hinxton, Cambridge CB10 1SD
> P: +44 1223 49 44 22
> F: +44 1223 49 44 68
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
--
With kind regards,
*Dr. Paul K Korir, PhD*
/Scientific Programmer/
EMBL-EBI
Main Building, A2-35,
WTGC, Hinxton, Cambridge CB10 1SD
P: +44 1223 49 44 22
F: +44 1223 49 44 68
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160609/3351772a/attachment.html>
More information about the vtkusers
mailing list