[vtkusers] hemispherical cap with hole at the bottom

David Gobbi david.gobbi at gmail.com
Sun Apr 14 17:06:17 EDT 2019


Hi Petr,

Unfortunately, vtkClipPolyData doesn't close off the surface after
clipping.  It wasn't designed to do that.  In fact, closing things off
after clipping is a rather difficult problem.

I recommend that you take another approach.  Your cap is rotationally
symmetric, right?  Try the rotational extrusion filter:
https://vtk.org/doc/nightly/html/classvtkRotationalExtrusionFilter.html

All you need to do is generate a cross-section of your cap, i.e. an arc.
Just do this by writing a couple "for" loops in python to build the arc
using sin() and cos(), make a polyline and stuff it in a vtkPolyData.  For
example,
https://lorensen.github.io/VTKExamples/site/Python/GeometricObjects/PolyLine1/

Once you have your cross-section, pass it through
vtkRotationalExtrusionFilter to generate the shape.

   David

On Sun, Apr 14, 2019 at 9:30 AM Petr Vokac <petr.2006 at centrum.cz> wrote:

> I am trying to create hemispherical cap using two spheres, clipping them by
> plane - it works, and clipping them by cylinder - it does not work as it
> leaves two surfaces unconnected, why?
>
> python script:
>
> #!/usr/bin/env python
>
> import vtk
> sphere = vtk.vtkSphereSource()
> sphere.SetRadius(10.0)
>
> spherei = vtk.vtkSphereSource()
> spherei.SetRadius(8.0)
>
> sphereir=vtk.vtkReverseSense()
> sphereir.SetInputConnection(spherei.GetOutputPort())
>
> ext=vtk.vtkAppendPolyData()
> ext.AddInputConnection(sphere.GetOutputPort())
> ext.AddInputConnection(sphereir.GetOutputPort())
>
> plane = vtk.vtkPlane()
> plane.SetOrigin([0.0,0.0,0.0])
> plane.SetNormal([0.0,-1.0,0.0])
>
> clipclose=vtk.vtkClipClosedSurface()
> pc = vtk.vtkPlaneCollection()
> pc.AddItem(plane)
> clipclose.SetClippingPlanes(pc)
> clipclose.SetInputConnection(ext.GetOutputPort())
>
> cyl = vtk.vtkCylinder()
> cyl.SetCenter(0,0,0)
> cyl.SetRadius(5.0)
> ib = vtk.vtkImplicitBoolean()
> ib.AddFunction(cyl)
>
> clipper = vtk.vtkClipPolyData()
> clipper.SetInputConnection(clipclose.GetOutputPort())
> clipper.SetClipFunction(ib)
> clipper.GenerateClippedOutputOn()
>
> mapper = vtk.vtkPolyDataMapper()
> mapper.SetInputConnection(clipper.GetOutputPort())
>
> actor = vtk.vtkActor()
> actor.SetMapper(mapper)
>
> ren = vtk.vtkRenderer()
> ren.AddActor(actor)
> ren.ResetCamera()
>
> renWin = vtk.vtkRenderWindow()
> renWin.AddRenderer(ren)
> iren = vtk.vtkRenderWindowInteractor()
> iren.SetRenderWindow(renWin)
>
> iren.Initialize()
> renWin.Render()
> iren.Start()
>
>
>
>
>
>
> --
> Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
> _______________________________________________
> 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:
> https://vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20190414/cfcbf17d/attachment.html>


More information about the vtkusers mailing list