Krita Source Code Documentation
Loading...
Searching...
No Matches
PerspectiveBasedAssistantHelper.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2022 Agata Cacko <cacko.azh@gmail.com>
3 */
4
5#ifndef _PERSPECTIVE_BASED_ASSISTANT_HELPER_H_
6#define _PERSPECTIVE_BASED_ASSISTANT_HELPER_H_
7
8
9#include <QObject>
10#include <boost/optional.hpp>
11
12#include "Ellipse.h"
15
16#include "kritaassistanttool_export.h"
17
18class KRITAASSISTANTTOOL_EXPORT PerspectiveBasedAssistantHelper
19{
20private:
23
24
25public:
26
28 {
29 public:
30 // vanishing points that one gets from getVanishingPoints
31 boost::optional<QPointF> vanishingPoint1 {boost::none};
32 boost::optional<QPointF> vanishingPoint2 {boost::none};
33
34 // distances from the horizon line to point 1, 2, 3 and 4 on the final polygon
36 qreal maxDistanceFromPoint {0.0};
37
38 QLineF horizon;
39
40 // final polygon
41 QPolygonF polygon;
42
43
44 typedef enum PerspectiveType {
47 TwoVps
48 } PerspectiveType;
49
50
52
53 };
54
55
56
57 // *** main functions ***
58
59 // creates the convex hull, returns false if it's not a quadrilateral/tetragon
60 static bool getTetragon(const QList<KisPaintingAssistantHandleSP> &handles, bool isAssistantComplete, QPolygonF& outPolygon);
61
62 // creates a fully connected tetragon (as in, every vertex is connected to every other vertex)
63 // this is useful for drawing a wrong state in perspective-based assistants (when one vertex is inside the triangle created by the rest of them)
64 static QPolygonF getAllConnectedTetragon(const QList<KisPaintingAssistantHandleSP>& handles);
65
66 // distance in Perspective grid
67 // used for calculating the Perspective sensor
68 static qreal distanceInGrid(const QList<KisPaintingAssistantHandleSP>& handles, bool isAssistantComplete, const QPointF &point);
69
70 // distance in Perspective grid
71 // used for calculating the Perspective sensor
72 static qreal distanceInGrid(const CacheData& cache, const QPointF &point);
73
74 static void updateCacheData(CacheData& cache, const QPolygonF& poly);
75
76 // vp1 - vp for lines 0-1 and 2-3
77 // vp2 - vp for lines 1-2 and 3-0
78 static bool getVanishingPointsOptional(const QPolygonF &poly, boost::optional<QPointF>& vp1, boost::optional<QPointF>& vp2);
79
80
81
82 static qreal localScale(const QTransform& transform, QPointF pt);
83
84 // returns the reciprocal of the maximum local scale at the points (0,0),(0,1),(1,0),(1,1)
85 static qreal inverseMaxLocalScale(const QTransform& transform);
86
87
88 // *** small helper functions ***
89
90 // perpendicular dot product
91 // it's basically a dot product between vector A(xa, ya) and vector B'(xb, -yb)
92 // or a dot product between vector A'(xa, -ya) and vector B(xb, yb)
93 // if it's needed elsewhere in Krita too, you can move it to KisAlgebra2D
94 static qreal pdot(const QPointF& a, const QPointF& b);
95
96};
97
98#endif