Merged changes in the trunk up to revision 53146.
[blender.git] / source / blender / freestyle / intern / view_map / Functions1D.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 "Functions1D.h"
23 using namespace std;
24
25 namespace Functions1D {
26
27   int GetXF1D::operator()(Interface1D& inter) {
28     result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration);
29         return 0;
30   }
31
32   int GetYF1D::operator()(Interface1D& inter) {
33     result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration);
34         return 0;
35   }
36
37   int GetZF1D::operator()(Interface1D& inter) {
38     result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration);
39         return 0;
40   }
41
42   int GetProjectedXF1D::operator()(Interface1D& inter) {
43     result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration);
44         return 0;
45   }
46
47   int GetProjectedYF1D::operator()(Interface1D& inter) {
48     result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration);
49         return 0;
50   }
51
52   int GetProjectedZF1D::operator()(Interface1D& inter) {
53     result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration);
54         return 0;
55   }
56
57   int Orientation2DF1D::operator()(Interface1D& inter) {
58     FEdge * fe = dynamic_cast<FEdge*>(&inter);
59     if(fe){
60       Vec3r res = fe->orientation2d();
61       result = Vec2f(res[0], res[1]);
62         } else {
63       result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration);
64         }
65         return 0;
66   }
67
68   int Orientation3DF1D::operator()(Interface1D& inter) {
69     result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration);
70         return 0;
71   }
72
73   int ZDiscontinuityF1D::operator()(Interface1D& inter) {
74     result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration);
75         return 0;
76   }
77   
78   int QuantitativeInvisibilityF1D::operator()(Interface1D& inter) {
79     ViewEdge* ve = dynamic_cast<ViewEdge*>(&inter);
80         if (ve) {
81           result = ve->qi();
82       return 0;
83         }
84     FEdge *fe = dynamic_cast<FEdge*>(&inter);
85         if (fe) {
86       result = ve->qi();
87           return 0;
88         }
89     result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration);
90         return 0;
91   }
92
93   int CurveNatureF1D::operator()(Interface1D& inter) {
94     ViewEdge* ve = dynamic_cast<ViewEdge*>(&inter);
95     if (ve)
96       result = ve->getNature();
97     else{
98       // we return a nature that contains every 
99       // natures of the viewedges spanned by the chain.
100       Nature::EdgeNature nat = Nature::NO_FEATURE;
101       Interface0DIterator it = inter.verticesBegin();
102       while(!it.isEnd()){
103         nat |= _func(it);
104         ++it;
105       }
106       result = nat;
107     }
108         return 0;
109   }
110   
111   int TimeStampF1D::operator()(Interface1D& inter) {
112     TimeStamp *timestamp = TimeStamp::instance();
113     inter.setTimeStamp(timestamp->getTimeStamp());
114         return 0;
115   }
116
117   int ChainingTimeStampF1D::operator()(Interface1D& inter) {
118     TimeStamp *timestamp = TimeStamp::instance();
119     ViewEdge *ve = dynamic_cast<ViewEdge*>(&inter);
120     if(ve)
121       ve->setChainingTimeStamp(timestamp->getTimeStamp());
122         return 0;
123   }
124   
125   int IncrementChainingTimeStampF1D::operator()(Interface1D& inter) {
126     ViewEdge *ve = dynamic_cast<ViewEdge*>(&inter);
127     if(ve)
128       ve->setChainingTimeStamp(ve->getChainingTimeStamp()+1);
129         return 0;
130   }
131
132   int GetShapeF1D::operator()(Interface1D& inter) {
133     vector<ViewShape*> shapesVector;
134     set<ViewShape*> shapesSet;
135     ViewEdge* ve = dynamic_cast<ViewEdge*>(&inter);
136     if (ve){
137       shapesVector.push_back(ve->viewShape());
138     }else{
139       Interface0DIterator it=inter.verticesBegin(), itend=inter.verticesEnd();
140       for(;it!=itend;++it)
141         shapesSet.insert(Functions0D::getShapeF0D(it));
142       shapesVector.insert<set<ViewShape*>::iterator>(shapesVector.begin(), shapesSet.begin(), shapesSet.end());
143     }
144     result = shapesVector;
145         return 0;
146   }
147
148   int GetOccludersF1D::operator()(Interface1D& inter) {
149     vector<ViewShape*> shapesVector;
150     set<ViewShape*> shapesSet;
151     ViewEdge* ve = dynamic_cast<ViewEdge*>(&inter);
152     if (ve){
153       result = ve->occluders();
154     }else{
155       Interface0DIterator it=inter.verticesBegin(), itend=inter.verticesEnd();
156       for(;it!=itend;++it){
157         Functions0D::getOccludersF0D(it, shapesSet);
158       }
159       shapesVector.insert(shapesVector.begin(), shapesSet.begin(), shapesSet.end());
160       result = shapesVector;
161     }
162         return 0;
163   }
164
165   int GetOccludeeF1D::operator()(Interface1D& inter) {
166     vector<ViewShape*> shapesVector;
167     set<ViewShape*> shapesSet;
168     ViewEdge* ve = dynamic_cast<ViewEdge*>(&inter);
169     if (ve){
170       ViewShape * aShape = ve->aShape();
171       shapesVector.push_back(aShape);
172     }else{
173       Interface0DIterator it=inter.verticesBegin(), itend=inter.verticesEnd();
174       for(;it!=itend;++it){
175         shapesSet.insert(Functions0D::getOccludeeF0D(it));
176       }
177     shapesVector.insert<set<ViewShape*>::iterator>(shapesVector.begin(), shapesSet.begin(), shapesSet.end());
178     }
179     result = shapesVector;
180         return 0;
181   }
182   // Internal
183   ////////////
184
185   void getOccludeeF1D(Interface1D& inter, set<ViewShape*>& oShapes){
186     ViewEdge* ve = dynamic_cast<ViewEdge*>(&inter);
187     if (ve){
188       ViewShape * aShape = ve->aShape();
189       if(aShape == 0){
190         oShapes.insert(0);
191         return;
192       }
193       oShapes.insert(aShape);
194     }
195     else{
196       Interface0DIterator it=inter.verticesBegin(), itend=inter.verticesEnd();
197       for(;it!=itend;++it)
198         oShapes.insert(Functions0D::getOccludeeF0D(it));
199     }
200   }
201
202   void getOccludersF1D(Interface1D& inter, set<ViewShape*>& oShapes){
203     ViewEdge* ve = dynamic_cast<ViewEdge*>(&inter);
204     if (ve){
205       vector<ViewShape*>& occluders = ve->occluders();
206       oShapes.insert<vector<ViewShape*>::iterator>(occluders.begin(), occluders.end());
207     }
208     else{
209       Interface0DIterator it=inter.verticesBegin(), itend=inter.verticesEnd();
210       for(;it!=itend;++it){
211         set<ViewShape*> shapes;
212         Functions0D::getOccludersF0D(it, shapes);
213         for(set<ViewShape*>::iterator s=shapes.begin(), send=shapes.end();
214             s!=send;
215             ++s)
216           oShapes.insert(*s);
217       }
218     }
219   }
220
221   void getShapeF1D(Interface1D& inter, set<ViewShape*>& oShapes){
222     ViewEdge* ve = dynamic_cast<ViewEdge*>(&inter);
223     if (ve){
224       oShapes.insert(ve->viewShape());
225     }else{
226       Interface0DIterator it=inter.verticesBegin(), itend=inter.verticesEnd();
227       for(;it!=itend;++it)
228         oShapes.insert(Functions0D::getShapeF0D(it));
229     }
230   }
231 } // end of namespace Functions1D