An update will be applied January 25th, between 12PM and 1:00PM EST (UTC -5:00). The site may be slow during that time.

Commit 6f2a7bb5 authored by Allison Vacanti's avatar Allison Vacanti
Browse files

Add log scaling to vtkPiecewiseFunction.

parent 4a2e0111
......@@ -23,6 +23,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestInterpolationFunctions.cxx
TestPath.cxx
TestPentagonalPrism.cxx
TestPiecewiseFunctionLogScale.cxx
TestPixelExtent.cxx
TestPointLocators.cxx
TestPolyDataRemoveCell.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestPiecewiseFunctionLogScale.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.
=========================================================================*/
#include "vtkPiecewiseFunction.h"
#include "vtkNew.h"
#include <cmath>
// Note that this may evaluate args twice. Use wisely.
#define TEST_ASSERT_FUZZY_EQUAL(expect, actual) \
if (std::fabs(expect - actual) >= 1e-5) \
{ \
std::cerr << "Error at line " << __LINE__ \
<< ": Expected value " << expect << ", got " \
<< actual << "\n"; \
return EXIT_FAILURE; \
}
int TestPiecewiseFunctionLogScale(int, char*[])
{
vtkNew<vtkPiecewiseFunction> func;
func->UseLogScaleOn();
// Add some points that will give easily predictable interpolations.
func->AddPoint( .01, -2.);
func->AddPoint(-.01, -2.);
func->AddPoint( 100., 2.);
func->AddPoint(-100., 2.);
// Check that the interpolations are correct in logarithmic space.
TEST_ASSERT_FUZZY_EQUAL(-1., func->GetValue( .1));
TEST_ASSERT_FUZZY_EQUAL(-1., func->GetValue(-.1));
TEST_ASSERT_FUZZY_EQUAL(0., func->GetValue( 1.));
TEST_ASSERT_FUZZY_EQUAL(0., func->GetValue(-1.));
TEST_ASSERT_FUZZY_EQUAL(1., func->GetValue( 10.));
TEST_ASSERT_FUZZY_EQUAL(1., func->GetValue(-10.));
return EXIT_SUCCESS;
}
......@@ -19,6 +19,7 @@
#include "vtkObjectFactory.h"
#include <cassert>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>
......@@ -105,6 +106,7 @@ vtkPiecewiseFunction::vtkPiecewiseFunction()
this->Function = nullptr;
this->AllowDuplicateScalars = 0;
this->UseLogScale = false;
this->Internal = new vtkPiecewiseFunctionInternals;
}
......@@ -811,7 +813,19 @@ void vtkPiecewiseFunction::GetTable( double xStart, double xEnd,
// we will be modifying this based on midpoint and
// sharpness to get the curve shape we want and to have
// it pass through (y1+y2)/2 at the midpoint.
double s = (x - x1) / (x2 - x1);
double s;
if (this->UseLogScale)
{
// Don't modify x1/x2 -- these are not reset on each iteration.
double xLog = std::log10(x);
double x1Log = std::log10(x1);
double x2Log = std::log10(x2);
s = (xLog - x1Log) / (x2Log - x1Log);
}
else
{
s = (x - x1) / (x2 - x1);
}
// Readjust based on the midpoint - linear adjustment
if ( s < midpoint )
......@@ -1016,5 +1030,6 @@ void vtkPiecewiseFunction::PrintSelf(ostream& os, vtkIndent indent)
}
os << indent << "AllowDuplicateScalars: " << this->AllowDuplicateScalars
<< endl;
os << indent << "UseLogScale: " << this->UseLogScale << endl;
}
......@@ -161,6 +161,16 @@ public:
vtkBooleanMacro( Clamping, int );
//@}
/**
* Interpolate between the control points in base-10 logrithmic space.
* Default is false.
* @{
*/
vtkSetMacro(UseLogScale, bool)
vtkGetMacro(UseLogScale, bool)
vtkBooleanMacro(UseLogScale, bool)
/**@}*/
/**
* Return the type of function:
* Function Types:
......@@ -241,6 +251,8 @@ protected:
int AllowDuplicateScalars;
bool UseLogScale;
private:
vtkPiecewiseFunction(const vtkPiecewiseFunction&) = delete;
void operator=(const vtkPiecewiseFunction&) = delete;
......
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