Commit 617ec438 authored by Allison Vacanti's avatar Allison Vacanti

Use axis properties to determine whether to log scale.

Rather than 'fake' the log support in the context items, integrate
with the charting code and use the existing log scaling implementation.

This also fixes some issue with the charts log implementation.
parent 26433fd1
......@@ -376,7 +376,10 @@ bool vtkChartXY::Paint(vtkContext2D* painter)
this->UpdateLayout(painter);
// Axes may have changed during updateLayout
if (this->MTime < this->ChartPrivate->axes[0]->GetMTime())
if (this->MTime < this->ChartPrivate->axes[0]->GetMTime() ||
this->MTime < this->ChartPrivate->axes[1]->GetMTime() ||
this->MTime < this->ChartPrivate->axes[2]->GetMTime() ||
this->MTime < this->ChartPrivate->axes[3]->GetMTime())
{
// Cause the plot transform to be recalculated if necessary
recalculateTransform = true;
......@@ -809,12 +812,12 @@ void vtkChartXY::RecalculatePlotBounds()
}
if (this->ForceAxesToBounds)
{
axis->SetMinimumLimit(range[0]);
axis->SetMaximumLimit(range[1]);
axis->SetUnscaledMinimumLimit(range[0]);
axis->SetUnscaledMaximumLimit(range[1]);
}
if (axis->GetBehavior() == vtkAxis::AUTO && initialized[i])
{
axis->SetRange(range[0], range[1]);
axis->SetUnscaledRange(range[0], range[1]);
axis->AutoScale();
}
}
......
......@@ -250,10 +250,3 @@ void vtkColorTransferControlPointsItem::ComputeBounds(double* bounds)
this->Superclass::ComputeBounds(bounds);
}
}
//-----------------------------------------------------------------------------
bool vtkColorTransferControlPointsItem::UsingLogScale()
{
return (this->ColorTransferFunction?
(this->ColorTransferFunction->UsingLogScale() != 0) : false);
}
......@@ -102,13 +102,6 @@ protected:
vtkColorTransferControlPointsItem();
~vtkColorTransferControlPointsItem() override;
/**
* Returns true if control points are to be rendered in log-space. This is
* true when vtkScalarsToColors is using log-scale, for example. Default
* implementation always return false.
*/
bool UsingLogScale() override;
void emitEvent(unsigned long event, void* params) override;
vtkMTimeType GetControlPointsMTime() override;
......
......@@ -12,6 +12,8 @@
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkAxis.h"
#include "vtkBrush.h"
#include "vtkCallbackCommand.h"
#include "vtkContext2D.h"
......@@ -116,7 +118,7 @@ void vtkColorTransferFunctionItem::ComputeTexture()
0, 0,
0, 0);
this->Texture->AllocateScalars(VTK_UNSIGNED_CHAR, 4);
bool isLogTable = this->UsingLogScale();
bool isLogTable = this->GetXAxis()->GetLogScaleActive();
double logBoundsMin = bounds[0] > 0.0 ? log10(bounds[0]) : 0.0;
double logBoundsDelta = (bounds[0] > 0.0 && bounds[1] > 0.0)?
(log10(bounds[1])-log10(bounds[0])) : 0.0;
......@@ -147,10 +149,3 @@ void vtkColorTransferFunctionItem::ComputeTexture()
}
delete [] values;
}
//-----------------------------------------------------------------------------
bool vtkColorTransferFunctionItem::UsingLogScale()
{
return this->ColorTransferFunction?
(this->ColorTransferFunction->UsingLogScale() != 0) : false;
}
......@@ -39,11 +39,6 @@ protected:
vtkColorTransferFunctionItem();
~vtkColorTransferFunctionItem() override;
// Description:
// Returns true if we are rendering in log space.
virtual bool UsingLogScale();
// Description:
// Reimplemented to return the range of the lookup table
void ComputeBounds(double bounds[4]) override;
......
......@@ -154,14 +154,6 @@ void vtkCompositeControlPointsItem::SetColorTransferFunction(vtkColorTransferFun
this->Superclass::SetColorTransferFunction(c);
}
//-----------------------------------------------------------------------------
bool vtkCompositeControlPointsItem::UsingLogScale()
{
return (this->PointsFunction != OpacityPointsFunction &&
this->ColorTransferFunction &&
this->ColorTransferFunction->UsingLogScale());
}
//-----------------------------------------------------------------------------
void vtkCompositeControlPointsItem::DrawPoint(vtkContext2D* painter, vtkIdType index)
{
......
......@@ -122,12 +122,6 @@ protected:
vtkCompositeControlPointsItem();
~vtkCompositeControlPointsItem() override;
/**
* Returns true if control points are to be rendered in log-space. This is
* true when vtkScalarsToColors is using log-scale, for example.
*/
bool UsingLogScale() override;
void emitEvent(unsigned long event, void* params) override;
vtkMTimeType GetControlPointsMTime() override;
......
......@@ -13,6 +13,7 @@
=========================================================================*/
#include "vtkAxis.h"
#include "vtkCallbackCommand.h"
#include "vtkCommand.h"
#include "vtkImageData.h"
......@@ -112,25 +113,44 @@ void vtkCompositeTransferFunctionItem::ComputeTexture()
this->Texture = vtkImageData::New();
}
const bool logX = this->GetXAxis()->GetLogScaleActive();
const bool logY = this->GetYAxis()->GetLogScaleActive();
const int dimension = this->GetTextureWidth();
double* values = new double[dimension];
this->OpacityFunction->GetTable(bounds[0], bounds[1], dimension, values);
this->OpacityFunction->GetTable(bounds[0], bounds[1], dimension, values, 1,
logX ? 1 : 0);
unsigned char* ptr =
reinterpret_cast<unsigned char*>(this->Texture->GetScalarPointer(0,0,0));
// TBD: maybe the shape should be defined somewhere else...
if (this->MaskAboveCurve || this->PolyLinePen->GetLineType() != vtkPen::SOLID_LINE)
{
this->Shape->SetNumberOfPoints(dimension);
double step = (bounds[1] - bounds[0]) / dimension;
if (logX)
{
bounds[0] = std::log10(bounds[0]);
bounds[1] = std::log10(bounds[1]);
}
const double step = (bounds[1] - bounds[0]) / dimension;
for (int i = 0; i < dimension; ++i)
{
ptr[3] = static_cast<unsigned char>(values[i] * this->Opacity * 255);
if (values[i] < 0. || values[i] > 1.)
{
vtkWarningMacro( << "Opacity at point " << i << " is " << values[i]
<< " which is outside the valid range of [0,1]");
}
this->Shape->SetPoint(i, bounds[0] + step * i, values[i]);
ptr[3] = static_cast<unsigned char>(values[i] * this->Opacity * 255);
double xValue = bounds[0] + step * i;
double yValue = values[i];
if (logY)
{
yValue = std::log10(yValue);
}
this->Shape->SetPoint(i, xValue, yValue);
ptr+=4;
}
}
......
......@@ -37,12 +37,6 @@ protected:
vtkCompositeTransferFunctionItem();
~vtkCompositeTransferFunctionItem() override;
// Description:
// Returns true if we are rendering in log space.
// Since vtkPiecewiseFunction doesn't support log, we show this transfer
// function in non-log space always.
bool UsingLogScale() override { return false; }
// Description:
// Reimplemented to return the range of the piecewise function
void ComputeBounds(double bounds[4]) override;
......
......@@ -365,17 +365,16 @@ void vtkControlPointsItem::TransformScreenToData(const vtkVector2f& in, vtkVecto
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.
double bounds[4];
this->ComputeBounds(bounds);
const bool logX = this->GetXAxis()->GetLogScaleActive();
const bool logY = this->GetYAxis()->GetLogScaleActive();
double posX = in.GetX();
double normVal = (posX - bounds[0])/(bounds[1] - bounds[0]);
double lval = log10(bounds[0]) + normVal*(log10(bounds[1]) - log10(bounds[0]));
posX = pow(10.0, lval);
out.SetX(posX);
if (logX)
{
out.SetX(std::pow(10., out.GetX()));
}
if (logY)
{
out.SetY(std::pow(10., out.GetY()));
}
}
......@@ -383,16 +382,17 @@ void vtkControlPointsItem::TransformScreenToData(const vtkVector2f& in, vtkVecto
void vtkControlPointsItem::TransformDataToScreen(const vtkVector2f& in, vtkVector2f& out)
{
out = in;
if (this->UsingLogScale())
{
double bounds[4];
this->ComputeBounds(bounds);
double posX = in.GetX();
double lnormVal = (log10(posX) - log10(bounds[0])) /
(log10(bounds[1]) - log10(bounds[0]));
posX = bounds[0] + lnormVal * (bounds[1] - bounds[0]);
out.SetX(posX);
const bool logX = this->GetXAxis()->GetLogScaleActive();
const bool logY = this->GetYAxis()->GetLogScaleActive();
if (logX)
{
out.SetX(std::log10(out.GetX()));
}
if (logY)
{
out.SetY(std::log10(out.GetY()));
}
// now, shift/scale to screen space.
......
......@@ -461,13 +461,6 @@ protected:
*/
virtual void ComputeBounds(double* bounds);
/**
* Returns true if control points are to be rendered in log-space. This is
* true when vtkScalarsToColors is using log-scale, for example. Default
* implementation always return false.
*/
virtual bool UsingLogScale() { return false; }
vtkCallbackCommand* Callback;
vtkPen* SelectedPointPen;
vtkBrush* SelectedPointBrush;
......
......@@ -13,6 +13,7 @@
=========================================================================*/
#include "vtkAxis.h"
#include "vtkBrush.h"
#include "vtkCallbackCommand.h"
#include "vtkContext2D.h"
......@@ -139,6 +140,20 @@ bool vtkScalarsToColorsItem::Paint(vtkContext2D* painter)
double dbounds[4];
this->GetBounds(dbounds);
const bool logX = this->GetXAxis()->GetLogScaleActive();
const bool logY = this->GetYAxis()->GetLogScaleActive();
if (logX)
{
dbounds[0] = std::log10(dbounds[0]);
dbounds[1] = std::log10(dbounds[1]);
}
if (logY)
{
dbounds[2] = std::log10(dbounds[2]);
dbounds[3] = std::log10(dbounds[3]);
}
// shift/scale to scale from data space to rendering space.
const vtkRectd& ss = this->ShiftScale;
float fbounds[4];
......
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