Runtime Class Reference

#include <runtime.h>

List of all members.

Public Member Functions

Valueapply (QString op, vector< Value * >)
bool requires_user_input (Value *)

Private Member Functions

Valueadd (Value *a, Value *b)
Valueadd (vector< Value * >)
Valueneg (Value *)
Valuesub (vector< Value * >)
Valuediv (Value *a, Value *b)
Valuediv (vector< Value * >)
Valuemul (Value *a, Value *b)
Valuemul (vector< Value * >)
Valueimage (QString filename)
Valueimage (Value *filename)
Valueimage ()
Valueimage (vector< Value * >)
Valueselect (Value *image)
Valueselect (vector< Value * >)
Valueline (Value *image)
Valueline (vector< Value * >)
Valuebox (Value *image)
Valuebox (vector< Value * >)
Valuecenter (Value *image, Value *center)
Valuecenter (vector< Value * >)
Valuezoom (ImageValue *image, PointValue *mult)
Valuezoomx (vector< Value * >)
Valuezoomy (vector< Value * >)
Valuezoom (vector< Value * >)
Valuestraighten (Value *image, Value *line)
Valuestraighten (vector< Value * >)
Valuecrop (Value *image, Value *box)
Valuecrop (vector< Value * > v)


Detailed Description

The runtime contains all functions that are known to the spreadsheet

Definition at line 14 of file runtime.h.


Member Function Documentation

Value * Runtime::add vector< Value * >   )  [private]
 

Definition at line 55 of file add.cpp.

References add().

00056 {
00057   Value * accumulated = values[0];
00058   for(unsigned int i = 1 ; i < values.size() ; i++)
00059       accumulated=add(accumulated,values[i]);
00060   return accumulated;
00061 }

Value * Runtime::add Value a,
Value b
[private]
 

Will add two values. If the values are textvalues, then they will be converted to numbers and added. If the inputs are images then the values, respecting the coordinate system will be added, thereby respecting the coordinate system. If the inputs are poitns, the x,y values are added and a new point returned.

Definition at line 13 of file add.cpp.

References ImageValue::bottomright(), ImageValue::channelcount(), max(), ImageValue::maxz(), min(), ImageValue::minz(), TextValue::number(), ImageValue::scale, ImageValue::topleft(), PointValue::x, and PointValue::y.

Referenced by add(), apply(), and sub().

00014 {
00015   if (!a || !b) return NULL;
00016   if (typeid(*a)==typeid(TextValue) && typeid(*b)==typeid(TextValue))
00017     {
00018       TextValue * A = (TextValue*)a;
00019       TextValue * B = (TextValue*)b;
00020       return new TextValue(A->number()+B->number());
00021     }
00022   if (typeid(*a)==typeid(ImageValue) && typeid(*b)==typeid(ImageValue))
00023     {
00024       ImageValue * A = (ImageValue*)a;
00025       ImageValue * B = (ImageValue*)b;
00026       
00027       PointValue topleft     = min(A->topleft(),B->topleft());
00028       PointValue bottomright = max(A->bottomright(),B->bottomright());
00029       PointValue maxres      = max(A->scale,B->scale);
00030       int cs = max(A->channelcount(),B->channelcount());
00031       ImageValue * O = new ImageValue(topleft,bottomright,maxres,cs);
00032       printf("O1: %g - %g\n",O->minz(),O->maxz());
00033       O->clear(0);
00034       printf("O2: %g - %g\n",O->minz(),O->maxz());
00035       printf("A: %g - %g\n",A->minz(),A->maxz());
00036       O->addFrom(A);
00037       printf("O3: %g - %g\n",O->minz(),O->maxz());
00038       printf("B: %g - %g\n",B->minz(),B->maxz());
00039       O->addFrom(B);
00040       printf("O4: %g - %g\n",O->minz(),O->maxz());
00041       return O;
00042     }
00043   if (typeid(*a)==typeid(PointValue) && typeid(*b)==typeid(PointValue))
00044     {
00045       PointValue * A = (PointValue*)a;
00046       PointValue * B = (PointValue*)b;
00047       PointValue * R = new PointValue();
00048       R->x=A->x+B->x;
00049       R->y=A->y+B->y;
00050       return R;
00051     }
00052   assert(0);
00053 }

Value * Runtime::apply QString  op,
vector< Value * > 
 

Definition at line 156 of file runtime.cpp.

References add(), box(), center(), crop(), div(), image(), line(), mul(), select(), straighten(), sub(), zoom(), zoomx(), and zoomy().

Referenced by IisCell::apply().

00157 {
00158   if (op=="+") return add(evaluated);
00159   if (op=="-") return sub(evaluated);
00160   if (op=="/") return div(evaluated);
00161   if (op=="*") return mul(evaluated);
00162   if (op=="image") return image(evaluated);
00163   // selection
00164   if (op=="select") return select(evaluated);
00165   if (op=="line") return line(evaluated);
00166   if (op=="box") return box(evaluated);
00167   // translation, rotation and affine transformation
00168   if (op=="center") return center(evaluated);
00169   if (op=="zoom") return zoom(evaluated);
00170   if (op=="zoomx") return zoomx(evaluated);
00171   if (op=="zoomy") return zoomy(evaluated);
00172   if (op=="straighten") return straighten(evaluated);
00173   if (op=="crop") return crop(evaluated);
00174   // projection like operations
00175   //  if (op=="distribution") return distribution(evaluated);
00176   //  if (op=="project") return project(evaluated);
00177 #ifdef PSYTRACK
00178   if (op=="morph") return morph(evaluated);
00179 #endif
00180   throw new Error("Unknown operator "+op);
00181 }

Value * Runtime::box vector< Value * >   )  [private]
 

Definition at line 35 of file box.cpp.

References box().

00036 {
00037   if (v.size()==1) return box(v[0]);
00038   return NULL;
00039 }

Value * Runtime::box Value image  )  [private]
 

Definition at line 24 of file box.cpp.

References image(), and BoxPicker::value().

Referenced by apply(), box(), and crop().

00025 {
00026   if (image==NULL)  return NULL;
00027   if (typeid(*image)!=typeid(ImageValue)) return NULL;
00028   ImageValue * I = (ImageValue*)image;
00029   BoxPicker ip(I);
00030   if (ip.exec()==QDialog::Accepted)
00031     return ip.value();
00032   return NULL;
00033 }

Value * Runtime::center vector< Value * >   )  [private]
 

Definition at line 21 of file center.cpp.

References center().

00022 {
00023   if (v.size()!=2) return NULL;
00024   return center(v[0],v[1]);
00025 }

Value * Runtime::center Value image,
Value newcenter
[private]
 

This function simply changes the coordinate system

Definition at line 7 of file center.cpp.

References ImageValue::center, ImageValue::deepCopy(), image(), and ImageValue::ocsToDcs().

Referenced by apply(), and center().

00008 {
00009   // input checks
00010   if (image==NULL)  return NULL;
00011   if (newcenter==NULL) return NULL;
00012   if (typeid(*image)!=typeid(ImageValue)) return NULL;
00013   if (typeid(*newcenter)!=typeid(PointValue)) return NULL;
00014   ImageValue * I = (ImageValue*)image;
00015   PointValue * nc = (PointValue*)newcenter;
00016   ImageValue * O = I->deepCopy();
00017   O->center = O->ocsToDcs(*nc);
00018   return O;
00019 }

Value * Runtime::crop vector< Value * >  v  )  [private]
 

This function implements an affien texture mapping from the first image onto a rectangle using specific coordinates. This paritcular member checks the input constriants.

Definition at line 47 of file crop.cpp.

References crop().

00048 {
00049   if (v.size()==2) return crop(v[0],v[1]);
00050   return NULL;
00051 }

Value * Runtime::crop Value image,
Value box
[private]
 

This function implements an affien texture mapping from the first image onto a rectangle using the input coordinates passed through the box.

Definition at line 5 of file crop.cpp.

References BoxValue::bl, box(), BoxValue::br, ImageValue::channelcount(), dist(), ImageValue::get_direct(), image(), max(), ImageValue::ocsToDcs(), pos(), ImageValue::set_direct(), BoxValue::tl, BoxValue::tr, DirectPoint::x, and DirectPoint::y.

Referenced by apply(), and crop().

00006 {
00007   // input checks
00008   if (image==NULL)  return NULL;
00009   if (box==NULL) return NULL;
00010   if (typeid(*image)!=typeid(ImageValue)) return NULL;
00011   if (typeid(*box)!=typeid(BoxValue)) return NULL;
00012   // convertions
00013   ImageValue * I = (ImageValue*)image;
00014   BoxValue   * B = (BoxValue*)box;
00015   PointValue & otl = B->tl;
00016   PointValue & otr = B->tr;
00017   PointValue & obl = B->bl;
00018   PointValue & obr = B->br;
00019 
00020   DirectPoint dtl = I->ocsToDcs(otl);
00021   DirectPoint dtr = I->ocsToDcs(otr);
00022   DirectPoint dbl = I->ocsToDcs(obl);
00023   DirectPoint dbr = I->ocsToDcs(obr);
00024   
00025   // final output size is the largest size we need to represent every
00026   // pixel
00027   int as = 1+(int)max(dist(dtl,dtr),dist(dbl,dbr));
00028   int bs = 1+(int)max(dist(dtl,dbl),dist(dtr,dbr));
00029   int cs = I->channelcount();
00030   ImageValue * O = new ImageValue(as,bs,cs);
00031   // we run trhough all the target pixels and fill in the values
00032   for(int c = 0 ; c < cs ; c++)
00033     for(int a = 0 ; a < as ; a++)
00034       for(int b = 0 ; b < bs ; b++)
00035         {
00036           int ml_x = pos(dtl.x,dbl.x,b,bs);
00037           int ml_y = pos(dtl.y,dbl.y,b,bs);
00038           int mr_x = pos(dtr.x,dbr.x,b,bs);
00039           int mr_y = pos(dtr.y,dbr.y,b,bs);
00040           int x = pos(ml_x,mr_x,a,as);
00041           int y = pos(ml_y,mr_y,a,as);
00042           O->set_direct(a,b,c,I->get_direct(x,y,c));
00043         }
00044   return O;
00045 }

Value * Runtime::div vector< Value * >   )  [private]
 

Definition at line 28 of file div.cpp.

References div().

00029 {
00030   if (values.size()!=2) return NULL;
00031   return div(values[0],values[1]);
00032 }

Value * Runtime::div Value a,
Value b
[private]
 

Definition at line 6 of file div.cpp.

References TextValue::number(), PointValue::x, and PointValue::y.

Referenced by apply(), and div().

00007 {
00008   if (!a || !b) return NULL;
00009   if (typeid(*a)==typeid(TextValue) && typeid(*b)==typeid(TextValue))
00010     {
00011       TextValue * A = (TextValue*)a;
00012       TextValue * B = (TextValue*)b;
00013       return new TextValue(A->number()/B->number());
00014     }
00015   if (typeid(*a)==typeid(PointValue) && typeid(*b)==typeid(TextValue))
00016     {
00017       PointValue * A = (PointValue*)a;
00018       TextValue  * B = (TextValue*)b;
00019       double       C = B->number();
00020       PointValue * R = new PointValue();
00021       R->x=A->x/C;
00022       R->y=A->y/C;
00023       return R;
00024     }
00025   assert(0);
00026 }

Value * Runtime::image vector< Value * >   )  [private]
 

Definition at line 359 of file image.cpp.

References image().

00360 {
00361   if (v.size()==0) return image();
00362   if (v.size()==1) return image(v[0]);
00363   return NULL;
00364 }

Value * Runtime::image  )  [private]
 

Definition at line 348 of file image.cpp.

Referenced by apply(), box(), center(), crop(), image(), line(), select(), and straighten().

00349 {
00350   QString s = QFileDialog::getOpenFileName(".",
00351                                            "Images (*.png *.xpm *.jpg)",
00352                                            NULL,
00353                                            "Select file to open",
00354                                            "Choose a file");
00355   if(s.isEmpty()) return NULL;
00356   return image(s);
00357 }

Value * Runtime::image Value filename  )  [private]
 

Definition at line 340 of file image.cpp.

References TextValue::getText(), and image().

00341 {
00342   if (what==NULL) return NULL;
00343   if (typeid(*what)!=typeid(TextValue)) return NULL;
00344   TextValue * t = (TextValue*)what;
00345   return image(t->getText());
00346 }

Value * Runtime::image QString  filename  )  [private]
 

Definition at line 335 of file image.cpp.

00336 {
00337   return new ImageValue(filename);
00338 }

Value * Runtime::line vector< Value * >   )  [private]
 

Definition at line 28 of file line.cpp.

References line().

00029 {
00030   if (v.size()==1) return line(v[0]);
00031   return NULL;
00032 }

Value * Runtime::line Value image  )  [private]
 

Definition at line 17 of file line.cpp.

References image(), and LinePicker::value().

Referenced by apply(), line(), and straighten().

00018 {
00019   if (image==NULL)  return NULL;
00020   if (typeid(*image)!=typeid(ImageValue)) return NULL;
00021   ImageValue * I = (ImageValue*)image;
00022   LinePicker ip(I);
00023   if (ip.exec()==QDialog::Accepted)
00024     return ip.value();
00025   return NULL;
00026 }

Value * Runtime::mul vector< Value * >   )  [private]
 

Definition at line 28 of file mul.cpp.

References mul().

00029 {
00030   Value * accumulated = values[0];
00031   for(unsigned int i = 1 ; i < values.size() ; i++)
00032     accumulated=mul(accumulated,values[i]);
00033   return accumulated;
00034 }

Value * Runtime::mul Value a,
Value b
[private]
 

Definition at line 6 of file mul.cpp.

References TextValue::number(), PointValue::x, and PointValue::y.

Referenced by apply(), and mul().

00007 {
00008   if (!a || !b) return NULL;
00009   if (typeid(*a)==typeid(TextValue) && typeid(*b)==typeid(TextValue))
00010     {
00011       TextValue * A = (TextValue*)a;
00012       TextValue * B = (TextValue*)b;
00013       return new TextValue(A->number()/B->number());
00014     }
00015   if (typeid(*a)==typeid(PointValue) && typeid(*b)==typeid(TextValue))
00016     {
00017       PointValue * A = (PointValue*)a;
00018       TextValue  * B = (TextValue*)b;
00019       double       C = B->number();
00020       PointValue * R = new PointValue();
00021       R->x=A->x*C;
00022       R->y=A->y*C;
00023       return R;
00024     }
00025   assert(0);
00026 }

Value * Runtime::neg Value a  )  [private]
 

Negates the value.

Definition at line 9 of file neg.cpp.

References ImageValue::deepCopy(), ImageValue::negate(), TextValue::number(), PointValue::x, and PointValue::y.

Referenced by sub().

00010 {
00011   if (!a) return NULL;
00012   if (typeid(*a)==typeid(TextValue))
00013     {
00014       TextValue * A = (TextValue*)a;
00015       return new TextValue(-A->number());
00016     }
00017   if (typeid(*a)==typeid(ImageValue))
00018     {
00019       ImageValue * A = (ImageValue*)a;
00020       ImageValue * R = A->deepCopy();
00021       R->negate();
00022       return R;
00023     }
00024   if (typeid(*a)==typeid(PointValue))
00025     {
00026       PointValue * A = (PointValue*)a;
00027       PointValue * R = new PointValue();
00028       R->x=-A->x;
00029       R->y=-A->y;
00030       return R;
00031     }
00032   assert(0);
00033 }

bool Runtime::requires_user_input Value  ) 
 

Definition at line 183 of file runtime.cpp.

References Expression::argc(), Expression::argv(), and Expression::op().

Referenced by IisCell::needs_user_input().

00184 {
00185   if (!val) return false;
00186   if (typeid(*val)!=typeid(Expression))
00187     return false;
00188   Expression * app = (Expression*)val;
00189   for(int i = 0 ; i < app->argc() ; i++)
00190     if (requires_user_input(app->argv(i))) return true;
00191   QString op = app->op();
00192   if (op=="image") return true;
00193   if (op=="select") return true;
00194   if (op=="line") return true;
00195   if (op=="box") return true;
00196   return false;
00197 }

Value * Runtime::select vector< Value * >   )  [private]
 

Definition at line 38 of file point.cpp.

References select().

00039 {
00040   if (v.size()==1) return select(v[0]);
00041   return NULL;
00042 }

Value * Runtime::select Value image  )  [private]
 

Definition at line 27 of file point.cpp.

References image(), and PointPicker::value().

Referenced by apply(), and select().

00028 {
00029   if (image==NULL)  return NULL;
00030   if (typeid(*image)!=typeid(ImageValue)) return NULL;
00031   ImageValue * I = (ImageValue*)image;
00032   PointPicker ip(I);
00033   if (ip.exec()==QDialog::Accepted)
00034     return ip.value();
00035   return NULL;
00036 }

Value * Runtime::straighten vector< Value * >   )  [private]
 

Definition at line 78 of file rotate.cpp.

References straighten().

00079 {
00080   if (v.size()!=2) return NULL;
00081   return straighten(v[0],v[1]);
00082 }

Value * Runtime::straighten Value image,
Value line
[private]
 

Definition at line 7 of file rotate.cpp.

References LineValue::a, LineValue::b, ImageValue::channelcount(), ImageValue::clear(), ImageValue::get_direct(), ImageValue::height_direct(), image(), line(), max(), ImageValue::maxz(), min(), ImageValue::ocsToDcs(), rotate(), ImageValue::set_direct(), ImageValue::width_direct(), DirectPoint::x, and DirectPoint::y.

Referenced by apply(), and straighten().

00008 {
00009   // input checks
00010   if (image==NULL)  return NULL;
00011   if (line==NULL) return NULL;
00012   if (typeid(*image)!=typeid(ImageValue)) return NULL;
00013   if (typeid(*line)!=typeid(LineValue)) return NULL;
00014   ImageValue * I = (ImageValue*)image;
00015   LineValue * l = (LineValue*)line;
00016 
00017   // we rotate the image data, afterwards we reestablish the
00018   // center and scaling factors
00019   
00020   // determine angle of line & normalize
00021   DirectPoint A = I->ocsToDcs(l->a);
00022   DirectPoint B = I->ocsToDcs(l->b);
00023   double da = B.x - A.x;
00024   double db = B.y - A.y;
00025   double angle = atan2(db,da);
00026   while(angle<0) angle+=2*M_PI;
00027   while(angle>=M_PI/4) angle-=M_PI/2;
00028 
00029   // rotate the corners
00030   int as = I->width_direct();
00031   int bs = I->height_direct();
00032   double cas = (double)as/2.0;
00033   double cbs = (double)bs/2.0;
00034   
00035   int tl_x, tl_y;
00036   int tr_x, tr_y;
00037   int bl_x, bl_y;
00038   int br_x, br_y;
00039   rotate(0, 0, cas,cbs,tl_x,tl_y,-angle);
00040   rotate(as,0, cas,cbs,tr_x,tr_y,-angle);
00041   rotate(0, bs,cas,cbs,bl_x,bl_y,-angle);
00042   rotate(as,bs,cas,cbs,br_x,br_y,-angle);
00043   int xs = max(tr_x,br_x)-min(tl_x,bl_x);
00044   int ys = max(br_y,bl_y)-min(tl_y,tr_y);
00045   // create output image
00046   ImageValue *O=new ImageValue(xs,ys,I->channelcount());
00047   O->clear(I->maxz());
00048   //scan through output area
00049   double cxs = (double)xs/2.0;
00050   double cys = (double)ys/2.0;
00051   for(int x = 0 ; x < xs ; x++)
00052     for(int y = 0 ; y < ys ; y++)
00053       {
00054         int a,b;
00055         rotate(x-cxs,y-cys,0,0,a,b,angle);
00056         a+=cas;
00057         b+=cbs;
00058         if (a<0) continue;
00059         if (a>=as) continue;
00060         if (b<0) continue;
00061         if (b>=bs) continue;
00062         for(int c = 0 ; c < I->channelcount();c++)
00063           O->set_direct(x,y,c,I->get_direct(a,b,c));
00064       }
00065   // calculate the new center;
00066   // first determine the position of the old center
00067   PointValue new_center;
00068   rotate(I->center.x-cas,I->center.y-cbs,0,0,
00069          new_center.x,new_center.y,-angle);
00070   // this is the rotation of the direct points
00071   O->center.x = new_center.x + cxs;
00072   O->center.y = new_center.y + cys;
00073   // calculate the new zoom factors
00074   // the scaling factor means: how many pixels per unit. 
00075   return O;
00076 }

Value * Runtime::sub vector< Value * >  values  )  [private]
 

Will subtract two values by inverting the second and return the addition of both.

Definition at line 10 of file sub.cpp.

References add(), and neg().

Referenced by apply().

00011 {
00012   if (values.size()==1)
00013     return neg(values[0]);
00014   else if (values.size()==2)
00015     return add(values[0],neg(values[1]));
00016   return NULL;
00017 }

Value * Runtime::zoom vector< Value * >   )  [private]
 

Definition at line 39 of file zoom.cpp.

References zoom().

00040 {
00041   if (v.size()!=2) return NULL;
00042   Value * I = v[0];
00043   Value * Z = v[1];
00044   if (I==NULL)  return NULL;
00045   if (Z==NULL) return NULL;
00046   if (typeid(*I)!=typeid(ImageValue)) return NULL;
00047   if (typeid(*Z)!=typeid(PointValue)) return NULL;
00048   return zoom((ImageValue*)I,(PointValue*)Z);
00049 }

Value * Runtime::zoom ImageValue image,
PointValue mult
[private]
 

Definition at line 4 of file zoom.cpp.

References ImageValue::deepCopy(), and ImageValue::scale.

Referenced by apply(), zoom(), zoomx(), and zoomy().

00005 {
00006   ImageValue * O = I->deepCopy();
00007   O->scale*=*mult;
00008   return O;
00009 }

Value * Runtime::zoomx vector< Value * >   )  [private]
 

Definition at line 11 of file zoom.cpp.

References PointValue::y, and zoom().

Referenced by apply().

00012 {
00013   if (v.size()!=2) return NULL;
00014   Value * I = v[0];
00015   Value * Z = v[1];
00016   if (I==NULL)  return NULL;
00017   if (Z==NULL) return NULL;
00018   if (typeid(*I)!=typeid(ImageValue)) return NULL;
00019   if (typeid(*Z)!=typeid(PointValue)) return NULL;
00020   PointValue zx = *(PointValue*)Z;
00021   zx.y = 1.0;
00022   return zoom((ImageValue*)I,&zx);
00023 }

Value * Runtime::zoomy vector< Value * >   )  [private]
 

Definition at line 25 of file zoom.cpp.

References PointValue::x, and zoom().

Referenced by apply().

00026 {
00027   if (v.size()!=2) return NULL;
00028   Value * I = v[0];
00029   Value * Z = v[1];
00030   if (I==NULL)  return NULL;
00031   if (Z==NULL) return NULL;
00032   if (typeid(*I)!=typeid(ImageValue)) return NULL;
00033   if (typeid(*Z)!=typeid(PointValue)) return NULL;
00034   PointValue zy = *(PointValue*)Z;
00035   zy.x = 1.0;
00036   return zoom((ImageValue*)I,&zy);
00037 }


The documentation for this class was generated from the following files:
Generated on Mon Jun 5 22:08:44 2006 for iis by  doxygen 1.4.6