[vtkusers] ImplicitFunction from vtkPolyData?
Theodore D. Sternberg
tdsternberg at lbl.gov
Thu Oct 24 13:20:06 EDT 2002
On Thu, 24 Oct 2002, Prabhu Ramachandran wrote:
> >>>>> "TDS" == Theodore D Sternberg <tdsternberg at lbl.gov> writes:
>
> TDS> I'd like to clip one vtkPolyData against a (non-planar)
> TDS> surface defined by another vtkPolyData. Image the first
> TDS> vtkPolyData is the Earth, and the second vtkPolyData is the
> TDS> shape of an impact crater; I'd like to show the Earth with a
> TDS> crater in it.
>
> TDS> To do this, I think I need a vtkImplicitFunction to pass to a
> TDS> vtkClipPolyData. Is there a good way to obtain the necessary
> TDS> vtkImplicitFunction from that second vtkPolyData?
>
> I dont know of a way to do exactly this but take a look at the
> vtkSelectPolyData class. It lets you define a loop on your PolyData
> and then lets you select everything within or outside that loop.
> Maybe you can use it to do what you need.
> prabhu
Thanks. It's not clear how I'd define a loop that encloses a volume,
though.
Before receiving your response, I was experimenting with
vtkImplicitDataSet, since that implements vtkImplicitFunction, which is
what I need for my clipping. I thought, start with the vtkPolyData whose
geometry I want to use to define my clipping function, pipe that into a
vtkImplicitModeler, pipe that to a vtkImplicitDataSet...and pass that to
the vtkClipPolyData's SetClipFunction method. This approach makes sense,
and hooking up that pipeline does not result in any complaints from VTK.
Unfortunately, the rendering doesn't show the clipping I want...so far.
Do you think I'm at least on the right track?
Here is examplesPython/hello.py (VTK v3.2) modified along these lines,
i.e. I'm trying to use the outline of the "HELLO" as a geometry to clip
away from a red plane.
----------------------------- hello-clipping.py ---------------------
#!/usr/local/bin/python
import os
try:
VTK_DATA = os.environ['VTK_DATA']
except KeyError:
VTK_DATA = '../../../vtkdata/'
from libVTKCommonPython import *
from libVTKGraphicsPython import *
from colors import *
# Create the RenderWindow, Renderer and both Actors
#
ren = vtkRenderer()
renWin = vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# create lines
reader = vtkPolyDataReader()
reader.SetFileName(VTK_DATA + "/hello.vtk")
lineMapper = vtkPolyDataMapper()
lineMapper.SetInput(reader.GetOutput())
lineActor = vtkActor()
lineActor.SetMapper(lineMapper)
lineActor.GetProperty().SetColor(red[0],red[1],red[2])
# create implicit model
imp = vtkImplicitModeller()
imp.SetInput(reader.GetOutput())
imp.SetSampleDimensions(110,40,20)
imp.SetMaximumDistance(25)
imp.SetModelBounds(-1.0,10.0,-1.0,3.0,-1.0,1.0)
contour = vtkContourFilter()
contour.SetInput(imp.GetOutput())
contour.SetValue(0,0.4)
impMapper = vtkPolyDataMapper()
impMapper.SetInput(contour.GetOutput())
impMapper.ScalarVisibilityOff()
impActor = vtkActor()
impActor.SetMapper(impMapper)
impActor.GetProperty().SetColor(peacock[0],peacock[1],peacock[2])
impActor.GetProperty().SetOpacity(0.5)
# Add the actors to the renderer, set the background and size
#
#ren.AddActor(lineActor)
ren.AddActor(impActor)
ren.SetBackground(1,1,1)
renWin.SetSize(600,250)
camera = vtkCamera()
camera.SetClippingRange(1.81325,90.6627)
camera.SetFocalPoint(4.5,1,0)
camera.SetPosition(4.5,1.0,6.73257)
camera.SetViewUp(0,1,0)
camera.Zoom(0.8)
ren.SetActiveCamera(camera)
#
# A plane, which we will clip against the "Hello".
#
plane_source = vtkPlaneSource()
plane_source.SetOrigin( -1,-1,0 )
plane_source.SetPoint1( -1,3,0 )
plane_source.SetPoint2( 10,-1,0 )
plane_mapper = vtkPolyDataMapper()
plane_actor = vtkActor()
plane_prop = vtkProperty()
plane_prop.SetColor( 1.0,0,0 )
hello_dataset = vtkImplicitDataSet()
hello_dataset.SetDataSet( imp.GetOutput() )
clipper = vtkClipPolyData()
clipper.SetInput( plane_source.GetOutput() )
clipper.SetClipFunction( hello_dataset )
clipper.SetValue( 2.0 )
clipper.GenerateClippedOutputOn()
clipper.InsideOutOn()
clipper.Update()
plane_mapper.SetInput( clipper.GetOutput() )
plane_actor.SetMapper( plane_mapper )
plane_actor.SetProperty( plane_prop )
ren.AddActor( plane_actor )
iren.Initialize()
iren.Start()
--------------------------------------------------------------------
More information about the vtkusers
mailing list