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 #ifndef __FREESTYLE_CANVAS_H__ |
| 29 #define __FREESTYLE_CANVAS_H__ |
| 30 |
| 31 /** \file blender/freestyle/intern/stroke/Canvas.h |
| 32 * \ingroup freestyle |
| 33 * \brief Class to define a canvas designed to draw style modules |
| 34 * \author Stephane Grabli |
| 35 * \date 20/10/2002 |
| 36 */ |
| 37 |
| 38 #include <cstring> |
| 39 #include <deque> |
| 40 #include <map> |
| 41 #include <vector> |
| 42 |
| 43 #include "StrokeLayer.h" |
| 44 |
| 45 #include "../geometry/BBox.h" |
| 46 #include "../geometry/Geom.h" |
| 47 |
| 48 #include "../system/FreestyleConfig.h" |
| 49 |
| 50 using namespace Geometry; |
| 51 |
| 52 struct ltstr |
| 53 { |
| 54 bool operator()(const char* s1, const char* s2) const |
| 55 { |
| 56 return strcmp(s1, s2) < 0; |
| 57 } |
| 58 }; |
| 59 |
| 60 class InformationMap; |
| 61 class StrokeRenderer; |
| 62 class ViewMap; |
| 63 class ViewEdge; |
| 64 class FEdge; |
| 65 class RGBImage; |
| 66 class GrayImage; |
| 67 class QImage; |
| 68 class ImagePyramid; |
| 69 class SteerableViewMap; |
| 70 class StyleModule; |
| 71 |
| 72 /*! Class to define the canvas on which strokes are drawn. |
| 73 * It's used to store state information about the drawing. |
| 74 */ |
| 75 class LIB_STROKE_EXPORT Canvas |
| 76 { |
| 77 public: |
| 78 /*! Returns a pointer on the Canvas instance */ |
| 79 static Canvas *getInstance() |
| 80 { |
| 81 return _pInstance; |
| 82 } |
| 83 |
| 84 typedef std::map<const char*, ImagePyramid*, ltstr> mapsMap; |
| 85 static const int NB_STEERABLE_VIEWMAP = 5; |
| 86 |
| 87 protected: |
| 88 static Canvas *_pInstance; |
| 89 std::deque<StrokeLayer*> _Layers; |
| 90 std::deque<StyleModule*> _StyleModules; |
| 91 FEdge *_SelectedFEdge; |
| 92 |
| 93 StrokeRenderer *_Renderer; |
| 94 StyleModule *_current_sm; |
| 95 mapsMap _maps; |
| 96 static const char *_MapsPath; |
| 97 SteerableViewMap *_steerableViewMap; |
| 98 bool _basic; |
| 99 |
| 100 public: |
| 101 /* Builds the Canvas */ |
| 102 Canvas(); |
| 103 /* Copy constructor */ |
| 104 Canvas(const Canvas& iBrother); |
| 105 /* Destructor */ |
| 106 virtual ~Canvas(); |
| 107 |
| 108 /* operations that need to be done before a draw */ |
| 109 virtual void preDraw(); |
| 110 |
| 111 /* Draw the canvas using the current shader */ |
| 112 virtual void Draw(); |
| 113 |
| 114 /* operations that need to be done after a draw */ |
| 115 virtual void postDraw(); |
| 116 |
| 117 /* Renders the created strokes */ |
| 118 virtual void Render(const StrokeRenderer *iRenderer); |
| 119 /* Basic Renders the created strokes */ |
| 120 virtual void RenderBasic(const StrokeRenderer *iRenderer); |
| 121 /* Renders a stroke */ |
| 122 virtual void RenderStroke(Stroke *iStroke) = 0; |
| 123 |
| 124 /* init the canvas */ |
| 125 virtual void init() = 0; |
| 126 |
| 127 /* Clears the Canvas (shaders stack, layers stack...) */ |
| 128 void Clear(); |
| 129 |
| 130 /* Erases the layers */ |
| 131 virtual void Erase();· |
| 132 |
| 133 /* Reads a pixel area from the canvas */ |
| 134 virtual void readColorPixels(int x, int y,int w, int h, RGBImage& oImage
) const = 0; |
| 135 /* Reads a depth pixel area from the canvas */ |
| 136 virtual void readDepthPixels(int x, int y,int w, int h, GrayImage& oImag
e) const = 0; |
| 137 |
| 138 /* update the canvas (display) */ |
| 139 virtual void update() = 0; |
| 140 |
| 141 /* checks whether the canvas is empty or not */ |
| 142 bool isEmpty() const |
| 143 { |
| 144 return (_Layers.empty()); |
| 145 } |
| 146 |
| 147 /* Maps management */ |
| 148 /*! Loads an image map. The map will be scaled (without preserving the r
atio in order to fit the actual |
| 149 * canvas size.). |
| 150 * The image must be a gray values image... |
| 151 * \param iFileName |
| 152 * The name of the image file |
| 153 * \param iMapName |
| 154 * The name that will be used to access this image |
| 155 * \param iNbLevels |
| 156 * The number of levels in the map pyramid. (default = 4). |
| 157 * If iNbLevels == 0, the complete pyramid is built. |
| 158 */ |
| 159 void loadMap(const char *iFileName, const char *iMapName, unsigned iNbLe
vels = 4, float iSigma = 1.0f); |
| 160 |
| 161 /*! Reads a pixel value in a map. |
| 162 * Returns a value between 0 and 1. |
| 163 * \param iMapName |
| 164 * The name of the map |
| 165 * \param level |
| 166 * The level of the pyramid from which the pixel must be read. |
| 167 * \param x |
| 168 * The abscissa of the desired pixel specified in level0 coordinate s
ystem. The origin is the lower left corner. |
| 169 * \param y |
| 170 * The ordinate of the desired pixel specified in level0 coordinate s
ystem. The origin is the lower left corner. |
| 171 */ |
| 172 float readMapPixel(const char *iMapName, int level, int x, int y); |
| 173 |
| 174 /*! Sets the steerable viewmap */ |
| 175 void loadSteerableViewMap(SteerableViewMap * iSVM) |
| 176 { |
| 177 _steerableViewMap = iSVM; |
| 178 } |
| 179 |
| 180 /*! Returns the steerable VM */ |
| 181 SteerableViewMap * getSteerableViewMap() |
| 182 { |
| 183 return _steerableViewMap; |
| 184 } |
| 185 |
| 186 /*! accessors */ |
| 187 inline const FEdge *selectedFEdge() const |
| 188 { |
| 189 return _SelectedFEdge; |
| 190 } |
| 191 |
| 192 inline FEdge *selectedFEdge() |
| 193 { |
| 194 return _SelectedFEdge; |
| 195 } |
| 196 |
| 197 virtual int width() const = 0; |
| 198 virtual int height() const = 0; |
| 199 virtual BBox<Vec3r> scene3DBBox() const = 0; |
| 200 |
| 201 inline const StrokeRenderer *renderer() const |
| 202 { |
| 203 return _Renderer; |
| 204 } |
| 205 |
| 206 inline StyleModule *getCurrentStyleModule() |
| 207 { |
| 208 return _current_sm; |
| 209 } |
| 210 |
| 211 virtual bool getRecordFlag() const |
| 212 { |
| 213 return false; |
| 214 } |
| 215 |
| 216 int stroke_count; |
| 217 |
| 218 /*! modifiers */ |
| 219 inline void setSelectedFEdge(FEdge *iFEdge) |
| 220 { |
| 221 _SelectedFEdge = iFEdge; |
| 222 } |
| 223 |
| 224 /*! inserts a shader at pos index+1 */ |
| 225 void PushBackStyleModule(StyleModule *iStyleModule); |
| 226 void InsertStyleModule(unsigned index, StyleModule *iStyleModule); |
| 227 void RemoveStyleModule(unsigned index); |
| 228 void SwapStyleModules(unsigned i1, unsigned i2); |
| 229 void ReplaceStyleModule(unsigned index, StyleModule *iStyleModule); |
| 230 void setVisible(unsigned index, bool iVisible) ; |
| 231 |
| 232 #if 0 |
| 233 inline void setDensityMap(InformationMap<RGBImage> *iMap) |
| 234 { |
| 235 _DensityMap = iMap; |
| 236 } |
| 237 #endif |
| 238 |
| 239 inline void AddLayer(StrokeLayer *iLayer) |
| 240 { |
| 241 _Layers.push_back(iLayer); |
| 242 } |
| 243 |
| 244 void resetModified(bool iMod = false); |
| 245 void causalStyleModules(std::vector<unsigned>& vec, unsigned index = 0); |
| 246 void setModified(unsigned index, bool b); |
| 247 }; |
| 248 |
| 249 #endif // __FREESTYLE_CANVAS_H__ |
OLD | NEW |