[vtkusers] Selecting/Updating Vertices and Edges in vtkGraph

Aytekin Vargun varguna at gmail.com
Mon Feb 2 14:15:51 EST 2009


Hi,
I am trying to use a combination of vtkRenderWindow and vtkSelectionList to
pick vertices and edges of a vtkGraph I am displaying. I will add/delete
vertices/edges after I get the ids of selected components.

The first problem is:When I drag the mouse to make selections, only the edge
colors change. As a note, the vertices are small spheres. Shouldn't vertex
colors change as well?

The second problem is if I try to get the ids of objects being selected, I
never get any single id for vertices. I suspect that when I click on a
sphere, All the points(or maybe small lines) that construct each sphere are
being picked. How can I just get the ids of vertices? By the way, picking
succeeds only for one vertex. If I do it for several vertices and if there
are edges among them, only the edges are picked!

What is the best way of extracting vertices and edges from the
vtkSelectionLink? I show how I attempt to do this in the following code. Any
suggestions?

Thanks a lot for your time and help.
Aytekin



Here is the first part of my code:
...
VTK_CREATE(vtkCallbackCommand,isPicked);
    isPicked->SetCallback(processVertexSelection);
    VTK_CREATE(vtkSelectionLink,link);
    VTK_CREATE(vtkSurfaceRepresentation, selections);
    selections->SetInputConnection(poly->GetOutputPort());
    selections->SetSelectionLink(link);
    view->AddRepresentation(selections);
    view->Update();
    isPicked->SetClientData((void *)static_cast<vtkSelectionLink*>(link));

    iren->AddObserver(vtkCommand::LeftButtonReleaseEvent,isPicked);
...


And some parts of the the function to be called after picking:

void processVertexSelection(vtkObject* caller, unsigned long event,
                            void* clientdata, void* callerdata) {


    vtkSelection *p =
static_cast<vtkSelectionLink*>(clientdata)->GetSelection();

    printf("I got %d nodes\n",p->GetNumberOfNodes());
    for(int counter=0; counter<p->GetNumberOfNodes(); counter++)
    {

        vtkSelectionNode *n = p->GetNode(counter);
        //n->SetFieldType(vtkSelectionNode::EDGE);
        //n->SetContentType(vtkSelectionNode::INDICES);
        printf("FieldType for %d is %d\n",counter,n->GetFieldType());
        cout<<"Num of Tuples: "<<n->GetSelectionList()->GetNumberOfTuples();
        cout<<endl<<endl;

        vtkAbstractArray* arra = n->GetSelectionList();
        for (int i=0;i<n->GetSelectionList()->GetNumberOfTuples();i++) {
             vtkVariant aaa=arra->GetVariantValue(i);
             cout<<"Type : "<<n->GetContentType()<<endl;
             cout<<"Variant : "<<i<<" "<<aaa.ToInt()<<endl;
         }
         cout<<endl<<endl;
    }
}



-- 
My web page: http://www.cs.rpi.edu/~vargua
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090202/002b344e/attachment.htm>


More information about the vtkusers mailing list