VTK  9.3.0
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 
31 #ifndef vtkPiecewiseFunction_h
32 #define vtkPiecewiseFunction_h
33 
34 #include "vtkCommonDataModelModule.h" // For export macro
35 #include "vtkDataObject.h"
36 
37 VTK_ABI_NAMESPACE_BEGIN
38 class vtkPiecewiseFunctionInternals;
39 
40 class VTKCOMMONDATAMODEL_EXPORT vtkPiecewiseFunction : public vtkDataObject
41 {
42 public:
45  void PrintSelf(ostream& os, vtkIndent indent) override;
46 
47  void DeepCopy(vtkDataObject* f) override;
48  void ShallowCopy(vtkDataObject* f) override;
49 
51  {
52  BINARY_SEARCH = 0,
53  INTERPOLATION_SEARCH = 1,
54  MAX_ENUM = 2
55  };
56 
60  int GetDataObjectType() override { return VTK_PIECEWISE_FUNCTION; }
61 
65  int GetSize();
66 
68 
74  int AddPoint(double x, double y);
75  int AddPoint(double x, double y, double midpoint, double sharpness);
77 
82  bool RemovePointByIndex(size_t id);
83 
88  int RemovePoint(double x);
89 
94  int RemovePoint(double x, double y);
95 
100 
106  void AddSegment(double x1, double y1, double x2, double y2);
107 
112  double GetValue(double x);
113 
115 
121  int GetNodeValue(int index, double val[4]);
122  int SetNodeValue(int index, double val[4]);
124 
126 
133  double* GetDataPointer();
134  void FillFromDataPointer(int, double*);
136 
138 
141  vtkGetVector2Macro(Range, double);
143 
149  int AdjustRange(double range[2]);
150 
152 
160  void GetTable(double x1, double x2, int size, float* table, int stride = 1, int logIncrements = 0,
161  double epsilon = 1e-5);
162  void GetTable(double x1, double x2, int size, double* table, int stride = 1,
163  int logIncrements = 0, double epsilon = 1e-5);
165 
172  void BuildFunctionFromTable(double x1, double x2, int size, double* table, int stride = 1);
173 
175 
183  vtkSetMacro(Clamping, vtkTypeBool);
184  vtkGetMacro(Clamping, vtkTypeBool);
185  vtkBooleanMacro(Clamping, vtkTypeBool);
187 
193  vtkSetMacro(UseLogScale, bool);
194  vtkGetMacro(UseLogScale, bool);
195  vtkBooleanMacro(UseLogScale, bool);
206  const char* GetType();
207 
213 
219  void Initialize() override;
220 
222 
228 
230 
234  vtkSetMacro(AllowDuplicateScalars, vtkTypeBool);
235  vtkGetMacro(AllowDuplicateScalars, vtkTypeBool);
236  vtkBooleanMacro(AllowDuplicateScalars, vtkTypeBool);
238 
243  int EstimateMinNumberOfSamples(double const& x1, double const& x2);
244 
250  void UpdateSearchMethod(double epsilon = 1e-12, double thresh = 1e-4);
251 
253 
260  void SetUseCustomSearchMethod(bool use);
264 
265 protected:
268 
276  void SortAndUpdateRange(bool updateSearchMethod = true);
277 
281  bool UpdateRange();
282 
287 
288  // The internal STL structures
289  vtkPiecewiseFunctionInternals* Internal;
290 
291  // Determines the function value outside of defined points
292  // Zero = always return 0.0 outside of defined points
293  // One = clamp to the lowest value below defined points and
294  // highest value above defined points
296 
297  // Array of points ((X,Y) pairs)
298  double* Function;
299 
300  // Min and max range of function point locations
301  double Range[2];
302 
304 
306 
307 private:
309  void operator=(const vtkPiecewiseFunction&) = delete;
310 };
311 
312 VTK_ABI_NAMESPACE_END
313 #endif
general representation of visualization data
Definition: vtkDataObject.h:55
a simple class to control print indentation
Definition: vtkIndent.h:29
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
Defines a 1D piecewise function.
int SetNodeValue(int index, double val[4])
For the node specified by index, set/get the location (X), value (Y), midpoint, and sharpness values ...
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.
static vtkPiecewiseFunction * GetData(vtkInformationVector *v, int i=0)
Retrieve an instance of this class from an information object.
int RemovePoint(double x)
Remove the first point found at the given x location Return the index of the remove point if any,...
double * GetDataPointer()
Returns a pointer to the data stored in the table.
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.
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)
void BuildFunctionFromTable(double x1, double x2, int size, double *table, int stride=1)
Constructs a piecewise function from a table.
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.
static vtkPiecewiseFunction * New()
const char * GetType()
Return the type of function: Function Types: 0 : Constant (No change in slope between end points) 1 :...
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.
static vtkPiecewiseFunction * GetData(vtkInformation *info)
Retrieve an instance of this class from an information object.
void AddSegment(double x1, double y1, double x2, double y2)
Add a line segment to the function.
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,...
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 ...
int GetDataObjectType() override
Return what type of dataset this is.
void ShallowCopy(vtkDataObject *f) override
The goal of the method is to copy the data up to the array pointers only.
@ info
Definition: vtkX3D.h:376
@ range
Definition: vtkX3D.h:238
@ type
Definition: vtkX3D.h:516
@ size
Definition: vtkX3D.h:253
@ index
Definition: vtkX3D.h:246
auto Range(IterablePtr iterable, Options &&... opts) -> typename detail::IterableTraits< typename detail::StripPointers< IterablePtr >::type >::RangeType
Generate an iterable STL proxy object for a VTK container.
Definition: vtkRange.h:74
int vtkTypeBool
Definition: vtkABI.h:64
#define VTK_PIECEWISE_FUNCTION
Definition: vtkType.h:70