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