OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * ***** BEGIN GPL LICENSE BLOCK ***** |
| 3 * |
| 4 * This program is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU General Public License |
| 6 * as published by the Free Software Foundation; either version 2 |
| 7 * of the License, or (at your option) any later version. |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with this program; if not, write to the Free Software Foundation, |
| 16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 * |
| 18 * The Original Code is Copyright (C) 2010 Blender Foundation. |
| 19 * All rights reserved. |
| 20 * |
| 21 * The Original Code is: all of this file. |
| 22 * |
| 23 * Contributor(s): none yet. |
| 24 * |
| 25 * ***** END GPL LICENSE BLOCK ***** |
| 26 */ |
| 27 |
| 28 /** \file blender/freestyle/intern/application/AppCanvas.cpp |
| 29 * \ingroup freestyle |
| 30 */ |
| 31 |
| 32 #include "Controller.h" |
| 33 #include "AppView.h" |
| 34 #include "../image/Image.h" |
| 35 #include "../system/TimeStamp.h" |
| 36 #include "../stroke/StrokeRenderer.h" |
| 37 #include "AppCanvas.h" |
| 38 #include "AppConfig.h" |
| 39 #include "../stroke/StyleModule.h" |
| 40 |
| 41 #include "../system/StringUtils.h" |
| 42 |
| 43 AppCanvas::AppCanvas() |
| 44 :Canvas() |
| 45 { |
| 46 _pViewer = 0; |
| 47 _MapsPath = StringUtils::toAscii(Config::Path::getInstance()->getMapsDir
()).c_str(); |
| 48 } |
| 49 |
| 50 AppCanvas::AppCanvas(AppView* iViewer) |
| 51 :Canvas() |
| 52 { |
| 53 _pViewer = iViewer; |
| 54 } |
| 55 |
| 56 AppCanvas::AppCanvas(const AppCanvas& iBrother) |
| 57 :Canvas(iBrother) |
| 58 { |
| 59 _pViewer = iBrother._pViewer; |
| 60 } |
| 61 |
| 62 AppCanvas::~AppCanvas() |
| 63 { |
| 64 _pViewer = 0; |
| 65 } |
| 66 |
| 67 void AppCanvas::setViewer(AppView *iViewer) |
| 68 { |
| 69 _pViewer = iViewer; |
| 70 } |
| 71 |
| 72 int AppCanvas::width() const· |
| 73 { |
| 74 return _pViewer->width(); |
| 75 } |
| 76 |
| 77 int AppCanvas::height() const |
| 78 { |
| 79 return _pViewer->height(); |
| 80 } |
| 81 |
| 82 BBox<Vec2i> AppCanvas::border() const |
| 83 { |
| 84 return _pViewer->border(); |
| 85 } |
| 86 |
| 87 float AppCanvas::thickness() const |
| 88 { |
| 89 return _pViewer->thickness(); |
| 90 } |
| 91 |
| 92 BBox<Vec3r> AppCanvas::scene3DBBox() const· |
| 93 { |
| 94 return _pViewer->scene3DBBox(); |
| 95 } |
| 96 |
| 97 void AppCanvas::preDraw() |
| 98 { |
| 99 Canvas::preDraw(); |
| 100 } |
| 101 |
| 102 void AppCanvas::init() |
| 103 { |
| 104 #if 0 |
| 105 static bool firsttime = true; |
| 106 if (firsttime) { |
| 107 _Renderer = new BlenderStrokeRenderer; |
| 108 if(!StrokeRenderer::loadTextures()) { |
| 109 cerr << "unable to load stroke textures" << endl; |
| 110 return; |
| 111 } |
| 112 } |
| 113 #endif |
| 114 } |
| 115 |
| 116 void AppCanvas::postDraw() |
| 117 { |
| 118 for (unsigned int i = 0; i < _StyleModules.size(); i++) { |
| 119 if(!_StyleModules[i]->getDisplayed() || !_Layers[i]) |
| 120 continue; |
| 121 _Layers[i]->ScaleThickness(thickness()); |
| 122 } |
| 123 Canvas::postDraw(); |
| 124 } |
| 125 |
| 126 void AppCanvas::Erase() |
| 127 { |
| 128 Canvas::Erase(); |
| 129 } |
| 130 |
| 131 // Abstract |
| 132 |
| 133 void AppCanvas::readColorPixels(int x,int y,int w, int h, RGBImage& oImage) cons
t |
| 134 { |
| 135 float *rgb = new float[3*w*h]; |
| 136 memset(rgb, 0, sizeof(float) * 3 * w * h); |
| 137 int xsch = width(); |
| 138 int ysch = height(); |
| 139 if (_pass_diffuse.buf) { |
| 140 int xmin = border().getMin().x(); |
| 141 int ymin = border().getMin().y(); |
| 142 int xmax = border().getMax().x(); |
| 143 int ymax = border().getMax().y(); |
| 144 int rectx = _pass_z.width; |
| 145 int recty = _pass_z.height; |
| 146 float xfac = ((float)rectx) / ((float)(xmax - xmin)); |
| 147 float yfac = ((float)recty) / ((float)(ymax - ymin)); |
| 148 #if 0 |
| 149 if (G.debug & G_DEBUG_FREESTYLE) { |
| 150 printf("readColorPixels %d x %d @ (%d, %d) in %d x %d [%
d x %d] -- %d x %d @ %d%%\n", w, h, x, y, xsch, ysch, |
| 151 xmax - xmin, ymax - ymin, rectx, recty, (int)(xfa
c * 100.0f)); |
| 152 } |
| 153 #endif |
| 154 int ii, jj; |
| 155 for (int j = 0; j < h; j++) { |
| 156 jj = (int)((y - ymin + j) * yfac); |
| 157 if (jj < 0 || jj >= recty) |
| 158 continue; |
| 159 for (int i = 0; i < w; i++) { |
| 160 ii = (int)((x - xmin + i) * xfac); |
| 161 if (ii < 0 || ii >= rectx) |
| 162 continue; |
| 163 memcpy(rgb + (w * j + i) * 3, _pass_diffuse.buf
+ (rectx * jj + ii) * 3, sizeof(float) * 3); |
| 164 } |
| 165 } |
| 166 } |
| 167 oImage.setArray(rgb, xsch, ysch, w, h, x, y, false); |
| 168 } |
| 169 |
| 170 void AppCanvas::readDepthPixels(int x,int y,int w, int h, GrayImage& oImage) con
st |
| 171 { |
| 172 float *z = new float[w*h]; |
| 173 memset(z, 0, sizeof(float) * w * h); |
| 174 int xsch = width(); |
| 175 int ysch = height(); |
| 176 if (_pass_z.buf) { |
| 177 int xmin = border().getMin().x(); |
| 178 int ymin = border().getMin().y(); |
| 179 int xmax = border().getMax().x(); |
| 180 int ymax = border().getMax().y(); |
| 181 int rectx = _pass_z.width; |
| 182 int recty = _pass_z.height; |
| 183 float xfac = ((float)rectx) / ((float)(xmax - xmin)); |
| 184 float yfac = ((float)recty) / ((float)(ymax - ymin)); |
| 185 #if 0 |
| 186 if (G.debug & G_DEBUG_FREESTYLE) { |
| 187 printf("readDepthPixels %d x %d @ (%d, %d) in %d x %d [%
d x %d] -- %d x %d @ %d%%\n", w, h, x, y, xsch, ysch, |
| 188 xmax - xmin, ymax - ymin, rectx, recty, (int)(xfa
c * 100.0f)); |
| 189 } |
| 190 #endif |
| 191 int ii, jj; |
| 192 for (int j = 0; j < h; j++) { |
| 193 jj = (int)((y - ymin + j) * yfac); |
| 194 if (jj < 0 || jj >= recty) |
| 195 continue; |
| 196 for (int i = 0; i < w; i++) { |
| 197 ii = (int)((x - xmin + i) * xfac); |
| 198 if (ii < 0 || ii >= rectx) |
| 199 continue; |
| 200 z[w * j + i] = _pass_z.buf[rectx * jj + ii]; |
| 201 } |
| 202 } |
| 203 } |
| 204 oImage.setArray(z, xsch, ysch, w, h, x, y, false); |
| 205 } |
| 206 |
| 207 void AppCanvas::RenderStroke(Stroke *iStroke) |
| 208 { |
| 209 if(_basic) |
| 210 iStroke->RenderBasic(_Renderer); |
| 211 else |
| 212 iStroke->Render(_Renderer); |
| 213 } |
| 214 |
| 215 |
| 216 void AppCanvas::update() |
| 217 { |
| 218 } |
OLD | NEW |