[vtkusers] vtkHardwareSelection produces bad a bad result

Eric E. Monson emonson at cs.duke.edu
Mon Oct 18 09:35:20 EDT 2010


I don't know the details of how the hardware selector works, but after playing a bit myself, too, I wouldn't be surprised if the problem is something about the relationship between the cell cross-section and the pixel size of the window. I don't get cells from the "back side" selected, but I do see problems with selecting very small or very narrow cells and it changes with the size of the window. (Screen shot attached. Just for the heck of it I'm also including an alternate version of my other Python script which does the selection extraction and displays the selected cells off to the side of the original sphere when you press "u".)

Maybe Dave DeMarle knows how to get around this... (Yup, I see he just replied.)

-Eric

# ==========================
import vtk

# Callback for when selection is changed
def selectionCallback(caller,eventId):
	global sel
	
	hsel = vtk.vtkHardwareSelector()
	hsel.SetFieldAssociation(vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS)
	hsel.SetRenderer(ren1)
	
	x,y = caller.GetRenderWindow().GetSize()
	
	# Create a small area around clicked point for selector area
	hsel.SetArea(0,0,x,y)
	res = hsel.Select()
	
	numNodes = res.GetNumberOfNodes()
	if (numNodes < 1):
		print "No visible cells"
	else:
		sel_node = res.GetNode(0)
		sel_list = sel_node.GetSelectionList()
		sel.GetNode(0).SetSelectionList(sel_list)
		renWin.Render()

sphere = vtk.vtkSphereSource()
sphere.SetCenter( 0, 0, 0 )
sphere.SetRadius( 5.0 )
sphere.SetThetaResolution(100)
sphere.SetPhiResolution(100)

sel = vtk.vtkSelection()
node = vtk.vtkSelectionNode()
node.SetContentType(vtk.vtkSelectionNode.INDICES)
node.SetFieldType(vtk.vtkSelectionNode.CELL)
sel.AddNode(node)

ext_sel = vtk.vtkExtractSelection()
ext_sel.SetInput(0, sphere.GetOutput())
ext_sel.SetInput(1, sel)
ext_sel.PreserveTopologyOff()

sel_mapper = vtk.vtkDataSetMapper()
sel_mapper.SetInputConnection(ext_sel.GetOutputPort(0))
sel_actor = vtk.vtkActor()
sel_actor.SetPickable(False)
sel_actor.SetMapper(sel_mapper)
sel_actor.GetProperty().SetColor(1,0,0)
sel_actor.SetPosition(10,0,0)

sphereMapper = vtk.vtkPolyDataMapper()
sphereMapper.SetInputConnection(sphere.GetOutputPort())

sphereActor = vtk.vtkActor()
sphereActor.SetMapper(sphereMapper)

ren1 = vtk.vtkRenderer()
ren1.AddActor(sphereActor)
ren1.AddActor(sel_actor)
ren1.SetBackground(0.1, 0.2, 0.4)
ren1.GetActiveCamera().ParallelProjectionOn()

renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
renWin.SetSize(300, 300)

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.AddObserver("UserEvent", selectionCallback)

style = vtk.vtkInteractorStyleTrackballCamera()
iren.SetInteractorStyle(style)
renWin.GetInteractor().SetInteractorStyle(style)

ren1.ResetCamera()
renWin.Render()

iren.Initialize()
iren.Start()

-------------- next part --------------
A non-text attachment was scrubbed...
Name: visible_cells.png
Type: image/png
Size: 20009 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101018/f3e18f8a/attachment.png>
-------------- next part --------------


On Oct 18, 2010, at 9:10 AM, s61500 at htw-dresden.de wrote:

> I think pictures will be the best illustration of the problem.
> 
> http://www2.htw-dresden.de/~s61500/example_sphere.png
> 
> 1. window --> viewport
> 2. window --> result with RenderWindow size of [300, 300]
> 3. window --> result with RenderWindow size of [1000, 1000]
> 4. window --> result with RenderWindow size of [1000, 1000]
> 
> http://www2.htw-dresden.de/~s61500/example_testobject.png
> 
> 1. window --> viewport
> 1. row --> result with RenderWindow size of [300, 300]
> 2. row --> result with RenderWindow size of [1000, 1000]
> 
> http://www2.htw-dresden.de/~s61500/example_testobject2.png
> 
> - detailed view of the problem
> 
> I hope that the screenshots clarify the problem in the best way.
> 
> Stefan
> 
>> Can you clarify what you mean by the result isn't right?
>> 
>> David E DeMarle
>> Kitware, Inc.
>> R&D Engineer
>> 28 Corporate Drive
>> Clifton Park, NY 12065-8662
>> Phone: 518-371-3971 x109
>> 
>> 
>> On Sun, Oct 17, 2010 at 1:12 PM, <s61500 at htw-dresden.de> wrote:
>> 
>>> Hi,
>>> 
>>> upon finding the error in the example code I noted that the result
> isn't right.
>>> 
>>> The example code can you find here:
>>> 
>>> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Broken/Filtering/ExtractVisibleCells
>>> 
>>> I find out that you get a better result when you set the size of the
> vtkRenderWindow higher.
>>> But with a size of [1000,1000] I don't get a perfect result by my test
> sphere object with 27.000 triangles. To set the window size high enough
> couldn't be the right way, because the program will work with nets of 1
> million triangles.
>>> 
>>> So my question, is there another way to get a better result without set
> the window size higher?
>>> 
>>> Stefan
>>> 
>>> _______________________________________________
>>> 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
>>> 
>> 
> 
> 
> 
> _______________________________________________
> 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