15 #include "../image/GaussianFilter.h"
16 #include "../image/Image.h"
17 #include "../image/ImagePyramid.h"
19 #include "../system/FreestyleConfig.h"
20 #include "../system/PseudoNoise.h"
21 #include "../system/TimeStamp.h"
23 #include "../view_map/SteerableViewMap.h"
37 Canvas *Canvas::_pInstance =
nullptr;
39 const char *Canvas::_MapsPath =
nullptr;
43 _SelectedFEdge =
nullptr;
47 _current_sm =
nullptr;
52 Canvas::Canvas(
const Canvas &iBrother)
74 for (mapsMap::iterator m = _maps.begin(), mend = _maps.end(); m != mend; ++m) {
79 delete _steerableViewMap;
82 void Canvas::preDraw()
88 if (_StyleModules.empty()) {
94 for (
unsigned int i = 0; i < _StyleModules.size(); ++i) {
95 _current_sm = _StyleModules[i];
97 if (i < _Layers.size() && _Layers[i]) {
101 _Layers[i] = _StyleModules[i]->execute();
106 stroke_count += _Layers[i]->strokes_size();
113 void Canvas::postDraw()
120 if (!_Layers.empty()) {
121 for (deque<StrokeLayer *>::iterator sl = _Layers.begin(), slend = _Layers.end(); sl != slend;
130 if (!_StyleModules.empty()) {
131 for (deque<StyleModule *>::iterator s = _StyleModules.begin(), send = _StyleModules.end();
138 _StyleModules.clear();
140 if (_steerableViewMap) {
141 _steerableViewMap->Reset();
149 if (!_Layers.empty()) {
150 for (deque<StrokeLayer *>::iterator sl = _Layers.begin(), slend = _Layers.end(); sl != slend;
157 if (_steerableViewMap) {
158 _steerableViewMap->Reset();
168 _StyleModules.push_back(iStyleModule);
169 _Layers.push_back(layer);
172 void Canvas::InsertStyleModule(
unsigned index,
StyleModule *iStyleModule)
174 unsigned size = _StyleModules.size();
176 if ((_StyleModules.empty()) || (index ==
size)) {
177 _StyleModules.push_back(iStyleModule);
178 _Layers.push_back(layer);
181 _StyleModules.insert(_StyleModules.begin() + index, iStyleModule);
182 _Layers.insert(_Layers.begin() + index, layer);
185 void Canvas::RemoveStyleModule(
unsigned index)
188 if (!_StyleModules.empty()) {
189 for (deque<StyleModule *>::iterator s = _StyleModules.begin(), send = _StyleModules.end();
197 _StyleModules.erase(s);
203 if (!_Layers.empty()) {
205 for (deque<StrokeLayer *>::iterator sl = _Layers.begin(), slend = _Layers.end(); sl != slend;
219 void Canvas::SwapStyleModules(
unsigned i1,
unsigned i2)
222 tmp = _StyleModules[
i1];
223 _StyleModules[
i1] = _StyleModules[i2];
224 _StyleModules[i2] = tmp;
228 _Layers[
i1] = _Layers[i2];
232 void Canvas::ReplaceStyleModule(
unsigned index,
StyleModule *iStyleModule)
235 for (deque<StyleModule *>::iterator s = _StyleModules.begin(), send = _StyleModules.end();
248 void Canvas::setVisible(
unsigned index,
bool iVisible)
253 void Canvas::setModified(
unsigned index,
bool iMod)
255 _StyleModules[index]->setModified(iMod);
258 void Canvas::resetModified(
bool iMod )
260 unsigned int size = _StyleModules.size();
261 for (
unsigned int i = 0; i <
size; ++i) {
262 setModified(i, iMod);
266 void Canvas::causalStyleModules(vector<unsigned> &vec,
unsigned index)
268 unsigned int size = _StyleModules.size();
270 for (
unsigned int i = index; i <
size; ++i) {
271 if (_StyleModules[i]->getCausal()) {
279 for (
unsigned int i = 0; i < _StyleModules.size(); ++i) {
280 if (!_StyleModules[i]->getDisplayed() || !_Layers[i]) {
283 _Layers[i]->Render(iRenderer);
289 for (
unsigned int i = 0; i < _StyleModules.size(); ++i) {
290 if (!_StyleModules[i]->getDisplayed() || !_Layers[i]) {
293 _Layers[i]->RenderBasic(iRenderer);
297 void Canvas::loadMap(
const char *iFileName,
298 const char *iMapName,
299 unsigned int iNbLevels,
303 if (!_maps.empty()) {
304 mapsMap::iterator m = _maps.find(iMapName);
305 if (m != _maps.end()) {
319 filePath = _MapsPath;
320 filePath += iFileName;
323 filePath = iFileName;
328 QImage newMap(filePath.c_str());
329 if (newMap.isNull()) {
330 cerr <<
"Could not load image file " << filePath << endl;
337 if (qimg ==
nullptr) {
338 cerr <<
"Could not load image file " << filePath << endl;
345 if ((newMap.width() !=
width()) || (newMap.height() !=
height())) {
346 scaledImg = newMap.scaled(
width(),
height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
351 if ((qimg->x !=
width()) || (qimg->y !=
height())) {
358 if (newMap->depth() != 8) {
359 int w = newMap->width();
360 int h = newMap->height();
361 QImage *tmp =
new QImage(
w, h, 8);
362 for (
unsigned int y = 0;
y < h; ++
y) {
363 for (
unsigned int x = 0;
x <
w; ++
x) {
364 int c = qGray(newMap->pixel(
x,
y));
365 tmp->setPixel(
x,
y,
c);
376 int rowbytes =
w * 4;
380 for (
y = 0;
y < h; ++
y) {
381 for (
x = 0;
x <
w; ++
x) {
382 pix = (
char *)qimg->rect +
y * rowbytes +
x * 4;
383 float c = (pix[0] * 11 + pix[1] * 16 + pix[2] * 5) / 32;
392 for (
y = 0;
y < h; ++
y) {
393 for (
x = 0;
x <
w; ++
x) {
401 int ow = pyramid->
width(0);
402 int oh = pyramid->
height(0);
403 string base(iMapName);
415 for (
y = 0;
y < oh; ++
y) {
416 for (
x = 0;
x < ow; ++
x) {
419 pix = (
char *)qtmp->
rect +
y * rowbytes +
x * 4;
420 pix[0] = pix[1] = pix[2] =
c;
424 stringstream filename;
426 filename << i <<
".bmp";
428 IMB_saveiff(qtmp,
const_cast<char *
>(filename.str().c_str()), 0);
432 QImage *qtmp =
new QImage(
w, h, 32);
433 for (
y = 0;
y < h; ++
y) {
434 for (
x = 0;
x <
w; ++
x) {
436 qtmp->setPixel(
x,
y, qRgb(
c,
c,
c));
443 _maps[iMapName] = pyramid;
447 float Canvas::readMapPixel(
const char *iMapName,
int level,
int x,
int y)
451 cout <<
"readMapPixel warning: no map was loaded " << endl;
455 mapsMap::iterator m = _maps.find(iMapName);
456 if (m == _maps.end()) {
458 cout <<
"readMapPixel warning: no map was loaded with the name " << iMapName << endl;
463 if ((
x < 0) || (
x >= pyramid->
width()) || (
y < 0) || (
y >= pyramid->
height())) {
Class to define a canvas designed to draw style modules.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_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
_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 width
bool IMB_scaleImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy)
struct ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
struct ImBuf * IMB_dupImBuf(const struct ImBuf *ibuf1)
struct ImBuf * IMB_loadiffname(const char *filepath, int flags, char colorspace[IM_MAX_SPACE])
bool IMB_saveiff(struct ImBuf *ibuf, const char *filepath, int flags)
Contains defines and structs used throughout the imbuf module.
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object instance
Classes to render a stroke with OpenGL.
Class representing a style module.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
SteerableViewMap * _steerableViewMap
StyleModule * _current_sm
StrokeRenderer * _Renderer
float getSmoothedPixel(Map *map, int x, int y)
float pixel(unsigned x, unsigned y) const
void setPixel(unsigned x, unsigned y, float v)
virtual float pixel(int x, int y, int level=0)
int getNumberOfLevels() const
virtual int height(int level=0)
virtual int width(int level=0)
void setDisplayed(bool b=true)
static void update(bNodeTree *ntree)