Blender  V3.3
Canvas.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
10 #include <cstring>
11 #include <deque>
12 #include <map>
13 #include <vector>
14 
15 #include "StrokeLayer.h"
16 
17 #include "../geometry/BBox.h"
18 #include "../geometry/Geom.h"
19 
20 #include "../system/FreestyleConfig.h"
21 
22 #ifdef WITH_CXX_GUARDEDALLOC
23 # include "MEM_guardedalloc.h"
24 #endif
25 
26 namespace Freestyle {
27 
28 using namespace Geometry;
29 
30 struct ltstr {
31  bool operator()(const char *s1, const char *s2) const
32  {
33  return strcmp(s1, s2) < 0;
34  }
35 };
36 
37 class InformationMap;
38 class StrokeRenderer;
39 class ViewMap;
40 class ViewEdge;
41 class FEdge;
42 class RGBImage;
43 class GrayImage;
44 class QImage;
45 class ImagePyramid;
46 class SteerableViewMap;
47 class StyleModule;
48 
52 class Canvas {
53  public:
55  static Canvas *getInstance()
56  {
57  return _pInstance;
58  }
59 
60  typedef std::map<const char *, ImagePyramid *, ltstr> mapsMap;
61  static const int NB_STEERABLE_VIEWMAP = 5;
62 
63  protected:
64  static Canvas *_pInstance;
65  std::deque<StrokeLayer *> _Layers;
66  std::deque<StyleModule *> _StyleModules;
68 
72  static const char *_MapsPath;
74  bool _basic;
76 
77  public:
78  /* Builds the Canvas */
79  Canvas();
80  /* Copy constructor */
81  Canvas(const Canvas &iBrother);
82  /* Destructor */
83  virtual ~Canvas();
84 
85  /* operations that need to be done before a draw */
86  virtual void preDraw();
87 
88  /* Draw the canvas using the current shader */
89  virtual void Draw();
90 
91  /* operations that need to be done after a draw */
92  virtual void postDraw();
93 
94  /* Renders the created strokes */
95  virtual void Render(const StrokeRenderer *iRenderer);
96  /* Basic Renders the created strokes */
97  virtual void RenderBasic(const StrokeRenderer *iRenderer);
98  /* Renders a stroke */
99  virtual void RenderStroke(Stroke *iStroke) = 0;
100 
101  /* init the canvas */
102  virtual void init() = 0;
103 
104  /* Clears the Canvas (shaders stack, layers stack...) */
105  void Clear();
106 
107  /* Erases the layers */
108  virtual void Erase();
109 
110  /* Reads a pixel area from the canvas */
111  virtual void readColorPixels(int x, int y, int w, int h, RGBImage &oImage) const = 0;
112  /* Reads a depth pixel area from the canvas */
113  virtual void readDepthPixels(int x, int y, int w, int h, GrayImage &oImage) const = 0;
114 
115  /* update the canvas (display) */
116  virtual void update() = 0;
117 
118  /* checks whether the canvas is empty or not */
119  bool isEmpty() const
120  {
121  return (_Layers.empty());
122  }
123 
124  /* Maps management */
136  void loadMap(const char *iFileName,
137  const char *iMapName,
138  unsigned iNbLevels = 4,
139  float iSigma = 1.0f);
140 
154  float readMapPixel(const char *iMapName, int level, int x, int y);
155 
158  {
159  _steerableViewMap = iSVM;
160  }
161 
164  {
165  return _steerableViewMap;
166  }
167 
169  inline const FEdge *selectedFEdge() const
170  {
171  return _SelectedFEdge;
172  }
173 
175  {
176  return _SelectedFEdge;
177  }
178 
179  virtual int width() const = 0;
180  virtual int height() const = 0;
181  virtual BBox<Vec2i> border() const = 0;
182  virtual BBox<Vec3r> scene3DBBox() const = 0;
183 
184  inline const StrokeRenderer *renderer() const
185  {
186  return _Renderer;
187  }
188 
190  {
191  return _current_sm;
192  }
193 
194  virtual bool getRecordFlag() const
195  {
196  return false;
197  }
198 
199  inline int getStrokeCount() const
200  {
201  return stroke_count;
202  }
203 
205  inline void setSelectedFEdge(FEdge *iFEdge)
206  {
207  _SelectedFEdge = iFEdge;
208  }
209 
211  void PushBackStyleModule(StyleModule *iStyleModule);
212  void InsertStyleModule(unsigned index, StyleModule *iStyleModule);
213  void RemoveStyleModule(unsigned index);
214  void SwapStyleModules(unsigned i1, unsigned i2);
215  void ReplaceStyleModule(unsigned index, StyleModule *iStyleModule);
216  void setVisible(unsigned index, bool iVisible);
217 
218 #if 0
219  inline void setDensityMap(InformationMap<RGBImage> *iMap)
220  {
221  _DensityMap = iMap;
222  }
223 #endif
224 
225  inline void AddLayer(StrokeLayer *iLayer)
226  {
227  _Layers.push_back(iLayer);
228  }
229 
230  void resetModified(bool iMod = false);
231  void causalStyleModules(std::vector<unsigned> &vec, unsigned index = 0);
232  void setModified(unsigned index, bool iMod);
233 
234 #ifdef WITH_CXX_GUARDEDALLOC
235  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Canvas")
236 #endif
237 };
238 
239 } /* namespace Freestyle */
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint i1
Read Guarded memory(de)allocation.
struct Render Render
Definition: RE_pipeline.h:39
Class to define a layer of strokes.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
SteerableViewMap * getSteerableViewMap()
Definition: Canvas.h:163
virtual void readDepthPixels(int x, int y, int w, int h, GrayImage &oImage) const =0
FEdge * _SelectedFEdge
Definition: Canvas.h:67
std::deque< StrokeLayer * > _Layers
Definition: Canvas.h:65
SteerableViewMap * _steerableViewMap
Definition: Canvas.h:73
static Canvas * getInstance()
Definition: Canvas.h:55
void AddLayer(StrokeLayer *iLayer)
Definition: Canvas.h:225
std::map< const char *, ImagePyramid *, ltstr > mapsMap
Definition: Canvas.h:60
bool isEmpty() const
Definition: Canvas.h:119
virtual BBox< Vec2i > border() const =0
virtual bool getRecordFlag() const
Definition: Canvas.h:194
virtual void readColorPixels(int x, int y, int w, int h, RGBImage &oImage) const =0
virtual int height() const =0
StyleModule * _current_sm
Definition: Canvas.h:70
virtual int width() const =0
const StrokeRenderer * renderer() const
Definition: Canvas.h:184
std::deque< StyleModule * > _StyleModules
Definition: Canvas.h:66
void loadSteerableViewMap(SteerableViewMap *iSVM)
Definition: Canvas.h:157
virtual BBox< Vec3r > scene3DBBox() const =0
FEdge * selectedFEdge()
Definition: Canvas.h:174
StyleModule * getCurrentStyleModule()
Definition: Canvas.h:189
int stroke_count
Definition: Canvas.h:75
int getStrokeCount() const
Definition: Canvas.h:199
static const char * _MapsPath
Definition: Canvas.h:72
virtual void init()=0
StrokeRenderer * _Renderer
Definition: Canvas.h:69
virtual void RenderStroke(Stroke *iStroke)=0
static Canvas * _pInstance
Definition: Canvas.h:64
void setSelectedFEdge(FEdge *iFEdge)
Definition: Canvas.h:205
mapsMap _maps
Definition: Canvas.h:71
const FEdge * selectedFEdge() const
Definition: Canvas.h:169
virtual void update()=0
inherits from class Rep
Definition: AppCanvas.cpp:18
static unsigned x[3]
Definition: RandGen.cpp:73
bool operator()(const char *s1, const char *s2) const
Definition: Canvas.h:31