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_ANIMATED_EDGE_H
18 #define VAC_ANIMATED_EDGE_H
19 
20 #include "InbetweenCell.h"
21 #include "EdgeCell.h"
22 
23 #include "Path.h"
24 #include "Cycle.h"
25 #include "AnimatedVertex.h"
26 #include "EdgeSample.h"
27 
28 #include <QList>
29 #include <QPair>
30 
31 namespace VectorAnimationComplex
32 {
33 
34 class InbetweenEdge: public InbetweenCell, public EdgeCell
35 {
36 public:
37     // Construct a inbetween open edge
38     InbetweenEdge(VAC * vac,
39                   const Path & beforePath,
40                   const Path & afterPath,
41                   const AnimatedVertex & startAnimatedVertex,
42                   const AnimatedVertex & endAnimatedVertex);
43 
44     // Construct a inbetween closed edge
45     InbetweenEdge(VAC * vac,
46                   const Cycle & beforeCycle,
47                   const Cycle & afterCycle);
48 
49     // Check if closed or open
50     bool isClosed() const;
51 
52     // Setters
53     void setBeforeCycleStartingPoint(double s0);
54     void setAfterCycleStartingPoint(double s0);
55 
56     // Getters
57     double beforeCycleStartingPoint() const;
58     double afterCycleStartingPoint() const;
59 
60     // Get boundary cells
61     KeyCellSet beforeCells() const;
62     KeyCellSet afterCells() const;
63     VertexCellSet startVertices() const;
64     VertexCellSet endVertices() const;
65 
66     // Get semantic boundary
67     //  -> inbetween open edge case
68     Path beforePath() const;
69     Path afterPath() const;
70     AnimatedVertex startAnimatedVertex() const;
71     AnimatedVertex endAnimatedVertex() const;
72     //   -> inbetween closed edge case
73     Cycle beforeCycle() const;
74     Cycle afterCycle() const;
75 
76     // Convenient getters
77     VertexCell * startVertex(Time time) const;
78     VertexCell * endVertex(Time time) const;
79 
80     // Drawing
81     void glColor3D_();
82     void drawRaw3D(View3DSettings & viewSettings);
83     //void drawRaw(Time time);
84     //void drawRawTopology(Time time, ViewSettings & viewSettings);
85     //void resetSampling();
86 
87     // Other
88     QList<EdgeSample> getSampling(Time time) const; // Note: repeat start and end vertices even when closed.
89     QList<Eigen::Vector2d> getGeometry(Time time); // Note: repeat start and end vertices even when closed.
90 
91 private:
92     // Cached geometry
93     QList< QList<Eigen::Vector3d> > surf_;
94     QList< QList<Eigen::Vector3d> > norm_;
95     virtual void clearCachedGeometry_();
96     void computeInbetweenSurface(View3DSettings & viewSettings);
97 
98     // Trusting operators
99     friend class VAC;
100     friend class Operator;
101     bool check_() const;
102 
103     ~InbetweenEdge();
104 
105     // Update Boundary
106     void updateBoundary_impl(KeyVertex * oldVertex, KeyVertex * newVertex);
107     void updateBoundary_impl(const KeyHalfedge & oldHalfedge, const KeyHalfedge & newHalfedge);
108     void updateBoundary_impl(KeyEdge * oldEdge, const KeyEdgeList & newEdges);
109 
110     // Interpolations
111     //QList<Eigen::Vector2d> getCoon(Time time, int N);
112     //QList<Eigen::Vector2d> getLinear(Time time, int N);
113 
114     // -- Inbetween Open Edge --
115     Path beforePath_;
116     Path afterPath_;
117     AnimatedVertex startAnimatedVertex_;
118     AnimatedVertex endAnimatedVertex_;
119 
120     // -- Inbetween Closed Edge --
121     Cycle beforeCycle_;
122     Cycle afterCycle_;
123 
124     // Implementation of triangulate
125     void triangulate_(Time time, Triangles & out) const;
126     void triangulate_(double width, Time time, Triangles & out) const;
127 
128 // --------- Cloning, Assigning, Copying, Serializing ----------
129 
130 protected:
131     // Cloning
132     InbetweenEdge(InbetweenEdge * other);
133     virtual InbetweenEdge * clone();
134     virtual void remapPointers(VAC * newVAC);
135 
136     // Serializing / Unserializing
137     virtual QString xmlType_() const;
138     virtual void write_(XmlStreamWriter & xml) const;
139     InbetweenEdge(VAC * vac, XmlStreamReader &xml);
140     virtual void read2ndPass();
141 
142     // Serializing / Unserializing DEPRECATED
143     virtual void save_(QTextStream & out);
stringType()144     QString stringType() const {return "InbetweenEdge";}
145     InbetweenEdge(VAC * vac, QTextStream & in);
146 public:
147     class Read1stPass {
148         friend Cell * Cell::read1stPass(VAC * vac, QTextStream & in);
create(VAC * g,QTextStream & in)149         static InbetweenEdge * create(VAC * g, QTextStream & in) {return new InbetweenEdge(g, in);}  };
150 };
151 
152 
153 }
154 
155 #endif
156