Class PDFunction
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.common.function.PDFunction
-
- All Implemented Interfaces:
COSObjectable
- Direct Known Subclasses:
PDFunctionType0
,PDFunctionType2
,PDFunctionType3
,PDFunctionType4
,PDFunctionTypeIdentity
public abstract class PDFunction extends java.lang.Object implements COSObjectable
This class represents a function in a PDF document.
-
-
Field Summary
Fields Modifier and Type Field Description private COSArray
domain
private COSDictionary
functionDictionary
private PDStream
functionStream
private int
numberOfInputValues
private int
numberOfOutputValues
private COSArray
range
-
Constructor Summary
Constructors Constructor Description PDFunction(COSBase function)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected float[]
clipToRange(float[] inputValues)
Clip the given input values to the ranges.protected float
clipToRange(float x, float rangeMin, float rangeMax)
Clip the given input value to the given range.static PDFunction
create(COSBase function)
Create the correct PD Model function based on the COS base function.abstract float[]
eval(float[] input)
Evaluates the function at the given input.COSArray
eval(COSArray input)
Deprecated.Replaced byeval(float[] input)
COSDictionary
getCOSObject()
Returns the stream.PDRange
getDomainForInput(int n)
This will get the range for a certain input parameter.private COSArray
getDomainValues()
Returns all domains for the input values as COSArray.abstract int
getFunctionType()
Returns the function type.int
getNumberOfInputParameters()
This will get the number of input parameters that have a domain specified.int
getNumberOfOutputParameters()
This will get the number of output parameters that have a range specified.protected PDStream
getPDStream()
Returns the underlying PDStream.PDRange
getRangeForOutput(int n)
This will get the range for a certain output parameters.protected COSArray
getRangeValues()
Returns all ranges for the output values as COSArray .protected float
interpolate(float x, float xRangeMin, float xRangeMax, float yRangeMin, float yRangeMax)
For a given value of x, interpolate calculates the y value on the line defined by the two points (xRangeMin , xRangeMax ) and (yRangeMin , yRangeMax ).void
setDomainValues(COSArray domainValues)
This will set the domain values.void
setRangeValues(COSArray rangeValues)
This will set the range values.java.lang.String
toString()
-
-
-
Field Detail
-
functionStream
private PDStream functionStream
-
functionDictionary
private COSDictionary functionDictionary
-
domain
private COSArray domain
-
range
private COSArray range
-
numberOfInputValues
private int numberOfInputValues
-
numberOfOutputValues
private int numberOfOutputValues
-
-
Constructor Detail
-
PDFunction
public PDFunction(COSBase function)
Constructor.- Parameters:
function
- The function stream.
-
-
Method Detail
-
getFunctionType
public abstract int getFunctionType()
Returns the function type. Possible values are: 0 - Sampled function 2 - Exponential interpolation function 3 - Stitching function 4 - PostScript calculator function- Returns:
- the function type.
-
getCOSObject
public COSDictionary getCOSObject()
Returns the stream.- Specified by:
getCOSObject
in interfaceCOSObjectable
- Returns:
- The stream for this object.
-
getPDStream
protected PDStream getPDStream()
Returns the underlying PDStream.- Returns:
- The stream.
-
create
public static PDFunction create(COSBase function) throws java.io.IOException
Create the correct PD Model function based on the COS base function.- Parameters:
function
- The COS function dictionary.- Returns:
- The PDModel Function object.
- Throws:
java.io.IOException
- If we are unable to create the PDFunction object.
-
getNumberOfOutputParameters
public int getNumberOfOutputParameters()
This will get the number of output parameters that have a range specified. A range for output parameters is optional so this may return zero for a function that does have output parameters, this will simply return the number that have the range specified.- Returns:
- The number of output parameters that have a range specified.
-
getRangeForOutput
public PDRange getRangeForOutput(int n)
This will get the range for a certain output parameters. This is will never return null. If it is not present then the range 0 to 0 will be returned.- Parameters:
n
- The output parameter number to get the range for.- Returns:
- The range for this component.
-
setRangeValues
public void setRangeValues(COSArray rangeValues)
This will set the range values.- Parameters:
rangeValues
- The new range values.
-
getNumberOfInputParameters
public int getNumberOfInputParameters()
This will get the number of input parameters that have a domain specified.- Returns:
- The number of input parameters that have a domain specified.
-
getDomainForInput
public PDRange getDomainForInput(int n)
This will get the range for a certain input parameter. This is will never return null. If it is not present then the range 0 to 0 will be returned.- Parameters:
n
- The parameter number to get the domain for.- Returns:
- The domain range for this component.
-
setDomainValues
public void setDomainValues(COSArray domainValues)
This will set the domain values.- Parameters:
domainValues
- The new domain values.
-
eval
@Deprecated public COSArray eval(COSArray input) throws java.io.IOException
Deprecated.Replaced byeval(float[] input)
- Parameters:
input
- The array of input values for the function.- Returns:
- The of outputs the function returns based on those inputs.
- Throws:
java.io.IOException
- if something went wrong.
-
eval
public abstract float[] eval(float[] input) throws java.io.IOException
Evaluates the function at the given input. ReturnValue = f(input)- Parameters:
input
- The array of input values for the function. In many cases will be an array of a single value, but not always.- Returns:
- The of outputs the function returns based on those inputs. In many cases will be an array of a single value, but not always.
- Throws:
java.io.IOException
- if something went wrong processing the function.
-
getRangeValues
protected COSArray getRangeValues()
Returns all ranges for the output values as COSArray . Required for type 0 and type 4 functions- Returns:
- the ranges array.
-
getDomainValues
private COSArray getDomainValues()
Returns all domains for the input values as COSArray. Required for all function types.- Returns:
- the domains array.
-
clipToRange
protected float[] clipToRange(float[] inputValues)
Clip the given input values to the ranges.- Parameters:
inputValues
- the input values- Returns:
- the clipped values
-
clipToRange
protected float clipToRange(float x, float rangeMin, float rangeMax)
Clip the given input value to the given range.- Parameters:
x
- the input valuerangeMin
- the min value of the rangerangeMax
- the max value of the range- Returns:
- the clipped value
-
interpolate
protected float interpolate(float x, float xRangeMin, float xRangeMax, float yRangeMin, float yRangeMax)
For a given value of x, interpolate calculates the y value on the line defined by the two points (xRangeMin , xRangeMax ) and (yRangeMin , yRangeMax ).- Parameters:
x
- the to be interpolated value.xRangeMin
- the min value of the x rangexRangeMax
- the max value of the x rangeyRangeMin
- the min value of the y rangeyRangeMax
- the max value of the y range- Returns:
- the interpolated y value
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-