ACF $AcfVersion:0$
CSampledFunction.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// ACF includes
6#include <istd/TArray.h>
7#include <istd/TIndex.h>
9
10
11namespace imath
12{
13
14
85{
86public:
88
91 explicit CSampledFunction(const imath::ISampledFunction& function);
92 explicit CSampledFunction(int size, double defaultValue = 0);
93
94 bool operator==(const CSampledFunction& other) const;
95
96 void Reset();
97 bool Initialize(int size, double defaultValue = 0);
98 double GetSampleValue(int index) const;
99 void SetSampleValue(int index, double value);
100 void SetLogicalRange(const istd::CRange& logicalRange);
101 double GetSamplingStep() const;
102 double GetSampleCoordinate(int index) const;
103
104 // reimplemented (imath::ISampledFunction)
105 virtual bool CreateFunction(double* dataPtr, const ArgumentType& sizes) override;
106 virtual int GetTotalSamplesCount() const override;
107 virtual double GetSampleAt(const SampleIndex& index) const override;
108 virtual int GetGridSize(int dimensionIndex) const override;
109 virtual istd::CRange GetLogicalRange(int dimensionIndex) const override;
110 virtual istd::CRange GetResultValueRange(int dimensionIndex, int resultDimension = -1) const override;
111 virtual std::vector<double> GetSamples() const override;
112
113 // reimplemented (imath::TIMathFunction)
114 virtual bool GetValueAt(const ArgumentType& argument, ResultType& result) const override;
115 virtual ResultType GetValueAt(const ArgumentType& argument) const override;
116
117 // reimplemented (istd::IChangeable)
118 virtual int GetSupportedOperations() const override;
119 virtual bool CopyFrom(const IChangeable& object, CompatibilityMode mode = CM_WITHOUT_REFS) override;
120 virtual bool IsEqual(const IChangeable& object) const override;
122 virtual bool ResetData(CompatibilityMode mode = CM_WITHOUT_REFS) override;
123
124private:
125 typedef std::vector<double> SamplesContainer;
126 SamplesContainer m_samplesContainer;
127 istd::CRange m_logicalRange;
128};
129
130
131// public inline methods
132
133inline double CSampledFunction::GetSampleValue(int index) const
134{
135 Q_ASSERT(index>= 0 && index < m_samplesContainer.size());
136
137 return m_samplesContainer[index];
138}
139
140
141inline void CSampledFunction::SetSampleValue(int index, double value)
142{
143 Q_ASSERT(index >= 0 && index < m_samplesContainer.size());
144
145 m_samplesContainer[index] = value;
146}
147
148
149inline void CSampledFunction::SetLogicalRange(const istd::CRange& logicalRange)
150{
151 m_logicalRange = logicalRange;
152}
153
154
156{
157 if (m_samplesContainer.size() >= 2){
158 return m_logicalRange.GetLength() / (m_samplesContainer.size() - 1);
159 }
160
161 return 0;
162}
163
164
165inline double CSampledFunction::GetSampleCoordinate(int index) const
166{
167 Q_ASSERT(m_samplesContainer.size() > 0);
168 Q_ASSERT(0 <= index);
169 Q_ASSERT(index < m_samplesContainer.size());
170
171 return m_logicalRange.GetValueFromAlpha(double(index) / double(m_samplesContainer.size() - 1));
172}
173
174
175} // namespace imath
176
177
Implementation of 1D sampled function with uniform sampling grid.
istd::TIndex< 1 > Index
CSampledFunction(const imath::ISampledFunction &function)
CSampledFunction(const CSampledFunction &function)
virtual bool CreateFunction(double *dataPtr, const ArgumentType &sizes) override
Create function from input data.
virtual bool CopyFrom(const IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS) override
virtual istd::CRange GetLogicalRange(int dimensionIndex) const override
Get logical range for the specified dimension.
virtual int GetSupportedOperations() const override
Get set of flags for supported operations.
double GetSampleCoordinate(int index) const
bool operator==(const CSampledFunction &other) const
virtual istd::IChangeableUniquePtr CloneMe(CompatibilityMode mode=CM_WITHOUT_REFS) const override
Make a copy of this object.
virtual std::vector< double > GetSamples() const override
Get all samples as a vector.
virtual bool IsEqual(const IChangeable &object) const override
virtual double GetSampleAt(const SampleIndex &index) const override
Get sample value at the given index.
virtual ResultType GetValueAt(const ArgumentType &argument) const override
virtual bool ResetData(CompatibilityMode mode=CM_WITHOUT_REFS) override
Reset data to its default state.
void SetSampleValue(int index, double value)
virtual int GetGridSize(int dimensionIndex) const override
Get number of samples for specified dimension.
bool Initialize(int size, double defaultValue=0)
virtual bool GetValueAt(const ArgumentType &argument, ResultType &result) const override
CSampledFunction(int size, double defaultValue=0)
virtual int GetTotalSamplesCount() const override
Get number of samples stored in this container.
void SetLogicalRange(const istd::CRange &logicalRange)
virtual istd::CRange GetResultValueRange(int dimensionIndex, int resultDimension=-1) const override
Get the range (boundary) of possible result values for the given axis.
double GetSampleValue(int index) const
BaseClass::ArgumentType ArgumentType
CompatibilityMode
Control how relationship betweeen objects are interpreted.
@ CM_WITHOUT_REFS
External references are simple ignored.
Multidimensional index used to addressing fixed-size array.
Definition TIndex.h:18
ValueType GetLength() const
Get length of this range.
Definition TRange.h:411
ValueType GetValueFromAlpha(double alpha) const
Get value based on 'alpha' factor.
Definition TRange.h:661
Package with mathematical functions and algebraical primitives.