Merged changes in the trunk up to revision 28600.
[blender.git] / source / blender / freestyle / intern / stroke / Chain.cpp
1
2 //
3 //  Copyright (C) : Please refer to the COPYRIGHT file distributed 
4 //   with this source distribution. 
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 //
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #include "Chain.h"
23 #include "../view_map/ViewMapIterators.h"
24 #include "../view_map/ViewMapAdvancedIterators.h"
25
26 void Chain::push_viewedge_back(ViewEdge *iViewEdge, bool orientation)
27 {
28   ViewEdge::vertex_iterator v;
29   ViewEdge::vertex_iterator vend;
30   ViewEdge::vertex_iterator vfirst;
31   Vec3r previous, current;
32   if(true == orientation)
33   {
34     v=iViewEdge->vertices_begin();
35     vfirst = v;
36     vend=iViewEdge->vertices_end();
37   }
38   else
39   {
40     v=iViewEdge->vertices_last();
41     vfirst = v;
42     vend=iViewEdge->vertices_end();
43   }
44
45   if(!_Vertices.empty())
46   {
47     previous = _Vertices.back()->point2d();
48     if(orientation)
49       ++v;
50     else
51       --v;
52   }
53   else
54     previous = (*v)->point2d(); 
55   do{
56     current = (*v)->point2d();
57     Curve::push_vertex_back(*v);
58     //_Length += (current-previous).norm();
59     previous = current;
60     if(orientation)
61       ++v;
62     else
63       --v;
64   }while((v!=vend) && (v!=vfirst));
65
66   if(v==vfirst)
67   {
68     //Add last one:
69     current = (*v)->point2d();
70     Curve::push_vertex_back(*v);
71     //_Length += (current-previous).norm();
72   }
73
74
75 void Chain::push_viewedge_front(ViewEdge *iViewEdge, bool orientation)
76 {
77   orientation = !orientation;
78   ViewEdge::vertex_iterator v;
79   ViewEdge::vertex_iterator vend;
80   ViewEdge::vertex_iterator vfirst;
81   Vec3r previous, current;
82   if(true == orientation)
83   {
84     v=iViewEdge->vertices_begin();
85     vfirst = v;
86     vend=iViewEdge->vertices_end();
87   }
88   else
89   {
90     v=iViewEdge->vertices_last();
91     vfirst = v;
92     vend=iViewEdge->vertices_end();
93   }
94
95   if(!_Vertices.empty())
96   {
97     previous = _Vertices.front()->point2d();
98     if(orientation)
99       ++v;
100     else
101       --v;
102   }
103   else
104     previous = (*v)->point2d(); 
105   do{
106     current = (*v)->point2d();
107     Curve::push_vertex_front((*v));
108     //_Length += (current-previous).norm();
109     previous = current;
110     if(orientation)
111       ++v;
112     else
113       --v;
114   }while((v!=vend) && (v!=vfirst));
115   
116   if(v==vfirst)
117   {
118     //Add last one:
119     current = (*v)->point2d();
120     Curve::push_vertex_front(*v);
121     //_Length += (current-previous).norm();
122   }
123 }
124
125
126