Commit c1c3a414 authored by Jordan P. Lefebvre's avatar Jordan P. Lefebvre
Browse files

WIP: Working vtkChart example into radixwidgets.

parent 3efc6701
Pipeline #14097 passed with stages
in 7 minutes and 35 seconds
......@@ -15,6 +15,7 @@ ENDIF()
TRIBITS_PACKAGE_DEFINE_DEPENDENCIES(
LIB_REQUIRED_TPLS ${QT_PACKAGES}
LIB_OPTIONAL_TPLS VTK
)
##---------------------------------------------------------------------------##
......
......@@ -21,6 +21,11 @@ ELSE()
QT5_WRAP_CPP(QMOC_FILES3
radixnumberpadwidget.hh
)
IF(TPL_ENABLE_VTK)
QT5_WRAP_CPP(QMOC_FILES4
radixvtkchartwidget.hh
)
ENDIF()
ENDIF()
TRIBITS_ADD_EXECUTABLE(radixtabwidget
NOEXEPREFIX
......@@ -36,3 +41,11 @@ TRIBITS_ADD_EXECUTABLE(radixnumberpadwidget
NOEXEPREFIX
SOURCES radixnumberpadwidget.cc ${QMOC_FILES3}
)
IF(USE_QT5 AND TPL_ENABLE_VTK)
MESSAGE("VTK_USE_FILE=${VTK_USE_FILE}")
TRIBITS_ADD_EXECUTABLE(radixvtkchartwidget
NOEXEPREFIX
SOURCES radixvtkchartwidget.cc ${QMOC_FILES4}
)
ENDIF()
/*
* @file: radixvtkchartwidget.cc
* @author: Jordan P. Lefebvre, lefebvrejp@ornl.gov
*/
#include "vtkAutoInit.h"
VTK_MODULE_INIT(vtkRenderingContextOpenGL2)
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)
VTK_MODULE_INIT(vtkRenderingFreeType)
#include "QVTKOpenGLWidget.h"
#include "vtkChartXY.h"
#include "vtkContextScene.h"
#include "vtkContextView.h"
#include "vtkFloatArray.h"
#include "vtkGenericOpenGLRenderWindow.h"
#include "vtkMath.h"
#include "vtkNew.h"
#include "vtkPlot.h"
#include "vtkPlotHistogram2D.h"
#include "vtkQtTableView.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkSmartPointer.h"
#include "vtkTable.h"
#include "vtkTimerLog.h"
#include <QApplication>
#include <QHBoxLayout>
#include <QMainWindow>
#include <QSurfaceFormat>
#include <QWidget>
#include <QApplication>
#include <QGridLayout>
#include <QHeaderView>
#include <QLabel>
#include <limits>
#include "radixvtkchartwidget.hh"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setGeometry(400, 250, 542, 390);
// needed to ensure appropriate OpenGL context is created for VTK rendering.
QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());
QVTKOpenGLWidget *qvtkWidget = new QVTKOpenGLWidget(this);
vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
qvtkWidget->SetRenderWindow(renderWindow);
// Set up my 2D world...
vtkNew<vtkContextView> view; // This contains a chart object
view->SetRenderWindow(renderWindow);
view->SetInteractor(renderWindow->GetInteractor());
// Create a table with some points in it...
vtkNew<vtkTable> table;
vtkNew<vtkFloatArray> arrX;
arrX->SetName("X Axis");
table->AddColumn(arrX);
vtkNew<vtkFloatArray> arrC;
arrC->SetName("Cosine");
table->AddColumn(arrC);
vtkNew<vtkFloatArray> arrS;
arrS->SetName("Sine");
table->AddColumn(arrS);
vtkNew<vtkFloatArray> arrSum;
arrSum->SetName("Sum");
table->AddColumn(arrSum);
// Test charting with a few more points...
int numPoints = 29;
float inc = 7.0 / (numPoints - 1);
table->SetNumberOfRows(numPoints);
for (int i = 0; i < numPoints; ++i)
{
table->SetValue(i, 0, i * inc);
table->SetValue(i, 1, std::cos(double(i * inc)));
table->SetValue(i, 2, std::sin(double(i * inc)));
table->SetValue(i, 3,
std::fabs(std::sin(double(i * inc))) +
std::fabs(std::cos(double(i * inc))));
}
// table->Update();
// Add multiple line plots, setting the colors etc
vtkNew<vtkChartXY> chart;
chart->SetShowLegend(true);
view->GetScene()->AddItem(chart);
vtkPlot *line = chart->AddPlot(vtkChart::LINE);
line->SetInputData(table, 0, 1); // x-axis and cos
line->SetColor(255, 0, 0, 255);
line->SetWidth(0.5);
line = chart->AddPlot(vtkChart::LINE);
line->SetInputData(table, 0, 2); // x-axis and sin
line->SetColor(0, 255, 0, 255);
line->SetWidth(5.0);
line = chart->AddPlot(vtkChart::LINE);
line->SetInputData(table, 0, 3); // x-axis and sum
line->SetColor(255, 0, 255, 255);
line->SetWidth(2.0);
// Now lets try to add a table view
QWidget *widget = new QWidget(this);
QGridLayout *layout = new QGridLayout(widget);
layout->addWidget(qvtkWidget, 0, 0);
setCentralWidget(widget);
}
MainWindow::~MainWindow() {}
/******************************************************************************/
/******************************** MAIN PROGRAM ********************************/
/******************************************************************************/
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MainWindow mainWindow;
mainWindow.show();
mainWindow.raise();
return app.exec();
}
#ifndef RADIX_RADIXWIDGETS_EXAMPLE_RADIXVTKCHARTDWIDGET_HH_
#define RADIX_RADIXWIDGETS_EXAMPLE_RADIXVTKCHARTDWIDGET_HH_
#include <QMainWindow>
namespace Ui
{
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
private:
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
};
#endif // RADIX_RADIXWIDGETS_EXAMPLE_RADIXVTKCHARTDWIDGET_HH_
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment