Blender  V2.93
Canvas.h
Go to the documentation of this file.
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 
24 #include <cstring>
25 #include <deque>
26 #include <map>
27 #include <vector>
28 
29 #include "StrokeLayer.h"
30 
31 #include "../geometry/BBox.h"
32 #include "../geometry/Geom.h"
33 
34 #include "../system/FreestyleConfig.h"
35 
36 #ifdef WITH_CXX_GUARDEDALLOC
37 # include "MEM_guardedalloc.h"
38 #endif
39 
40 namespace Freestyle {
41 
42 using namespace Geometry;
43 
44 struct ltstr {
45  bool operator()(const char *s1, const char *s2) const
46  {
47  return strcmp(s1, s2) < 0;
48  }
49 };
50 
51 class InformationMap;
52 class StrokeRenderer;
53 class ViewMap;
54 class ViewEdge;
55 class FEdge;
56 class RGBImage;
57 class GrayImage;
58 class QImage;
59 class ImagePyramid;
60 class SteerableViewMap;
61 class StyleModule;
62 
66 class Canvas {
67  public:
69  static Canvas *getInstance()
70  {
71  return _pInstance;
72  }
73 
74  typedef std::map<const char *, ImagePyramid *, ltstr> mapsMap;
75  static const int NB_STEERABLE_VIEWMAP = 5;
76 
77  protected:
78  static Canvas *_pInstance;
79  std::deque<StrokeLayer *> _Layers;
80  std::deque<StyleModule *> _StyleModules;
82 
86  static const char *_MapsPath;
88  bool _basic;
90 
91  public:
92  /* Builds the Canvas */
93  Canvas();
94  /* Copy constructor */
95  Canvas(const Canvas &iBrother);
96  /* Destructor */
97  virtual ~Canvas();
98 
99  /* operations that need to be done before a draw */
100  virtual void preDraw();
101 
102  /* Draw the canvas using the current shader */
103  virtual void Draw();
104 
105  /* operations that need to be done after a draw */
106  virtual void postDraw();
107 
108  /* Renders the created strokes */
109  virtual void Render(const StrokeRenderer *iRenderer);
110  /* Basic Renders the created strokes */
111  virtual void RenderBasic(const StrokeRenderer *iRenderer);
112  /* Renders a stroke */
113  virtual void RenderStroke(Stroke *iStroke) = 0;
114 
115  /* init the canvas */
116  virtual void init() = 0;
117 
118  /* Clears the Canvas (shaders stack, layers stack...) */
119  void Clear();
120 
121  /* Erases the layers */
122  virtual void Erase();
123 
124  /* Reads a pixel area from the canvas */
125  virtual void readColorPixels(int x, int y, int w, int h, RGBImage &oImage) const = 0;
126  /* Reads a depth pixel area from the canvas */
127  virtual void readDepthPixels(int x, int y, int w, int h, GrayImage &oImage) const = 0;
128 
129  /* update the canvas (display) */
130  virtual void update() = 0;
131 
132  /* checks whether the canvas is empty or not */
133  bool isEmpty() const
134  {
135  return (_Layers.empty());
136  }
137 
138  /* Maps management */
150  void loadMap(const char *iFileName,
151  const char *iMapName,
152  unsigned iNbLevels = 4,
153  float iSigma = 1.0f);
154 
168  float readMapPixel(const char *iMapName, int level, int x, int y);
169 
172  {
173  _steerableViewMap = iSVM;
174  }
175 
178  {
179  return _steerableViewMap;
180  }
181 
183  inline const FEdge *selectedFEdge() const
184  {
185  return _SelectedFEdge;
186  }
187 
189  {
190  return _SelectedFEdge;
191  }
192 
193  virtual int width() const = 0;
194  virtual int height() const = 0;
195  virtual BBox<Vec2i> border() const = 0;
196  virtual BBox<Vec3r> scene3DBBox() const = 0;
197 
198  inline const StrokeRenderer *renderer() const
199  {
200  return _Renderer;
201  }
202 
204  {
205  return _current_sm;
206  }
207 
208  virtual bool getRecordFlag() const
209  {
210  return false;
211  }
212 
213  inline int getStrokeCount() const
214  {
215  return stroke_count;
216  }
217 
219  inline void setSelectedFEdge(FEdge *iFEdge)
220  {
221  _SelectedFEdge = iFEdge;
222  }
223 
225  void PushBackStyleModule(StyleModule *iStyleModule);
226  void InsertStyleModule(unsigned index, StyleModule *iStyleModule);
227  void RemoveStyleModule(unsigned index);
228  void SwapStyleModules(unsigned i1, unsigned i2);
229  void ReplaceStyleModule(unsigned index, StyleModule *iStyleModule);
230  void setVisible(unsigned index, bool iVisible);
231 
232 #if 0
233  inline void setDensityMap(InformationMap<RGBImage> *iMap)
234  {
235  _DensityMap = iMap;
236  }
237 #endif
238 
239  inline void AddLayer(StrokeLayer *iLayer)
240  {
241  _Layers.push_back(iLayer);
242  }
243 
244  void resetModified(bool iMod = false);
245  void causalStyleModules(std::vector<unsigned> &vec, unsigned index = 0);
246  void setModified(unsigned index, bool iMod);
247 
248 #ifdef WITH_CXX_GUARDEDALLOC
249  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Canvas")
250 #endif
251 };
252 
253 } /* 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 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
_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
Read Guarded memory(de)allocation.
struct Render Render
Definition: RE_pipeline.h:54
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:177
virtual void readDepthPixels(int x, int y, int w, int h, GrayImage &oImage) const =0
FEdge * _SelectedFEdge
Definition: Canvas.h:81
std::deque< StrokeLayer * > _Layers
Definition: Canvas.h:79
SteerableViewMap * _steerableViewMap
Definition: Canvas.h:87
static Canvas * getInstance()
Definition: Canvas.h:69
void AddLayer(StrokeLayer *iLayer)
Definition: Canvas.h:239
std::map< const char *, ImagePyramid *, ltstr > mapsMap
Definition: Canvas.h:74
bool isEmpty() const
Definition: Canvas.h:133
virtual BBox< Vec2i > border() const =0
virtual bool getRecordFlag() const
Definition: Canvas.h:208
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:84
virtual int width() const =0
const StrokeRenderer * renderer() const
Definition: Canvas.h:198
std::deque< StyleModule * > _StyleModules
Definition: Canvas.h:80
void loadSteerableViewMap(SteerableViewMap *iSVM)
Definition: Canvas.h:171
virtual BBox< Vec3r > scene3DBBox() const =0
FEdge * selectedFEdge()
Definition: Canvas.h:188
StyleModule * getCurrentStyleModule()
Definition: Canvas.h:203
int stroke_count
Definition: Canvas.h:89
int getStrokeCount() const
Definition: Canvas.h:213
static const char * _MapsPath
Definition: Canvas.h:86
virtual void init()=0
StrokeRenderer * _Renderer
Definition: Canvas.h:83
virtual void RenderStroke(Stroke *iStroke)=0
static Canvas * _pInstance
Definition: Canvas.h:78
void setSelectedFEdge(FEdge *iFEdge)
Definition: Canvas.h:219
mapsMap _maps
Definition: Canvas.h:85
const FEdge * selectedFEdge() const
Definition: Canvas.h:183
virtual void update()=0
inherits from class Rep
Definition: AppCanvas.cpp:32
static unsigned x[3]
Definition: RandGen.cpp:87
bool operator()(const char *s1, const char *s2) const
Definition: Canvas.h:45