Blender  V2.93
AppCanvas.cpp
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 
21 #include "AppCanvas.h"
22 #include "AppConfig.h"
23 #include "AppView.h"
24 #include "Controller.h"
25 
26 #include "../image/Image.h"
27 #include "../stroke/StrokeRenderer.h"
28 #include "../stroke/StyleModule.h"
29 #include "../system/TimeStamp.h"
30 
31 #include "../system/StringUtils.h"
32 namespace Freestyle {
33 
35 {
36  _pViewer = nullptr;
38 }
39 
41 {
42  _pViewer = iViewer;
43 }
44 
45 AppCanvas::AppCanvas(const AppCanvas &iBrother) : Canvas(iBrother)
46 {
47  _pViewer = iBrother._pViewer;
48 }
49 
51 {
52  _pViewer = nullptr;
53 }
54 
56 {
57  _pViewer = iViewer;
58 }
59 
60 int AppCanvas::width() const
61 {
62  return _pViewer->width();
63 }
64 
65 int AppCanvas::height() const
66 {
67  return _pViewer->height();
68 }
69 
71 {
72  return _pViewer->border();
73 }
74 
75 float AppCanvas::thickness() const
76 {
77  return _pViewer->thickness();
78 }
79 
81 {
82  return _pViewer->scene3DBBox();
83 }
84 
86 {
88 }
89 
91 {
92 #if 0
93  static bool firsttime = true;
94  if (firsttime) {
97  cerr << "unable to load stroke textures" << endl;
98  return;
99  }
100  }
101 #endif
102 }
103 
105 {
106  for (unsigned int i = 0; i < _StyleModules.size(); i++) {
107  if (!_StyleModules[i]->getDisplayed() || !_Layers[i]) {
108  continue;
109  }
110  _Layers[i]->ScaleThickness(thickness());
111  }
113 }
114 
116 {
117  Canvas::Erase();
118 }
119 
120 // Abstract
121 
122 void AppCanvas::readColorPixels(int x, int y, int w, int h, RGBImage &oImage) const
123 {
124  float *rgb = new float[3 * w * h];
125  memset(rgb, 0, sizeof(float[3]) * w * h);
126  int xsch = width();
127  int ysch = height();
128  if (_pass_diffuse.buf) {
129  int xmin = border().getMin().x();
130  int ymin = border().getMin().y();
131  int xmax = border().getMax().x();
132  int ymax = border().getMax().y();
133  int rectx = _pass_diffuse.width;
134  int recty = _pass_diffuse.height;
135  float xfac = ((float)rectx) / ((float)(xmax - xmin));
136  float yfac = ((float)recty) / ((float)(ymax - ymin));
137 #if 0
138  if (G.debug & G_DEBUG_FREESTYLE) {
139  printf("readColorPixels %d x %d @ (%d, %d) in %d x %d [%d x %d] -- %d x %d @ %d%%\n",
140  w,
141  h,
142  x,
143  y,
144  xsch,
145  ysch,
146  xmax - xmin,
147  ymax - ymin,
148  rectx,
149  recty,
150  (int)(xfac * 100.0f));
151  }
152 #endif
153  int ii, jj;
154  for (int j = 0; j < h; j++) {
155  jj = (int)((y - ymin + j) * yfac);
156  if (jj < 0 || jj >= recty) {
157  continue;
158  }
159  for (int i = 0; i < w; i++) {
160  ii = (int)((x - xmin + i) * xfac);
161  if (ii < 0 || ii >= rectx) {
162  continue;
163  }
164  memcpy(rgb + (w * j + i) * 3, _pass_diffuse.buf + (rectx * jj + ii) * 3, sizeof(float[3]));
165  }
166  }
167  }
168  oImage.setArray(rgb, xsch, ysch, w, h, x, y, false);
169 }
170 
171 void AppCanvas::readDepthPixels(int x, int y, int w, int h, GrayImage &oImage) const
172 {
173  float *z = new float[w * h];
174  memset(z, 0, sizeof(float) * w * h);
175  int xsch = width();
176  int ysch = height();
177  if (_pass_z.buf) {
178  int xmin = border().getMin().x();
179  int ymin = border().getMin().y();
180  int xmax = border().getMax().x();
181  int ymax = border().getMax().y();
182  int rectx = _pass_z.width;
183  int recty = _pass_z.height;
184  float xfac = ((float)rectx) / ((float)(xmax - xmin));
185  float yfac = ((float)recty) / ((float)(ymax - ymin));
186 #if 0
187  if (G.debug & G_DEBUG_FREESTYLE) {
188  printf("readDepthPixels %d x %d @ (%d, %d) in %d x %d [%d x %d] -- %d x %d @ %d%%\n",
189  w,
190  h,
191  x,
192  y,
193  xsch,
194  ysch,
195  xmax - xmin,
196  ymax - ymin,
197  rectx,
198  recty,
199  (int)(xfac * 100.0f));
200  }
201 #endif
202  int ii, jj;
203  for (int j = 0; j < h; j++) {
204  jj = (int)((y - ymin + j) * yfac);
205  if (jj < 0 || jj >= recty) {
206  continue;
207  }
208  for (int i = 0; i < w; i++) {
209  ii = (int)((x - xmin + i) * xfac);
210  if (ii < 0 || ii >= rectx) {
211  continue;
212  }
213  z[w * j + i] = _pass_z.buf[rectx * jj + ii];
214  }
215  }
216  }
217  oImage.setArray(z, xsch, ysch, w, h, x, y, false);
218 }
219 
221 {
222  if (_basic) {
223  iStroke->RenderBasic(_Renderer);
224  }
225  else {
226  iStroke->Render(_Renderer);
227  }
228 }
229 
231 {
232 }
233 
234 } /* namespace Freestyle */
Configuration file.
typedef float(TangentPoint)[2]
@ G_DEBUG_FREESTYLE
Definition: BKE_global.h:140
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:171
virtual BBox< Vec2i > border() const
Definition: AppCanvas.cpp:70
void setViewer(AppView *iViewer)
Definition: AppCanvas.cpp:55
virtual void Erase()
Definition: AppCanvas.cpp:115
virtual void RenderStroke(Stroke *)
Definition: AppCanvas.cpp:220
virtual void preDraw()
Definition: AppCanvas.cpp:85
virtual BBox< Vec3r > scene3DBBox() const
Definition: AppCanvas.cpp:80
virtual void postDraw()
Definition: AppCanvas.cpp:104
virtual void readColorPixels(int x, int y, int w, int h, RGBImage &oImage) const
Definition: AppCanvas.cpp:122
virtual float thickness() const
Definition: AppCanvas.cpp:75
virtual void init()
Definition: AppCanvas.cpp:90
virtual void update()
Definition: AppCanvas.cpp:230
AppView * _pViewer
Definition: AppCanvas.h:64
virtual ~AppCanvas()
Definition: AppCanvas.cpp:50
unsigned int height()
Definition: AppView.h:51
BBox< Vec2i > border()
Definition: AppView.h:55
float thickness()
Definition: AppView.h:59
BBox< Vec3r > scene3DBBox() const
Definition: AppView.h:220
unsigned int width()
Definition: AppView.h:47
virtual void Erase()
Definition: Canvas.cpp:161
virtual void postDraw()
Definition: Canvas.cpp:127
virtual void preDraw()
Definition: Canvas.cpp:96
std::deque< StrokeLayer * > _Layers
Definition: Canvas.h:79
std::deque< StyleModule * > _StyleModules
Definition: Canvas.h:80
static const char * _MapsPath
Definition: Canvas.h:86
StrokeRenderer * _Renderer
Definition: Canvas.h:83
static Path * getInstance()
Definition: AppConfig.cpp:66
const string & getMapsDir() const
Definition: AppConfig.h:78
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:812
void RenderBasic(const StrokeRenderer *iRenderer)
Definition: Stroke.cpp:820
inherits from class Rep
Definition: AppCanvas.cpp:32
static unsigned x[3]
Definition: RandGen.cpp:87
#define G(x, y, z)