Blender  V2.93
Chain.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
22 #include "Chain.h"
23 
24 #include "../view_map/ViewMapAdvancedIterators.h"
25 #include "../view_map/ViewMapIterators.h"
26 
27 namespace Freestyle {
28 
29 void Chain::push_viewedge_back(ViewEdge *iViewEdge, bool orientation)
30 {
34  Vec3r previous, current;
35  if (true == orientation) {
36  v = iViewEdge->vertices_begin();
37  vfirst = v;
38  vend = iViewEdge->vertices_end();
39  }
40  else {
41  v = iViewEdge->vertices_last();
42  vfirst = v;
43  vend = iViewEdge->vertices_end();
44  }
45 
46  if (!_Vertices.empty()) {
47  previous = _Vertices.back()->point2d();
48  if (orientation) {
49  ++v;
50  }
51  else {
52  --v;
53  }
54  // Ensure the continuity of underlying FEdges
55  CurvePoint *cp =
56  _Vertices.back(); // assumed to be instantiated as new CurvePoint(iSVertex, 0, 0.0f);
57  SVertex *sv_first = (*vfirst);
58  FEdge *fe = _fedgeB->duplicate();
59  fe->setTemporary(true);
60  fe->setVertexB(sv_first);
61  fe->vertexA()->shape()->AddEdge(fe);
62  fe->vertexA()->AddFEdge(fe);
63  fe->vertexB()->AddFEdge(fe);
64  cp->setA(sv_first);
65  }
66  else {
67  previous = (*v)->point2d();
68  }
69  do {
70  current = (*v)->point2d();
72  //_Length += (current - previous).norm();
73  previous = current;
74  if (orientation) {
75  ++v;
76  }
77  else {
78  --v;
79  }
80  } while ((v != vend) && (v != vfirst));
81 
82  if (v == vfirst) {
83  // Add last one:
84  current = (*v)->point2d();
86  //_Length += (current - previous).norm();
87  }
88 
89  _fedgeB = (orientation) ? iViewEdge->fedgeB() : iViewEdge->fedgeA();
90 }
91 
92 void Chain::push_viewedge_front(ViewEdge *iViewEdge, bool orientation)
93 {
94  orientation = !orientation;
98  Vec3r previous, current;
99  if (true == orientation) {
100  v = iViewEdge->vertices_begin();
101  vfirst = v;
102  vend = iViewEdge->vertices_end();
103  }
104  else {
105  v = iViewEdge->vertices_last();
106  vfirst = v;
107  vend = iViewEdge->vertices_end();
108  }
109 
110  if (!_Vertices.empty()) {
111  previous = _Vertices.front()->point2d();
112  if (orientation) {
113  ++v;
114  }
115  else {
116  --v;
117  }
118  // Ensure the continuity of underlying FEdges
119  CurvePoint *cp =
120  _Vertices.front(); // assumed to be instantiated as new CurvePoint(iSVertex, 0, 0.0f);
121  SVertex *sv_last = cp->A();
122  SVertex *sv_curr = (*v);
123  FEdge *fe = (orientation) ? iViewEdge->fedgeA() : iViewEdge->fedgeB();
124  FEdge *fe2 = fe->duplicate();
125  fe2->setTemporary(true);
126  fe2->setVertexA(sv_curr);
127  fe2->setVertexB(sv_last);
128  sv_last->AddFEdge(fe2);
129  sv_curr->AddFEdge(fe2);
130  sv_curr->shape()->AddEdge(fe2);
131  }
132  else {
133  previous = (*v)->point2d();
134  }
135  do {
136  current = (*v)->point2d();
138  //_Length += (current - previous).norm();
139  previous = current;
140  if (orientation) {
141  ++v;
142  }
143  else {
144  --v;
145  }
146  } while ((v != vend) && (v != vfirst));
147 
148  if (v == vfirst) {
149  // Add last one:
150  current = (*v)->point2d();
152  //_Length += (current - previous).norm();
153  }
154 
155  if (!_fedgeB) {
156  _fedgeB = (orientation) ? iViewEdge->fedgeB() : iViewEdge->fedgeA();
157  }
158 }
159 
160 } /* namespace Freestyle */
Class to define a chain of viewedges.
ATTR_WARN_UNUSED_RESULT const BMVert * v
void push_viewedge_front(ViewEdge *iViewEdge, bool orientation)
Definition: Chain.cpp:92
void push_viewedge_back(ViewEdge *iViewEdge, bool orientation)
Definition: Chain.cpp:29
FEdge * _fedgeB
Definition: Chain.h:38
void setA(SVertex *iA)
Definition: Curve.h:275
SVertex * A()
Definition: Curve.h:249
void push_vertex_back(Vertex *iVertex)
Definition: Curve.h:439
vertex_container _Vertices
Definition: Curve.h:393
void push_vertex_front(Vertex *iVertex)
Definition: Curve.h:463
void setTemporary(bool iFlag)
Definition: Silhouette.h:830
void setVertexB(SVertex *vB)
Definition: Silhouette.h:743
virtual FEdge * duplicate()
Definition: Silhouette.h:603
SVertex * vertexA()
Definition: Silhouette.h:611
SVertex * vertexB()
Definition: Silhouette.h:617
void setVertexA(SVertex *vA)
Definition: Silhouette.h:737
void AddEdge(FEdge *iEdge)
Definition: Silhouette.h:1565
SShape * shape()
Definition: Silhouette.h:277
void AddFEdge(FEdge *iFEdge)
Definition: Silhouette.h:373
const_vertex_iterator vertices_end() const
Definition: ViewMap.cpp:741
FEdge * fedgeB()
Definition: ViewMap.h:1095
FEdge * fedgeA()
Definition: ViewMap.h:1089
const_vertex_iterator vertices_last() const
Definition: ViewMap.cpp:731
const_vertex_iterator vertices_begin() const
embedding vertex iterator
Definition: ViewMap.cpp:721
inherits from class Rep
Definition: AppCanvas.cpp:32