VTK  9.7.20261008
vtkPiecewiseFunction.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3
119
120#ifndef vtkPiecewiseFunction_h
121#define vtkPiecewiseFunction_h
122
123#include "vtkCommonDataModelModule.h" // For export macro
124#include "vtkDataObject.h"
125#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
126
127#include <vector> // for arg, return
128
129VTK_ABI_NAMESPACE_BEGIN
130class vtkPiecewiseFunctionInternals;
131
132class VTKCOMMONDATAMODEL_EXPORT VTK_MARSHALAUTO vtkPiecewiseFunction : public vtkDataObject
133{
134public:
137 void PrintSelf(ostream& os, vtkIndent indent) override;
138
139 void DeepCopy(vtkDataObject* f) override;
140 void ShallowCopy(vtkDataObject* f) override;
141
148
152 int GetDataObjectType() VTK_FUTURE_CONST override { return VTK_PIECEWISE_FUNCTION; }
153
157 int GetSize();
158
160
166 int AddPoint(double x, double y);
167 int AddPoint(double x, double y, double midpoint, double sharpness);
169
174 bool RemovePointByIndex(size_t id);
175
180 int RemovePoint(double x);
181
186 int RemovePoint(double x, double y);
187
192
198 void AddSegment(double x1, double y1, double x2, double y2);
199
204 double GetValue(double x);
205
207
213 int GetNodeValue(int index, double val[4]);
214 int SetNodeValue(int index, double val[4]);
216
218
225 double* GetDataPointer();
226 void FillFromDataPointer(int, double*);
228
230
240 void SetNodeValues(const std::vector<double>& values);
241 std::vector<double> GetNodeValues() const;
243
245
248 vtkGetVector2Macro(Range, double);
250
256 int AdjustRange(double range[2]);
257
259
267 void GetTable(double x1, double x2, int size, float* table, int stride = 1, int logIncrements = 0,
268 double epsilon = 1e-5);
269 void GetTable(double x1, double x2, int size, double* table, int stride = 1,
270 int logIncrements = 0, double epsilon = 1e-5);
272
279 void BuildFunctionFromTable(double x1, double x2, int size, double* table, int stride = 1);
280
282
290 vtkSetMacro(Clamping, vtkTypeBool);
291 vtkGetMacro(Clamping, vtkTypeBool);
292 vtkBooleanMacro(Clamping, vtkTypeBool);
294
300 vtkSetMacro(UseLogScale, bool);
301 vtkGetMacro(UseLogScale, bool);
302 vtkBooleanMacro(UseLogScale, bool);
304
313 const char* GetType();
314
320
326 void Initialize() override;
327
329
335
337
345
350 int EstimateMinNumberOfSamples(double const& x1, double const& x2);
351
357 void UpdateSearchMethod(double epsilon = 1e-12, double thresh = 1e-4);
358
360
368 void SetCustomSearchMethod(int type);
371
372protected:
375
383 void SortAndUpdateRange(bool updateSearchMethod = true);
384
389
394
395 // The internal STL structures
396 vtkPiecewiseFunctionInternals* Internal;
397
398 // Determines the function value outside of defined points
399 // Zero = always return 0.0 outside of defined points
400 // One = clamp to the lowest value below defined points and
401 // highest value above defined points
403
404 // Array of points ((X,Y) pairs)
405 double* Function;
406
407 // Min and max range of function point locations
408 double Range[2];
409
411
413
414private:
416 void operator=(const vtkPiecewiseFunction&) = delete;
417};
418
419VTK_ABI_NAMESPACE_END
420#endif
a simple class to control print indentation
Definition vtkIndent.h:108
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
int SetNodeValue(int index, double val[4])
For the node specified by index, set/get the location (X), value (Y), midpoint, and sharpness values ...
std::vector< double > GetNodeValues() const
Get/Set all the (x, y, midpoint, sharpness) samples as a flat interleaved array: x0,...
void GetTable(double x1, double x2, int size, float *table, int stride=1, int logIncrements=0, double epsilon=1e-5)
Fills in an array of function values evaluated at regular intervals.
int AdjustRange(double range[2])
Remove all points out of the new range, and make sure there is a point at each end of that range.
double GetValue(double x)
Returns the value of the function at the specified location using the specified interpolation.
int AddPoint(double x, double y, double midpoint, double sharpness)
Add points to the function.
int RemovePoint(double x)
Remove the first point found at the given x location Return the index of the remove point if any,...
void UpdateSearchMethod(double epsilon=1e-12, double thresh=1e-4)
Analyses the point distribution and automatically updates the search method to optimize the time proc...
int AddPoint(double x, double y)
Add points to the function.
double GetFirstNonZeroValue()
Returns the first point location which precedes a non-zero segment of the function.
void GetTable(double x1, double x2, int size, double *table, int stride=1, int logIncrements=0, double epsilon=1e-5)
Fills in an array of function values evaluated at regular intervals.
void SetNodeValues(const std::vector< double > &values)
Get/Set all the (x, y, midpoint, sharpness) samples as a flat interleaved array: x0,...
int GetAutomaticSearchMethod()
Methods to set / get the search method used.
int RemovePoint(double x, double y)
Remove the first point found at the given x and y location Return the index of the remove point if an...
vtkPiecewiseFunctionInternals * Internal
void FillFromDataPointer(int, double *)
Returns a pointer to the data stored in the table.
void SetUseCustomSearchMethod(bool use)
int GetDataObjectType() VTK_FUTURE_CONST override
Return what type of dataset this is.
void BuildFunctionFromTable(double x1, double x2, int size, double *table, int stride=1)
Constructs a piecewise function from a table.
static vtkPiecewiseFunction * GetData(vtkInformationVector *v, int i=0)
Retrieve an instance of this class from an information object.
int GetSize()
Get the number of points used to specify the function.
void SetCustomSearchMethod(int type)
~vtkPiecewiseFunction() override
void Initialize() override
Clears out the current function.
bool UpdateRange()
Returns true if the range has been updated and Modified() has been called.
void RemoveAllPoints()
Removes all points from the function.
void DeepCopy(vtkDataObject *f) override
The goal of the method is to copy the complete data from src into this object.
double FindMinimumXDistance()
Traverses the nodes to find the minimum distance.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
const char * GetType()
Return the type of function: Function Types: 0 : Constant (No change in slope between end points) 1 :...
void AddSegment(double x1, double y1, double x2, double y2)
Add a line segment to the function.
static vtkPiecewiseFunction * GetData(vtkInformation *info)
Retrieve an instance of this class from an information object.
int EstimateMinNumberOfSamples(double const &x1, double const &x2)
Estimates the minimum size of a table such that it would correctly sample this function.
bool RemovePointByIndex(size_t id)
Remove a point from the function at a given id Return true if point has been found and removed,...
double * GetDataPointer()
Returns a pointer to the data stored in the table.
void SortAndUpdateRange(bool updateSearchMethod=true)
Internal methods to sort the vector and update the Range whenever a node is added,...
int GetNodeValue(int index, double val[4])
For the node specified by index, set/get the location (X), value (Y), midpoint, and sharpness values ...
void ShallowCopy(vtkDataObject *f) override
The goal of the method is to copy the data up to the array pointers only.
static vtkPiecewiseFunction * New()
int vtkTypeBool
Definition vtkABI.h:64
@ VTK_PIECEWISE_FUNCTION
Definition vtkType.h:114
#define VTK_MARSHALAUTO