a09964a4e7940ed04d881548aaa79f5b807bf017
[blender.git] / source / blender / freestyle / intern / application / Controller.h
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * ***** END GPL LICENSE BLOCK *****
19  */
20
21 #ifndef __CONTROLLER_H__
22 #define __CONTROLLER_H__
23
24 /** \file blender/freestyle/intern/application/Controller.h
25  *  \ingroup freestyle
26  *  \brief The spinal tap of the system.
27  *  \author Stephane Grabli
28  *  \date 01/07/2002
29  */
30
31 #include <string>
32
33 //#include "ConfigIO.h"
34 #include "../geometry/FastGrid.h"
35 #include "../scene_graph/SceneHash.h"
36 #include "../system/Interpreter.h"
37 #include "../system/ProgressBar.h"
38 #include "../system/Precision.h"
39 #include "../system/RenderMonitor.h"
40 #include "../system/TimeUtils.h"
41 #include "../view_map/FEdgeXDetector.h"
42 #include "../view_map/ViewMapBuilder.h"
43
44 extern "C" {
45 #include "render_types.h"
46 #include "DNA_scene_types.h"
47 }
48
49 #ifdef WITH_CXX_GUARDEDALLOC
50 #include "MEM_guardedalloc.h"
51 #endif
52
53 namespace Freestyle {
54
55 class AppView;
56 class NodeGroup;
57 class WShape;
58 class SShape;
59 class ViewMap;
60 class ViewEdge;
61 class AppCanvas;
62 class InteractiveShader;
63 class Shader;
64 class StrokeRenderer;
65
66 class Controller
67 {
68 public:
69         Controller();
70         ~Controller();
71
72         void setView(AppView *iView);
73         void setRenderMonitor(RenderMonitor *iRenderMonitor);
74         void setPassDiffuse(float *buf, int width, int height);
75         void setPassZ(float *buf, int width, int height);
76         void setContext(bContext *C);
77
78         //soc
79         void init_options();
80
81         int  LoadMesh(Render *re, SceneRenderLayer *srl);
82         int  Load3DSFile(const char *iFileName);
83         void CloseFile();
84         void ComputeViewMap();
85         void ComputeSteerableViewMap();
86         void saveSteerableViewMapImages();
87         void toggleEdgeTesselationNature(Nature::EdgeNature iNature);
88         void DrawStrokes();
89         void ResetRenderCount();
90         Render *RenderStrokes(Render *re, bool render);
91         void SwapStyleModules(unsigned i1, unsigned i2);
92         void InsertStyleModule(unsigned index, const char *iFileName);
93         void InsertStyleModule(unsigned index, const char *iName, const char *iBuffer);
94         void InsertStyleModule(unsigned index, const char *iName, struct Text *iText);
95         void AddStyleModule(const char *iFileName);
96         void RemoveStyleModule(unsigned index);
97         void ReloadStyleModule(unsigned index, const char * iFileName);
98         void Clear();
99         void ClearRootNode();
100         void DeleteWingedEdge();
101         void DeleteViewMap(bool freeCache = false);
102         void toggleLayer(unsigned index, bool iDisplay);
103         void setModified(unsigned index, bool iMod);
104         void resetModified(bool iMod=false);
105         void updateCausalStyleModules(unsigned index);
106         void displayDensityCurves(int x, int y);
107
108         ViewEdge *SelectViewEdge(real x, real y);
109         FEdge *SelectFEdge(real x, real y);
110         NodeGroup *BuildRep(vector<ViewEdge*>::iterator vedges_begin, vector<ViewEdge*>::iterator vedges_end) ;
111
112 #if 0
113         NodeGroup *debugNode() {return _DebugNode;}
114         AppView *view() {return _pView;}
115         NodeGroup *debugScene() {return _DebugNode;}
116         Grid& grid() {return _Grid;}
117 #endif
118
119         void toggleVisibilityAlgo();
120         void setVisibilityAlgo(int algo);
121         int getVisibilityAlgo();
122
123         void setViewMapCache(bool iBool);
124         bool getViewMapCache() const;
125         void setQuantitativeInvisibility(bool iBool); // if true, we compute quantitativeInvisibility
126         bool getQuantitativeInvisibility() const;
127         void setFaceSmoothness(bool iBool);
128         bool getFaceSmoothness() const;
129
130         void setComputeRidgesAndValleysFlag(bool b);
131         bool getComputeRidgesAndValleysFlag() const;
132         void setComputeSuggestiveContoursFlag(bool b);
133         bool getComputeSuggestiveContoursFlag() const;
134         void setComputeMaterialBoundariesFlag(bool b);
135         bool getComputeMaterialBoundariesFlag() const;
136
137         void setComputeSteerableViewMapFlag(bool iBool);
138         bool getComputeSteerableViewMapFlag() const;
139         void setCreaseAngle(real angle) {_creaseAngle = angle;}
140         real getCreaseAngle() const {return _creaseAngle;}
141         void setSphereRadius(real s) {_sphereRadius = s;}
142         real getSphereRadius() const {return _sphereRadius;}
143         void setSuggestiveContourKrDerivativeEpsilon(real dkr) {_suggestiveContourKrDerivativeEpsilon = dkr;}
144         real getSuggestiveContourKrDerivativeEpsilon() const {return _suggestiveContourKrDerivativeEpsilon;}
145
146         void setModelsDir(const string& dir);
147         string getModelsDir() const;
148         void setModulesDir(const string& dir);
149         string getModulesDir() const;
150
151         bool hitViewMapCache();
152
153         void resetInterpreter();
154
155 public:
156         // Viewmap data structure
157         ViewMap *_ViewMap;
158
159         // Canvas
160         AppCanvas *_Canvas;
161
162 private:
163         // Main Window:
164         //AppMainWindow *_pMainWindow;
165
166         // List of models currently loaded
167         vector<string> _ListOfModels;
168
169         // Current directories
170         //ConfigIO* _current_dirs;
171
172         //View
173         // 3D
174         AppView *_pView;
175
176         // 2D
177 #if 0
178         Viewer2DWindow *_pView2DWindow;
179         Viewer2D *_pView2D;
180 #endif
181
182         RenderMonitor *_pRenderMonitor;
183
184         //Model
185         // Drawing Structure
186         NodeGroup *_RootNode;
187
188         // Winged-Edge structure
189         WingedEdge *_winged_edge;
190
191         // Silhouette structure:
192 #if 0
193         std::vector<SShape*> _SShapes;
194         NodeGroup *_SRoot;
195 #endif
196
197         // Silhouette
198         NodeGroup *_SilhouetteNode;
199         NodeGroup *_ProjectedSilhouette;
200         NodeGroup *_VisibleProjectedSilhouette;
201
202         // more Debug info
203         NodeGroup *_DebugNode;
204
205         // debug
206         //NodeUser<ViewMap> *_ViewMapNode; // FIXME
207
208         // Chronometer:
209         Chronometer _Chrono;
210
211         // Progress Bar
212         ProgressBar *_ProgressBar;
213
214         // edges tesselation nature
215         int _edgeTesselationNature;
216
217         FastGrid _Grid;
218         //HashGrid _Grid;
219
220         BBox<Vec3r> _Scene3dBBox;
221         unsigned int _SceneNumFaces;
222         real _minEdgeSize;
223         real _EPSILON;
224         real _bboxDiag;
225
226         int _render_count;
227
228         //AppStyleWindow *_pStyleWindow;
229         //AppOptionsWindow *_pOptionsWindow;
230         //AppDensityCurvesWindow *_pDensityCurvesWindow;
231
232         ViewMapBuilder::visibility_algo _VisibilityAlgo;
233
234         // Script Interpreter
235         Interpreter *_inter;
236
237         string _help_index;
238         string _browser_cmd;
239
240         bool _EnableViewMapCache;
241         bool _EnableQI;
242         bool _EnableFaceSmoothness;
243         bool _ComputeRidges;
244         bool _ComputeSuggestive;
245         bool _ComputeMaterialBoundaries;
246         real _creaseAngle;
247         real _sphereRadius;
248         real _suggestiveContourKrDerivativeEpsilon;
249
250         bool _ComputeSteerableViewMap;
251
252         FEdgeXDetector edgeDetector;
253
254         SceneHash sceneHashFunc;
255         real prevSceneHash;
256
257 #ifdef WITH_CXX_GUARDEDALLOC
258         MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Controller")
259 #endif
260 };
261
262 extern Controller *g_pController;
263
264 } /* namespace Freestyle */
265
266 #endif // __CONTROLLER_H__