Commit a28e31ce authored by Marcus D. Hanwell's avatar Marcus D. Hanwell
Browse files

BUG: Fixed segfaults, incorrect rendering.

Fixed segfaults in the new horizontal bar graph test. I also corrected
places where the equality operator should have been used, allowing the
chart to be rendered correctly. Also fixed the findNearestPoint method
for horizontal bars (needed to actually use the internal variable).

Change-Id: I6e31657006ef9374a343539d359e7ffdf5b7a93c
parent 13daf3a9
......@@ -15,9 +15,7 @@
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkSmartPointer.h"
#include "vtkChartXY.h"
#include "vtkPlot.h"
#include "vtkPlotBar.h"
#include "vtkTable.h"
#include "vtkIntArray.h"
......@@ -78,19 +76,19 @@ int TestBarGraphHorizontal(int , char * [])
vtkPlotBar* barPlot = 0;
plot = chart->AddPlot(vtkChart::BAR);
barPlot = vtkPlotBar::SafeDownCast(barPlot);
barPlot = vtkPlotBar::SafeDownCast(plot);
barPlot->SetInput(table.GetPointer(), 0, 1);
barPlot->SetOrientation(vtkPlotBar::HORIZONTAL);
barPlot->SetColor(0, 255, 0, 255);
plot = chart->AddPlot(vtkChart::BAR);
barPlot = vtkPlotBar::SafeDownCast(barPlot);
barPlot = vtkPlotBar::SafeDownCast(plot);
barPlot->SetInput(table.GetPointer(), 0, 2);
barPlot->SetOrientation(vtkPlotBar::HORIZONTAL);
barPlot->SetColor(255, 0, 0, 255);
plot = chart->AddPlot(vtkChart::BAR);
barPlot = vtkPlotBar::SafeDownCast(barPlot);
barPlot = vtkPlotBar::SafeDownCast(plot);
barPlot->SetInput(table.GetPointer(), 0, 3);
barPlot->SetOrientation(vtkPlotBar::HORIZONTAL);
barPlot->SetColor(0, 0, 255, 255);
......
......@@ -160,7 +160,7 @@ class vtkPlotBarSegment : public vtkObject {
for (int i = 0; i < n; ++i)
{
if (orientation != vtkPlotBar::VERTICAL) // Also default fallback
if (orientation == vtkPlotBar::VERTICAL)
{
if (p)
painter->DrawRect(f[2*i]-(width/2)-offset, p[2*i+1],
......@@ -217,12 +217,8 @@ class vtkPlotBarSegment : public vtkObject {
// of the search uses the assumption that X = bar position, Y = bar
// value; swapping the target X and Y is simpler that swapping the
// X and Y of all the other references to the bar data.
vtkVector2f targetPoint;
if (orientation != vtkPlotBar::VERTICAL) // Also default fallback
{
targetPoint.Set(point.X(), point.Y()); // Copy
}
else // HORIZONTAL orientation
vtkVector2f targetPoint(point);
if (orientation == vtkPlotBar::HORIZONTAL)
{
targetPoint.Set(point.Y(), point.X()); // Swap x and y
}
......@@ -231,23 +227,23 @@ class vtkPlotBarSegment : public vtkObject {
// When searching, invert the behavior of the offset and
// compensate for the half width overlap.
std::vector<vtkVector2f>::iterator low;
vtkVector2f lowPoint(point.X()-(offset * -1)-halfWidth, 0.0f);
vtkVector2f lowPoint(targetPoint.X()-(offset * -1)-halfWidth, 0.0f);
low = std::lower_bound(v.begin(), v.end(), lowPoint, compVector2fX);
while (low != v.end())
{
// Is the left side of the bar beyond the point?
if (low->X()-offset-halfWidth > point.X())
if (low->X()-offset-halfWidth > targetPoint.X())
{
break;
}
// Does the bar surround the point?
else if (low->X()-halfWidth-offset < point.X() &&
low->X()+halfWidth-offset > point.X())
else if (low->X()-halfWidth-offset < targetPoint.X() &&
low->X()+halfWidth-offset > targetPoint.X())
{
// Is the point within the vertical extent of the bar?
if ((point.Y() >= 0 && point.Y() < low->Y()) ||
(point.Y() < 0 && point.Y() > low->Y()))
if ((targetPoint.Y() >= 0 && targetPoint.Y() < low->Y()) ||
(targetPoint.Y() < 0 && targetPoint.Y() > low->Y()))
{
*location = *low;
return true;
......@@ -417,7 +413,7 @@ bool vtkPlotBar::PaintLegend(vtkContext2D *painter, const vtkRectf& rect,
void vtkPlotBar::GetBounds(double bounds[4])
{
int seriesLow, seriesHigh, valuesLow, valuesHigh;
if (this->Orientation != vtkPlotBar::VERTICAL) // Also default fallback
if (this->Orientation == vtkPlotBar::VERTICAL)
{
seriesLow = 0; // Xmin
seriesHigh = 1; // Xmax
......@@ -456,7 +452,7 @@ void vtkPlotBar::GetBounds(double bounds[4])
}
else
{
return;
return;
}
y->GetRange(&bounds[valuesLow]);
......
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