2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Authors
|
2023-06-14 23:30:43 +10:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup freestyle
|
2023-08-18 08:51:29 +10:00
|
|
|
* \brief Class to define a chain of view-edges.
|
2012-12-28 20:21:05 +00:00
|
|
|
*/
|
2008-04-30 15:41:54 +00:00
|
|
|
|
|
|
|
|
#include "Chain.h"
|
2012-12-28 20:21:05 +00:00
|
|
|
|
2014-04-17 16:04:01 +06:00
|
|
|
#include "../view_map/ViewMapAdvancedIterators.h"
|
2020-04-21 12:39:12 +02:00
|
|
|
#include "../view_map/ViewMapIterators.h"
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
namespace Freestyle {
|
|
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
void Chain::push_viewedge_back(ViewEdge *iViewEdge, bool orientation)
|
|
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
ViewEdge::vertex_iterator v;
|
|
|
|
|
ViewEdge::vertex_iterator vend;
|
|
|
|
|
ViewEdge::vertex_iterator vfirst;
|
|
|
|
|
Vec3r previous, current;
|
|
|
|
|
if (true == orientation) {
|
|
|
|
|
v = iViewEdge->vertices_begin();
|
|
|
|
|
vfirst = v;
|
|
|
|
|
vend = iViewEdge->vertices_end();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
v = iViewEdge->vertices_last();
|
|
|
|
|
vfirst = v;
|
|
|
|
|
vend = iViewEdge->vertices_end();
|
|
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
if (!_Vertices.empty()) {
|
|
|
|
|
previous = _Vertices.back()->point2d();
|
2019-05-31 22:51:19 +10:00
|
|
|
if (orientation) {
|
2012-12-28 20:21:05 +00:00
|
|
|
++v;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2012-12-28 20:21:05 +00:00
|
|
|
--v;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
// Ensure the continuity of underlying FEdges
|
|
|
|
|
CurvePoint *cp =
|
2020-11-06 11:25:27 +11:00
|
|
|
_Vertices.back(); // assumed to be instantiated as new CurvePoint(iSVertex, 0, 0.0f);
|
2012-12-28 20:21:05 +00:00
|
|
|
SVertex *sv_first = (*vfirst);
|
|
|
|
|
FEdge *fe = _fedgeB->duplicate();
|
2014-10-02 15:26:53 +09:00
|
|
|
fe->setTemporary(true);
|
2012-12-28 20:21:05 +00:00
|
|
|
fe->setVertexB(sv_first);
|
|
|
|
|
fe->vertexA()->shape()->AddEdge(fe);
|
|
|
|
|
fe->vertexA()->AddFEdge(fe);
|
|
|
|
|
fe->vertexB()->AddFEdge(fe);
|
|
|
|
|
cp->setA(sv_first);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
previous = (*v)->point2d();
|
|
|
|
|
}
|
|
|
|
|
do {
|
|
|
|
|
current = (*v)->point2d();
|
|
|
|
|
Curve::push_vertex_back(*v);
|
|
|
|
|
//_Length += (current - previous).norm();
|
|
|
|
|
previous = current;
|
2019-05-31 22:51:19 +10:00
|
|
|
if (orientation) {
|
2012-12-28 20:21:05 +00:00
|
|
|
++v;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2012-12-28 20:21:05 +00:00
|
|
|
--v;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
} while ((v != vend) && (v != vfirst));
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
if (v == vfirst) {
|
2019-04-30 17:50:57 +10:00
|
|
|
// Add last one:
|
2012-12-28 20:21:05 +00:00
|
|
|
current = (*v)->point2d();
|
|
|
|
|
Curve::push_vertex_back(*v);
|
|
|
|
|
//_Length += (current - previous).norm();
|
|
|
|
|
}
|
2011-10-16 22:54:08 +00:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
_fedgeB = (orientation) ? iViewEdge->fedgeB() : iViewEdge->fedgeA();
|
|
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
|
|
|
|
|
void Chain::push_viewedge_front(ViewEdge *iViewEdge, bool orientation)
|
|
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
orientation = !orientation;
|
|
|
|
|
ViewEdge::vertex_iterator v;
|
|
|
|
|
ViewEdge::vertex_iterator vend;
|
|
|
|
|
ViewEdge::vertex_iterator vfirst;
|
|
|
|
|
Vec3r previous, current;
|
|
|
|
|
if (true == orientation) {
|
|
|
|
|
v = iViewEdge->vertices_begin();
|
|
|
|
|
vfirst = v;
|
|
|
|
|
vend = iViewEdge->vertices_end();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
v = iViewEdge->vertices_last();
|
|
|
|
|
vfirst = v;
|
|
|
|
|
vend = iViewEdge->vertices_end();
|
|
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
if (!_Vertices.empty()) {
|
|
|
|
|
previous = _Vertices.front()->point2d();
|
2019-05-31 22:51:19 +10:00
|
|
|
if (orientation) {
|
2012-12-28 20:21:05 +00:00
|
|
|
++v;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2012-12-28 20:21:05 +00:00
|
|
|
--v;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
// Ensure the continuity of underlying FEdges
|
|
|
|
|
CurvePoint *cp =
|
2020-11-06 11:25:27 +11:00
|
|
|
_Vertices.front(); // assumed to be instantiated as new CurvePoint(iSVertex, 0, 0.0f);
|
2012-12-28 20:21:05 +00:00
|
|
|
SVertex *sv_last = cp->A();
|
|
|
|
|
SVertex *sv_curr = (*v);
|
|
|
|
|
FEdge *fe = (orientation) ? iViewEdge->fedgeA() : iViewEdge->fedgeB();
|
|
|
|
|
FEdge *fe2 = fe->duplicate();
|
2014-10-02 15:26:53 +09:00
|
|
|
fe2->setTemporary(true);
|
2012-12-28 20:21:05 +00:00
|
|
|
fe2->setVertexA(sv_curr);
|
|
|
|
|
fe2->setVertexB(sv_last);
|
|
|
|
|
sv_last->AddFEdge(fe2);
|
|
|
|
|
sv_curr->AddFEdge(fe2);
|
|
|
|
|
sv_curr->shape()->AddEdge(fe2);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
previous = (*v)->point2d();
|
|
|
|
|
}
|
|
|
|
|
do {
|
|
|
|
|
current = (*v)->point2d();
|
2022-09-25 15:14:13 +10:00
|
|
|
Curve::push_vertex_front(*v);
|
2012-12-28 20:21:05 +00:00
|
|
|
//_Length += (current - previous).norm();
|
|
|
|
|
previous = current;
|
2019-05-31 22:51:19 +10:00
|
|
|
if (orientation) {
|
2012-12-28 20:21:05 +00:00
|
|
|
++v;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2012-12-28 20:21:05 +00:00
|
|
|
--v;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
} while ((v != vend) && (v != vfirst));
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
if (v == vfirst) {
|
2019-04-30 17:50:57 +10:00
|
|
|
// Add last one:
|
2012-12-28 20:21:05 +00:00
|
|
|
current = (*v)->point2d();
|
|
|
|
|
Curve::push_vertex_front(*v);
|
|
|
|
|
//_Length += (current - previous).norm();
|
|
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!_fedgeB) {
|
2012-12-28 20:21:05 +00:00
|
|
|
_fedgeB = (orientation) ? iViewEdge->fedgeB() : iViewEdge->fedgeA();
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
2013-04-09 00:46:49 +00:00
|
|
|
|
|
|
|
|
} /* namespace Freestyle */
|