<div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Here is a quick example to illustrate what David said, I'll add this and a C++ version to VTKExamples.</div><div class="gmail_default" style="font-size:small">Petr, you should consider using [VTK Discourse](<a href="https://discourse.vtk.org/">https://discourse.vtk.org/</a>) instead of this site.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">##############################################</div><div class="gmail_default" style="font-size:small"><pre style="color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:18pt"><span style="color:rgb(128,128,128);font-style:italic">#!/usr/bin/env python<br></span><span style="color:rgb(128,128,128);font-style:italic"><br></span><span style="color:rgb(0,0,128);font-weight:bold">import </span>math<br><br><span style="color:rgb(0,0,128);font-weight:bold">import </span>vtk<br><br><br><span style="color:rgb(0,0,128);font-weight:bold">def </span>get_program_parameters():<br>    <span style="color:rgb(0,0,128);font-weight:bold">import </span>argparse<br>    description = <span style="color:rgb(0,128,128);font-weight:bold">''<br></span><span style="color:rgb(0,128,128);font-weight:bold">    </span>epilogue = <span style="color:rgb(0,128,128);font-weight:bold">'''<br></span><span style="color:rgb(0,128,128);font-weight:bold"><br></span><span style="color:rgb(0,128,128);font-weight:bold">   '''<br></span><span style="color:rgb(0,128,128);font-weight:bold">    </span>parser = argparse.ArgumentParser(<span style="color:rgb(102,0,153)">description</span>=description, <span style="color:rgb(102,0,153)">epilog</span>=epilogue,<br>                                     <span style="color:rgb(102,0,153)">formatter_class</span>=argparse.RawDescriptionHelpFormatter)<br>    parser.add_argument(<span style="color:rgb(0,128,128);font-weight:bold">'angle'</span>, <span style="color:rgb(102,0,153)">default</span>=<span style="color:rgb(0,0,255)">90</span>, <span style="color:rgb(102,0,153)">type</span>=<span style="color:rgb(0,0,128)">float</span>, <span style="color:rgb(102,0,153)">nargs</span>=<span style="color:rgb(0,128,128);font-weight:bold">'?'</span>,<br>                        <span style="color:rgb(102,0,153)">help</span>=<span style="color:rgb(0,128,128);font-weight:bold">'The arc of the sphere, an angle in degrees from +y in the +x direction.'</span>)<br>    parser.add_argument(<span style="color:rgb(0,128,128);font-weight:bold">'step'</span>, <span style="color:rgb(102,0,153)">default</span>=<span style="color:rgb(0,0,255)">1</span>, <span style="color:rgb(102,0,153)">type</span>=<span style="color:rgb(0,0,128)">float</span>, <span style="color:rgb(102,0,153)">nargs</span>=<span style="color:rgb(0,128,128);font-weight:bold">'?'</span>, <span style="color:rgb(102,0,153)">help</span>=<span style="color:rgb(0,128,128);font-weight:bold">'The step angle in degrees.'</span>)<br>    parser.add_argument(<span style="color:rgb(0,128,128);font-weight:bold">'radius'</span>, <span style="color:rgb(102,0,153)">default</span>=<span style="color:rgb(0,0,255)">1</span>, <span style="color:rgb(102,0,153)">type</span>=<span style="color:rgb(0,0,128)">float</span>, <span style="color:rgb(102,0,153)">nargs</span>=<span style="color:rgb(0,128,128);font-weight:bold">'?'</span>, <span style="color:rgb(102,0,153)">help</span>=<span style="color:rgb(0,128,128);font-weight:bold">'The radius of the sphere.'</span>)<br>    parser.add_argument(<span style="color:rgb(0,128,128);font-weight:bold">'-c'</span>, <span style="color:rgb(0,128,128);font-weight:bold">'--closed'</span>, <span style="color:rgb(102,0,153)">action</span>=<span style="color:rgb(0,128,128);font-weight:bold">'store_true'</span>, <span style="color:rgb(102,0,153)">help</span>=<span style="color:rgb(0,128,128);font-weight:bold">'Add a closed cap.'</span>)<br>    args = parser.parse_args()<br>    <span style="color:rgb(0,0,128);font-weight:bold">return </span>args.angle, args.step, args.radius, args.closed<br><br><br><span style="color:rgb(0,0,128);font-weight:bold">def </span>main():<br>    angle, step, radius, closed = get_program_parameters()<br>    angle = math.radians(angle)<br>    step = math.radians(step)<br>    precision = <span style="color:rgb(0,0,255)">1.0e-6<br></span><span style="color:rgb(0,0,255)">    </span>start = math.radians(<span style="color:rgb(0,0,255)">90</span>)<br>    pts = <span style="color:rgb(0,0,128)">list</span>()<br>    <span style="color:rgb(128,128,128);font-style:italic"># Do the curved line<br></span><span style="color:rgb(128,128,128);font-style:italic">    </span>theta = <span style="color:rgb(0,0,255)">0.0<br></span><span style="color:rgb(0,0,255)">    </span><span style="color:rgb(0,0,128);font-weight:bold">while </span>theta <= angle:<br>        x = radius * math.cos(start - theta)<br>        z = radius * math.sin(-start + theta)<br>        <span style="color:rgb(0,0,128);font-weight:bold">if </span><span style="color:rgb(0,0,128)">abs</span>(x) < precision:<br>            x = <span style="color:rgb(0,0,255)">0<br></span><span style="color:rgb(0,0,255)">        </span><span style="color:rgb(0,0,128);font-weight:bold">if </span><span style="color:rgb(0,0,128)">abs</span>(z) < precision:<br>            z = <span style="color:rgb(0,0,255)">0<br></span><span style="color:rgb(0,0,255)">        </span>pts.append((x, <span style="color:rgb(0,0,255)">0</span>, z))<br>        theta += step<br><br>    <span style="color:rgb(0,0,128);font-weight:bold">if </span>closed:<br>        <span style="color:rgb(128,128,128);font-style:italic"># Drop a perpendicular from the last point to the x-axis<br></span><span style="color:rgb(128,128,128);font-style:italic">        </span>last_point = pts[-<span style="color:rgb(0,0,255)">1</span>]<br>        num_pts = <span style="color:rgb(0,0,255)">10<br></span><span style="color:rgb(0,0,255)">        </span>interval = <span style="color:rgb(0,0,128)">float</span>(num_pts) / radius<br>        <span style="color:rgb(0,0,128);font-weight:bold">if </span>last_point[<span style="color:rgb(0,0,255)">0</span>] > precision:<br>            <span style="color:rgb(0,0,128);font-weight:bold">for </span>i <span style="color:rgb(0,0,128);font-weight:bold">in </span><span style="color:rgb(0,0,128)">range</span>(<span style="color:rgb(0,0,255)">1</span>, num_pts):<br>                x = last_point[<span style="color:rgb(0,0,255)">0</span>] - i / interval<br>                z = last_point[<span style="color:rgb(0,0,255)">2</span>]<br>                <span style="color:rgb(0,0,128);font-weight:bold">if </span><span style="color:rgb(0,0,128)">abs</span>(x) < precision:<br>                    x = <span style="color:rgb(0,0,255)">0<br></span><span style="color:rgb(0,0,255)">                </span><span style="color:rgb(0,0,128);font-weight:bold">if </span><span style="color:rgb(0,0,128)">abs</span>(z) < precision:<br>                    z = <span style="color:rgb(0,0,255)">0<br></span><span style="color:rgb(0,0,255)">                </span>pts.append((x, <span style="color:rgb(0,0,255)">0</span>, z))<br>        <span style="color:rgb(0,0,128);font-weight:bold">if </span>pts[-<span style="color:rgb(0,0,255)">1</span>][<span style="color:rgb(0,0,255)">0</span>] > precision:<br>            pts.append((<span style="color:rgb(0,0,255)">0</span>, <span style="color:rgb(0,0,255)">0</span>, z))<br><br>    <span style="color:rgb(128,128,128);font-style:italic"># Setup points and lines<br></span><span style="color:rgb(128,128,128);font-style:italic">    </span>points = vtk.vtkPoints()<br>    lines = vtk.vtkCellArray()<br>    <span style="color:rgb(0,0,128);font-weight:bold">for </span>pt <span style="color:rgb(0,0,128);font-weight:bold">in </span>pts:<br>        <span style="color:rgb(128,128,128)">pt_id </span>= points.InsertNextPoint(pt)<br>    <span style="color:rgb(0,0,128);font-weight:bold">for </span>i <span style="color:rgb(0,0,128);font-weight:bold">in </span><span style="color:rgb(0,0,128)">range</span>(<span style="color:rgb(0,0,255)">0</span>, <span style="color:rgb(0,0,128)">len</span>(pts) - <span style="color:rgb(0,0,255)">1</span>):<br>        line = vtk.vtkLine()<br>        line.GetPointIds().SetId(<span style="color:rgb(0,0,255)">0</span>, i)<br>        line.GetPointIds().SetId(<span style="color:rgb(0,0,255)">1</span>, i + <span style="color:rgb(0,0,255)">1</span>)<br>        lines.InsertNextCell(line)<br><br>    polydata = vtk.vtkPolyData()<br>    polydata.SetPoints(points)<br>    polydata.SetLines(lines)<br><br>    <span style="color:rgb(128,128,128);font-style:italic"># Extrude the profile to make the capped sphere.<br></span><span style="color:rgb(128,128,128);font-style:italic">    #<br></span><span style="color:rgb(128,128,128);font-style:italic">    </span>extrude = vtk.vtkRotationalExtrusionFilter()<br>    extrude.SetInputData(polydata)<br>    extrude.SetResolution(<span style="color:rgb(0,0,255)">60</span>)<br><br>    <span style="color:rgb(128,128,128);font-style:italic">#  Visualize<br></span><span style="color:rgb(128,128,128);font-style:italic">    </span>colors = vtk.vtkNamedColors()<br><br>    mapper = vtk.vtkPolyDataMapper()<br>    <span style="color:rgb(128,128,128);font-style:italic"># To see the line<br></span><span style="color:rgb(128,128,128);font-style:italic">    # mapper.SetInputData(polydata)<br></span><span style="color:rgb(128,128,128);font-style:italic">    # To see the surface<br></span><span style="color:rgb(128,128,128);font-style:italic">    </span>mapper.SetInputConnection(extrude.GetOutputPort())<br><br>    actor = vtk.vtkActor()<br>    actor.SetMapper(mapper)<br>    actor.GetProperty().SetLineWidth(<span style="color:rgb(0,0,255)">4</span>)<br>    actor.GetProperty().SetColor(colors.GetColor3d(<span style="color:rgb(0,128,128);font-weight:bold">'Cornsilk'</span>))<br><br>    ren = vtk.vtkRenderer()<br>    renWin = vtk.vtkRenderWindow()<br>    renWin.AddRenderer(ren)<br>    iren = vtk.vtkRenderWindowInteractor()<br>    iren.SetRenderWindow(renWin)<br><br>    ren.AddActor(actor)<br>    ren.SetBackground(colors.GetColor3d(<span style="color:rgb(0,128,128);font-weight:bold">'DarkGreen'</span>))<br><br>    ren.ResetCamera()<br>    ren.GetActiveCamera().Azimuth(<span style="color:rgb(0,0,255)">0</span>)<br>    ren.GetActiveCamera().Elevation(<span style="color:rgb(0,0,255)">60</span>)<br>    ren.ResetCameraClippingRange()<br><br>    renWin.SetSize(<span style="color:rgb(0,0,255)">600</span>, <span style="color:rgb(0,0,255)">600</span>)<br>    renWin.Render()<br>    renWin.SetWindowName(<span style="color:rgb(0,128,128);font-weight:bold">'CappedSphere'</span>)<br>    iren.Start()<br><br><br><span style="color:rgb(0,0,128);font-weight:bold">if </span>__name__ == <span style="color:rgb(0,128,128);font-weight:bold">'__main__'</span>:<br>    main()<br></pre></div><div class="gmail_default" style="font-size:small">##############################################<br></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br><br>---------- Forwarded message ----------<br>From: David Gobbi <<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>><br>To: VTK Users <<a href="mailto:vtkusers@vtk.org" target="_blank">vtkusers@vtk.org</a>><br>Cc: <br>Bcc: <br>Date: Sun, 14 Apr 2019 15:06:17 -0600<br>Subject: Re: [vtkusers] hemispherical cap with hole at the bottom<br><div dir="ltr"><div>Hi Petr,</div><div><br></div><div>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.</div><div><br></div><div>I recommend that you take another approach.  Your cap is rotationally symmetric, right?  Try the rotational extrusion filter: <a href="https://vtk.org/doc/nightly/html/classvtkRotationalExtrusionFilter.html" target="_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 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, <a href="https://lorensen.github.io/VTKExamples/site/Python/GeometricObjects/PolyLine1/" target="_blank">https://lorensen.github.io/VTKExamples/site/Python/GeometricObjects/PolyLine1/</a></div><div><br></div><div>Once you have your cross-section, pass it through vtkRotationalExtrusionFilter to generate the shape.</div><span class="gmail-m_6875413692765619131gmail-HOEnZb gmail-m_6875413692765619131gmail-adL"><font color="#888888"><div><br></div><div>   David</div></font></span></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Apr 14, 2019 at 9:30 AM Petr Vokac <<a href="mailto:petr.2006@centrum.cz" target="_blank">petr.2006@centrum.cz</a>> wrote:<br></div><blockquote class="gmail_quote" style="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, clipping 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 = vtk.vtkSphereSource()<br>
sphere.SetRadius(10.0)<br>
<br>
spherei = vtk.vtkSphereSource()<br>
spherei.SetRadius(8.0)<br>
<br>
sphereir=vtk.vtkReverseSense()<br>
sphereir.SetInputConnection(spherei.GetOutputPort())<br>
<br>
ext=vtk.vtkAppendPolyData()<br>
ext.AddInputConnection(sphere.GetOutputPort())<br>
ext.AddInputConnection(sphereir.GetOutputPort())<br>
<br>
plane = vtk.vtkPlane()<br>
plane.SetOrigin([0.0,0.0,0.0])<br>
plane.SetNormal([0.0,-1.0,0.0])<br>
<br>
clipclose=vtk.vtkClipClosedSurface()<br>
pc = vtk.vtkPlaneCollection()<br>
pc.AddItem(plane)<br>
clipclose.SetClippingPlanes(pc)<br>
clipclose.SetInputConnection(ext.GetOutputPort())<br>
<br>
cyl = vtk.vtkCylinder()<br>
cyl.SetCenter(0,0,0)<br>
cyl.SetRadius(5.0)<br>
ib = vtk.vtkImplicitBoolean()<br>
ib.AddFunction(cyl)<br>
<br>
clipper = vtk.vtkClipPolyData()<br>
clipper.SetInputConnection(clipclose.GetOutputPort())<br>
clipper.SetClipFunction(ib)<br>
clipper.GenerateClippedOutputOn()<br>
<br>
mapper = vtk.vtkPolyDataMapper()<br>
mapper.SetInputConnection(clipper.GetOutputPort())<br>
<br>
actor = vtk.vtkActor()<br>
actor.SetMapper(mapper)<br>
<br>
ren = vtk.vtkRenderer()<br>
ren.AddActor(actor)<br>
ren.ResetCamera()<br>
<br>
renWin = vtk.vtkRenderWindow()<br>
renWin.AddRenderer(ren)<br>
iren = 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="http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html" rel="noreferrer" target="_blank">http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html</a><br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://vtk.org/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">https://vtk.org/mailman/listinfo/vtkusers</a><br>
</blockquote></div>
<br><br><br></blockquote></div>-- <br><div dir="ltr" class="gmail_signature">___________________________________________<br>Andrew J. P. Maclean<br><br>___________________________________________</div></div></div>