Skip to content

PiecewiseFunction

Introduction

vtkPiecewiseFunction Defines a piecewise function mapping. This mapping allows the addition of control points, and allows the user to control the function between the control points. A piecewise hermite curve is used between control points, based on the sharpness and midpoint parameters. A sharpness of 0 yields a piecewise linear function and a sharpness of 1 yields a piecewise constant function. The midpoint is the normalized distance between control points at which the curve reaches the median Y value.

The midpoint and sharpness values specified when adding a node are used to control the transition to the next node (the last node's values are ignored) Outside the range of nodes, the values are 0 if Clamping is off, or the nearest node point if Clamping is on. Using the legacy methods for adding points (which do not have Sharpness and Midpoint parameters) will default to Midpoint = 0.5 (halfway between the control points) and Sharpness = 0.0 (linear).

Usage

js
const ofun = vtkPiecewiseFunction.newInstance();
ofun.addPoint(200.0, 0.0);
ofun.addPoint(1200.0, 0.2);
ofun.addPoint(4000.0, 0.4);

See Also

vtkColorTransferFunction

Methods

addPoint

Add points to the function.

ArgumentTypeRequiredDescription
xNumberYesThe x coordinate.
yNumberYesThe y coordinate.

addPointLong

Add points to the function.

ArgumentTypeRequiredDescription
xNumberYesThe x coordinate.
yNumberYesThe y coordinate.
midpointNumberYes
sharpnessNumberYes

addSegment

Add a line segment to the function.

ArgumentTypeRequiredDescription
x1NumberYesThe first point x coordinate.
y1NumberYesThe first point y coordinate.
x2NumberYesThe second point x coordinate.
y2NumberYesThe second point y coordinate.

adjustRange

Remove all points out of the new range, and make sure there is a point at each end of that range.

ArgumentTypeRequiredDescription
rangeRangeYes

estimateMinNumberOfSamples

Estimates the minimum size of a table such that it would correctly sample this function.

extend

Method used to decorate a given object (publicAPI+model) with vtkPiecewiseFunction characteristics.

ArgumentTypeRequiredDescription
publicAPIYesobject on which methods will be bounds (public)
modelYesobject on which data structure will be bounds (protected)
initialValuesIPiecewiseFunctionInitialValuesNo(default: {})

findMinimumXDistance

Traverses the nodes to find the minimum distance.

getAllowDuplicateScalars

Toggle whether to allow duplicate scalar values in the piecewise function (off by default).

getClamping

When zero range clamping is Off, GetValue() returns 0.0 when a value is requested outside of the points specified.

When zero range clamping is On, GetValue() returns the value at the value at the lowest point for a request below all points specified and returns the value at the highest point for a request above all points specified. On is the default.

getDataPointer

Returns a pointer to the data stored in the table.

getFirstNonZeroValue

Returns the first point location which precedes a non-zero segment of the function.

getNodeValue

For the node specified by index, set/get the location (X), value (Y), midpoint, and sharpness values at the node.

ArgumentTypeRequiredDescription
indexNumberYes
valYes

getRange

Returns the min and max node locations of the function.

getRangeByReference

Returns the min and max node locations of the function.

getSize

Get the number of points used to specify the function.

getTable

Fills in an array of function values evaluated at regular intervals.

ArgumentTypeRequiredDescription
xStartNumberYes
xEndNumberYes
sizeNumberYes
tableYes
strideNumberNo

getType

Return the type of function: Function Types:

  • 0 : Constant (No change in slope between end points)
  • 1 : NonDecreasing (Always increasing or zero slope)
  • 2 : NonIncreasing (Always decreasing or zero slope)
  • 3 : Varied (Contains both decreasing and increasing slopes)

getValue

Returns the value of the function at the specified location using the specified interpolation.

newInstance

Method used to create a new instance of vtkPiecewiseFunction.

ArgumentTypeRequiredDescription
initialValuesIPiecewiseFunctionInitialValuesNofor pre-setting some of its content

removeAllPoints

Removes all points from the function.

removePoint

Remove the first point found at the given x location Return the index of the remove point if any, -1 otherwise.

ArgumentTypeRequiredDescription
xNumberYes

setAllowDuplicateScalars

ArgumentTypeRequiredDescription
allowDuplicateScalarsBooleanYes

setClamping

When zero range clamping is Off, GetValue() returns 0.0 when a value is requested outside of the points specified.

When zero range clamping is On, GetValue() returns the value at the value at the lowest point for a request below all points specified and returns the value at the highest point for a request above all points specified. On is the default.

ArgumentTypeRequiredDescription
clampingBooleanYes

setNodeValue

ArgumentTypeRequiredDescription
indexNumberYes
valYes

setNodes

ArgumentTypeRequiredDescription
nodesYes

setRange

ArgumentTypeRequiredDescription
minNumberYes
maxNumberYes

setRange

ArgumentTypeRequiredDescription
rangeRangeYes

setRangeFrom

ArgumentTypeRequiredDescription
rangeRangeYes

sortAndUpdateRange

Internal method to sort the vector and update the Range whenever a node is added, edited or removed.

updateRange

Returns true if the range has been updated and Modified() has been called.