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