Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Chain.cpp « stroke « intern « freestyle « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b3f4d4547e925dd875bd369cbddeece825b00c51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* SPDX-License-Identifier: GPL-2.0-or-later */

/** \file
 * \ingroup freestyle
 * \brief Class to define a chain of viewedges.
 */

#include "Chain.h"

#include "../view_map/ViewMapAdvancedIterators.h"
#include "../view_map/ViewMapIterators.h"

namespace Freestyle {

void Chain::push_viewedge_back(ViewEdge *iViewEdge, bool 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();
  }

  if (!_Vertices.empty()) {
    previous = _Vertices.back()->point2d();
    if (orientation) {
      ++v;
    }
    else {
      --v;
    }
    // Ensure the continuity of underlying FEdges
    CurvePoint *cp =
        _Vertices.back();  // assumed to be instantiated as new CurvePoint(iSVertex, 0, 0.0f);
    SVertex *sv_first = (*vfirst);
    FEdge *fe = _fedgeB->duplicate();
    fe->setTemporary(true);
    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;
    if (orientation) {
      ++v;
    }
    else {
      --v;
    }
  } while ((v != vend) && (v != vfirst));

  if (v == vfirst) {
    // Add last one:
    current = (*v)->point2d();
    Curve::push_vertex_back(*v);
    //_Length += (current - previous).norm();
  }

  _fedgeB = (orientation) ? iViewEdge->fedgeB() : iViewEdge->fedgeA();
}

void Chain::push_viewedge_front(ViewEdge *iViewEdge, bool orientation)
{
  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();
  }

  if (!_Vertices.empty()) {
    previous = _Vertices.front()->point2d();
    if (orientation) {
      ++v;
    }
    else {
      --v;
    }
    // Ensure the continuity of underlying FEdges
    CurvePoint *cp =
        _Vertices.front();  // assumed to be instantiated as new CurvePoint(iSVertex, 0, 0.0f);
    SVertex *sv_last = cp->A();
    SVertex *sv_curr = (*v);
    FEdge *fe = (orientation) ? iViewEdge->fedgeA() : iViewEdge->fedgeB();
    FEdge *fe2 = fe->duplicate();
    fe2->setTemporary(true);
    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();
    Curve::push_vertex_front(*v);
    //_Length += (current - previous).norm();
    previous = current;
    if (orientation) {
      ++v;
    }
    else {
      --v;
    }
  } while ((v != vend) && (v != vfirst));

  if (v == vfirst) {
    // Add last one:
    current = (*v)->point2d();
    Curve::push_vertex_front(*v);
    //_Length += (current - previous).norm();
  }

  if (!_fedgeB) {
    _fedgeB = (orientation) ? iViewEdge->fedgeB() : iViewEdge->fedgeA();
  }
}

} /* namespace Freestyle */