Blender V4.3
AppCanvas.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "AppCanvas.h"
10#include "AppConfig.h"
11#include "AppView.h"
12#include "Controller.h"
13
14#include "../image/Image.h"
17#include "../system/TimeStamp.h"
18
20namespace Freestyle {
21
27
29{
30 _pViewer = iViewer;
31}
32
33AppCanvas::AppCanvas(const AppCanvas &iBrother) : Canvas(iBrother)
34{
35 _pViewer = iBrother._pViewer;
36}
37
39{
40 _pViewer = nullptr;
41}
42
44{
45 _pViewer = iViewer;
46}
47
48int AppCanvas::width() const
49{
50 return _pViewer->width();
51}
52
53int AppCanvas::height() const
54{
55 return _pViewer->height();
56}
57
59{
60 return _pViewer->border();
61}
62
64{
65 return _pViewer->thickness();
66}
67
72
77
79{
80#if 0
81 static bool firsttime = true;
82 if (firsttime) {
85 cerr << "unable to load stroke textures" << endl;
86 return;
87 }
88 }
89#endif
90}
91
93{
94 for (uint i = 0; i < _StyleModules.size(); i++) {
95 if (!_StyleModules[i]->getDisplayed() || !_Layers[i]) {
96 continue;
97 }
98 _Layers[i]->ScaleThickness(thickness());
99 }
101}
102
104{
106}
107
108// Abstract
109
110void AppCanvas::readColorPixels(int x, int y, int w, int h, RGBImage &oImage) const
111{
112 float *rgb = new float[3 * w * h];
113 memset(rgb, 0, sizeof(float[3]) * w * h);
114 int xsch = width();
115 int ysch = height();
116 if (_pass_diffuse.buf) {
117 int xmin = border().getMin().x();
118 int ymin = border().getMin().y();
119 int xmax = border().getMax().x();
120 int ymax = border().getMax().y();
121 int rectx = _pass_diffuse.width;
122 int recty = _pass_diffuse.height;
123 float xfac = float(rectx) / float(xmax - xmin);
124 float yfac = float(recty) / float(ymax - ymin);
125#if 0
126 if (G.debug & G_DEBUG_FREESTYLE) {
127 printf("readColorPixels %d x %d @ (%d, %d) in %d x %d [%d x %d] -- %d x %d @ %d%%\n",
128 w,
129 h,
130 x,
131 y,
132 xsch,
133 ysch,
134 xmax - xmin,
135 ymax - ymin,
136 rectx,
137 recty,
138 int(xfac * 100.0f));
139 }
140#endif
141 int ii, jj;
142 for (int j = 0; j < h; j++) {
143 jj = int((y - ymin + j) * yfac);
144 if (jj < 0 || jj >= recty) {
145 continue;
146 }
147 for (int i = 0; i < w; i++) {
148 ii = int((x - xmin + i) * xfac);
149 if (ii < 0 || ii >= rectx) {
150 continue;
151 }
152 memcpy(rgb + (w * j + i) * 3, _pass_diffuse.buf + (rectx * jj + ii) * 3, sizeof(float[3]));
153 }
154 }
155 }
156 oImage.setArray(rgb, xsch, ysch, w, h, x, y, false);
157}
158
159void AppCanvas::readDepthPixels(int x, int y, int w, int h, GrayImage &oImage) const
160{
161 float *z = new float[w * h];
162 memset(z, 0, sizeof(float) * w * h);
163 int xsch = width();
164 int ysch = height();
165 if (_pass_z.buf) {
166 int xmin = border().getMin().x();
167 int ymin = border().getMin().y();
168 int xmax = border().getMax().x();
169 int ymax = border().getMax().y();
170 int rectx = _pass_z.width;
171 int recty = _pass_z.height;
172 float xfac = float(rectx) / float(xmax - xmin);
173 float yfac = float(recty) / float(ymax - ymin);
174#if 0
175 if (G.debug & G_DEBUG_FREESTYLE) {
176 printf("readDepthPixels %d x %d @ (%d, %d) in %d x %d [%d x %d] -- %d x %d @ %d%%\n",
177 w,
178 h,
179 x,
180 y,
181 xsch,
182 ysch,
183 xmax - xmin,
184 ymax - ymin,
185 rectx,
186 recty,
187 int(xfac * 100.0f));
188 }
189#endif
190 int ii, jj;
191 for (int j = 0; j < h; j++) {
192 jj = int((y - ymin + j) * yfac);
193 if (jj < 0 || jj >= recty) {
194 continue;
195 }
196 for (int i = 0; i < w; i++) {
197 ii = int((x - xmin + i) * xfac);
198 if (ii < 0 || ii >= rectx) {
199 continue;
200 }
201 z[w * j + i] = _pass_z.buf[rectx * jj + ii];
202 }
203 }
204 }
205 oImage.setArray(z, xsch, ysch, w, h, x, y, false);
206}
207
209{
210 if (_basic) {
211 iStroke->RenderBasic(_Renderer);
212 }
213 else {
214 iStroke->Render(_Renderer);
215 }
216}
217
219
220} /* namespace Freestyle */
Configuration file.
@ G_DEBUG_FREESTYLE
unsigned int uint
The spinal tap of the system.
Class to encapsulate an array of RGB or Gray level values.
String utilities.
Classes to render a stroke with OpenGL.
Class representing a style module.
Class defining a singleton used as timestamp.
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
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
virtual BBox< Vec2i > border() const
Definition AppCanvas.cpp:58
void setViewer(AppView *iViewer)
Definition AppCanvas.cpp:43
virtual void Erase()
virtual void RenderStroke(Stroke *)
virtual void preDraw()
Definition AppCanvas.cpp:73
virtual BBox< Vec3r > scene3DBBox() const
Definition AppCanvas.cpp:68
virtual void postDraw()
Definition AppCanvas.cpp:92
virtual void readColorPixels(int x, int y, int w, int h, RGBImage &oImage) const
virtual float thickness() const
Definition AppCanvas.cpp:63
virtual void init()
Definition AppCanvas.cpp:78
virtual void update()
BBox< Vec2i > border()
Definition AppView.h:43
float thickness()
Definition AppView.h:47
BBox< Vec3r > scene3DBBox() const
Definition AppView.h:208
virtual void Erase()
Definition Canvas.cpp:151
virtual void postDraw()
Definition Canvas.cpp:115
virtual void preDraw()
Definition Canvas.cpp:86
std::deque< StrokeLayer * > _Layers
Definition Canvas.h:67
std::deque< StyleModule * > _StyleModules
Definition Canvas.h:68
static const char * _MapsPath
Definition Canvas.h:74
StrokeRenderer * _Renderer
Definition Canvas.h:71
const string & getMapsDir() const
Definition AppConfig.h:66
static Path * getInstance()
Definition AppConfig.cpp:55
void setArray(float *lvl, uint width, uint height, uint sw, uint sh, uint x, uint y, bool copy=true)
Definition Image.h:378
virtual void setArray(float *rgb, uint width, uint height, uint sw, uint sh, uint x, uint y, bool copy=true)
Definition Image.h:272
void Render(const StrokeRenderer *iRenderer)
Definition Stroke.cpp:805
void RenderBasic(const StrokeRenderer *iRenderer)
Definition Stroke.cpp:813
#define printf
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
#define G(x, y, z)
inherits from class Rep
Definition AppCanvas.cpp:20