Commit 54e5828b authored by Purves, Murray's avatar Purves, Murray
Browse files

Updating radixvtkerrorbars example to match test submitted to VTK for error bar capability

parent 64974ce7
Pipeline #15693 passed with stages
in 8 minutes and 23 seconds
...@@ -35,64 +35,95 @@ vtkChartMainWindow::vtkChartMainWindow(QWidget* parent) ...@@ -35,64 +35,95 @@ vtkChartMainWindow::vtkChartMainWindow(QWidget* parent)
// Create a table with some points in it // Create a table with some points in it
vtkNew<vtkTable> table; vtkNew<vtkTable> table;
vtkNew<vtkFloatArray> arrX; vtkNew<vtkFloatArray> xArray;
arrX->SetName("X Axis"); xArray->SetName("x");
table->AddColumn(arrX); table->AddColumn(xArray);
vtkNew<vtkFloatArray> arrC; vtkNew<vtkFloatArray> sinArray;
arrC->SetName("Cosine"); sinArray->SetName("sin");
table->AddColumn(arrC); table->AddColumn(sinArray);
vtkNew<vtkFloatArray> arrS; vtkNew<vtkFloatArray> cosArray;
arrS->SetName("Sine"); cosArray->SetName("cos");
table->AddColumn(arrS); table->AddColumn(cosArray);
vtkNew<vtkFloatArray> arrSum; vtkNew<vtkFloatArray> sumArray;
arrSum->SetName("Sum"); sumArray->SetName("sum");
table->AddColumn(arrSum); table->AddColumn(sumArray);
vtkNew<vtkFloatArray> arrXErr; vtkNew<vtkFloatArray> subArray;
arrXErr->SetName("x error"); subArray->SetName("subtract");
table->AddColumn(arrXErr); table->AddColumn(subArray);
vtkNew<vtkFloatArray> arrCosErr; vtkNew<vtkFloatArray> multArray;
arrCosErr->SetName("cos error"); multArray->SetName("multiply");
table->AddColumn(arrCosErr); table->AddColumn(multArray);
vtkNew<vtkFloatArray> arrSumErr; vtkNew<vtkFloatArray> xErrorArray;
arrSumErr->SetName("Sum error"); xErrorArray->SetName("x error");
table->AddColumn(arrSumErr); table->AddColumn(xErrorArray);
int numPoints = 29; vtkNew<vtkFloatArray> cosErrorArray;
float inc = 7.0 / (numPoints - 1); 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); table->SetNumberOfRows(numPoints);
for (int i = 0; i < numPoints; ++i) for (int i = 0; i < numPoints; ++i)
{ {
float x = i * inc, sin = std::sin(x), cos = std::cos(x), float num = i * maxX / numPoints;
sum = std::fabs(sin) + std::fabs(cos), xErr = x / 10.0, table->SetValue(i, 0, num);
cosErr = cos / 5.0, sumErr = sum / 5.0; table->SetValue(i, 1, sin(num));
table->SetValue(i, 2, cos(num) + 1.0);
table->SetValue(i, 0, x); table->SetValue(i, 3, sin(num) + cos(num) + 3.0);
table->SetValue(i, 1, cos); table->SetValue(i, 4, sin(num) - cos(num) + 4.0);
table->SetValue(i, 2, sin); table->SetValue(i, 5, sin(num) * cos(num) + 5.0);
table->SetValue(i, 3, sum); table->SetValue(i, 6, abs(num / 10.0));
table->SetValue(i, 4, xErr); table->SetValue(i, 7, abs(cos(num) / 3.0));
table->SetValue(i, 5, cosErr); table->SetValue(i, 8, abs((sin(num) + cos(num)) / 3.0));
table->SetValue(i, 6, sumErr); table->SetValue(i, 9, abs((sin(num) - cos(num)) / 3.0));
} }
vtkPlotLineErrorBars* cosLine = vtkPlotLineErrorBars::New(); // Add a line plot without errors (sin)
vtkChartWidget->chartXY()->AddPlot(cosLine); vtkPlotLineErrorBars* sinPlot = vtkPlotLineErrorBars::New();
cosLine->SetInputData(table, 0, 1, 4, 5); // x-axis and cos with errors vtkChartWidget->chartXY()->AddPlot(sinPlot);
cosLine->SetPlotErrorBars(1); sinPlot->SetInputData(table, 0, 1);
cosLine->SetColor(255, 0, 0, 255); sinPlot->SetColor(0, 0, 0, 255);
cosLine->SetWidth(0.5); sinPlot->SetWidth(1.0);
vtkPlotPointsErrorBars* sinPoints = vtkPlotPointsErrorBars::New(); // Add a points plot with errors (cos)
vtkChartWidget->chartXY()->AddPlot(sinPoints); vtkPlotPointsErrorBars* cosPlot = vtkPlotPointsErrorBars::New();
sinPoints->SetInputData(table, 0, 2); // x-axis and sin vtkChartWidget->chartXY()->AddPlot(cosPlot);
sinPoints->SetColor(0, 255, 0, 255); cosPlot->SetInputData(table, 0, 2, 6, 7);
sinPoints->SetWidth(5.0); cosPlot->SetPlotErrorBars(1);
cosPlot->SetColor(0, 255, 0, 255);
vtkPlotPointsErrorBars* sumPoints = vtkPlotPointsErrorBars::New(); cosPlot->SetWidth(2.0);
vtkChartWidget->chartXY()->AddPlot(sumPoints);
sumPoints->SetInputData(table, 0, 3, 4, 6); // x-axis and sum with errors // Add a points plot with errors, but don't plot the errors (sum)
sumPoints->SetPlotErrorBars(1); vtkPlotPointsErrorBars* sumPlot = vtkPlotPointsErrorBars::New();
sumPoints->SetColor(255, 0, 255, 255); vtkChartWidget->chartXY()->AddPlot(sumPlot);
sumPoints->SetWidth(2.0); 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() {} vtkChartMainWindow::~vtkChartMainWindow() {}
......
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