Fix for [#36374] Read unitialized memory in Freestyle.
[blender-staging.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 "../system/Interpreter.h"
36 #include "../system/ProgressBar.h"
37 #include "../system/Precision.h"
38 #include "../system/RenderMonitor.h"
39 #include "../system/TimeUtils.h"
40 #include "../view_map/FEdgeXDetector.h"
41 #include "../view_map/ViewMapBuilder.h"
42
43 extern "C" {
44 #include "render_types.h"
45 #include "DNA_scene_types.h"
46 }
47
48 #ifdef WITH_CXX_GUARDEDALLOC
49 #include "MEM_guardedalloc.h"
50 #endif
51
52 namespace Freestyle {
53
54 class AppView;
55 class NodeGroup;
56 class WShape;
57 class SShape;
58 class ViewMap;
59 class ViewEdge;
60 class AppCanvas;
61 class InteractiveShader;
62 class Shader;
63 class StrokeRenderer;
64
65 class Controller
66 {
67 public:
68         Controller();
69         ~Controller();
70
71         void setView(AppView *iView);
72         void setRenderMonitor(RenderMonitor *iRenderMonitor);
73         void setPassDiffuse(float *buf, int width, int height);
74         void setPassZ(float *buf, int width, int height);
75         void setContext(bContext *C);
76
77         //soc
78         void init_options();
79
80         int  LoadMesh(Render *re, SceneRenderLayer *srl);
81         int  Load3DSFile(const char *iFileName);
82         void CloseFile();
83         void ComputeViewMap();
84         void ComputeSteerableViewMap();
85         void saveSteerableViewMapImages();
86         void toggleEdgeTesselationNature(Nature::EdgeNature iNature);
87         void DrawStrokes();
88         void ResetRenderCount();
89         Render *RenderStrokes(Render *re, bool render);
90         void SwapStyleModules(unsigned i1, unsigned i2);
91         void InsertStyleModule(unsigned index, const char *iFileName);
92         void InsertStyleModule(unsigned index, const char *iName, struct Text *iText);
93         void AddStyleModule(const char *iFileName);
94         void RemoveStyleModule(unsigned index);
95         void ReloadStyleModule(unsigned index, const char * iFileName);
96         void Clear();
97         void ClearRootNode();
98         void DeleteWingedEdge();
99         void DeleteViewMap();
100         void toggleLayer(unsigned index, bool iDisplay);
101         void setModified(unsigned index, bool iMod);
102         void resetModified(bool iMod=false);
103         void updateCausalStyleModules(unsigned index);
104         void displayDensityCurves(int x, int y);
105
106         ViewEdge *SelectViewEdge(real x, real y);
107         FEdge *SelectFEdge(real x, real y);
108         NodeGroup *BuildRep(vector<ViewEdge*>::iterator vedges_begin, vector<ViewEdge*>::iterator vedges_end) ;
109
110 #if 0
111         NodeGroup *debugNode() {return _DebugNode;}
112         AppView *view() {return _pView;}
113         NodeGroup *debugScene() {return _DebugNode;}
114         Grid& grid() {return _Grid;}
115 #endif
116
117         void toggleVisibilityAlgo();
118         void setVisibilityAlgo(int algo);
119         int getVisibilityAlgo();
120
121         void setQuantitativeInvisibility(bool iBool); // if true, we compute quantitativeInvisibility
122         bool getQuantitativeInvisibility() const;
123         void setFaceSmoothness(bool iBool);
124         bool getFaceSmoothness() const;
125
126         void setComputeRidgesAndValleysFlag(bool b);
127         bool getComputeRidgesAndValleysFlag() const;
128         void setComputeSuggestiveContoursFlag(bool b);
129         bool getComputeSuggestiveContoursFlag() const;
130         void setComputeMaterialBoundariesFlag(bool b);
131         bool getComputeMaterialBoundariesFlag() const;
132
133         void setComputeSteerableViewMapFlag(bool iBool);
134         bool getComputeSteerableViewMapFlag() const;
135         void setCreaseAngle(real angle) {_creaseAngle = angle;}
136         real getCreaseAngle() const {return _creaseAngle;}
137         void setSphereRadius(real s) {_sphereRadius = s;}
138         real getSphereRadius() const {return _sphereRadius;}
139         void setSuggestiveContourKrDerivativeEpsilon(real dkr) {_suggestiveContourKrDerivativeEpsilon = dkr;}
140         real getSuggestiveContourKrDerivativeEpsilon() const {return _suggestiveContourKrDerivativeEpsilon;}
141
142         void setModelsDir(const string& dir);
143         string getModelsDir() const;
144         void setModulesDir(const string& dir);
145         string getModulesDir() const;
146
147         void resetInterpreter();
148
149 public:
150         // Viewmap data structure
151         ViewMap *_ViewMap;
152
153         // Canvas
154         AppCanvas *_Canvas;
155
156 private:
157         // Main Window:
158         //AppMainWindow *_pMainWindow;
159
160         // List of models currently loaded
161         vector<string> _ListOfModels;
162
163         // Current directories
164         //ConfigIO* _current_dirs;
165
166         //View
167         // 3D
168         AppView *_pView;
169
170         // 2D
171 #if 0
172         Viewer2DWindow *_pView2DWindow;
173         Viewer2D *_pView2D;
174 #endif
175
176         RenderMonitor *_pRenderMonitor;
177
178         //Model
179         // Drawing Structure
180         NodeGroup *_RootNode;
181
182         // Winged-Edge structure
183         WingedEdge *_winged_edge;
184
185         // Silhouette structure:
186 #if 0
187         std::vector<SShape*> _SShapes;
188         NodeGroup *_SRoot;
189 #endif
190
191         // Silhouette
192         NodeGroup *_SilhouetteNode;
193         NodeGroup *_ProjectedSilhouette;
194         NodeGroup *_VisibleProjectedSilhouette;
195
196         // more Debug info
197         NodeGroup *_DebugNode;
198
199         // debug
200         //NodeUser<ViewMap> *_ViewMapNode; // FIXME
201
202         // Chronometer:
203         Chronometer _Chrono;
204
205         // Progress Bar
206         ProgressBar *_ProgressBar;
207
208         // edges tesselation nature
209         int _edgeTesselationNature;
210
211         FastGrid _Grid;
212         //HashGrid _Grid;
213
214         BBox<Vec3r> _Scene3dBBox;
215         unsigned int _SceneNumFaces;
216         real _minEdgeSize;
217         real _EPSILON;
218         real _bboxDiag;
219
220         int _render_count;
221
222         //AppStyleWindow *_pStyleWindow;
223         //AppOptionsWindow *_pOptionsWindow;
224         //AppDensityCurvesWindow *_pDensityCurvesWindow;
225
226         ViewMapBuilder::visibility_algo _VisibilityAlgo;
227
228         // Script Interpreter
229         Interpreter *_inter;
230
231         string _help_index;
232         string _browser_cmd;
233
234         bool _EnableQI;
235         bool _EnableFaceSmoothness;
236         bool _ComputeRidges;
237         bool _ComputeSuggestive;
238         bool _ComputeMaterialBoundaries;
239         real _creaseAngle;
240         real _sphereRadius;
241         real _suggestiveContourKrDerivativeEpsilon;
242
243         bool _ComputeSteerableViewMap;
244
245         FEdgeXDetector edgeDetector;
246
247 #ifdef WITH_CXX_GUARDEDALLOC
248         MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Controller")
249 #endif
250 };
251
252 extern Controller *g_pController;
253
254 } /* namespace Freestyle */
255
256 #endif // __CONTROLLER_H__