1 // Copyright (C) 2012-2019 The VPaint Developers.
2 // See the COPYRIGHT file at the top-level directory of this distribution
3 // and at https://github.com/dalboris/vpaint/blob/master/COPYRIGHT
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef VAC_INSTANT_VERTEX_H
18 #define VAC_INSTANT_VERTEX_H
19 
20 #include "KeyCell.h"
21 #include "VertexCell.h"
22 #include "Halfedge.h"
23 #include "Eigen.h"
24 
25 namespace VectorAnimationComplex
26 {
27 
28 class KeyVertex: public KeyCell, public VertexCell
29 {
30 public:
31     // Constructor
32     KeyVertex(VAC * vac, Time time, const Eigen::Vector2d & pos);
33     KeyVertex(VAC * vac, Time time, const EdgeSample& sample);
34     KeyVertex(VAC * vac, Time time);
35 
36     // Geometry
37     void setPos(const Eigen::Vector2d & pos);
pos(Time)38     Eigen::Vector2d pos(Time ) const
39         { return pos(); }
40     Eigen::Vector2d pos() const;
41     //double size() const;
42     //double size(Time time) const;
43     void computePosFromEdges();
44     void correctEdgesGeometry();
45     Eigen::Vector2d catmullRomTangent(bool slowInOut = false) const;
46     Eigen::Vector2d dividedDifferencesTangent(bool slowInOut = false) const;
47 
48     // manipulation
49     void prepareDragAndDrop();
50     void performDragAndDrop(double dx, double dy);
51     void prepareAffineTransform();
52     void performAffineTransform(const Eigen::Affine2d & xf);
53 
54     // For cubic spline interpolation
55     KeyVertexList beforeVertices() const;
56     KeyVertexList afterVertices() const;
57 
58     EIGEN_MAKE_ALIGNED_OPERATOR_NEW
59 
60 
61 private:
62         friend class VAC;
63     ~KeyVertex();
64 
65     // Geometry
66     Eigen::Vector2d pos_;
67     double size_;
68 
69     // Tangents
70     QList< QPair< KeyHalfedge, KeyHalfedge> > tangentEdges_;
71 
72     // Trusting operators
73     friend class Operator;
74     bool check_() const;
75 
76     // dragAndDrop
77     Eigen::Vector2d posBack_;
78 
79     void initColor();
80 
81 
82 // --------- Cloning, Assigning, Copying, Serializing ----------
83 
84 protected:
85     // Cloning
86     KeyVertex(KeyVertex * other);
87     virtual KeyVertex * clone();
88     virtual void remapPointers(VAC * newVAC);
89 
90     // Serializing / Unserializing
91     virtual QString xmlType_() const;
92     virtual void write_(XmlStreamWriter & xml) const;
93     KeyVertex(VAC * vac, XmlStreamReader &xml);
94     virtual void read2ndPass();
95 
96     // Serializing / Unserializing DEPRECATED
stringType()97     virtual QString stringType() const {return "Vertex";}
98     virtual void save_(QTextStream & out);
99     KeyVertex(VAC * vac, QTextStream & in);
100     public: class Read1stPass {
101         friend Cell * Cell::read1stPass(VAC * vac, QTextStream & in);
create(VAC * g,QTextStream & in)102         static KeyVertex * create(VAC * g, QTextStream & in)
103             {return new KeyVertex(g, in);} };
104 };
105 
106 }
107 
108 #endif
109