Commit 2bb06f6d authored by David Gobbi's avatar David Gobbi
Browse files

BUG: Negative range for log scale lookup produced no results.

The log lookup table was designed to work with negative values,
as long as both ends of the range were negative.  Apparently this
feature was untested (it wasn't working).

Change-Id: Ie088e22679eeef62234cb16818063c9d63d2639c
parent c5980de7
......@@ -19,6 +19,7 @@ create_test_sourcelist(Tests ${vtk-module}CxxTests.cxx
TestDataArrayComponentNames.cxx
TestGarbageCollector.cxx
# TestInstantiator.cxx # Have not enabled instantiators.
TestLookupTable.cxx
TestMath.cxx
TestMinimalStandardRandomSequence.cxx
TestNew.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestLookupTable.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// Test some generic features of vtkLookupTable
#include "vtkLookupTable.h"
#include "vtkMath.h"
#include "vtkCommand.h"
#include "vtkSmartPointer.h"
// simple macro for performing tests
#define TestAssert(t) \
if (!(t)) \
{ \
cerr << "In " << __FILE__ << ":"; \
cerr << " Test assertion failed line " << __LINE__ << ": " << #t << "\n"; \
rval |= 1; \
}
// a simple error observer
namespace {
class errorObserver
{
public:
errorObserver() : EventId(0) {}
void Reset() { this->EventId = 0; }
unsigned long GetEvent() const { return this->EventId; }
void Callback(vtkObject *, unsigned long e, void *) {
this->EventId = e; }
private:
unsigned long EventId;
};
}
int TestLookupTable(int,char *[])
{
int rval = 0;
vtkSmartPointer<vtkLookupTable> table =
vtkSmartPointer<vtkLookupTable>::New();
// == check computation of table index ==
// basic mapping test
double lo = 3.234;
double hi = 6.123;
double tol = 1e-6;
double step = (hi - lo)/255.0;
table->SetTableRange(lo,hi);
TestAssert(table->GetIndex(lo) == 0);
TestAssert(table->GetIndex(hi) == 255);
TestAssert(table->GetIndex(lo+tol) == 0);
TestAssert(table->GetIndex(hi-tol) == 255);
TestAssert(table->GetIndex(lo-step) == 0);
TestAssert(table->GetIndex(hi+step) == 255);
TestAssert(table->GetIndex(lo+step) == 1);
TestAssert(table->GetIndex(hi-step) == 254);
// log range test
lo = pow(10,lo);
hi = pow(10,hi);
step = pow(10,step);
table->SetScaleToLog10();
table->SetTableRange(lo,hi);
TestAssert(table->GetIndex(lo) == 0);
TestAssert(table->GetIndex(hi) == 255);
TestAssert(table->GetIndex(lo+tol) == 0);
TestAssert(table->GetIndex(hi-tol) == 255);
TestAssert(table->GetIndex(lo/step) == 0);
TestAssert(table->GetIndex(hi*step) == 255);
TestAssert(table->GetIndex(lo*step) == 1);
TestAssert(table->GetIndex(hi/step) == 254);
// negative log range
double tmp = hi;
hi = -lo;
lo = -tmp;
step = 1.0/step;
table->SetScaleToLog10();
table->SetTableRange(lo,hi);
TestAssert(table->GetIndex(lo) == 0);
TestAssert(table->GetIndex(hi) == 255);
TestAssert(table->GetIndex(lo+tol) == 0);
TestAssert(table->GetIndex(hi-tol) == 255);
TestAssert(table->GetIndex(lo/step) == 0);
TestAssert(table->GetIndex(hi*step) == 255);
TestAssert(table->GetIndex(lo*step) == 1);
TestAssert(table->GetIndex(hi/step) == 254);
// == check error reporting ==
errorObserver observer;
unsigned long observerId =
table->AddObserver(
vtkCommand::ErrorEvent, &observer, &errorObserver::Callback);
// linear table, range is null, permitted (step function)
observer.Reset();
table->SetScaleToLinear();
table->SetTableRange(0,0);
TestAssert(observer.GetEvent() == 0);
// linear table, range is inverted, illegal
observer.Reset();
table->SetScaleToLinear();
table->SetTableRange(1,-1);
TestAssert(observer.GetEvent() != 0);
// log table, range is null, permitted (step function)
observer.Reset();
table->SetScaleToLog10();
table->SetTableRange(0,0);
TestAssert(observer.GetEvent() == 0);
// log table, zero on upper end of range, permitted
observer.Reset();
table->SetScaleToLog10();
table->SetTableRange(-1.2,0);
TestAssert(observer.GetEvent() == 0);
// log table, zero on lower end of range, permitted
observer.Reset();
table->SetScaleToLog10();
table->SetTableRange(0,1.3);
TestAssert(observer.GetEvent() == 0);
// log table, range straddles zero, illegal
observer.Reset();
table->SetScaleToLog10();
table->SetTableRange(-0.5,1.1);
TestAssert(observer.GetEvent() != 0);
table->RemoveObserver(observerId);
return rval;
}
......@@ -319,13 +319,13 @@ void vtkLookupTableLogRange(const double range[2], double logRange[2])
if (rmax < 0) // rmin and rmax have same sign now
{
logRange[0] = log10(-static_cast<double>(rmin));
logRange[1] = log10(-static_cast<double>(rmax));
logRange[0] = -log10(-rmin);
logRange[1] = -log10(-rmax);
}
else
{
logRange[0] = log10(static_cast<double>(rmin));
logRange[1] = log10(static_cast<double>(rmax));
logRange[0] = log10(rmin);
logRange[1] = log10(rmax);
}
}
......@@ -339,7 +339,7 @@ inline double vtkApplyLogScale(double v, const double range[2],
{
if (v < 0)
{
v = log10(-static_cast<double>(v));
v = -log10(-v);
}
else if (range[0] > range[1])
{
......@@ -354,9 +354,9 @@ inline double vtkApplyLogScale(double v, const double range[2],
{
if (v > 0)
{
v = log10(static_cast<double>(v));
v = log10(v);
}
else if (range[0] < range[1])
else if (range[0] <= range[1])
{
v = logRange[0];
}
......@@ -434,7 +434,6 @@ double vtkLookupTable::ApplyLogScale(double v, const double range[2],
//----------------------------------------------------------------------------
// Given a scalar value v, return an index into the lookup table
// TODO: Return -1 when isnan(v) is true.
vtkIdType vtkLookupTable::GetIndex(double v)
{
if ( this->IndexedLookup )
......
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