File indexing completed on 2024-12-22 04:10:01
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef __KIS_NU_BSPLINE_2D_H 0008 #define __KIS_NU_BSPLINE_2D_H 0009 0010 #include <kritaimage_export.h> 0011 0012 #include <QScopedPointer> 0013 #include <QVector> 0014 #include <QPointF> 0015 #include <QSize> 0016 0017 #include "kis_bspline.h" 0018 0019 0020 namespace KisBSplines { 0021 0022 class KRITAIMAGE_EXPORT KisNUBSpline2D 0023 { 0024 public: 0025 KisNUBSpline2D(const QVector<double> &xSamples, BorderCondition bcX, 0026 const QVector<double> &ySamples, BorderCondition bcY); 0027 0028 ~KisNUBSpline2D(); 0029 0030 template <class FunctionOp> 0031 inline void initializeSpline(const FunctionOp &op) { 0032 0033 const int xSize = m_xSamples.size(); 0034 const int ySize = m_ySamples.size(); 0035 0036 QVector<float> values(xSize * ySize); 0037 0038 for (int x = 0; x < xSize; x++) { 0039 double fx = m_xSamples[x]; 0040 0041 for (int y = 0; y < ySize; y++) { 0042 double fy = m_ySamples[y]; 0043 float v = op(fx, fy); 0044 values[x * ySize + y] = v; 0045 } 0046 } 0047 0048 initializeSplineImpl(values); 0049 } 0050 0051 float value(float x, float y) const; 0052 0053 QPointF topLeft() const; 0054 QPointF bottomRight() const; 0055 0056 BorderCondition borderConditionX() const; 0057 BorderCondition borderConditionY() const; 0058 0059 private: 0060 void initializeSplineImpl(const QVector<float> &values); 0061 0062 private: 0063 struct Private; 0064 const QScopedPointer<Private> m_d; 0065 0066 /** 0067 * We need to store them separately, because they should 0068 * be accessible from the templated part 0069 */ 0070 const QVector<double> m_xSamples; 0071 const QVector<double> m_ySamples; 0072 }; 0073 0074 } 0075 0076 #endif /* __KIS_NU_BSPLINE_2D_H */