vtkParallelCoordinatesView with Qt

Zoltan Kovacs <[email protected]>
Newsgroups gmane.comp.lib.vtk.user
Message-ID <AM4PR0902MB176404BF2D727274F12405A9B7D10@AM4PR0902MB1764.eurprd09.prod.outlook.com>
Dear all,



Based on the example

https://www.vtk.org/Wiki/VTK/Examples/Cxx/InfoVis/ParallelCoordinatesView

I created a simple Qt project using the class vtkParallelCoordinatesView.  It has only a main window with a PushButton and a QWidget to launch a file

opening dialog for any CSV file and view its content. I also created a Qt Form Class called "ParallelCoordinatesView" with the public function "View", which contains the CSV file reading and the parallel coordinates visualization code from the example. I attached the files.

There are two issues with the functions setting up the render window and the interactor in the public function "View".



These function calls are commented out in the code:



    // Set up render window

    view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);

    view->GetRenderer()->GradientBackgroundOff();

    view->GetRenderWindow()->SetSize(1200,600);

    //view->SetInteractor(renderWindowInteractor);

    //view->SetRenderWindow(renderWindow);

    view->ResetCamera();

    view->Render();

    //view->GetInteractor()->Start();



When I compile and run the code in this form, the parallel coordinates view appears in a window detached from the Qt MainWindow after the file test.csv has been read from the file opening dialog.



If I remove the comments only from

   //view->SetInteractor(renderWindowInteractor);

    //view->SetRenderWindow(renderWindow);

and compile and run the code then the view window appears in the QWidget in the MainWindow, as expected,

but as soon as I start to move the cursor, everything blacks out in the Mainwindow.



If remove the comment only from the line

 //view->GetInteractor()->Start();

the I can select lines in the parallel coodinates view vindow, as expected with starting the interactor,

but the Mainwindow hangs.



I would like to ask if there is a proper setup of the render window and the interactor for the class vtkParallelCoordinatesView with Qt? Thank you very much for your help.



Kind regards,

Zoltan

_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
main.cpp (text/x-c++src, 172 B)
#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}
mainwindow.cpp (text/x-c++src, 517 B)
#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    OGLWidget = new QVTKOpenGLWidget();
    widget2 = new ParallelCoordinatesView(OGLWidget, ui->widget);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    QString fileName = QFileDialog::getOpenFileName( this, tr("Open File"), QDir::homePath(), "CSV Files (*.csv)" );
    widget2->View(fileName);
}
mainwindow.h (text/x-chdr, 479 B)
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QFileDialog>
#include "parallelcoordinatesview.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void on_pushButton_clicked();

private:
    Ui::MainWindow *ui;
    QVTKOpenGLWidget        *OGLWidget;
    ParallelCoordinatesView *widget2;
};

#endif // MAINWINDOW_H
mainwindow.ui (application/x-designer, 1.4 KB) - not displayed
parallelcoordinatesview.cpp (text/x-c++src, 3 KB)
#include "parallelcoordinatesview.h"
#include "ui_parallelcoordinatesview.h"

ParallelCoordinatesView::ParallelCoordinatesView(QVTKOpenGLWidget *OGLWidget, QWidget *widget, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ParallelCoordinatesView)
{
    ui->setupUi(this);
    ui->setupUi(this);
    QHBoxLayout * layout = new QHBoxLayout();
    layout->addWidget(OGLWidget);
    widget->setLayout(layout);

    renderer                = vtkSmartPointer<vtkRenderer>::New();
    renderWindow            = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();

    table                   = vtkSmartPointer<vtkTable>::New();
    reader                  = vtkSmartPointer<vtkDelimitedTextReader>::New();
    polydata                = vtkSmartPointer<vtkPolyData>::New();
    rep                     = vtkSmartPointer<vtkParallelCoordinatesRepresentation>::New();
    view                    = vtkSmartPointer<vtkParallelCoordinatesView>::New();

    OGLWidget->SetRenderWindow(renderWindow);
    renderWindowInteractor  = OGLWidget->GetRenderWindow()->GetInteractor();
    renderWindowInteractor->SetRenderWindow(renderWindow);
    renderer->SetBackground(1,1,1);
    renderWindow->AddRenderer(renderer);
}

ParallelCoordinatesView::~ParallelCoordinatesView()
{
    delete ui;
}

void ParallelCoordinatesView::View(QString fileName)
{
    std::string title;
    std::string inputFilename = fileName.toStdString();

    reader->SetFileName(inputFilename.c_str());
    reader->SetHaveHeaders(1);
    reader->DetectNumericColumnsOn();
    reader->SetFieldDelimiterCharacters(",");
    reader->Update();

    table = reader->GetOutput();
    title = vtksys::SystemTools::GetFilenameWithoutExtension(
                vtksys::SystemTools::GetFilenameName(inputFilename));

    for (vtkIdType i = 0; i < table->GetNumberOfColumns(); ++i)
        polydata->GetPointData()->AddArray(table->GetColumn(i));

    rep->SetInputData(polydata);

    for (vtkIdType i = 0; i < table->GetNumberOfColumns(); ++i)
    {
        if (vtkStringArray::SafeDownCast(table->GetColumn(i)))
            continue;
        else
            rep->SetInputArrayToProcess(i, 0, 0, 0, table->GetColumn(i)->GetName());
    }

    rep->SetFontSize(.5);
    rep->SetPlotTitle(title.c_str());
    rep->SetLineOpacity(0.5);
    rep->SetLineColor(0.7, 0.7, 0.7);
    rep->SetAxisColor(0.0, 0.0, 0.0);
    rep->SetAxisLabelColor(0.0, 0.0, 0.0);

    // Set up the Parallel Coordinates View and hook in the Representation
    view->SetRepresentation(rep);
    view->SetInspectMode(1);
    view->SetDisplayHoverText(1);

    // Brush Mode determines the type of interaction you perform to select data
    view->SetBrushModeToLasso();
    view->SetBrushOperatorToReplace();

    // Set up render window
    view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
    view->GetRenderer()->GradientBackgroundOff();
    view->GetRenderWindow()->SetSize(1200,600);
    //view->SetInteractor(renderWindowInteractor);
    //view->SetRenderWindow(renderWindow);
    view->ResetCamera();
    view->Render();
    view->GetInteractor()->Start();
}
parallelcoordinatesview.h (text/x-chdr, 1.8 KB)
#ifndef PARALLELCOORDINATESVIEW_H
#define PARALLELCOORDINATESVIEW_H

#include <QWidget>
#include <QHBoxLayout>
#include <vtkAutoInit.h>
#ifndef _VTK_MODULE_INIT_
#define _VTK_MODULE_INIT_
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
#endif
#include "QVTKOpenGLWidget.h"
#include "vtkGenericOpenGLRenderWindow.h"
#include <vtkPolyData.h>
#include <vtkDelimitedTextReader.h>
#include <vtkTable.h>
#include <vtkPointData.h>
#include <vtkParallelCoordinatesView.h>
#include <vtkParallelCoordinatesRepresentation.h>
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include <vtkTable.h>
#include <vtkDelimitedTextReader.h>
#include <vtkStringArray.h>
#include <vtkDoubleArray.h>
#include <vtkFloatArray.h>
#include <vtkIntArray.h>
#include <vtksys/SystemTools.hxx>

namespace Ui {
class ParallelCoordinatesView;
}

class ParallelCoordinatesView : public QWidget
{
    Q_OBJECT

public:
    explicit ParallelCoordinatesView(QVTKOpenGLWidget *OGLWidget, QWidget *widget, QWidget *parent = 0);
    ~ParallelCoordinatesView();
    void View(QString filenName);

private:
    Ui::ParallelCoordinatesView *ui;
    vtkSmartPointer<vtkRenderer>                            renderer;
    vtkSmartPointer<vtkGenericOpenGLRenderWindow>           renderWindow;
    vtkSmartPointer<vtkRenderWindowInteractor>              renderWindowInteractor;
    vtkSmartPointer<vtkTable>                               table;
    vtkSmartPointer<vtkDelimitedTextReader>                 reader;
    vtkSmartPointer<vtkPolyData>                            polydata;
    vtkSmartPointer<vtkParallelCoordinatesRepresentation>   rep;
    vtkSmartPointer<vtkParallelCoordinatesView>             view;
};

#endif // PARALLELCOORDINATESVIEW_H
parallelcoordinatesview.ui (application/x-designer, 416 B) - not displayed
ParCoordView.pro (application/octet-stream, 4.2 KB) - not displayed
test.csv (application/octet-stream, 1.3 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.