Re: hemispherical cap with hole at the bottom

David Gobbi <[email protected]> Sun, 14 Apr 2019 15:06:17 -0600
Newsgroups gmane.comp.lib.vtk.user
Message-ID <CANwS1=H2ZGJMbd_c04syvATXmDqW9qJ7z-uM+J9ja1OzthEvcg@mail.gmail.com>
--===============1772541703==
Content-Type: multipart/alternative; boundary="000000000000d35994058683e8de"

--000000000000d35994058683e8de
Content-Type: text/plain; charset="UTF-8"

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 <[email protected]> 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
>

--000000000000d35994058683e8de
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hi Petr,</div><div><br></div><div>Unfortunately, vtkC=
lipPolyData doesn&#39;t close off the surface after clipping.=C2=A0 It wasn=
&#39;t designed to do that.=C2=A0 In fact, closing things off after clippin=
g is a rather difficult problem.</div><div><br></div><div>I recommend that =
you take another approach.=C2=A0 Your cap is rotationally symmetric, right?=
=C2=A0 Try the rotational extrusion filter:=C2=A0<a href=3D"https://vtk.org=
/doc/nightly/html/classvtkRotationalExtrusionFilter.html" target=3D"_blank"=
>https://vtk.org/doc/nightly/html/classvtkRotationalExtrusionFilter.html</a=
></div><div><br></div><div>All you need to do is generate a cross-section o=
f your cap, i.e. an arc.=C2=A0 Just do this by writing a couple &quot;for&q=
uot; loops in python to build the arc using sin() and cos(), make a polylin=
e and stuff it in a vtkPolyData.=C2=A0 For example,=C2=A0<a href=3D"https:/=
/lorensen.github.io/VTKExamples/site/Python/GeometricObjects/PolyLine1/" ta=
rget=3D"_blank">https://lorensen.github.io/VTKExamples/site/Python/Geometri=
cObjects/PolyLine1/</a></div><div><br></div><div>Once you have your cross-s=
ection, pass it through vtkRotationalExtrusionFilter to generate the shape.=
</div><span class=3D"gmail-HOEnZb gmail-adL"><font color=3D"#888888"><div><=
br></div><div>=C2=A0 =C2=A0David</div></font></span></div><br><div class=3D=
"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Sun, Apr 14, 2019 at=
 9:30 AM Petr Vokac &lt;<a href=3D"mailto:[email protected]">petr.2006@c=
entrum.cz</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding=
-left:1ex">I am trying to create hemispherical cap using two spheres, clipp=
ing them by<br>
plane - it works, and clipping them by cylinder - it does not work as it<br=
>
leaves two surfaces unconnected, why?<br>
<br>
python script:<br>
<br>
#!/usr/bin/env python<br>
<br>
import vtk<br>
sphere =3D vtk.vtkSphereSource()<br>
sphere.SetRadius(10.0)<br>
<br>
spherei =3D vtk.vtkSphereSource()<br>
spherei.SetRadius(8.0)<br>
<br>
sphereir=3Dvtk.vtkReverseSense()<br>
sphereir.SetInputConnection(spherei.GetOutputPort())<br>
<br>
ext=3Dvtk.vtkAppendPolyData()<br>
ext.AddInputConnection(sphere.GetOutputPort())<br>
ext.AddInputConnection(sphereir.GetOutputPort())<br>
<br>
plane =3D vtk.vtkPlane()<br>
plane.SetOrigin([0.0,0.0,0.0])<br>
plane.SetNormal([0.0,-1.0,0.0])<br>
<br>
clipclose=3Dvtk.vtkClipClosedSurface()<br>
pc =3D vtk.vtkPlaneCollection()<br>
pc.AddItem(plane)<br>
clipclose.SetClippingPlanes(pc)<br>
clipclose.SetInputConnection(ext.GetOutputPort())<br>
<br>
cyl =3D vtk.vtkCylinder()<br>
cyl.SetCenter(0,0,0)<br>
cyl.SetRadius(5.0)<br>
ib =3D vtk.vtkImplicitBoolean()<br>
ib.AddFunction(cyl)<br>
<br>
clipper =3D vtk.vtkClipPolyData()<br>
clipper.SetInputConnection(clipclose.GetOutputPort())<br>
clipper.SetClipFunction(ib)<br>
clipper.GenerateClippedOutputOn()<br>
<br>
mapper =3D vtk.vtkPolyDataMapper()<br>
mapper.SetInputConnection(clipper.GetOutputPort())<br>
<br>
actor =3D vtk.vtkActor()<br>
actor.SetMapper(mapper)<br>
<br>
ren =3D vtk.vtkRenderer()<br>
ren.AddActor(actor)<br>
ren.ResetCamera()<br>
<br>
renWin =3D vtk.vtkRenderWindow()<br>
renWin.AddRenderer(ren)<br>
iren =3D vtk.vtkRenderWindowInteractor()<br>
iren.SetRenderWindow(renWin)<br>
<br>
iren.Initialize()<br>
renWin.Render()<br>
iren.Start()<br>
<br>
<br>
<br>
<br>
<br>
<br>
--<br>
Sent from: <a href=3D"http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.h=
tml" rel=3D"noreferrer" target=3D"_blank">http://vtk.1045678.n5.nabble.com/=
VTK-Users-f1224199.html</a><br>
_______________________________________________<br>
Powered by <a href=3D"http://www.kitware.com" rel=3D"noreferrer" target=3D"=
_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href=3D"http://www.kitware.c=
om/opensource/opensource.html" rel=3D"noreferrer" target=3D"_blank">http://=
www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href=3D"http://w=
ww.vtk.org/Wiki/VTK_FAQ" rel=3D"noreferrer" target=3D"_blank">http://www.vt=
k.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a href=3D"http://markmail.org/search/?q=3Dvtk=
users" rel=3D"noreferrer" target=3D"_blank">http://markmail.org/search/?q=
=3Dvtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href=3D"https://vtk.org/mailman/listinfo/vtkusers" rel=3D"noreferrer" ta=
rget=3D"_blank">https://vtk.org/mailman/listinfo/vtkusers</a><br>
</blockquote></div>

--000000000000d35994058683e8de--

--===============1772541703==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
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

--===============1772541703==--