[vtkusers] Cutting a cylinder out of a cube

David.Pont at ensisjv.com David.Pont at ensisjv.com
Tue Jul 31 17:04:39 EDT 2007


"Tilo Junge" <pult34 at gmx.de> wrote on 27/07/2007 20:32:48:

> Hello.
>
> I tried to cut a cylinder out of a cube, but it does not work right.
> I use python and my code looks like this:
>
> import vtkpython
>
> cylinder = vtkpython.vtkCylinder()
> cylinder.SetRadius(0.25)
> cylinder.SetCenter(0.0, 0.0, 0.0)
> vertPlane = vtkpython.vtkPlane()
> vertPlane.SetOrigin(0, -2, 0)
> vertPlane.SetNormal(0, -1, 0)
> basePlane = vtkpython.vtkPlane()
> basePlane.SetOrigin(0, 2, 0)
> basePlane.SetNormal(0, 1, 0)
>
> cube = vtkpython.vtkCubeSource()
> cube.SetXLength(2.0)
> cube.SetYLength(2.0)
> cube.SetZLength(2.0)
> cube.SetCenter(0.0, 0.0, 0.0)
>
> theCylinder = vtkpython.vtkImplicitBoolean()
> theCylinder.SetOperationTypeToIntersection()
> theCylinder.AddFunction(cylinder)
> theCylinder.AddFunction(vertPlane)
> theCylinder.AddFunction(basePlane)
>
> clipper = vtkpython.vtkClipPolyData()
> clipper.SetInput(cube.GetOutput())
> clipper.SetClipFunction(theCylinder)
> clipper.InsideOutOff()
>
> mapper = vtkpython.vtkPolyDataMapper()
> mapper.SetInput(clipper.GetOutput())
>
> actor = vtkpython.vtkActor()
> actor.SetMapper(mapper)
> actor.GetProperty().SetColor(0, 1, 0)
>
> ren1= vtkpython.vtkRenderer()
> ren1.AddActor(actor)
> ren1.SetBackground(1, 1, 1)
>
> renWin = vtkpython.vtkRenderWindow()
> renWin.AddRenderer( ren1 )
> renWin.SetSize( 500, 500 )
> iren = vtkpython.vtkRenderWindowInteractor()
> iren.SetRenderWindow(renWin)
>
> iren.Initialize()
> renWin.Render()
> iren.Start()
>
> I also tried to use vtkCutter, but the result isnt what I wanted either.
> Maybe someone can help me?

vtkCubeSource probably generates just 6 polygons (I've never actually used
it), which is exactly what it should do. But using this as the input to
clipping will not give what you expect. Clipping removes any cells
completely inside the implicit surface and it clips any cells that have
some points inside the surface and some points outside the surface. The
points defining your cube are ALL outside the implicit surface so nothing
is clipped!

What you need are cube surfaces that are made of many cells, some inside,
some outside and some crossing the implicit surface, then you will see
clipping. With say just 4 cells per cube surface you will get a very ugly
square hole. As the number of cells (and points) increases you will get a
better approximation to the circular hole you are expecting.

To get more cells/points on the cube surfaces you could use:
vtkPlaneSource (one per cube surface, thats 6 of them) and use
SetResolution to increase the number of cells.
vtkLinearSubdivisionFilter to subdivide the cells in your vtkCubeSource,
try 2 or 3 iterations for a start.

   how do I know this.... yep I have been exactly where you are

good luck, Dave P

>
> Thanks
> --
> Psssst! Schon vom neuen GMX MultiMessenger gehört?
> Der kanns mit allen: http://www.gmx.net/de/go/multimessenger
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.
> org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070801/dd60cee8/attachment.htm>


More information about the vtkusers mailing list