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)
// 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() {}
......
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