ACF $AcfVersion:0$
CSampledFunction2d.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/CIndex2d.h>
9
10
11namespace imath
12{
13
14
19{
20public:
23 explicit CSampledFunction2d(const imath::ISampledFunction2d& function2d);
24 explicit CSampledFunction2d(const istd::CIndex2d& size, double defaultValue = 0);
25
26 void Reset();
27 bool CreateGrid2d(const istd::CIndex2d& size, double defaultValue = 0);
29 double GetSampleValue(const istd::CIndex2d& index) const;
30 void SetSampleValue(const istd::CIndex2d& index, double value);
31
32 // reimplemented (imath::ISampledFunction2d)
33 virtual bool CreateFunction(double* dataPtr, const ArgumentType& sizes) override;
34 virtual int GetTotalSamplesCount() const override;
35 virtual int GetGridSize(int dimensionIndex) const override;
36 virtual double GetSampleAt(const SampleIndex& index) const override;
37 virtual istd::CRange GetLogicalRange(int dimensionIndex) const override;
38 virtual istd::CRange GetResultValueRange(int dimensionIndex, int resultDimension = -1) const override;
39 virtual std::vector<double> GetSamples() const override;
40
41 // reimplemented (imath::TIMathFunction)
42 virtual bool GetValueAt(const ArgumentType& argument, ResultType& result) const override;
43 virtual ResultType GetValueAt(const ArgumentType& argument) const override;
44
45private:
47
48 SamplesContainer m_samplesContainer;
49};
50
51
52// public inline methods
53
55{
56 return m_samplesContainer.GetSizes();
57}
58
59
60inline double CSampledFunction2d::GetSampleValue(const istd::CIndex2d& index) const
61{
62 Q_ASSERT(index.IsInside(m_samplesContainer.GetSizes()));
63
64 return m_samplesContainer.GetAt(index);
65}
66
67
68inline void CSampledFunction2d::SetSampleValue(const istd::CIndex2d& index, double value)
69{
70 Q_ASSERT(index.IsInside(m_samplesContainer.GetSizes()));
71
72 m_samplesContainer.SetAt(index, value);
73}
74
75
76} // namespace imath
77
78
Implementation of the resampled 2D-function.
virtual istd::CRange GetLogicalRange(int dimensionIndex) const override
Get logical range for the specified dimension.
virtual ResultType GetValueAt(const ArgumentType &argument) const override
virtual int GetGridSize(int dimensionIndex) const override
Get number of samples for specified dimension.
virtual istd::CRange GetResultValueRange(int dimensionIndex, int resultDimension=-1) const override
Get the range (boundary) of possible result values for the given axis.
istd::CIndex2d GetGridSize2d() const
bool CreateGrid2d(const istd::CIndex2d &size, double defaultValue=0)
virtual double GetSampleAt(const SampleIndex &index) const override
Get sample value at the given index.
CSampledFunction2d(const imath::ISampledFunction2d &function2d)
virtual std::vector< double > GetSamples() const override
Get all samples as a vector.
virtual bool CreateFunction(double *dataPtr, const ArgumentType &sizes) override
Create function from input data.
CSampledFunction2d(const CSampledFunction2d &function2d)
CSampledFunction2d(const istd::CIndex2d &size, double defaultValue=0)
void SetSampleValue(const istd::CIndex2d &index, double value)
virtual int GetTotalSamplesCount() const override
Get number of samples stored in this container.
double GetSampleValue(const istd::CIndex2d &index) const
virtual bool GetValueAt(const ArgumentType &argument, ResultType &result) const override
Interface for a resampled function with a regular grid design.
BaseClass::ResultType ResultType
BaseClass::ArgumentType ArgumentType
Index implementation for addressing elements in 2D-space.
Definition CIndex2d.h:21
Multidimensional array with fixed number of dimensions.
Definition TArray.h:24
const Element & GetAt(const IndexType &index) const
Get element stored at specified index.
Definition TArray.h:227
void SetAt(const IndexType &index, const Element &value)
Set element at specified index.
Definition TArray.h:251
const SizesType & GetSizes() const
Get list of all sizes.
Definition TArray.h:210
Multidimensional index used to addressing fixed-size array.
Definition TIndex.h:18
bool IsInside(const TIndex &boundaries) const
Check if index is inside boundaries.
Definition TIndex.h:457
Package with mathematical functions and algebraical primitives.