Pencil2D  ff90c0872e88be3bf81c548cd60f01983012ec49
Pencil2D is an animation software for both bitmap and vector graphics. It is free, multi-platform, and open source.
 All Classes Functions
beziercurve.h
1 /*
2 
3 Pencil - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; version 2 of the License.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 */
16 #ifndef BEZIERCURVE_H
17 #define BEZIERCURVE_H
18 
19 #include <QtXml>
20 #include <QPainter>
21 
22 class Object;
23 class Status;
24 
26 {
27  QPointF point;
28  qreal t1, t2;
29 };
30 
32 {
33 public:
34  BezierCurve();
35  BezierCurve(QList<QPointF> pointList);
36  BezierCurve(QList<QPointF> pointList, QList<qreal> pressureList, double tol);
37 
38  Status createDomElement(QXmlStreamWriter &xmlStream);
39  void loadDomElement(QDomElement element);
40 
41  qreal getWidth() const { return width; }
42  qreal getFeather() const { return feather; }
43  bool getVariableWidth() const { return variableWidth; }
44  int getColourNumber() const { return colourNumber; }
45  void decreaseColourNumber() { colourNumber--; }
46  int getVertexSize() const { return vertex.size(); }
47  QPointF getOrigin() const { return origin; }
48  QPointF getVertex(int i) const { if (i==-1) { return origin; } else { return vertex.at(i);} }
49  QPointF getC1(int i) const { return c1.at(i); }
50  QPointF getC2(int i) const { return c2.at(i); }
51  qreal getPressure(int i) const { return pressure.at(i); }
52  bool isSelected(int i) const { return selected.at(i+1); }
53  bool isSelected() const { bool result=true; for(int i=0; i<selected.size(); i++) result = result && selected[i]; return result; }
54  bool isPartlySelected() const { bool result=false; for(int i=0; i<selected.size(); i++) result = result || selected[i]; return result; }
55  bool isInvisible() const { return invisible; }
56  bool intersects(QPointF point, qreal distance);
57  bool intersects(QRectF rectangle);
58 
59  void setOrigin(const QPointF& point);
60  void setOrigin(const QPointF& point, const qreal& pressureValue, const bool& trueOrFalse);
61  void setC1(int i, const QPointF& point);
62  void setC2(int i, const QPointF& point);
63  void setVertex(int i, const QPointF& point);
64  void setLastVertex(const QPointF& point);
65  void setWidth(qreal desiredWidth);
66  void setFeather(qreal desiredFeather);
67  void setVariableWidth(bool YesOrNo);
68  void setInvisibility(bool YesOrNo);
69  void setColourNumber(int colourNumber) { this->colourNumber = colourNumber; }
70  void setSelected(bool YesOrNo) { for(int i=0; i<selected.size(); i++) { selected[i] = YesOrNo; } }
71  void setSelected(int i, bool YesOrNo);
72 
73  BezierCurve transformed(QTransform transformation);
74  void transform(QTransform transformation);
75 
76  void appendCubic(const QPointF& c1Point, const QPointF& c2Point, const QPointF& vertexPoint, qreal pressureValue);
77  void addPoint(int position, const QPointF point);
78  void addPoint(int position, const qreal t);
79  QPointF getPointOnCubic(int i, qreal t);
80  void removeVertex(int i);
81  QPainterPath getStraightPath();
82  QPainterPath getSimplePath();
83  QPainterPath getStrokedPath();
84  QPainterPath getStrokedPath(qreal width);
85  QPainterPath getStrokedPath(qreal width, bool pressure);
86  QRectF getBoundingRect();
87 
88  void drawPath(QPainter& painter, Object* object, QTransform transformation, bool simplified, bool showThinLines );
89  void createCurve(QList<QPointF>& pointList, QList<qreal>& pressureList );
90  void smoothCurve();
91 
92  static void simplify(double tol, QList<QPointF>& inputList, int j, int k, QList<bool>& markList);
93 
94  // general useful functions -> to be placed elsewhere?
95  static qreal eLength(const QPointF point); // returns the Euclidean length of a point (seen as a vector)
96  static qreal mLength(const QPointF point); // returns the Manhattan length of a point (seen as a vector)
97  static void normalise(QPointF& point); // normalises a point (seen as a vector);
98  static qreal findDistance(BezierCurve curve, int i, QPointF P, QPointF& nearestPoint, qreal& t); //finds the distance between a cubic section and a point
99  static bool findIntersection(BezierCurve curve1, int i1, BezierCurve curve2, int i2, QList<Intersection>& intersections); //finds the intersection between two cubic sections
100 
101 private:
102  QPointF origin;
103  QList<QPointF> c1;
104  QList<QPointF> c2;
105  QList<QPointF> vertex;
106  QList<float> pressure; // this list has one more element than the other list (the first element is for the origin)
107  int colourNumber;
108  float width;
109  float feather;
110  bool variableWidth;
111  bool invisible;
112  QList<bool> selected; // this list has one more element than the other list (the first element is for the origin)
113 };
114 
115 #endif
Definition: object.h:71