[vtkusers] How to get all visible Triangles?
Eric E. Monson
emonson at cs.duke.edu
Mon Oct 11 09:38:27 EDT 2010
That basic idea seems to work for me. To try it quickly I did it in Python instead, and I just printed out the SelectionList from the vtkSelectionNode that's attached to the vtkSelection returned by the hardware selector instead of trying to use vtkExtractSelection. The "UserEvent" looks for the "u" key.
==================
import vtk
import vtk.util.numpy_support as VN
# Callback for when selection is changed
def selectionCallback(caller,eventId):
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)
print 'Visible cell IDs: ', VN.vtk_to_numpy(sel_node.GetSelectionList()).tolist()
sphere = vtk.vtkSphereSource()
sphere.SetCenter( 0, 0, 0 )
sphere.SetRadius( 5.0 )
sphereMapper = vtk.vtkPolyDataMapper()
sphereMapper.SetInputConnection(sphere.GetOutputPort())
sphereActor = vtk.vtkActor()
sphereActor.SetMapper(sphereMapper)
ren1 = vtk.vtkRenderer()
ren1.AddActor(sphereActor)
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()
==================
Note that the default ContentType for the SelectionNode is INDICES, so if you want to get pedigree ids, or something else, you'll have to convert the selection afterwards.
Hope this helps get you going in the right direction,
-Eric
------------------------------------------------------
Eric E Monson
Duke Visualization Technology Group
On Oct 10, 2010, at 6:39 PM, s61500 at htw-dresden.de wrote:
> Hello,
>
> I've tried to implement the code from the example, but I get the same error.
> The problem is that the vtkExtractSelection object has 0 nodes, but it has
> to have 1 node.
>
> The vtkHardwareSelector seems to be the right way, when I've understand
> the documentation.
>
> "Select will cause the attached vtkRenderer to render in a special color
> mode, where each cell/point is given it own color so that later inspection
> of the Rendered Pixels can determine what cells are visible. Select()
> returns a new vtkSelection instance with the cells/points selected."
>
> This was my first idea to solve the problem before I've worked with VTK.
> I've wrote a prototype in Python (without VTK), which solve the problem in
> this way, but the prototype is to slow.
>
> Is there maybe another way to get a triangle list with vtkHardwareSelector?
>
>
>
>> Probably the vtkAreaPicker should work for that .
>>
>> Darshan
>>
>> On Thu, Oct 7, 2010 at 11:11 AM, David Doria <daviddoria at gmail.com> wrote:
>>
>>> On Thu, Oct 7, 2010 at 9:00 AM, <s61500 at htw-dresden.de> wrote:
>>>
>>>> Hello,
>>>>
>>>> I've an object in a STL-File and imported the object. Know I have to
>>>> get
>>>> all triangles which are visible from a given point, but I don't find a
>>>> way
>>>> to do this.
>>>>
>>>> I've searched in several forums and in this mailing list, but I haven't
>>>> find any answer.
>>>>
>>>> May anybody of you can help me.
>>>>
>>>> Stefan
>>>>
>>>>
>>> I think this is very close to what you're looking for. Unfortunately, I
>>> get
>>> a "Selection must have a single node" error.
>>>
>>>
>>> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Broken/Filtering/ExtractVisibleCells
>>>
>>> David
>>>
>>> _______________________________________________
>>> 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