Commit cc970dac authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Merge branch 'vtkchartwidget' into 'master'

vtk chart classes shared build and error handling

See merge request !53
parents 7ad77cda decd45a2
Pipeline #16060 passed with stages
in 9 minutes and 43 seconds
......@@ -35,64 +35,95 @@ vtkChartMainWindow::vtkChartMainWindow(QWidget* parent)
// 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);
vtkNew<vtkFloatArray> arrXErr;
arrXErr->SetName("x error");
table->AddColumn(arrXErr);
vtkNew<vtkFloatArray> arrCosErr;
arrCosErr->SetName("cos error");
table->AddColumn(arrCosErr);
vtkNew<vtkFloatArray> arrSumErr;
arrSumErr->SetName("Sum error");
table->AddColumn(arrSumErr);
int numPoints = 29;
float inc = 7.0 / (numPoints - 1);
vtkNew<vtkFloatArray> xArray;
xArray->SetName("x");
table->AddColumn(xArray);
vtkNew<vtkFloatArray> sinArray;
sinArray->SetName("sin");
table->AddColumn(sinArray);
vtkNew<vtkFloatArray> cosArray;
cosArray->SetName("cos");
table->AddColumn(cosArray);
vtkNew<vtkFloatArray> sumArray;
sumArray->SetName("sum");
table->AddColumn(sumArray);
vtkNew<vtkFloatArray> subArray;
subArray->SetName("subtract");
table->AddColumn(subArray);
vtkNew<vtkFloatArray> multArray;
multArray->SetName("multiply");
table->AddColumn(multArray);
vtkNew<vtkFloatArray> xErrorArray;
xErrorArray->SetName("x error");
table->AddColumn(xErrorArray);
vtkNew<vtkFloatArray> cosErrorArray;
cosErrorArray->SetName("cos error");
table->AddColumn(cosErrorArray);
vtkNew<vtkFloatArray> sumErrorArray;
sumErrorArray->SetName("sum error");
table->AddColumn(sumErrorArray);
vtkNew<vtkFloatArray> subErrorArray;
subErrorArray->SetName("sub error");
table->AddColumn(subErrorArray);
// Add some data points to the chart
int numPoints = 100;
float maxX = 15.0f;
table->SetNumberOfRows(numPoints);
for (int i = 0; i < numPoints; ++i)
{
float x = i * inc, sin = std::sin(x), cos = std::cos(x),
sum = std::fabs(sin) + std::fabs(cos), xErr = x / 10.0,
cosErr = cos / 5.0, sumErr = sum / 5.0;
table->SetValue(i, 0, x);
table->SetValue(i, 1, cos);
table->SetValue(i, 2, sin);
table->SetValue(i, 3, sum);
table->SetValue(i, 4, xErr);
table->SetValue(i, 5, cosErr);
table->SetValue(i, 6, sumErr);
float num = i * maxX / numPoints;
table->SetValue(i, 0, num);
table->SetValue(i, 1, sin(num));
table->SetValue(i, 2, cos(num) + 1.0);
table->SetValue(i, 3, sin(num) + cos(num) + 3.0);
table->SetValue(i, 4, sin(num) - cos(num) + 4.0);
table->SetValue(i, 5, sin(num) * cos(num) + 5.0);
table->SetValue(i, 6, abs(num / 10.0));
table->SetValue(i, 7, abs(cos(num) / 3.0));
table->SetValue(i, 8, abs((sin(num) + cos(num)) / 3.0));
table->SetValue(i, 9, abs((sin(num) - cos(num)) / 3.0));
}
vtkPlotLineErrorBars* cosLine = vtkPlotLineErrorBars::New();
vtkChartWidget->chartXY()->AddPlot(cosLine);
cosLine->SetInputData(table, 0, 1, 4, 5); // x-axis and cos with errors
cosLine->SetPlotErrorBars(1);
cosLine->SetColor(255, 0, 0, 255);
cosLine->SetWidth(0.5);
vtkPlotPointsErrorBars* sinPoints = vtkPlotPointsErrorBars::New();
vtkChartWidget->chartXY()->AddPlot(sinPoints);
sinPoints->SetInputData(table, 0, 2); // x-axis and sin
sinPoints->SetColor(0, 255, 0, 255);
sinPoints->SetWidth(5.0);
vtkPlotPointsErrorBars* sumPoints = vtkPlotPointsErrorBars::New();
vtkChartWidget->chartXY()->AddPlot(sumPoints);
sumPoints->SetInputData(table, 0, 3, 4, 6); // x-axis and sum with errors
sumPoints->SetPlotErrorBars(1);
sumPoints->SetColor(255, 0, 255, 255);
sumPoints->SetWidth(2.0);
// Add a line plot without errors (sin)
vtkPlotLineErrorBars* sinPlot = vtkPlotLineErrorBars::New();
vtkChartWidget->chartXY()->AddPlot(sinPlot);
sinPlot->SetInputData(table, 0, 1);
sinPlot->SetColor(0, 0, 0, 255);
sinPlot->SetWidth(1.0);
// Add a points plot with errors (cos)
vtkPlotPointsErrorBars* cosPlot = vtkPlotPointsErrorBars::New();
vtkChartWidget->chartXY()->AddPlot(cosPlot);
cosPlot->SetInputData(table, 0, 2, 6, 7);
cosPlot->SetPlotErrorBars(1);
cosPlot->SetColor(0, 255, 0, 255);
cosPlot->SetWidth(2.0);
// Add a points plot with errors, but don't plot the errors (sum)
vtkPlotPointsErrorBars* sumPlot = vtkPlotPointsErrorBars::New();
vtkChartWidget->chartXY()->AddPlot(sumPlot);
sumPlot->SetInputData(table, 0, 3, 6, 8);
sumPlot->SetPlotErrorBars(0);
sumPlot->SetColor(0, 0, 255, 255);
sumPlot->SetWidth(2.0);
// Add a line plot with errors (subtract)
vtkPlotLineErrorBars* subPlot = vtkPlotLineErrorBars::New();
vtkChartWidget->chartXY()->AddPlot(subPlot);
subPlot->SetInputData(table, 0, 4, 6, 9);
subPlot->SetPlotErrorBars(1);
subPlot->SetColor(255, 0, 0, 255);
subPlot->SetWidth(1.0);
// Add a points plot without errors, but set PlotErrorBars = true (multiply)
// (no error bars should be plotted)
vtkPlotPointsErrorBars* multPlot = vtkPlotPointsErrorBars::New();
vtkChartWidget->chartXY()->AddPlot(multPlot);
multPlot->SetInputData(table, 0, 5);
multPlot->SetPlotErrorBars(1);
multPlot->SetColor(255, 0, 255, 255);
multPlot->SetWidth(2.0);
}
vtkChartMainWindow::~vtkChartMainWindow() {}
......
......@@ -27,6 +27,8 @@
#ifndef RADIX_RADIXWIDGETS_VTKPLOTERRORBARS_HH_
#define RADIX_RADIXWIDGETS_VTKPLOTERRORBARS_HH_
#include "radixcore/visibility.hh"
#include "vtkChartsCoreModule.h" // For export macro
#include "vtkContextItem.h"
#include "vtkContextPolygon.h" // For vtkContextPolygon
......@@ -44,7 +46,7 @@ class vtkBrush;
class vtkAxis;
class vtkStringArray;
class VTKCHARTSCORE_EXPORT vtkPlotErrorBars : public vtkPlot
class RADIX_PUBLIC vtkPlotErrorBars : public vtkPlot
{
public:
vtkTypeMacro(vtkPlotErrorBars, vtkPlot);
......
......@@ -27,9 +27,10 @@
#include "vtkChartsCoreModule.h" // For export macro
#include "radixcore/visibility.hh"
#include "radixwidgets/vtkPlotPointsErrorBars.hh"
class VTKCHARTSCORE_EXPORT vtkPlotLineErrorBars : public vtkPlotPointsErrorBars
class RADIX_PUBLIC vtkPlotLineErrorBars : public vtkPlotPointsErrorBars
{
public:
vtkTypeMacro(vtkPlotLineErrorBars, vtkPlotPointsErrorBars);
......
......@@ -865,19 +865,24 @@ bool vtkPlotPointsErrorBars::UpdateTableCache(vtkTable *table)
this->YErrors = vtkFloatArray::New();
}
vtkDataArray *xErr = array[2];
switch (xErr->GetDataType())
if (xErr)
{
vtkTemplateMacro(CopyToXErrors(
this->XErrors, static_cast<VTK_TT *>(xErr->GetVoidPointer(0)),
int(xErr->GetNumberOfTuples()), this->ShiftScale));
switch (xErr->GetDataType())
{
vtkTemplateMacro(CopyToXErrors(
this->XErrors, static_cast<VTK_TT *>(xErr->GetVoidPointer(0)),
int(xErr->GetNumberOfTuples()), this->ShiftScale));
}
}
vtkDataArray *yErr = array[3];
switch (yErr->GetDataType())
if (yErr)
{
vtkTemplateMacro(CopyToYErrors(
this->YErrors, static_cast<VTK_TT *>(yErr->GetVoidPointer(0)),
yErr->GetNumberOfTuples(), this->ShiftScale));
switch (yErr->GetDataType())
{
vtkTemplateMacro(CopyToYErrors(
this->YErrors, static_cast<VTK_TT *>(yErr->GetVoidPointer(0)),
int(yErr->GetNumberOfTuples()), this->ShiftScale));
}
}
}
......
......@@ -32,6 +32,7 @@
#ifndef RADIX_RADIXWIDGETS_VTKPLOTPOINTSERRORBARS_HH_
#define RADIX_RADIXWIDGETS_VTKPLOTPOINTSERRORBARS_HH_
#include "radixcore/visibility.hh"
#include "radixwidgets/vtkPlotErrorBars.hh"
#include "vtkChartsCoreModule.h" // For export macro
......@@ -50,7 +51,7 @@ class vtkImageData;
class vtkScalarsToColors;
class vtkUnsignedCharArray;
class VTKCHARTSCORE_EXPORT vtkPlotPointsErrorBars : public vtkPlotErrorBars
class RADIX_PUBLIC vtkPlotPointsErrorBars : public vtkPlotErrorBars
{
public:
vtkTypeMacro(vtkPlotPointsErrorBars, vtkPlotErrorBars);
......
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