vtkplotbar issue with large range on x axis
I obtain weird results on bar plots when the x-axis range is larger than 1e10. For instance, with the following code:
vtkNew<vtkContextView> view;
vtkNew<vtkChartXY> chart;
view->GetScene()->AddItem(chart.GetPointer());
vtkNew<vtkTable> t;
vtkNew<vtkFloatArray> a;
a->SetName("bins");
a->SetNumberOfTuples(2);
*a->GetPointer(0) = -2e12;
*a->GetPointer(1) = -1.5e12;
t->AddColumn(a.GetPointer());
vtkNew<vtkIntArray> b;
b->SetName("count");
b->SetNumberOfTuples(2);
*b->GetPointer(0) = 10;
*b->GetPointer(1) = 20;
t->AddColumn(b.GetPointer());
chart->GetAxis(1)->SetBehavior(1);
chart->GetAxis(1)->SetUnscaledRange(-3e12, -1e12);
auto pb = chart->AddPlot(vtkChart::BAR);
pb->SetInputData(t.GetPointer(), a->GetName(), b->GetName());
view->GetInteractor()->Initialize();
view->GetInteractor()->Start();
the chart is filled in black instead of showing 2 bars. I am testing with VTK-6.3; I know this is a bit old but the culprit code looks like it hasn't been modified since.
I tracked it down to the following in vtkChart:
for (int i = 0; i < 2; ++i)
{
if (fabs(log10(origin[i] / scale[i])) > 2)
{
shift[i] = floor(log10(origin[i] / scale[i]) / 3.0) * 3.0;
shift[i] = -origin[i];
}
if (fabs(log10(scale[i])) > 10)
{
// We need to scale the transform to show all data, do this in blocks.
factor[i] = pow(10.0, floor(log10(scale[i]) / 10.0) * -10.0);
scale[i] = scale[i] * factor[i];
}
}
x->SetScalingFactor(factor[0]);
x->SetShift(shift[0]);
y->SetScalingFactor(factor[1]);
y->SetShift(shift[1]);
which is forwarded into every plot's ShiftScale and used in vtkPlotBar.
I can solve the issue by commenting out the latter code in vtkChart. I fail to understand what this all about; does anyone remember?