Krita Source Code Documentation
Loading...
Searching...
No Matches
KisCubicCurve Class Reference

#include <kis_cubic_curve.h>

+ Inheritance diagram for KisCubicCurve:

Public Member Functions

int addPoint (const KisCubicCurvePoint &point)
 
int addPoint (const QPointF &position)
 
int addPoint (const QPointF &position, bool setAsCorner)
 
const QList< KisCubicCurvePoint > & curvePoints () const
 
 Data ()
 
 Data (const Data &data)
 
const QVector< qreal > floatTransfer (int size=256) const
 
Q_DECL_DEPRECATED void fromString (const QString &)
 
void invalidate ()
 
bool isConstant (qreal c) const
 
bool isIdentity () const
 
void keepSorted ()
 
 KisCubicCurve ()
 
 KisCubicCurve (const KisCubicCurve &curve)
 
 KisCubicCurve (const QList< KisCubicCurvePoint > &points)
 
 KisCubicCurve (const QList< QPointF > &points)
 
 KisCubicCurve (const QList< QPointF > &points, bool setAsCorner)
 
 KisCubicCurve (const QString &curveString)
 
const QString & name () const
 
KisCubicCurve & operator= (const KisCubicCurve &curve)
 
bool operator== (const KisCubicCurve &curve) const
 
Q_DECL_DEPRECATED QList< QPointF > points () const
 
void removePoint (int idx)
 
void setName (const QString &name)
 
void setPoint (int idx, const KisCubicCurvePoint &point)
 
void setPoint (int idx, const QPointF &position)
 
void setPoint (int idx, const QPointF &position, bool setAsCorner)
 
void setPointAsCorner (int idx, bool setAsCorner)
 
void setPointPosition (int idx, const QPointF &position)
 
void setPoints (const QList< KisCubicCurvePoint > &points)
 
void setPoints (const QList< QPointF > &points)
 
QString toString () const
 
const QVector< quint16 > uint16Transfer (int size=256) const
 
void updateSpline ()
 
template<typename _T_ , typename _T2_ >
void updateTransfer (QVector< _T_ > *transfer, bool &valid, _T2_ min, _T2_ max, int size)
 
qreal value (qreal x)
 
qreal value (qreal x) const
 
 ~Data ()
 
 ~KisCubicCurve ()
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Static Public Member Functions

static qreal interpolateLinear (qreal normalizedValue, const QVector< qreal > &transfer)
 

Public Attributes

QSharedDataPointer< Data > data
 
QVector< qreal > fTransfer
 
QString name
 
QList< KisCubicCurvePoint > points
 
KisCubicSpline< KisCubicCurvePoint, qreal > spline
 
QVector< quint16 > u16Transfer
 
QVector< quint8 > u8Transfer
 
bool validFTransfer {false}
 
bool validSpline {false}
 
bool validU16Transfer {false}
 
bool validU8Transfer {false}
 
- Public Attributes inherited from Private
KisCanvas2 * canvas
 
int displayedFrame
 
int intendedFrame
 

Private Attributes

Private *const d {nullptr}
 

Detailed Description

Hold the data for a cubic curve.

Definition at line 76 of file kis_cubic_curve.cpp.

Constructor & Destructor Documentation

◆ ~Data()

KisCubicCurve::~Data ( )
inline

Definition at line 83 of file kis_cubic_curve.cpp.

83 {
84 }

◆ KisCubicCurve() [1/6]

KisCubicCurve::KisCubicCurve ( )

Definition at line 158 of file kis_cubic_curve.cpp.

159 : d(new Private)
160{
161 d->data = new Data;
162 d->data->points.append({ 0.0, 0.0, false });
163 d->data->points.append({ 1.0, 1.0, false });
164}
Private *const d

References d, and Data().

◆ KisCubicCurve() [2/6]

KisCubicCurve::KisCubicCurve ( const QList< QPointF > & points)

Definition at line 166 of file kis_cubic_curve.cpp.

167 : KisCubicCurve(points, false)
168{
169}
QList< KisCubicCurvePoint > points

◆ KisCubicCurve() [3/6]

KisCubicCurve::KisCubicCurve ( const QList< QPointF > & points,
bool setAsCorner )

Definition at line 171 of file kis_cubic_curve.cpp.

172 : d(new Private)
173{
174 d->data = new Data;
175 d->data->points.reserve(points.size());
176 Q_FOREACH(const QPointF p, points) {
177 d->data->points.append({ p, setAsCorner });
178 }
179 d->data->keepSorted();
180}
const Params2D p

References d, Data(), p, and points.

◆ KisCubicCurve() [4/6]

KisCubicCurve::KisCubicCurve ( const QList< KisCubicCurvePoint > & points)

Definition at line 182 of file kis_cubic_curve.cpp.

183 : d(new Private)
184{
185 d->data = new Data;
186 d->data->points = points;
187 d->data->keepSorted();
188}

References d, Data(), and points.

◆ KisCubicCurve() [5/6]

KisCubicCurve::KisCubicCurve ( const QString & curveString)

Definition at line 195 of file kis_cubic_curve.cpp.

196 : d(new Private)
197{
198 // Curve string format: a semi-colon separated list of point entries.
199 // Previous point entry format: a pair of numbers, separated by a comma,
200 // that represent the x and y coordinates of the point, in that order.
201 // Examples: identity "0.0,0.0;1.0,1.0;"
202 // U-shaped curve "0.0,1.0;0.5,0.0;1.0,1.0"
203 // New point entry format: a list of comma separated point properties. The
204 // first and second properties are required and should be numbers
205 // that represent the x and y coordinates of the point, in that order.
206 // After those, some optional properties/flags may be present or not.
207 // If there are no optional properties for any point entry, then the
208 // format of the string is identical to the old one.
209 // Currently, only the "is_corner" flag is supported. All other
210 // present optional properties are ignored.
211 // Examples: identity "0.0,0.0;1.0,1.0;"
212 // V-shaped curve "0.0,1.0;0.5,0.0,is_corner;1.0,1.0"
213
214 d->data = new Data;
215
216 KIS_SAFE_ASSERT_RECOVER(!curveString.isEmpty()) {
217 *this = KisCubicCurve();
218 return;
219 }
220
221 const QStringList data = curveString.split(';', Qt::SkipEmptyParts);
222
224 Q_FOREACH (const QString &entry, data) {
225 const QStringList entryData = entry.split(',', Qt::SkipEmptyParts);
226 KIS_SAFE_ASSERT_RECOVER(entryData.size() > 1) {
227 *this = KisCubicCurve();
228 return;
229 }
230 bool ok;
231 const qreal x = KisDomUtils::toDouble(entryData[0], &ok);
233 *this = KisCubicCurve();
234 return;
235 }
236 const qreal y = KisDomUtils::toDouble(entryData[1], &ok);
238 *this = KisCubicCurve();
239 return;
240 }
241 bool isCorner = false;
242 for (int i = 2; i < entryData.size(); ++i) {
243 if (entryData[i] == "is_corner") {
244 isCorner = true;
245 }
246 }
247 points.append({ x, y, isCorner });
248 }
249
251}
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
double toDouble(const QString &str, bool *ok=nullptr)
void setPoints(const QList< QPointF > &points)
QSharedDataPointer< Data > data

References d, Data(), data, KIS_SAFE_ASSERT_RECOVER, KisCubicCurve(), points, setPoints(), and KisDomUtils::toDouble().

◆ KisCubicCurve() [6/6]

KisCubicCurve::KisCubicCurve ( const KisCubicCurve & curve)

Definition at line 190 of file kis_cubic_curve.cpp.

191 : d(new Private(*curve.d))
192{
193}

◆ ~KisCubicCurve()

KisCubicCurve::~KisCubicCurve ( )

Definition at line 253 of file kis_cubic_curve.cpp.

254{
255 delete d;
256}

References d.

Member Function Documentation

◆ addPoint() [1/3]

int KisCubicCurve::addPoint ( const KisCubicCurvePoint & point)

Add a point to the curve, the list of point is always sorted.

Returns
the index of the inserted point

Definition at line 342 of file kis_cubic_curve.cpp.

343{
344 d->data.detach();
345 d->data->points.append(point);
346 d->data->keepSorted();
347 d->data->invalidate();
348
349 return d->data->points.indexOf(point);
350}

References d.

◆ addPoint() [2/3]

int KisCubicCurve::addPoint ( const QPointF & position)

Definition at line 357 of file kis_cubic_curve.cpp.

358{
359 return addPoint({ position, false });
360}
int addPoint(const KisCubicCurvePoint &point)

References addPoint().

◆ addPoint() [3/3]

int KisCubicCurve::addPoint ( const QPointF & position,
bool setAsCorner )

Definition at line 352 of file kis_cubic_curve.cpp.

353{
354 return addPoint({ position, setAsCorner });
355}

References addPoint().

◆ curvePoints()

const QList< KisCubicCurvePoint > & KisCubicCurve::curvePoints ( ) const

Definition at line 287 of file kis_cubic_curve.cpp.

288{
289 return d->data->points;
290}

References d.

◆ Data() [1/2]

KisCubicCurve::Data ( )
inline

Definition at line 77 of file kis_cubic_curve.cpp.

77 {
78 }

◆ Data() [2/2]

KisCubicCurve::Data ( const Data & data)
inline

Definition at line 79 of file kis_cubic_curve.cpp.

79 : QSharedData() {
80 points = data.points;
81 name = data.name;
82 }

◆ floatTransfer()

const QVector< qreal > KisCubicCurve::floatTransfer ( int size = 256) const

Definition at line 473 of file kis_cubic_curve.cpp.

474{
475 d->data->updateTransfer<qreal, qreal>(&d->data->fTransfer, d->data->validFTransfer, 0.0, 1.0, size);
476 return d->data->fTransfer;
477}
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References d.

◆ fromString()

void KisCubicCurve::fromString ( const QString & string)

Definition at line 462 of file kis_cubic_curve.cpp.

463{
464 *this = KisCubicCurve(string);
465}

References KisCubicCurve().

◆ interpolateLinear()

qreal KisCubicCurve::interpolateLinear ( qreal normalizedValue,
const QVector< qreal > & transfer )
static

Definition at line 405 of file kis_cubic_curve.cpp.

406{
407 const qreal maxValue = transfer.size() - 1;
408
409 const qreal bilinearX = qBound(0.0, maxValue * normalizedValue, maxValue);
410 const qreal xFloored = std::floor(bilinearX);
411 const qreal xCeiled = std::ceil(bilinearX);
412
413 const qreal t = bilinearX - xFloored;
414
415 constexpr qreal eps = 1e-6;
416
417 qreal newValue = normalizedValue;
418
419 if (t < eps) {
420 newValue = transfer[int(xFloored)];
421 } else if (t > (1.0 - eps)) {
422 newValue = transfer[int(xCeiled)];
423 } else {
424 qreal a = transfer[int(xFloored)];
425 qreal b = transfer[int(xCeiled)];
426
427 newValue = a + t * (b - a);
428 }
429
430 return KisAlgebra2D::copysign(newValue, normalizedValue);
431}
const qreal eps
T copysign(T x, T y)

References KisAlgebra2D::copysign(), and eps.

◆ invalidate()

void KisCubicCurve::invalidate ( )

◆ isConstant()

bool KisCubicCurve::isConstant ( qreal c) const

Definition at line 387 of file kis_cubic_curve.cpp.

388{
389 const QList<KisCubicCurvePoint> &points = d->data->points;
390
391 Q_FOREACH (const KisCubicCurvePoint &pt, points) {
392 if (!qFuzzyCompare(c, pt.y())) {
393 return false;
394 }
395 }
396
397 return true;
398}
static bool qFuzzyCompare(half p1, half p2)

References d, points, qFuzzyCompare(), and KisCubicCurvePoint::y().

◆ isIdentity()

bool KisCubicCurve::isIdentity ( ) const

Definition at line 369 of file kis_cubic_curve.cpp.

370{
371 const QList<KisCubicCurvePoint> &points = d->data->points;
372
373 if (points.first().x() != 0.0 || points.first().y() != 0.0 ||
374 points.last().x() != 1.0 || points.last().y() != 1.0) {
375 return false;
376 }
377
378 for (int i = 1; i < points.size() - 1; i++) {
379 if (!qFuzzyCompare(points[i].x(), points[i].y())) {
380 return false;
381 }
382 }
383
384 return true;
385}

References d, points, and qFuzzyCompare().

◆ keepSorted()

void KisCubicCurve::keepSorted ( )

◆ name()

const QString & KisCubicCurve::name ( ) const

◆ operator=()

KisCubicCurve & KisCubicCurve::operator= ( const KisCubicCurve & curve)

Definition at line 258 of file kis_cubic_curve.cpp.

259{
260 if (&curve != this) {
261 *d = *curve.d;
262 }
263 return *this;
264}

References d.

◆ operator==()

bool KisCubicCurve::operator== ( const KisCubicCurve & curve) const

Definition at line 266 of file kis_cubic_curve.cpp.

267{
268 if (d->data == curve.d->data) return true;
269 return d->data->points == curve.d->data->points;
270}

References d.

◆ points()

Q_DECL_DEPRECATED QList< QPointF > KisCubicCurve::points ( ) const

Deprecated. Use curvePoints instead

◆ removePoint()

void KisCubicCurve::removePoint ( int idx)

Definition at line 362 of file kis_cubic_curve.cpp.

363{
364 d->data.detach();
365 d->data->points.removeAt(idx);
366 d->data->invalidate();
367}

References d.

◆ setName()

void KisCubicCurve::setName ( const QString & name)

This allows us to carry around a display name for the curve internally. It is used currently in Sketch for perchannel, but would potentially be useful anywhere curves are used in the UI

Definition at line 433 of file kis_cubic_curve.cpp.

434{
435 d->data->name = name;
436}

References d, and name.

◆ setPoint() [1/3]

void KisCubicCurve::setPoint ( int idx,
const KisCubicCurvePoint & point )

Definition at line 309 of file kis_cubic_curve.cpp.

310{
311 d->data.detach();
312 d->data->points[idx] = point;
313 d->data->keepSorted();
314 d->data->invalidate();
315}

References d.

◆ setPoint() [2/3]

void KisCubicCurve::setPoint ( int idx,
const QPointF & position )

Definition at line 322 of file kis_cubic_curve.cpp.

323{
324 setPointPosition(idx, position);
325}
void setPointPosition(int idx, const QPointF &position)

References setPointPosition().

◆ setPoint() [3/3]

void KisCubicCurve::setPoint ( int idx,
const QPointF & position,
bool setAsCorner )

Definition at line 317 of file kis_cubic_curve.cpp.

318{
319 setPoint(idx, { position, setAsCorner });
320}
void setPoint(int idx, const KisCubicCurvePoint &point)

References setPoint().

◆ setPointAsCorner()

void KisCubicCurve::setPointAsCorner ( int idx,
bool setAsCorner )

Definition at line 335 of file kis_cubic_curve.cpp.

336{
337 d->data.detach();
338 d->data->points[idx].setAsCorner(setAsCorner);
339 d->data->invalidate();
340}

References d.

◆ setPointPosition()

void KisCubicCurve::setPointPosition ( int idx,
const QPointF & position )

Definition at line 327 of file kis_cubic_curve.cpp.

328{
329 d->data.detach();
330 d->data->points[idx].setPosition(position);
331 d->data->keepSorted();
332 d->data->invalidate();
333}

References d.

◆ setPoints() [1/2]

void KisCubicCurve::setPoints ( const QList< KisCubicCurvePoint > & points)

Definition at line 302 of file kis_cubic_curve.cpp.

303{
304 d->data.detach();
305 d->data->points = points;
306 d->data->invalidate();
307}

References d, and points.

◆ setPoints() [2/2]

void KisCubicCurve::setPoints ( const QList< QPointF > & points)

Definition at line 292 of file kis_cubic_curve.cpp.

293{
294 d->data.detach();
295 d->data->points.clear();
296 Q_FOREACH(const QPointF &p, points) {
297 d->data->points.append({ p, false });
298 }
299 d->data->invalidate();
300}

References d, p, and points.

◆ toString()

QString KisCubicCurve::toString ( ) const

Definition at line 438 of file kis_cubic_curve.cpp.

439{
440 // See comments in KisCubicCurve(const QString &curveString) for the
441 // specification of the string format
442
443 QString sCurve;
444
445 if(d->data->points.count() < 1)
446 return sCurve;
447
448 Q_FOREACH (const KisCubicCurvePoint &point, d->data->points) {
449 sCurve += QString::number(point.x());
450 sCurve += ',';
451 sCurve += QString::number(point.y());
452 if (point.isSetAsCorner()) {
453 sCurve += ',';
454 sCurve += "is_corner";
455 }
456 sCurve += ';';
457 }
458
459 return sCurve;
460}
bool isSetAsCorner() const

References d, KisCubicCurvePoint::isSetAsCorner(), KisCubicCurvePoint::x(), and KisCubicCurvePoint::y().

◆ uint16Transfer()

const QVector< quint16 > KisCubicCurve::uint16Transfer ( int size = 256) const

Definition at line 467 of file kis_cubic_curve.cpp.

468{
469 d->data->updateTransfer<quint16, int>(&d->data->u16Transfer, d->data->validU16Transfer, 0x0, 0xFFFF, size);
470 return d->data->u16Transfer;
471}

References d.

◆ updateSpline()

void KisCubicCurve::updateSpline ( )

◆ updateTransfer()

template<typename _T_ , typename _T2_ >
void KisCubicCurve::updateTransfer ( QVector< _T_ > * transfer,
bool & valid,
_T2_ min,
_T2_ max,
int size )

◆ value() [1/2]

qreal KisCubicCurve::value ( qreal x)

◆ value() [2/2]

qreal KisCubicCurve::value ( qreal x) const

Definition at line 272 of file kis_cubic_curve.cpp.

273{
274 qreal value = d->data->value(x);
275 return value;
276}
qreal value(qreal x)

References d, and value().

Member Data Documentation

◆ d

Private* const KisCubicCurve::d {nullptr}
private

Definition at line 120 of file kis_cubic_curve.h.

120{nullptr};

◆ data

QSharedDataPointer<Data> KisCubicCurve::data

Definition at line 155 of file kis_cubic_curve.cpp.

◆ fTransfer

QVector<qreal> KisCubicCurve::fTransfer
mutable

Definition at line 94 of file kis_cubic_curve.cpp.

◆ name

const QString & KisCubicCurve::name
mutable

Definition at line 86 of file kis_cubic_curve.cpp.

◆ points

QList< QPointF > KisCubicCurve::points

Definition at line 88 of file kis_cubic_curve.cpp.

◆ spline

KisCubicSpline<KisCubicCurvePoint, qreal> KisCubicCurve::spline
mutable

Definition at line 87 of file kis_cubic_curve.cpp.

◆ u16Transfer

QVector<quint16> KisCubicCurve::u16Transfer
mutable

Definition at line 92 of file kis_cubic_curve.cpp.

◆ u8Transfer

QVector<quint8> KisCubicCurve::u8Transfer
mutable

Definition at line 90 of file kis_cubic_curve.cpp.

◆ validFTransfer

bool KisCubicCurve::validFTransfer {false}
mutable

Definition at line 95 of file kis_cubic_curve.cpp.

95{false};

◆ validSpline

bool KisCubicCurve::validSpline {false}
mutable

Definition at line 89 of file kis_cubic_curve.cpp.

89{false};

◆ validU16Transfer

bool KisCubicCurve::validU16Transfer {false}
mutable

Definition at line 93 of file kis_cubic_curve.cpp.

93{false};

◆ validU8Transfer

bool KisCubicCurve::validU8Transfer {false}
mutable

Definition at line 91 of file kis_cubic_curve.cpp.

91{false};

The documentation for this class was generated from the following files: