29 #include "../image/GaussianFilter.h"
30 #include "../image/Image.h"
31 #include "../image/ImagePyramid.h"
33 #include "../system/FreestyleConfig.h"
34 #include "../system/PseudoNoise.h"
35 #include "../system/TimeStamp.h"
37 #include "../view_map/SteerableViewMap.h"
51 Canvas *Canvas::_pInstance =
nullptr;
53 const char *Canvas::_MapsPath =
nullptr;
57 _SelectedFEdge =
nullptr;
61 _current_sm =
nullptr;
66 Canvas::Canvas(
const Canvas &iBrother)
88 for (mapsMap::iterator m = _maps.begin(), mend = _maps.end(); m != mend; ++m) {
93 delete _steerableViewMap;
96 void Canvas::preDraw()
102 if (_StyleModules.empty()) {
106 TimeStamp *timestamp = TimeStamp::instance();
108 for (
unsigned int i = 0; i < _StyleModules.size(); ++i) {
109 _current_sm = _StyleModules[i];
111 if (i < _Layers.size() && _Layers[i]) {
115 _Layers[i] = _StyleModules[i]->execute();
120 stroke_count += _Layers[i]->strokes_size();
127 void Canvas::postDraw()
134 if (!_Layers.empty()) {
135 for (deque<StrokeLayer *>::iterator sl = _Layers.begin(), slend = _Layers.end(); sl != slend;
144 if (!_StyleModules.empty()) {
145 for (deque<StyleModule *>::iterator s = _StyleModules.begin(), send = _StyleModules.end();
152 _StyleModules.clear();
154 if (_steerableViewMap) {
155 _steerableViewMap->Reset();
163 if (!_Layers.empty()) {
164 for (deque<StrokeLayer *>::iterator sl = _Layers.begin(), slend = _Layers.end(); sl != slend;
171 if (_steerableViewMap) {
172 _steerableViewMap->Reset();
182 _StyleModules.push_back(iStyleModule);
183 _Layers.push_back(layer);
186 void Canvas::InsertStyleModule(
unsigned index,
StyleModule *iStyleModule)
188 unsigned size = _StyleModules.size();
190 if ((_StyleModules.empty()) || (index ==
size)) {
191 _StyleModules.push_back(iStyleModule);
192 _Layers.push_back(layer);
195 _StyleModules.insert(_StyleModules.begin() + index, iStyleModule);
196 _Layers.insert(_Layers.begin() + index, layer);
199 void Canvas::RemoveStyleModule(
unsigned index)
202 if (!_StyleModules.empty()) {
203 for (deque<StyleModule *>::iterator s = _StyleModules.begin(), send = _StyleModules.end();
211 _StyleModules.erase(s);
217 if (!_Layers.empty()) {
219 for (deque<StrokeLayer *>::iterator sl = _Layers.begin(), slend = _Layers.end(); sl != slend;
233 void Canvas::SwapStyleModules(
unsigned i1,
unsigned i2)
236 tmp = _StyleModules[
i1];
237 _StyleModules[
i1] = _StyleModules[i2];
238 _StyleModules[i2] = tmp;
242 _Layers[
i1] = _Layers[i2];
246 void Canvas::ReplaceStyleModule(
unsigned index,
StyleModule *iStyleModule)
249 for (deque<StyleModule *>::iterator s = _StyleModules.begin(), send = _StyleModules.end();
262 void Canvas::setVisible(
unsigned index,
bool iVisible)
267 void Canvas::setModified(
unsigned index,
bool iMod)
269 _StyleModules[index]->setModified(iMod);
272 void Canvas::resetModified(
bool iMod )
274 unsigned int size = _StyleModules.size();
275 for (
unsigned int i = 0; i <
size; ++i) {
276 setModified(i, iMod);
280 void Canvas::causalStyleModules(vector<unsigned> &vec,
unsigned index)
282 unsigned int size = _StyleModules.size();
284 for (
unsigned int i = index; i <
size; ++i) {
285 if (_StyleModules[i]->getCausal()) {
293 for (
unsigned int i = 0; i < _StyleModules.size(); ++i) {
294 if (!_StyleModules[i]->getDisplayed() || !_Layers[i]) {
297 _Layers[i]->Render(iRenderer);
303 for (
unsigned int i = 0; i < _StyleModules.size(); ++i) {
304 if (!_StyleModules[i]->getDisplayed() || !_Layers[i]) {
307 _Layers[i]->RenderBasic(iRenderer);
311 void Canvas::loadMap(
const char *iFileName,
312 const char *iMapName,
313 unsigned int iNbLevels,
317 if (!_maps.empty()) {
318 mapsMap::iterator m = _maps.find(iMapName);
319 if (m != _maps.end()) {
333 filePath = _MapsPath;
334 filePath += iFileName;
337 filePath = iFileName;
342 QImage newMap(filePath.c_str());
343 if (newMap.isNull()) {
344 cerr <<
"Could not load image file " << filePath << endl;
351 if (qimg ==
nullptr) {
352 cerr <<
"Could not load image file " << filePath << endl;
359 if ((newMap.width() !=
width()) || (newMap.height() !=
height())) {
360 scaledImg = newMap.scaled(
width(),
height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
365 if ((qimg->x !=
width()) || (qimg->y !=
height())) {
372 if (newMap->depth() != 8) {
373 int w = newMap->width();
374 int h = newMap->height();
375 QImage *tmp =
new QImage(
w, h, 8);
376 for (
unsigned int y = 0;
y < h; ++
y) {
377 for (
unsigned int x = 0;
x <
w; ++
x) {
378 int c = qGray(newMap->pixel(
x,
y));
379 tmp->setPixel(
x,
y,
c);
390 int rowbytes =
w * 4;
394 for (
y = 0;
y < h; ++
y) {
395 for (
x = 0;
x <
w; ++
x) {
396 pix = (
char *)qimg->rect +
y * rowbytes +
x * 4;
397 float c = (pix[0] * 11 + pix[1] * 16 + pix[2] * 5) / 32;
406 for (
y = 0;
y < h; ++
y) {
407 for (
x = 0;
x <
w; ++
x) {
415 int ow = pyramid->
width(0);
416 int oh = pyramid->
height(0);
417 string base(iMapName);
429 for (
y = 0;
y < oh; ++
y) {
430 for (
x = 0;
x < ow; ++
x) {
433 pix = (
char *)qtmp->
rect +
y * rowbytes +
x * 4;
434 pix[0] = pix[1] = pix[2] =
c;
438 stringstream filename;
440 filename << i <<
".bmp";
442 IMB_saveiff(qtmp,
const_cast<char *
>(filename.str().c_str()), 0);
446 QImage *qtmp =
new QImage(
w, h, 32);
447 for (
y = 0;
y < h; ++
y) {
448 for (
x = 0;
x <
w; ++
x) {
450 qtmp->setPixel(
x,
y, qRgb(
c,
c,
c));
457 _maps[iMapName] = pyramid;
461 float Canvas::readMapPixel(
const char *iMapName,
int level,
int x,
int y)
465 cout <<
"readMapPixel warning: no map was loaded " << endl;
469 mapsMap::iterator m = _maps.find(iMapName);
470 if (m == _maps.end()) {
472 cout <<
"readMapPixel warning: no map was loaded with the name " << iMapName << endl;
477 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 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
_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 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
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.
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)