Blender  V3.3
AppCanvas.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "AppCanvas.h"
8 #include "AppConfig.h"
9 #include "AppView.h"
10 #include "Controller.h"
11 
12 #include "../image/Image.h"
13 #include "../stroke/StrokeRenderer.h"
14 #include "../stroke/StyleModule.h"
15 #include "../system/TimeStamp.h"
16 
17 #include "../system/StringUtils.h"
18 namespace Freestyle {
19 
21 {
22  _pViewer = nullptr;
24 }
25 
27 {
28  _pViewer = iViewer;
29 }
30 
31 AppCanvas::AppCanvas(const AppCanvas &iBrother) : Canvas(iBrother)
32 {
33  _pViewer = iBrother._pViewer;
34 }
35 
37 {
38  _pViewer = nullptr;
39 }
40 
42 {
43  _pViewer = iViewer;
44 }
45 
46 int AppCanvas::width() const
47 {
48  return _pViewer->width();
49 }
50 
51 int AppCanvas::height() const
52 {
53  return _pViewer->height();
54 }
55 
57 {
58  return _pViewer->border();
59 }
60 
61 float AppCanvas::thickness() const
62 {
63  return _pViewer->thickness();
64 }
65 
67 {
68  return _pViewer->scene3DBBox();
69 }
70 
72 {
74 }
75 
77 {
78 #if 0
79  static bool firsttime = true;
80  if (firsttime) {
83  cerr << "unable to load stroke textures" << endl;
84  return;
85  }
86  }
87 #endif
88 }
89 
91 {
92  for (unsigned int i = 0; i < _StyleModules.size(); i++) {
93  if (!_StyleModules[i]->getDisplayed() || !_Layers[i]) {
94  continue;
95  }
96  _Layers[i]->ScaleThickness(thickness());
97  }
99 }
100 
102 {
103  Canvas::Erase();
104 }
105 
106 // Abstract
107 
108 void AppCanvas::readColorPixels(int x, int y, int w, int h, RGBImage &oImage) const
109 {
110  float *rgb = new float[3 * w * h];
111  memset(rgb, 0, sizeof(float[3]) * w * h);
112  int xsch = width();
113  int ysch = height();
114  if (_pass_diffuse.buf) {
115  int xmin = border().getMin().x();
116  int ymin = border().getMin().y();
117  int xmax = border().getMax().x();
118  int ymax = border().getMax().y();
119  int rectx = _pass_diffuse.width;
120  int recty = _pass_diffuse.height;
121  float xfac = ((float)rectx) / ((float)(xmax - xmin));
122  float yfac = ((float)recty) / ((float)(ymax - ymin));
123 #if 0
124  if (G.debug & G_DEBUG_FREESTYLE) {
125  printf("readColorPixels %d x %d @ (%d, %d) in %d x %d [%d x %d] -- %d x %d @ %d%%\n",
126  w,
127  h,
128  x,
129  y,
130  xsch,
131  ysch,
132  xmax - xmin,
133  ymax - ymin,
134  rectx,
135  recty,
136  (int)(xfac * 100.0f));
137  }
138 #endif
139  int ii, jj;
140  for (int j = 0; j < h; j++) {
141  jj = (int)((y - ymin + j) * yfac);
142  if (jj < 0 || jj >= recty) {
143  continue;
144  }
145  for (int i = 0; i < w; i++) {
146  ii = (int)((x - xmin + i) * xfac);
147  if (ii < 0 || ii >= rectx) {
148  continue;
149  }
150  memcpy(rgb + (w * j + i) * 3, _pass_diffuse.buf + (rectx * jj + ii) * 3, sizeof(float[3]));
151  }
152  }
153  }
154  oImage.setArray(rgb, xsch, ysch, w, h, x, y, false);
155 }
156 
157 void AppCanvas::readDepthPixels(int x, int y, int w, int h, GrayImage &oImage) const
158 {
159  float *z = new float[w * h];
160  memset(z, 0, sizeof(float) * w * h);
161  int xsch = width();
162  int ysch = height();
163  if (_pass_z.buf) {
164  int xmin = border().getMin().x();
165  int ymin = border().getMin().y();
166  int xmax = border().getMax().x();
167  int ymax = border().getMax().y();
168  int rectx = _pass_z.width;
169  int recty = _pass_z.height;
170  float xfac = ((float)rectx) / ((float)(xmax - xmin));
171  float yfac = ((float)recty) / ((float)(ymax - ymin));
172 #if 0
173  if (G.debug & G_DEBUG_FREESTYLE) {
174  printf("readDepthPixels %d x %d @ (%d, %d) in %d x %d [%d x %d] -- %d x %d @ %d%%\n",
175  w,
176  h,
177  x,
178  y,
179  xsch,
180  ysch,
181  xmax - xmin,
182  ymax - ymin,
183  rectx,
184  recty,
185  (int)(xfac * 100.0f));
186  }
187 #endif
188  int ii, jj;
189  for (int j = 0; j < h; j++) {
190  jj = (int)((y - ymin + j) * yfac);
191  if (jj < 0 || jj >= recty) {
192  continue;
193  }
194  for (int i = 0; i < w; i++) {
195  ii = (int)((x - xmin + i) * xfac);
196  if (ii < 0 || ii >= rectx) {
197  continue;
198  }
199  z[w * j + i] = _pass_z.buf[rectx * jj + ii];
200  }
201  }
202  }
203  oImage.setArray(z, xsch, ysch, w, h, x, y, false);
204 }
205 
207 {
208  if (_basic) {
209  iStroke->RenderBasic(_Renderer);
210  }
211  else {
212  iStroke->Render(_Renderer);
213  }
214 }
215 
217 {
218 }
219 
220 } /* namespace Freestyle */
Configuration file.
typedef float(TangentPoint)[2]
@ G_DEBUG_FREESTYLE
Definition: BKE_global.h:181
The spinal tap of the system.
_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 GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
_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
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
virtual void readDepthPixels(int x, int y, int w, int h, GrayImage &oImage) const
Definition: AppCanvas.cpp:157
virtual BBox< Vec2i > border() const
Definition: AppCanvas.cpp:56
void setViewer(AppView *iViewer)
Definition: AppCanvas.cpp:41
virtual void Erase()
Definition: AppCanvas.cpp:101
virtual void RenderStroke(Stroke *)
Definition: AppCanvas.cpp:206
virtual void preDraw()
Definition: AppCanvas.cpp:71
virtual BBox< Vec3r > scene3DBBox() const
Definition: AppCanvas.cpp:66
virtual void postDraw()
Definition: AppCanvas.cpp:90
virtual void readColorPixels(int x, int y, int w, int h, RGBImage &oImage) const
Definition: AppCanvas.cpp:108
virtual float thickness() const
Definition: AppCanvas.cpp:61
virtual void init()
Definition: AppCanvas.cpp:76
virtual void update()
Definition: AppCanvas.cpp:216
AppView * _pViewer
Definition: AppCanvas.h:50
virtual ~AppCanvas()
Definition: AppCanvas.cpp:36
unsigned int height()
Definition: AppView.h:37
BBox< Vec2i > border()
Definition: AppView.h:41
float thickness()
Definition: AppView.h:45
BBox< Vec3r > scene3DBBox() const
Definition: AppView.h:206
unsigned int width()
Definition: AppView.h:33
virtual void Erase()
Definition: Canvas.cpp:147
virtual void postDraw()
Definition: Canvas.cpp:113
virtual void preDraw()
Definition: Canvas.cpp:82
std::deque< StrokeLayer * > _Layers
Definition: Canvas.h:65
std::deque< StyleModule * > _StyleModules
Definition: Canvas.h:66
static const char * _MapsPath
Definition: Canvas.h:72
StrokeRenderer * _Renderer
Definition: Canvas.h:69
static Path * getInstance()
Definition: AppConfig.cpp:52
const string & getMapsDir() const
Definition: AppConfig.h:64
void setArray(float *lvl, unsigned width, unsigned height, unsigned sw, unsigned sh, unsigned x, unsigned y, bool copy=true)
virtual void setArray(float *rgb, unsigned width, unsigned height, unsigned sw, unsigned sh, unsigned x, unsigned y, bool copy=true)
void Render(const StrokeRenderer *iRenderer)
Definition: Stroke.cpp:798
void RenderBasic(const StrokeRenderer *iRenderer)
Definition: Stroke.cpp:806
#define G(x, y, z)
inherits from class Rep
Definition: AppCanvas.cpp:18
static unsigned x[3]
Definition: RandGen.cpp:73
static const pxr::TfToken rgb("rgb", pxr::TfToken::Immortal)