[vtkusers] vtkChart large axis ranges

Marcus D. Hanwell marcus.hanwell at kitware.com
Wed Jun 4 12:24:02 EDT 2014


Hi Andrew,

I haven't forgotten this, but have been really busy. I will try to
take a look at this soon, thanks for the sample code.

Marcus

On Thu, May 22, 2014 at 10:10 PM, Andrew Ward
<andrew.derek.ward at gmail.com> wrote:
> Hi Marcus,
>
> Here is some code to reproduce the problem. Changing the RANGE_HIGH define
> to 1e11 causes the plot to render incorrectly and the function to disappear.
> I tried removing the relevant code in vtkChart::CalculatePlotTransform,
> which helped with this range, but there were still problems with the full
> float32 range.
>
> Regards,
>
> Andrew Ward.
>
>
> #include <vtkRenderer.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkSmartPointer.h>
> #include <vtkContextView.h>
> #include <vtkContextScene.h>
> #include <vtkPiecewiseFunctionItem.h>
> #include <vtkPiecewiseControlPointsItem.h>
> #include <vtkPiecewiseFunction.h>
> #include <vtkChartXY.h>
> #include <vtkAxis.h>
> #include <vtkTextProperty.h>
> #include <vtkPlotBar.h>
> #include <vtkPen.h>
> #include <vtkBrush.h>
> #include <vtkTable.h>
> #include <vtkFloatArray.h>
>
> #define RANGE_LOW -1e4
>
> // Change this value to 1e11 and the bar plot renders incorrectly, plus the
> // piecewise function points disappear.
> #define RANGE_HIGH 1e9
>
> vtkSmartPointer< vtkChartXY > GetNewChart()
> {
>     vtkSmartPointer< vtkChartXY > chart = vtkSmartPointer< vtkChartXY
>>::New();
>
>     vtkAxis *yAxis = chart->GetAxis(vtkAxis::LEFT);
>     vtkAxis *xAxis = chart->GetAxis(vtkAxis::BOTTOM);
>
>     xAxis->SetRange( RANGE_LOW, RANGE_HIGH);
>     xAxis->SetMinimumLimit( RANGE_LOW );
>     xAxis->SetMaximumLimit( RANGE_HIGH );
>     xAxis->SetBehavior(vtkAxis::FIXED);
>     yAxis->SetRange(0.0, 1.0);
>     yAxis->SetBehavior(vtkAxis::FIXED);
>
>     vtkSmartPointer< vtkTable > table = vtkSmartPointer< vtkTable >::New();
>     table->Initialize();
>
>     vtkSmartPointer< vtkFloatArray > xs =
>         vtkSmartPointer< vtkFloatArray >::New();
>     xs->SetName("X");
>     table->AddColumn(xs);
>
>     vtkSmartPointer< vtkFloatArray > ys =
>         vtkSmartPointer< vtkFloatArray >::New();
>     ys->SetName("Y");
>     table->AddColumn(ys);
>
>     double halfRange = ((RANGE_HIGH - RANGE_LOW) / 2.0);
>
>     table->SetNumberOfRows(3);
>     table->SetValue(0, 0, RANGE_LOW);
>     table->SetValue(0, 1, 0.5);
>     table->SetValue(1, 0, RANGE_LOW + halfRange);
>     table->SetValue(1, 1, 1.0);
>     table->SetValue(2, 0, RANGE_HIGH);
>     table->SetValue(2, 1, 0.2);
>
>     vtkSmartPointer< vtkPlotBar > plot = vtkSmartPointer< vtkPlotBar
>>::New();
>     plot->SetInputData(table, 0, 1);
>     plot->GetPen()->SetLineType(vtkPen::NO_PEN);
>     plot->GetBrush()->SetColorF(0.0, 0.0, 0.0, 0.25);
>     chart->AddPlot(plot);
>
>     vtkSmartPointer<vtkPiecewiseFunction> f =
>         vtkSmartPointer<vtkPiecewiseFunction>::New();
>     f->AddPoint(RANGE_LOW, 0.2);
>     f->AddPoint(RANGE_LOW + halfRange, 0.5);
>     f->AddPoint(RANGE_HIGH, 0.9);
>
>     vtkSmartPointer< vtkPiecewiseFunctionItem > opacityFunctionItem =
>         vtkSmartPointer< vtkPiecewiseFunctionItem >::New();
>     opacityFunctionItem->SetPiecewiseFunction(f);
>     chart->AddPlot(opacityFunctionItem);
>
>     vtkSmartPointer< vtkPiecewiseControlPointsItem > controlPoints =
>         vtkSmartPointer< vtkPiecewiseControlPointsItem >::New();
>     controlPoints->SetPiecewiseFunction(f);
>     chart->AddPlot(controlPoints);
>
>     return chart;
> }
>
> int main(int, char *[])
> {
>   vtkSmartPointer<vtkContextView> view =
> vtkSmartPointer<vtkContextView>::New();
>   view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
>   view->GetRenderWindow()->SetSize(800, 600);
>   view->GetScene()->AddItem(GetNewChart());
>   view->GetRenderWindow()->GetInteractor()->Initialize();
>   view->GetRenderWindow()->GetInteractor()->CreateOneShotTimer(10);
>   view->GetRenderWindow()->GetInteractor()->Start();
> }
>
>
>
> On 23 May 2014 05:49, Marcus D. Hanwell <marcus.hanwell at kitware.com> wrote:
>>
>> On Mon, May 19, 2014 at 8:48 PM, Andrew Ward
>> <andrew.derek.ward at gmail.com> wrote:
>> > Hello,
>> >
>> > I am attempting to use a vtkChartXY with an x-axis in the range of
>> > 32-bit
>> > floating-point numbers (-3.40282e+038 to 3.40282e+038), however when
>> > adding
>> > values with a range greater than 1e10, the chart fails to render
>> > properly.
>> >
>> > I tracked one possible problem down to vtkChart::CalculatePlotTransform,
>> > where the scaling factor is altered for large ranges, which at least
>> > explains why the issue appears over the 1e10 limit, but I am at a loss
>> > as to
>> > whether this is a bug, or whether I am using the chart incorrectly.
>> >
>> > Any suggestions much appreciated,
>> >
>> I wrote most of this code, if you could supply a few lines of code to
>> trigger it I will take a look. The scaling is there to support double
>> precision data that needs to be plotted and it sounds like my tests
>> miss a case that is hitting you here.
>>
>> Thanks,
>>
>> Marcus
>
>


More information about the vtkusers mailing list