Commit c0b6a7c9 authored by T.J. Corona's avatar T.J. Corona
Browse files

Correct bounds and integer width computation in vtkPlotHistogram2D.

This fix is in reference to bug report 0015325. The formula for width now
avoids a conversion from int to double back to int, and bounds are correctly
computed. TestHistogram2D and its resultant image have also been updated to
more closely match the original test image.
parent 9656347a
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
int TestHistogram2D(int, char * []) int TestHistogram2D(int, char * [])
{ {
// Set up a 2D scene, add an XY chart to it // Set up a 2D scene, add an XY chart to it
int size = 401; int size = 400;
vtkNew<vtkContextView> view; vtkNew<vtkContextView> view;
view->GetRenderWindow()->SetSize(size, size); view->GetRenderWindow()->SetSize(size, size);
vtkNew<vtkChartHistogram2D> chart; vtkNew<vtkChartHistogram2D> chart;
......
a7f0877d744e789cab1f21d356e20373 6dfef47ccee43e63802c1edcc673cab0
...@@ -52,14 +52,7 @@ bool vtkPlotHistogram2D::Paint(vtkContext2D *painter) ...@@ -52,14 +52,7 @@ bool vtkPlotHistogram2D::Paint(vtkContext2D *painter)
if (this->Input) if (this->Input)
{ {
double bounds[4]; double bounds[4];
int *extent = this->Input->GetExtent(); this->GetBounds(bounds);
bounds[0] = this->Input->GetOrigin()[0];
bounds[1] = bounds[0] +
(extent[1] - extent[0] + 1) * this->Input->GetSpacing()[0];
bounds[2] = this->Input->GetOrigin()[1];
bounds[3] = bounds[2] +
(extent[3] - extent[2] + 1) * this->Input->GetSpacing()[1];
this->Position = vtkRectf(bounds[0], bounds[2], this->Position = vtkRectf(bounds[0], bounds[2],
bounds[1] - bounds[0], bounds[3] - bounds[2]); bounds[1] - bounds[0], bounds[3] - bounds[2]);
} }
...@@ -101,11 +94,11 @@ void vtkPlotHistogram2D::GetBounds(double bounds[4]) ...@@ -101,11 +94,11 @@ void vtkPlotHistogram2D::GetBounds(double bounds[4])
int *extent = this->Input->GetExtent(); int *extent = this->Input->GetExtent();
bounds[0] = this->Input->GetOrigin()[0]; bounds[0] = this->Input->GetOrigin()[0];
bounds[1] = bounds[0] + bounds[1] = bounds[0] +
(extent[1] - extent[0]) * this->Input->GetSpacing()[0]; (extent[1] - extent[0] + 1) * this->Input->GetSpacing()[0];
bounds[2] = this->Input->GetOrigin()[1]; bounds[2] = this->Input->GetOrigin()[1];
bounds[3] = bounds[2] + bounds[3] = bounds[2] +
(extent[3] - extent[2]) * this->Input->GetSpacing()[1]; (extent[3] - extent[2] + 1) * this->Input->GetSpacing()[1];
} }
else else
{ {
...@@ -148,7 +141,7 @@ vtkIdType vtkPlotHistogram2D::GetNearestPoint(const vtkVector2f& point, ...@@ -148,7 +141,7 @@ vtkIdType vtkPlotHistogram2D::GetNearestPoint(const vtkVector2f& point,
// rendered as the bottom left corner of a histogram cell, not the center // rendered as the bottom left corner of a histogram cell, not the center
int locX = vtkMath::Floor( (point.GetX() - bounds[0]) / spacing[0] ); int locX = vtkMath::Floor( (point.GetX() - bounds[0]) / spacing[0] );
int locY = vtkMath::Floor( (point.GetY() - bounds[2]) / spacing[1] ); int locY = vtkMath::Floor( (point.GetY() - bounds[2]) / spacing[1] );
int width = vtkMath::Ceil( (bounds[1] - bounds[0]) / spacing[0] ) + 1; int width = this->Input->GetExtent()[1] - this->Input->GetExtent()[0] + 1;
// Discretize to ImageData point values // Discretize to ImageData point values
location->SetX(locX * spacing[0] + bounds[0]); location->SetX(locX * spacing[0] + bounds[0]);
...@@ -170,8 +163,7 @@ vtkStdString vtkPlotHistogram2D::GetTooltipLabel(const vtkVector2d &plotPos, ...@@ -170,8 +163,7 @@ vtkStdString vtkPlotHistogram2D::GetTooltipLabel(const vtkVector2d &plotPos,
double bounds[4]; double bounds[4];
this->GetBounds(bounds); this->GetBounds(bounds);
int width = vtkMath::Ceil( (bounds[1] - bounds[0]) / int width = this->Input->GetExtent()[1] - this->Input->GetExtent()[0] + 1;
this->Input->GetSpacing()[0] ) + 1;
int pointX = seriesIndex % width; int pointX = seriesIndex % width;
int pointY = seriesIndex / width; int pointY = seriesIndex / width;
......
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