Commit 4b1e6445 authored by Purves, Murray's avatar Purves, Murray
Browse files

#20 WIP Adding test class to base work off of

parent 63b00f28
......@@ -60,10 +60,12 @@ ELSE()
IF(TPL_ENABLE_VTK)
SET(HEADERS ${HEADERS}
vtkchartwidget.hh
vtkPlotPointsErrorBars.hh
)
SET(SOURCES
${SOURCES}
vtkchartwidget.cc
vtkPlotPointsErrorBars.cc
)
ENDIF()
QT5_WRAP_CPP(MOC_FILES
......
......@@ -25,8 +25,11 @@ ELSE()
QT5_WRAP_CPP(QMOC_FILES4
radixvtkchartwidget.hh
)
QT5_WRAP_CPP(QMOC_FILES5
radixvtkerrorbars.hh
)
ENDIF()
QT5_WRAP_CPP(QMOC_FILES5
QT5_WRAP_CPP(QMOC_FILES6
radixnavigationwidget.hh
)
TRIBITS_ADD_EXECUTABLE(radixnumberpadwidget
......@@ -36,7 +39,7 @@ ELSE()
)
TRIBITS_ADD_EXECUTABLE(radixnavigationwidget
NOEXEPREFIX
SOURCES radixnavigationwidget.cc ${QMOC_FILES5}
SOURCES radixnavigationwidget.cc ${QMOC_FILES6}
radixnavigationwidget.hh
)
IF(TPL_ENABLE_VTK)
......@@ -45,6 +48,10 @@ ELSE()
NOEXEPREFIX
SOURCES radixvtkchartwidget.cc ${QMOC_FILES4}
)
TRIBITS_ADD_EXECUTABLE(radixvtkerrorbars
NOEXEPREFIX
SOURCES radixvtkerrorbars.cc ${QMOC_FILES5}
)
ENDIF()
ENDIF()
TRIBITS_ADD_EXECUTABLE(radixtabwidget
......
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingContextOpenGL2)
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)
VTK_MODULE_INIT(vtkRenderingFreeType)
#include <QApplication>
#include <QGridLayout>
#include <QMainWindow>
#include <QWidget>
#include "vtkFloatArray.h"
#include "vtkPlot.h"
#include "vtkTable.h"
#include "radixvtkerrorbars.hh"
#include "radixwidgets/vtkchartwidget.hh"
vtkChartMainWindow::vtkChartMainWindow(QWidget* parent)
: QMainWindow(parent)
{
setGeometry(400, 250, 542, 390);
// needed to ensure appropriate OpenGL context is created for VTK rendering.
QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());
// Test widget
QWidget* widget = new QWidget(this);
QGridLayout* layout = new QGridLayout(widget);
radix::VTKChartWidget* vtkChartWidget = new radix::VTKChartWidget(this);
layout->addWidget(vtkChartWidget, 0, 0);
setCentralWidget(widget);
// 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);
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))));
}
vtkPlot* line = vtkChartWidget->chartXY()->AddPlot(vtkChart::LINE);
line->SetInputData(table, 0, 1); // x-axis and cos
line->SetColor(255, 0, 0, 255);
line->SetWidth(0.5);
line = vtkChartWidget->chartXY()->AddPlot(vtkChart::LINE);
line->SetInputData(table, 0, 2); // x-axis and sin
line->SetColor(0, 255, 0, 255);
line->SetWidth(5.0);
line = vtkChartWidget->chartXY()->AddPlot(vtkChart::POINTS);
line->SetInputData(table, 0, 3); // x-axis and sum
line->SetColor(255, 0, 255, 255);
line->SetWidth(2.0);
}
vtkChartMainWindow::~vtkChartMainWindow() {}
/******************************************************************************/
/******************************** MAIN PROGRAM ********************************/
/******************************************************************************/
int main(int argc, char** argv)
{
QApplication app(argc, argv);
vtkChartMainWindow mainWindow;
mainWindow.show();
mainWindow.raise();
return app.exec();
}
#ifndef RADIX_RADIXWIDGETS_EXAMPLE_RADIXVTKERRORBARS_HH_
#define RADIX_RADIXWIDGETS_EXAMPLE_RADIXVTKERRORBARS_HH_
#include <QMainWindow>
namespace Ui
{
class vtkChartMainWindow;
}
class vtkChartMainWindow : public QMainWindow
{
Q_OBJECT
private:
public:
explicit vtkChartMainWindow(QWidget *parent = 0);
~vtkChartMainWindow();
};
#endif // RADIX_RADIXWIDGETS_EXAMPLE_RADIXVTKERRORBARS_HH_
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPlotPoints.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkPlotPoints
* @brief Class for drawing an points given two columns from a
* vtkTable.
*
*
* This class draws points in a plot given two columns from a table. If you need
* a line as well you should use vtkPlotLine which derives from vtkPlotPoints
* and is capable of drawing both points and a line.
*
* Extended by Murray Purves, ORNL
*
* @sa
* vtkPlotLine
*/
#ifndef RADIX_RADIXWIDGETS_VTKPLOTPOINTSERRORBARS_HH_
#define RADIX_RADIXWIDGETS_VTKPLOTPOINTSERRORBARS_HH_
#include "vtkChartsCoreModule.h" // For export macro
#include "vtkNew.h" // For ivars
#include "vtkPlot.h"
#include "vtkRenderingCoreEnums.h" // For marker enum
#include "vtkScalarsToColors.h" // For VTK_COLOR_MODE_DEFAULT and _MAP_SCALARS
#include "vtkStdString.h" // For color array name
class vtkCharArray;
class vtkContext2D;
class vtkTable;
class vtkPoints2D;
class vtkFloatArray;
class vtkStdString;
class vtkImageData;
class vtkScalarsToColors;
class vtkUnsignedCharArray;
class VTKCHARTSCORE_EXPORT vtkPlotPoints : public vtkPlot
{
public:
vtkTypeMacro(vtkPlotPoints, vtkPlot);
void PrintSelf(ostream &os, vtkIndent indent) override;
/**
* Creates a 2D Chart object.
*/
static vtkPlotPoints *New();
/**
* Perform any updates to the item that may be necessary before rendering.
* The scene should take care of calling this on all items before their
* Paint function is invoked.
*/
void Update() override;
/**
* Paint event for the XY plot, called whenever the chart needs to be drawn
*/
bool Paint(vtkContext2D *painter) override;
/**
* Paint legend event for the XY plot, called whenever the legend needs the
* plot items symbol/mark/line drawn. A rect is supplied with the lower left
* corner of the rect (elements 0 and 1) and with width x height (elements 2
* and 3). The plot can choose how to fill the space supplied.
*/
bool PaintLegend(vtkContext2D *painter, const vtkRectf &rect,
int legendIndex) override;
/**
* Get the bounds for this plot as (Xmin, Xmax, Ymin, Ymax).
*/
void GetBounds(double bounds[4]) override;
/**
* Get the non-log-scaled bounds on chart inputs for this plot as (Xmin, Xmax,
* Ymin, Ymax).
*/
void GetUnscaledInputBounds(double bounds[4]) override;
//@{
/**
* Specify a lookup table for the mapper to use.
*/
void SetLookupTable(vtkScalarsToColors *lut);
vtkScalarsToColors *GetLookupTable();
//@}
/**
* Create default lookup table. Generally used to create one when none
* is available with the scalar data.
*/
virtual void CreateDefaultLookupTable();
//@{
/**
* Turn on/off flag to control whether scalar data is used to color objects.
*/
vtkSetMacro(ScalarVisibility, int);
vtkGetMacro(ScalarVisibility, int);
vtkBooleanMacro(ScalarVisibility, int);
//@}
//@{
/**
* When ScalarMode is set to UsePointFieldData or UseCellFieldData,
* you can specify which array to use for coloring using these methods.
* The lookup table will decide how to convert vectors to colors.
*/
void SelectColorArray(vtkIdType arrayNum);
void SelectColorArray(const vtkStdString &arrayName);
//@}
/**
* Get the array name to color by.
*/
vtkStdString GetColorArrayName();
/**
* Function to query a plot for the nearest point to the specified coordinate.
* Returns the index of the data series with which the point is associated or
* -1.
*/
vtkIdType GetNearestPoint(const vtkVector2f &point,
const vtkVector2f &tolerance,
vtkVector2f *location) override;
/**
* Select all points in the specified rectangle.
*/
bool SelectPoints(const vtkVector2f &min, const vtkVector2f &max) override;
/**
* Select all points in the specified polygon.
*/
bool SelectPointsInPolygon(const vtkContextPolygon &polygon) override;
/**
* Enum containing various marker styles that can be used in a plot.
*/
enum
{
NONE = VTK_MARKER_NONE,
CROSS = VTK_MARKER_CROSS,
PLUS = VTK_MARKER_PLUS,
SQUARE = VTK_MARKER_SQUARE,
CIRCLE = VTK_MARKER_CIRCLE,
DIAMOND = VTK_MARKER_DIAMOND
};
//@{
/**
* Get/set the marker style that should be used. The default is none, the enum
* in this class is used as a parameter.
*/
vtkGetMacro(MarkerStyle, int);
vtkSetMacro(MarkerStyle, int);
//@}
//@{
/**
* Get/set the marker size that should be used. The default is negative, and
* in that case it is 2.3 times the pen width, if less than 8 will be used.
*/
vtkGetMacro(MarkerSize, float);
vtkSetMacro(MarkerSize, float);
//@}
//@{
/**
* Get/set the valid point mask array name.
*/
vtkGetMacro(ValidPointMaskName, vtkStdString)
vtkSetMacro(ValidPointMaskName, vtkStdString)
//@}
protected : vtkPlotPoints();
~vtkPlotPoints() override;
/**
* Populate the data arrays ready to operate on input data.
*/
bool GetDataArrays(vtkTable *table, vtkDataArray *array[2]);
/**
* Update the table cache.
*/
bool UpdateTableCache(vtkTable *table);
/**
* Calculate the unscaled input bounds from the input arrays.
*/
void CalculateUnscaledInputBounds();
/**
* Handle calculating the log of the x or y series if necessary. Should be
* called by UpdateTableCache once the data has been updated in Points.
*/
void CalculateLogSeries();
/**
* Find all of the "bad points" in the series. This is mainly used to cache
* bad points for performance reasons, but could also be used plot the bad
* points in the future.
*/
void FindBadPoints();
/**
* Calculate the bounds of the plot, ignoring the bad points.
*/
void CalculateBounds(double bounds[4]);
/**
* Create the sorted point list if necessary.
*/
void CreateSortedPoints();
//@{
/**
* Store a well packed set of XY coordinates for this data series.
*/
vtkPoints2D *Points;
vtkNew<vtkFloatArray> SelectedPoints;
//@}
//@{
/**
* Sorted points, used when searching for the nearest point.
*/
class VectorPIMPL;
VectorPIMPL *Sorted;
//@}
/**
* An array containing the indices of all the "bad points", meaning any x, y
* pair that has an infinity, -infinity or not a number value.
*/
vtkIdTypeArray *BadPoints;
/**
* Array which marks valid points in the array. If nullptr (the default), all
* points in the input array are considered valid.
*/
vtkCharArray *ValidPointMask;
/**
* Name of the valid point mask array.
*/
vtkStdString ValidPointMaskName;
/**
* The point cache is marked dirty until it has been initialized.
*/
vtkTimeStamp BuildTime;
//@{
/**
* The marker style that should be used
*/
int MarkerStyle;
float MarkerSize;
//@}
bool LogX, LogY;
//@{
/**
* Lookup Table for coloring points by scalar value
*/
vtkScalarsToColors *LookupTable;
vtkUnsignedCharArray *Colors;
int ScalarVisibility;
vtkStdString ColorArrayName;
//@}
/**
* Cached bounds on the plot input axes
*/
double UnscaledInputBounds[4];
private:
vtkPlotPoints(const vtkPlotPoints &) = delete;
void operator=(const vtkPlotPoints &) = delete;
};
#endif // RADIX_RADIXWIDGETS_VTKPLOTPOINTSERRORBARS_HH_
Markdown is supported
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