[vtkusers] vtkCutter and vtkImplicitDataSet combined

David Gobbi david.gobbi at gmail.com
Sat Dec 19 18:05:57 EST 2009


Hi Stein,

I don't think that vtkImplicitDataSet will do what you need.  It
generates values by interpolating the scalars from the data.  It seems
that you need an implicit function that will use the normals to
compute the distance from a surface, generating either negative or
positive distances and evaluating to zero at the surface itself.

Maybe someone can help out and suggest a VTK class that will do this.
Basically it would have to be an implicit function that does roughly
the same thing that vtkImplicitModeller does, except that it would
also have to use the data normals to make the distance negative
depending on what side of the cell the evaluated position is on.

  David



On Sat, Dec 19, 2009 at 3:09 PM, Stein Erik Berthelsen
<zebern at hotmail.com> wrote:
> The idea is the cut through a StructuredGrid with a curved surface (a
> surface interactively defined by the user).
> The curved surface will be vertical so it will look like a curvy carpet.
> Working with vtkCutter and vtkImplicitDataSet. In theory it should work, but
> I cannot get it going!!! Unfortunately.
> I am able to create a cut surface using a vtkPlane or a vtkSphere as the
> ImplicitFunction cutFunction, but using vtkImplicitDataSet as the
> ImplicitFunction is playing games with me...
> Rgds Stein Erik
> ----------------------------------------------------------
> Parts os the code (Python):
> # Create Grid to be cut
> gridSource = vtk.vtkStructuredGrid()
> gridSource.SetDimensions(11,11,11)
> gridSource.SetPoints(points)
> gridSource.GetCellData().SetScalars(cells)
> gridSource.GetPointData().SetScalars(pointScalars)
> gridMapper = vtk.vtkDataSetMapper()
> gridMapper.SetInput(gridSource)
> gridMapper.ScalarVisibilityOn()
> #gridMapper.SetScalarModeToUseCellData()
> gridMapper.SetScalarModeToUsePointData()
> gridActor = vtk.vtkActor()
> gridActor.SetMapper(gridMapper)
> gridActor.GetProperty().SetColor(1.0, 1.0, 1.0)
> gridActor.GetProperty().SetRepresentationToWireframe()
> #gridActor.GetProperty().SetRepresentationToSurface()
> # Create Cutting Surface
> sgReader = vtk.vtkStructuredGridReader()
> sgReader.SetFileName("StructuredGrid_Test.vtk")
> sgReader.Update()
> gridextractFilter = vtk.vtkStructuredGridGeometryFilter()
> gridextractFilter.SetInputConnection(sgReader.GetOutputPort())
> gridextractFilter.SetExtent(0,19,0,2,0,0)
> gridextractFilter.Update()
> gridextractNormalsFilter = vtk.vtkPolyDataNormals()
> gridextractNormalsFilter.SetInputConnection(gridextractFilter.GetOutputPort())
> gridextractNormalsFilter.Update()
> cutTriangles = vtk.vtkTriangleFilter()
> cutTriangles.SetInputConnection(gridextractNormalsFilter.GetOutputPort())
> implicitFunc = vtk.vtkImplicitDataSet()
> implicitFunc.SetDataSet(gridextractNormalsFilter.GetOutput())
> # Create Cutter
> cutter = vtk.vtkCutter()
> cutter.SetCutFunction(implicitFunc)
> cutter.SetInput(gridSource)
> cutterMapper=vtk.vtkPolyDataMapper()
> cutterMapper.SetInputConnection(cutter.GetOutputPort())
> cutterActor = vtk.vtkActor()
> cutterActor.SetMapper(cutterMapper)
> cutterActor.GetProperty().SetColor(1.0, 0.0, 1.0)
> #cutterActor.GetProperty().SetRepresentationToSurface()
> cutterActor.GetProperty().SetRepresentationToWireframe()
> # Create the usual rendering stuff
> ren = vtk.vtkRenderer()
> renWin = vtk.vtkRenderWindow()
> renWin.AddRenderer(ren)
> iren = vtk.vtkRenderWindowInteractor()
> iren.SetRenderWindow(renWin)
> # Add the actors to the renderer, set the background and size
> ren.AddActor(gridActor)
> ren.AddActor(cutterActor)
> renWin.SetSize(500, 500)
> iren.Initialize()
> renWin.Render()
> iren.Start()
>
> ________________________________
> Windows Live: Make it easier for your friends to see what you’re up to on
> Facebook.
> _______________________________________________
> 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
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>



More information about the vtkusers mailing list