Commit 9085e579 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

BUG #14599: Handle double values properly.

Plots used to rendering transfer functions failed to work correctly when
the values/ranges they were presenting were in the double realm. This
was because these classes didn't handle vtkPlot::ShiftScale at all. This
fixes that issue.

Change-Id: I08c487c6e735b5a7055daff7e537e97036449e96
parent 2c4871aa
......@@ -358,6 +358,12 @@ void vtkControlPointsItem::ComputePoints()
void vtkControlPointsItem::TransformScreenToData(const vtkVector2f& in, vtkVector2f& out)
{
out = in;
// inverse shift/scale from screen space.
const vtkRectd& ss = this->ShiftScale;
out.SetX(static_cast<float>((out.GetX() / ss[2]) - ss[0]));
out.SetY(static_cast<float>((out.GetY() / ss[3]) - ss[1]));
if (this->UsingLogScale())
{
// using log scale.
......@@ -387,6 +393,11 @@ void vtkControlPointsItem::TransformDataToScreen(const vtkVector2f& in, vtkVecto
posX = bounds[0] + lnormVal * (bounds[1] - bounds[0]);
out.SetX(posX);
}
// now, shift/scale to screen space.
const vtkRectd& ss = this->ShiftScale;
out.SetX(static_cast<float>((out.GetX() + ss[0]) * ss[2]));
out.SetY(static_cast<float>((out.GetY() + ss[1]) * ss[3]));
}
//-----------------------------------------------------------------------------
......
......@@ -136,6 +136,12 @@ bool vtkPiecewisePointHandleItem::Paint(vtkContext2D *painter)
this->CurrentPointIndex = currentIdx;
double point[4];
parentControl->GetControlPoint(parentControl->GetCurrentPoint(), point);
// shift/scale to scale from data space to rendering space.
const vtkRectd& ss = parentControl->GetShiftScale();
point[0] = (point[0] + ss[0]) * ss[2];
point[1] = (point[1] + ss[1]) * ss[3];
unsigned char brushOpacity = painter->GetBrush()->GetOpacity();
unsigned char penColor[3];
painter->GetPen()->GetColor(penColor);
......@@ -180,6 +186,13 @@ bool vtkPiecewisePointHandleItem::Paint(vtkContext2D *painter)
double blPos[2]={prePoint[0],prePoint[1]};
double trPos[2]={nxtPoint[0],nxtPoint[1]};
blPos[0] = (blPos[0] + ss[0]) * ss[2];
blPos[1] = (blPos[1] + ss[1]) * ss[3];
trPos[0] = (trPos[0] + ss[0]) * ss[2];
trPos[1] = (trPos[1] + ss[1]) * ss[3];
double screenBLPos[2], screenTRPos[2];
sceneTransform->TransformPoints(blPos, screenBLPos, 1);
sceneTransform->TransformPoints(trPos, screenTRPos, 1);
......
......@@ -20,6 +20,7 @@
#include "vtkContextScene.h"
#include "vtkFloatArray.h"
#include "vtkImageData.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkPen.h"
#include "vtkPoints2D.h"
......@@ -135,15 +136,25 @@ bool vtkScalarsToColorsItem::Paint(vtkContext2D* painter)
const int size = this->Shape->GetNumberOfPoints();
if (!this->MaskAboveCurve || size < 2)
{
double bounds[4];
this->GetBounds(bounds);
painter->DrawQuad(bounds[0], bounds[2],
bounds[0], bounds[3],
bounds[1], bounds[3],
bounds[1], bounds[2]);
double dbounds[4];
this->GetBounds(dbounds);
// shift/scale to scale from data space to rendering space.
const vtkRectd& ss = this->ShiftScale;
float fbounds[4];
fbounds[0] = static_cast<float>((dbounds[0] + ss[0]) * ss[2]);
fbounds[1] = static_cast<float>((dbounds[1] + ss[0]) * ss[2]);
fbounds[2] = static_cast<float>((dbounds[2] + ss[1]) * ss[3]);
fbounds[3] = static_cast<float>((dbounds[3] + ss[1]) * ss[3]);
painter->DrawQuad(fbounds[0], fbounds[2],
fbounds[0], fbounds[3],
fbounds[1], fbounds[3],
fbounds[1], fbounds[2]);
}
else
{
const vtkRectd& ss = this->ShiftScale;
vtkPoints2D* trapezoids = vtkPoints2D::New();
trapezoids->SetNumberOfPoints(2*size);
double point[2];
......@@ -151,6 +162,10 @@ bool vtkScalarsToColorsItem::Paint(vtkContext2D* painter)
for (vtkIdType i = 0; i < size; ++i)
{
this->Shape->GetPoint(i, point);
// shift/scale to scale from data space to rendering space.
point[0] = (point[0] + ss[0]) * ss[2];
point[1] = (point[1] + ss[1]) * ss[3];
trapezoids->SetPoint(++j, point[0], 0.);
trapezoids->SetPoint(++j, point);
}
......@@ -160,8 +175,21 @@ bool vtkScalarsToColorsItem::Paint(vtkContext2D* painter)
if (this->PolyLinePen->GetLineType() != vtkPen::NO_PEN)
{
const vtkRectd& ss = this->ShiftScale;
vtkNew<vtkPoints2D> transformedShape;
transformedShape->SetNumberOfPoints(size);
for (vtkIdType i = 0; i < size; ++i)
{
double point[2];
this->Shape->GetPoint(i, point);
// shift/scale to scale from data space to rendering space.
point[0] = (point[0] + ss[0]) * ss[2];
point[1] = (point[1] + ss[1]) * ss[3];
transformedShape->SetPoint(i, point);
}
painter->ApplyPen(this->PolyLinePen);
painter->DrawPoly(this->Shape);
painter->DrawPoly(transformedShape.GetPointer());
}
return true;
......
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