The article shows how to use vtkViewUpdater to update different views when the selections changed.

Relevant development environment:

VTK-8.1.1;
Qt 5.11.2 (x86_64-little_endian-lp64 shared (dynamic) release build;
Clang 8.1.0 (clang-802.0.42) (Apple)) on “cocoa”;
macOS 10.14 [darwin version 18.5.0];

#include <QApplication>

#include <qsurfaceformat.h>
#include <QVTKOpenGLWidget.h>
#include <vtkRandomGraphSource.h>
#include <vtkDataObjectToTable.h>
#include <vtkQtTableView.h>
#include <vtkGraphLayoutView.h>
#include <vtkDataRepresentation.h>
#include <vtkViewUpdater.h>
#include <vtkSmartPointer.h>
#include <vtkRenderWindow.h>
#include <vtkSelectionNode.h>
#include <vtkAnnotationLink.h>

#define vSP vtkSmartPointer
#define vSPNew(Var, Type) vSP<Type> Var = vSP<Type>::New();
#define VTK_FREE(Object) if(Object) { Object->Delete(); Object = NULL; }
#define CPP_New(Var, Type) Type *Var = new Type();
#define CPP_FREE(Object) if(Object) { delete Object; Object = 0; }

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    vSPNew( annLink, vtkAnnotationLink );

    // Create the graph source and table conversion
    vSPNew( src, vtkRandomGraphSource );
    src->Update();

    vSPNew( o2t, vtkDataObjectToTable );
    o2t->SetInputConnection(src->GetOutputPort());
    o2t->SetFieldType(vtkDataObjectToTable::VERTEX_DATA);
    o2t->Update();

    // Create Qt table view and add a representation
    vSPNew( tv, vtkQtTableView );
    vtkDataRepresentation *tr =
            tv->AddRepresentationFromInputConnection(o2t->GetOutputPort());
    tr->SetAnnotationLink( annLink );
    tr->SetSelectionType( vtkSelectionNode::PEDIGREEIDS );
    tv->Update();

    // Create graph layout view
    vSPNew( gv, vtkGraphLayoutView );
    gv->SetVertexLabelArrayName("vertex id");
    gv->VertexLabelVisibilityOn();
    gv->SetLayoutStrategyToSimple2D();

    // Add representation to graph view
    vtkDataRepresentation *gr =
            gv->AddRepresentationFromInputConnection(src->GetOutputPort());
    gv->Update();
    gr->SetSelectionType( tr->GetSelectionType() );
    gr->SetAnnotationLink( annLink );

    // Ensure both views update when selection changes
    vSPNew( vu, vtkViewUpdater );
    vu->AddView(gv);
    vu->AddView(tv);
    vu->AddAnnotationLink( annLink );

    gv->ResetCamera();
    gv->Render();
// gv->GetInteractor()->Start();

    tv->GetWidget()->show();
    return app.exec();
}



If we choose multiple vertex id in qt table, the vtkGraphLayoutView object can also update highlight parts.


0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Tex To PDF
: convert the Latex file which suffix is tex to a PDF file

X
0
Would love your thoughts, please comment.x
()
x