00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _CANVAS_H_
00028 #define _CANVAS_H_
00029
00030 #include "RGB.h"
00031
00032 #include <string>
00033 #include <cassert>
00034 #include <map>
00035
00036 using namespace std;
00037
00038 namespace columbia
00039 {
00040 class Canvas
00041 {
00042 public:
00043 explicit Canvas(int resoH = 512, int resoV = 512) : hReso(resoH), vReso(resoV), filename("tmp.ppm"), data(0) { init(); }
00044 ~Canvas() { delete [] data; }
00045 void Clear(RGB const&);
00046
00047
00048 RGB* operator[] (int r) { assert(r>=0 && r<vReso); return data + r*hReso; }
00049 RGB& Pixel(int row, int col);
00050
00051
00052
00053
00054
00055
00056 void ScanLineSegment(int x1, int y1, RGB const& color1, int x2, int y2, RGB const& color2, multimap<int, int>* output=0);
00057
00058 void WireCircle(int center_x, int center_y, int radius, int reso, RGB const& col);
00059
00060
00061
00062
00063 void SolidCircle(int center_x, int center_y, int radius, RGB const& col);
00064 void SolidRectangle(int minx, int miny, int maxx, int maxy, RGB const& col);
00065
00066 void SolidTriangle(int x1, int y1, RGB const& col1, int x2, int y2, RGB const& col2, int x3, int y3, RGB const& col3);
00067
00068 void WritePPM(const char* = 0) const;
00069
00070 int hReso, vReso;
00071 std::string filename;
00072 private:
00073 RGB* data;
00074 bool swap_xy, flip_y;
00075
00076 void init();
00077
00078
00079 void scanLineSegment(int x1, int y1, RGB const& col1, int x2, int y2, RGB const& col2, multimap<int, int>* output);
00080 };
00081
00082
00083 inline RGB& Canvas :: Pixel(int row, int col)
00084 {
00085 if(row >= vReso)
00086 {
00087 cout << "row = " << row << endl;
00088 throw "row number overflow\n";
00089 }
00090 if(row < 0)
00091 {
00092 cout << "row = " << row << endl;
00093 throw "row number underflow\n";
00094 }
00095 if(col >= hReso)
00096 {
00097 cout << "col = " << col << endl;
00098 throw "col number overrflow\n";
00099 }
00100 if(col < 0)
00101 {
00102 cout << "col = " << col << endl;
00103 throw "col number underflow\n";
00104 }
00105 return *(data + row * hReso + col);
00106 }
00107
00108
00109 }
00110
00111 #endif