[vtkusers] deleting a face from polydata

Goodwin Lawlor goodwin.lawlor at ucd.ie
Wed Apr 7 17:53:52 EDT 2004


Hi John,

vtkPolyData::DeleteCell just marks a cells as a VTK_EMPTY_CELL type...
It doesn't actually delete it from the dataset.

I have a class and tcl example that does what you want. You can get the
source code here:
http://www.bioengineering-research.com/vtk/vtkRemoveCellsFilter.htm

Hth,

Goodwin

Message: 3
To: VTK Users <vtkusers at public.kitware.com>
From: John Hunter <jdhunter at ace.bsd.uchicago.edu>
Date: Wed, 07 Apr 2004 15:32:48 -0500
Subject: [vtkusers] deleting a face from polydata


I am interested in removing some data from my scene by clicking on it
with a mouse.  I've returned to my trusty sphere as a demo case.  I use
a cell picker to get the cell id.  When I call
polyData.DeleteCell(cellId) on the poly data, I would like that cell to
be removed from my scene

I initialize my scene with 

    sphere = vtk.vtkSphereSource()
    sphere.SetRadius(20)
    res = 5
    sphere.SetThetaResolution(res)
    sphere.SetPhiResolution(res)
    sphere.SetCenter(0,0,0)
    polyData = sphere.GetOutput()
    polyData.BuildCells()
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInput(polyData)

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    renderer.AddActor(actor)

and this is my pick function

def pick_cell(renwinInteractor, event):
    x, y = renwinInteractor.GetEventPosition()

    picker = vtk.vtkCellPicker()
    picker.PickFromListOn()
    picker.AddPickList(actor)
    picker.SetTolerance(0.01)
    picker.Pick(x, y, 0, renderer)
    cellId = picker.GetCellId()
    if cellId==-1:
        print 'swing and a miss'
        return

    polyData.DeleteCell(cellId)
    print 'deleted cell', cellId
    mapper.Update()

I am pretty sure I am selecting the right cell, because I can insert a
marker on each of the cell points and correctly mark the vertices
under the triangle that I click on.   If I use cell =
polyData.GetCell(cellId) the type is identified as vtkTriangle.  If I
successively click on the same point, I never get the same cell id
twice, suggesting the cells are being removed from the poly data.  But
they are not disappearing from the rendered scene.

Any suggestions?  Complete example below.

John Hunter

#!/usr/bin/env python

import vtk

renderer = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(renderer)
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(renWin)

sphere = vtk.vtkSphereSource()
sphere.SetRadius(20)
res = 5
sphere.SetThetaResolution(res)
sphere.SetPhiResolution(res)
sphere.SetCenter(0,0,0)
polyData = sphere.GetOutput()
polyData.BuildCells()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(polyData)

actor = vtk.vtkActor()
actor.SetMapper(mapper)
#actor.GetProperty().SetOpacity(0.5)

renderer.AddActor(actor)

def mark(x,y,z):
    sphere = vtk.vtkSphereSource()
    sphere.SetRadius(1)
    res = 20
    sphere.SetThetaResolution(res)
    sphere.SetPhiResolution(res)
    sphere.SetCenter(x,y,z)
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInput(sphere.GetOutput())

    marker = vtk.vtkActor()
    marker.SetMapper(mapper)
    renderer.AddActor(marker)
    marker.GetProperty().SetColor( (1,0,0) )
    interactor.Render()

def pick_cell(renwinInteractor, event):
    x, y = renwinInteractor.GetEventPosition()

    picker = vtk.vtkCellPicker()
    picker.PickFromListOn()
    picker.AddPickList(actor)
    picker.SetTolerance(0.01)
    picker.Pick(x, y, 0, renderer)
    cellId = picker.GetCellId()
    if cellId==-1:
        print 'swing and a miss'
        return

    polyData.DeleteCell(cellId)
    print 'deleted cell', cellId
    mapper.Update()


interactor.AddObserver('LeftButtonPressEvent', pick_cell)


interactor.Initialize()
interactor.Start()



--__--__--

Message: 4
Date: Wed, 07 Apr 2004 16:59:44 -0400
From: Jeff Lee <jeff at cdnorthamerica.com>
Organization: Computational Dynamics North America
To: John Hunter <jdhunter at nitace.bsd.uchicago.edu>
Cc: VTK Users <vtkusers at public.kitware.com>
Subject: Re: [vtkusers] deleting a face from polydata

mabey polydata.Update() or polydata.Modified() after the removal? -Jeff

John Hunter wrote:

>I am interested in removing some data from my scene by clicking on it 
>with a mouse.  I've returned to my trusty sphere as a demo case.  I use

>a cell picker to get the cell id.  When I call
>polyData.DeleteCell(cellId) on the poly data, I would like that cell to

>be removed from my scene
>
>I initialize my scene with
>
>    sphere = vtk.vtkSphereSource()
>    sphere.SetRadius(20)
>    res = 5
>    sphere.SetThetaResolution(res)
>    sphere.SetPhiResolution(res)
>    sphere.SetCenter(0,0,0)
>    polyData = sphere.GetOutput()
>    polyData.BuildCells()
>    mapper = vtk.vtkPolyDataMapper()
>    mapper.SetInput(polyData)
>
>    actor = vtk.vtkActor()
>    actor.SetMapper(mapper)
>    renderer.AddActor(actor)
>
>and this is my pick function
>
>def pick_cell(renwinInteractor, event):
>    x, y = renwinInteractor.GetEventPosition()
>
>    picker = vtk.vtkCellPicker()
>    picker.PickFromListOn()
>    picker.AddPickList(actor)
>    picker.SetTolerance(0.01)
>    picker.Pick(x, y, 0, renderer)
>    cellId = picker.GetCellId()
>    if cellId==-1:
>        print 'swing and a miss'
>        return
>
>    polyData.DeleteCell(cellId)
>    print 'deleted cell', cellId
>    mapper.Update()
>
>I am pretty sure I am selecting the right cell, because I can insert a 
>marker on each of the cell points and correctly mark the vertices
>under the triangle that I click on.   If I use cell =
>polyData.GetCell(cellId) the type is identified as vtkTriangle.  If I 
>successively click on the same point, I never get the same cell id 
>twice, suggesting the cells are being removed from the poly data.  But 
>they are not disappearing from the rendered scene.
>
>Any suggestions?  Complete example below.
>
>John Hunter
>
>#!/usr/bin/env python
>
>import vtk
>
>renderer = vtk.vtkRenderer()
>renWin = vtk.vtkRenderWindow()
>renWin.AddRenderer(renderer)
>interactor = vtk.vtkRenderWindowInteractor()
>interactor.SetRenderWindow(renWin)
>
>sphere = vtk.vtkSphereSource()
>sphere.SetRadius(20)
>res = 5
>sphere.SetThetaResolution(res)
>sphere.SetPhiResolution(res)
>sphere.SetCenter(0,0,0)
>polyData = sphere.GetOutput()
>polyData.BuildCells()
>mapper = vtk.vtkPolyDataMapper()
>mapper.SetInput(polyData)
>
>actor = vtk.vtkActor()
>actor.SetMapper(mapper)
>#actor.GetProperty().SetOpacity(0.5)
>
>renderer.AddActor(actor)
>
>def mark(x,y,z):
>    sphere = vtk.vtkSphereSource()
>    sphere.SetRadius(1)
>    res = 20
>    sphere.SetThetaResolution(res)
>    sphere.SetPhiResolution(res)
>    sphere.SetCenter(x,y,z)
>    mapper = vtk.vtkPolyDataMapper()
>    mapper.SetInput(sphere.GetOutput())
>
>    marker = vtk.vtkActor()
>    marker.SetMapper(mapper)
>    renderer.AddActor(marker)
>    marker.GetProperty().SetColor( (1,0,0) )
>    interactor.Render()
>
>def pick_cell(renwinInteractor, event):
>    x, y = renwinInteractor.GetEventPosition()
>
>    picker = vtk.vtkCellPicker()
>    picker.PickFromListOn()
>    picker.AddPickList(actor)
>    picker.SetTolerance(0.01)
>    picker.Pick(x, y, 0, renderer)
>    cellId = picker.GetCellId()
>    if cellId==-1:
>        print 'swing and a miss'
>        return
>
>    polyData.DeleteCell(cellId)
>    print 'deleted cell', cellId
>    mapper.Update()
>
>
>interactor.AddObserver('LeftButtonPressEvent', pick_cell)
>
>
>interactor.Initialize()
>interactor.Start()
>
>
>_______________________________________________
>This is the private VTK discussion list.
>Please keep messages on-topic. Check the FAQ at:
<http://public.kitware.com/cgi-bin/vtkfaq>
>Follow this link to subscribe/unsubscribe:
>http://www.vtk.org/mailman/listinfo/vtkusers
>
>  
>

--__--__--

Message: 5
To: Jeff Lee <jeff at cdnorthamerica.com>
Cc: VTK Users <vtkusers at public.kitware.com>
Subject: Re: [vtkusers] deleting a face from polydata
From: John Hunter <jdhunter at ace.bsd.uchicago.edu>
Date: Wed, 07 Apr 2004 15:44:55 -0500

>>>>> "Jeff" == Jeff Lee <jeff at cdnorthamerica.com> writes:

    Jeff> mabey polydata.Update() or polydata.Modified() after the
    Jeff> removal?  -Jeff

Yeah, tried that on the mapper and the polydata.  No help.  I also tried
inserting a filter in the pipeline and completely rebuilding the scene
with

    polyData.DeleteCell(cellId)
    polyData.Update()
    print 'deleted cell', cellId
    print 'num polys', polyData.GetPolys().GetNumberOfCells()
    renderer.RemoveActor(actor)
    actor = vtk.vtkActor()

    filter = vtk.vtkCleanPolyData()
    filter.SetInput(polyData)
    filter.Update()
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInput(filter.GetOutput())
    actor.SetMapper(mapper)
    renderer.AddActor(actor)

No help either.

Tellingly, though, the number of polys reported by the call to
polyData.GetPolys().GetNumberOfCells() remains constant at 30 suggesting
the polyData.DeleteCell doesn't do what I think it does.

JDH


--__--__--

_______________________________________________
vtkusers mailing list
vtkusers at vtk.org
http://www.vtk.org/mailman/listinfo/vtkusers


End of vtkusers Digest




More information about the vtkusers mailing list