00001 /** 00002 *\file Canvas.h 00003 * 00004 *\brief The Canvas class is a discrete simulation of the real life canvas. 00005 * 00006 * The canvas is cutted into grid structure, with <b><var>vReso</var></b> grids along 00007 * vertical (<b><var>Row</var></b>) direction and <b><var>hReso</var></b> horizontal grids along 00008 * horizontal(<b><var>Col</var></b>) direction. Each rectangular grid is called a pixel, or picture 00009 * element, and is specified by its lower-left <b><var>(row, col)</var></b> position. 00010 * The coordinate system has the lower-left corner of the canvas as its origin, 00011 * with <b><var>Row</var></b> going up and <b><var>Col</var></b> going right. The lower-left corner 00012 * pixel has a coordinate of <b><var>(0,0)</var></b>, and the upper-right one of <b><var> 00013 * (hReso - 1, vReso - 1)</var></b>. 00014 * 00015 * A <b><var>(x, y)</var></b> pair means <b><var>col = x+hReso/2, and row = y+vReso/2</var></b>. 00016 * 00017 * To each piexel <b><var>(row, col)</var></b> on the Canvas, a RGB color value is associated, 00018 * which can be accessed via index operator [<b><var>row</var></b>][<b><var>col</var></b>]. 00019 * 00020 * WritePPM() writes the Canvas to an image file of PPM format. 00021 * 00022 *\author Xianming Chen 00023 * 00024 */ 00025 00026 00027 #ifndef _CANVAS_H_ 00028 #define _CANVAS_H_ 00029 00030 #include "RGB.h" 00031 #include "color.h" 00032 00033 #include <string> 00034 #include <cassert> 00035 00036 using namespace std; 00037 00038 namespace columbia 00039 { 00040 class Canvas 00041 { 00042 public: 00043 Canvas(int resoH = 512, int resoV = 512) : hReso(resoH), vReso(resoV), data(0) { init(); } 00044 ~Canvas() { delete [] data; } 00045 00046 RGB* operator[] (int r) { assert(r>=0 && r<vReso); return data+r*hReso; } 00047 00048 void WritePPM(const char* = 0) const; 00049 00050 int hReso, vReso; //! Resolutions (pixel #)at horizontal and vertical directions. 00051 std::string filename; //! write as PPM image file name. 00052 private: 00053 RGB* data; 00054 void init(); 00055 }; 00056 00057 } 00058 #endif
1.3.6