Skip to content

Commit 688bf20

Browse files
committed
Merge remote-tracking branch 'opentoonz/master' into feature08_assistants
2 parents f551296 + 737bda7 commit 688bf20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1017
-8596
lines changed

toonz/sources/colorfx/colorfxutils.cpp

Lines changed: 0 additions & 274 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "colorfxutils.h"
44
#include "drawutil.h"
55
#include "tregion.h"
6-
#include "tflash.h"
76

87
RubberDeform::RubberDeform() : m_pPolyOri(0), m_polyLoc() {}
98

@@ -100,276 +99,3 @@ void RubberDeform::refinePoly(const double rf) {
10099
}
101100
m_polyLoc = tmpv;
102101
}
103-
104-
// ------------------- SFlashUtils -------------------------------------------
105-
106-
void SFlashUtils::computeOutline(const TRegion *region,
107-
TRegionOutline::PointVector &polyline) const {
108-
if (!region) return;
109-
110-
const double pixelSize = 1.0;
111-
polyline.clear();
112-
113-
std::vector<TPointD> polyline2d;
114-
115-
int edgeSize = region->getEdgeCount();
116-
117-
for (int i = 0; i < edgeSize; i++) {
118-
TEdge &edge = *region->getEdge(i);
119-
stroke2polyline(polyline2d, *edge.m_s, pixelSize, edge.m_w0, edge.m_w1);
120-
}
121-
int pointNumber = polyline2d.size();
122-
polyline.reserve(pointNumber);
123-
for (int j = 0; j < pointNumber; j++) {
124-
polyline.push_back(T3DPointD(polyline2d[j], 0.0));
125-
}
126-
}
127-
128-
void SFlashUtils::computeRegionOutline() {
129-
if (!m_r) return;
130-
131-
int subRegionNumber = m_r->getSubregionCount();
132-
TRegionOutline::PointVector app;
133-
134-
m_ro.m_exterior.clear();
135-
computeOutline(m_r, app);
136-
137-
m_ro.m_exterior.push_back(app);
138-
m_ro.m_interior.clear();
139-
m_ro.m_interior.reserve(subRegionNumber);
140-
for (int i = 0; i < subRegionNumber; i++) {
141-
app.clear();
142-
computeOutline(m_r->getSubregion(i), app);
143-
m_ro.m_interior.push_back(app);
144-
}
145-
146-
m_ro.m_bbox = m_r->getBBox();
147-
}
148-
149-
void SFlashUtils::PointVector2QuadsArray(const std::vector<T3DPointD> &pv,
150-
std::vector<TQuadratic *> &quadArray,
151-
std::vector<TQuadratic *> &toBeDeleted,
152-
const bool isRounded) const {
153-
int nbPv = pv.size();
154-
quadArray.clear();
155-
156-
if (isRounded) {
157-
if (nbPv <= 2) {
158-
if (nbPv == 1) {
159-
TPointD p0, p1, p2;
160-
p0 = TPointD(pv[0].x, pv[0].y);
161-
p1 = TPointD(pv[0].x, pv[0].y);
162-
p2 = TPointD(pv[0].x, pv[0].y);
163-
quadArray.push_back(new TQuadratic(p0, p1, p2));
164-
toBeDeleted.push_back(quadArray.back());
165-
}
166-
if (nbPv == 2) {
167-
TPointD p0, p1, p2;
168-
p0 = TPointD(pv[0].x, pv[0].y);
169-
p1 = TPointD((pv[0].x + pv[1].x) / 2, (pv[0].y + pv[1].y) / 2);
170-
p2 = TPointD(pv[1].x, pv[1].y);
171-
quadArray.push_back(new TQuadratic(p0, p1, p2));
172-
toBeDeleted.push_back(quadArray.back());
173-
}
174-
return;
175-
}
176-
177-
for (int i = 0; i < (nbPv - 2); i++) {
178-
TPointD p0, p1, p2;
179-
p0 = TPointD((pv[i].x + pv[i + 1].x) / 2, (pv[i].y + pv[i + 1].y) / 2);
180-
p1 = TPointD(pv[i + 1].x, pv[i + 1].y);
181-
p2 = TPointD((pv[i + 1].x + pv[i + 2].x) / 2,
182-
(pv[i + 1].y + pv[i + 2].y) / 2);
183-
quadArray.push_back(new TQuadratic(p0, p1, p2));
184-
toBeDeleted.push_back(quadArray.back());
185-
}
186-
TPointD p0, p1, p2;
187-
p0 = TPointD((pv[nbPv - 2].x + pv[nbPv - 1].x) / 2,
188-
(pv[nbPv - 2].y + pv[nbPv - 1].y) / 2);
189-
p1 = TPointD(pv[nbPv - 1].x, pv[nbPv - 1].y);
190-
p2 = TPointD((pv[0].x + pv[1].x) / 2, (pv[0].y + pv[1].y) / 2);
191-
quadArray.push_back(new TQuadratic(p0, p1, p2));
192-
toBeDeleted.push_back(quadArray.back());
193-
} else {
194-
for (int i = 0; i < (nbPv - 1); i++) {
195-
TPointD p0, p1, p2;
196-
p0 = TPointD(pv[i].x, pv[i].y);
197-
p2 = TPointD(pv[i + 1].x, pv[i + 1].y);
198-
p1 = TPointD((p0.x + p2.x) * 0.5, (p0.y + p2.y) * 0.5);
199-
quadArray.push_back(new TQuadratic(p0, p1, p2));
200-
toBeDeleted.push_back(quadArray.back());
201-
}
202-
TPointD p0, p1, p2;
203-
p0 = TPointD(pv[nbPv - 1].x, pv[nbPv - 1].y);
204-
p2 = TPointD(pv[0].x, pv[0].y);
205-
p1 = TPointD((p0.x + p2.x) * 0.5, (p0.y + p2.y) * 0.5);
206-
quadArray.push_back(new TQuadratic(p0, p1, p2));
207-
toBeDeleted.push_back(quadArray.back());
208-
}
209-
}
210-
211-
void SFlashUtils::drawRegionOutline(TFlash &flash, const bool isRounded) const {
212-
if (!m_r) return;
213-
214-
std::vector<std::vector<TQuadratic *>> quads;
215-
std::vector<TQuadratic *> toBeDeleted;
216-
std::vector<TQuadratic *> quadArray;
217-
PointVector2QuadsArray(*(m_ro.m_exterior.begin()), quadArray, toBeDeleted,
218-
isRounded);
219-
quads.push_back(quadArray);
220-
221-
TRegionOutline::Boundary::const_iterator iinter = m_ro.m_interior.begin();
222-
TRegionOutline::Boundary::const_iterator iinter_end = m_ro.m_interior.end();
223-
for (; iinter != iinter_end; iinter++) {
224-
PointVector2QuadsArray(*iinter, quadArray, toBeDeleted, isRounded);
225-
quads.push_back(quadArray);
226-
}
227-
228-
flash.drawPolygon(quads);
229-
clearPointerContainer(toBeDeleted);
230-
}
231-
232-
int SFlashUtils::nbDiffVerts(const std::vector<TPointD> &pv) const {
233-
std::vector<TPointD> lpv;
234-
if (pv.size() == 0) return 0;
235-
lpv.push_back(pv[0]);
236-
for (int i = 1; i < (int)pv.size(); i++) {
237-
bool isDiff = true;
238-
for (int j = 0; j < (int)lpv.size() && isDiff; j++)
239-
isDiff = lpv[j] == pv[i] ? false : isDiff;
240-
if (isDiff) {
241-
lpv.push_back(pv[i]);
242-
}
243-
}
244-
return lpv.size();
245-
}
246-
247-
void SFlashUtils::Triangle2Quad(std::vector<TPointD> &p) const {
248-
TPointD e;
249-
int i, j;
250-
i = j = -1;
251-
if (p[0] == p[1]) {
252-
i = 0;
253-
j = 1;
254-
e = p[2] - p[3];
255-
} else if (p[0] == p[2]) {
256-
} else if (p[0] == p[3]) {
257-
i = 0;
258-
j = 3;
259-
e = p[2] - p[1];
260-
} else if (p[1] == p[2]) {
261-
i = 1;
262-
j = 2;
263-
e = p[3] - p[0];
264-
} else if (p[1] == p[3]) {
265-
} else if (p[2] == p[3]) {
266-
i = 2;
267-
j = 3;
268-
e = p[0] - p[1];
269-
}
270-
e = normalize(e);
271-
p[j] = p[i] + e * 0.001;
272-
}
273-
274-
void SFlashUtils::drawGradedPolyline(TFlash &flash, std::vector<TPointD> &pvv,
275-
const TPixel32 &c1,
276-
const TPixel32 &c2) const {
277-
std::vector<TPointD> pv;
278-
pv = pvv;
279-
int nbDV = nbDiffVerts(pv);
280-
if (nbDV < 3 || nbDV > 4) return;
281-
if (nbDV == 3) Triangle2Quad(pv);
282-
283-
// Direction Of polyline
284-
TPointD u = pv[0] - pv[1];
285-
TPointD up = (pv[0] + pv[1]) * 0.5;
286-
u = normalize(u);
287-
u = rotate90(u);
288-
TPointD up1 = up + u;
289-
TPointD up2 = up - u;
290-
double d1 = (tdistance(up1, pv[2]) + tdistance(up1, pv[3])) * 0.5;
291-
double d2 = (tdistance(up2, pv[2]) + tdistance(up2, pv[3])) * 0.5;
292-
293-
std::vector<TPointD> lpv;
294-
if (d1 > d2) {
295-
lpv = pv;
296-
} else {
297-
lpv.push_back(pv[1]);
298-
lpv.push_back(pv[0]);
299-
lpv.push_back(pv[3]);
300-
lpv.push_back(pv[2]);
301-
}
302-
303-
// Transformation of gradient square
304-
const double flashGrad = 16384.0; // size of gradient square
305-
flash.setGradientFill(true, c1, c2, 0);
306-
TPointD p0((lpv[0] + lpv[3]) * 0.5);
307-
TPointD p1((lpv[1] + lpv[2]) * 0.5);
308-
double lv = (tdistance(p0, p1));
309-
double lh = 0.5 * (tdistance(lpv[0], lpv[3]) + tdistance(lpv[1], lpv[2]));
310-
TPointD center =
311-
0.25 * lpv[0] + 0.25 * lpv[1] + 0.25 * lpv[2] + 0.25 * lpv[3];
312-
TPointD e(p0 - p1);
313-
314-
double angle = rad2degree(atan(e));
315-
angle = angle <= 0 ? 270 + angle : angle - 90;
316-
TRotation rM(angle);
317-
TTranslation tM(center.x, center.y);
318-
TScale sM(lh / (flashGrad), lv / (flashGrad));
319-
320-
flash.setFillStyleMatrix(tM * sM * rM);
321-
flash.drawPolyline(pv);
322-
}
323-
324-
//------------------------------------------------------------
325-
326-
//------------------------------------------------------------
327-
void SFlashUtils::drawGradedRegion(TFlash &flash, std::vector<TPointD> &pvv,
328-
const TPixel32 &c1, const TPixel32 &c2,
329-
const TRegion &r) const {
330-
std::vector<TPointD> pv;
331-
pv = pvv;
332-
int nbDV = nbDiffVerts(pv);
333-
if (nbDV < 3 || nbDV > 4) return;
334-
if (nbDV == 3) Triangle2Quad(pv);
335-
336-
// Direction Of polyline
337-
TPointD u = pv[0] - pv[1];
338-
TPointD up = (pv[0] + pv[1]) * 0.5;
339-
u = normalize(u);
340-
u = rotate90(u);
341-
TPointD up1 = up + u;
342-
TPointD up2 = up - u;
343-
double d1 = (tdistance(up1, pv[2]) + tdistance(up1, pv[3])) * 0.5;
344-
double d2 = (tdistance(up2, pv[2]) + tdistance(up2, pv[3])) * 0.5;
345-
346-
std::vector<TPointD> lpv;
347-
if (d1 > d2) {
348-
lpv = pv;
349-
} else {
350-
lpv.push_back(pv[1]);
351-
lpv.push_back(pv[0]);
352-
lpv.push_back(pv[3]);
353-
lpv.push_back(pv[2]);
354-
}
355-
356-
// Transformation of gradient square
357-
const double flashGrad = 16384.0; // size of gradient square
358-
flash.setGradientFill(true, c1, c2, 0);
359-
TPointD p0((lpv[0] + lpv[3]) * 0.5);
360-
TPointD p1((lpv[1] + lpv[2]) * 0.5);
361-
double lv = (tdistance(p0, p1));
362-
double lh = 0.5 * (tdistance(lpv[0], lpv[3]) + tdistance(lpv[1], lpv[2]));
363-
TPointD center =
364-
0.25 * lpv[0] + 0.25 * lpv[1] + 0.25 * lpv[2] + 0.25 * lpv[3];
365-
TPointD e(p0 - p1);
366-
367-
double angle = rad2degree(atan(e));
368-
angle = angle <= 0 ? 270 + angle : angle - 90;
369-
TRotation rM(angle);
370-
TTranslation tM(center.x, center.y);
371-
TScale sM(lh / (flashGrad), lv / (flashGrad));
372-
373-
flash.setFillStyleMatrix(tM * sM * rM);
374-
flash.drawRegion(r);
375-
}

toonz/sources/colorfx/colorfxutils.h

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,4 @@ class RubberDeform {
3131
void deform(const double n);
3232
};
3333

34-
class SFlashUtils {
35-
void computeOutline(const TRegion *region,
36-
TRegionOutline::PointVector &polyline) const;
37-
void PointVector2QuadsArray(const std::vector<T3DPointD> &pv,
38-
std::vector<TQuadratic *> &quadArray,
39-
std::vector<TQuadratic *> &toBeDeleted,
40-
const bool isRounded) const;
41-
int nbDiffVerts(const std::vector<TPointD> &pv) const;
42-
void Triangle2Quad(std::vector<TPointD> &p) const;
43-
44-
public:
45-
const TRegion *m_r;
46-
TRegionOutline m_ro;
47-
48-
SFlashUtils(){};
49-
SFlashUtils(const TRegion *r) : m_r(r){};
50-
virtual ~SFlashUtils(){};
51-
52-
void computeRegionOutline();
53-
void drawRegionOutline(TFlash &flash, const bool isRounded = true) const;
54-
void drawGradedPolyline(TFlash &flash, std::vector<TPointD> &pv,
55-
const TPixel32 &c1, const TPixel32 &c2) const;
56-
void drawGradedRegion(TFlash &flash, std::vector<TPointD> &pv,
57-
const TPixel32 &c1, const TPixel32 &c2,
58-
const TRegion &r) const;
59-
};
60-
6134
#endif

0 commit comments

Comments
 (0)