image.h

Go to the documentation of this file.
00001 #ifndef IIS_IMAGE_H
00002 #define IIS_IMAGE_H
00003 #include "value.h"
00004 #include "point.h"
00005 
00015 class DirectPoint
00016 {
00017  public:
00018   int x;
00019   int y;
00020 
00024   DirectPoint()
00025     {
00026       x = 0;
00027       y = 0;
00028     };
00029 
00033   DirectPoint(int a, int b)
00034     {
00035       x = a;
00036       y = b;
00037     }
00038 
00042   DirectPoint(Token data)
00043     {
00044       x = (Signed4)data["x"];
00045       y = (Signed4)data["y"];
00046     }
00047 
00052   Data getSaveDescription() 
00053     {
00054       Token r;
00055       r["type"]=Symbol("directpoint");
00056       r["x"]=Signed4(x);
00057       r["y"]=Signed4(y);
00058       return r;
00059     };
00060 
00065   void copyFrom(const PointValue & other)
00066     {
00067       x = (int)other.x;
00068       y = (int)other.y;
00069     }
00070 
00075   operator PointValue()
00076     {
00077       PointValue result;
00078       result.x = x;
00079       result.y = y;
00080       return result;
00081     }
00082 
00086   DirectPoint & operator +=(const DirectPoint & other)
00087     {
00088       x+=other.x;
00089       y+=other.y;
00090       return * this;
00091     }
00092 
00096   DirectPoint operator -(const DirectPoint & other) const
00097     {
00098       DirectPoint result;
00099       result.x = x - other.x;
00100       result.y = y - other.y;
00101       return result;
00102     }
00103 
00107   bool operator ==(const DirectPoint & other) const
00108     {
00109       return x==other.x && y==other.y;
00110     }
00111 };
00112 
00123 class ImageValue: public Value
00124 {
00125   typedef Array<3,float> Image;
00126   typedef Array<2,float> Plane;
00127   typedef Array<2,float> ColorLine;
00128   Image data;
00129   static const int channels = 0;
00130   static const int imagex = 1;
00131   static const int imagey = 2;
00132   static const int colorlinex = 1;
00133  protected:
00134   void loadImage(QString str);
00135   void loadImage(QImage & i);
00136  public:
00140   DirectPoint center;
00141 
00145   PointValue scale;
00146 
00151   virtual Data getSaveDescription(QString );
00152 
00159   ImageValue(int xs, int ys, int c);
00160 
00165   ImageValue(PointValue topleft, PointValue bottomright, PointValue resolution, int channels);
00166 
00172   ImageValue(QImage &i);
00173 
00179   ImageValue(QString str);
00180 
00184   ImageValue(Token data);
00185 
00189   ImageValue * deepCopy();
00190 
00191   virtual QString toString() {return "<image>";};
00192   virtual bool equals_same_type(Value * other);
00193   // accessors
00194   void   set_direct(int x, int y, int c, double v)
00195     {
00196       data[Position<3>(c,x,y)]=v;
00197     };
00198   void   inc_direct(int x, int y, int c)
00199     {
00200       data[Position<3>(c,x,y)]+=1.0; 
00201     };
00202   double get_direct(int x, int y, int c)
00203     { 
00204       return data[Position<3>(c,x,y)]; 
00205     };
00206 
00210   int    width_direct() 
00211     {
00212       return data.size(imagex); 
00213     };
00214   
00218   int    height_direct() 
00219     {
00220       return data.size(imagey); 
00221     };
00222 
00226   bool outside(DirectPoint & dp)
00227     {
00228       return dp.x < 0 ||
00229         dp.y < 0 ||
00230         dp.x>=width_direct() ||
00231         dp.y>=height_direct();
00232     }
00233   
00237   int channelcount() 
00238     {
00239       return data.size(channels); 
00240     };
00241 
00246   double horiz()
00247     {
00248       return 1.0/scale.x;
00249     }
00250 
00255   double vertic()
00256     {
00257       return 1.0/scale.y;
00258     }
00259 
00263   double left()
00264     {
00265       return (0-center.x)/scale.x;
00266     }
00267 
00271   double right()
00272     {
00273       return ((width_direct()-1)-center.x)/scale.x;
00274     }
00275 
00279   double top()
00280     {
00281       return (0-center.y)/scale.y;
00282     }
00283 
00287   double bottom()
00288     {
00289       return ((height_direct()-1)-center.y)/scale.y;
00290     }
00291   
00295   PointValue topleft()
00296     {
00297       return PointValue(left(),top());
00298     }
00299 
00303   PointValue bottomright()
00304     {
00305       return PointValue(right(),bottom());
00306     }
00307   
00311   double maxz();
00312   
00316   double minz();
00317 
00321   double medianz();
00322   
00327   void   clear(double v)
00328     { 
00329       data=v;
00330     };
00331 
00337   void addFrom(ImageValue * i);
00338 
00342   void negate();
00343 
00349   QImage getQImage(bool draw_axes);
00350 
00356   void drawAxes(QImage * onto);
00357 
00361   void drawLegend(QPainter * painter, int as, int bs);
00362 
00367   DirectPoint ocsToDcs(const PointValue& in);
00368   
00373   void ocsToDcs(const PointValue& in, double &x, double &y)
00374     {
00375       DirectPoint r = ocsToDcs(in);
00376       x = r.x;
00377       y = r.y;
00378     }
00379   
00384   PointValue dcsToOcs(const DirectPoint& in);
00385 };
00386 
00387 #endif
00388 

Generated on Mon Jun 5 22:08:42 2006 for iis by  doxygen 1.4.6