00001 package commandline.Encoder;
00002
00003 import commandline.ImageStuff.Image;
00004 import commandline.ImageStuff.Loc;
00005 import commandline.ImageStuff.GeometricObjects.ParametrizedPiercingVertex;
00006
00007 public class LSEncoderEdge extends EncoderEdge {
00008
00009
00010 float a;
00011 float b;
00012 Loc begin;
00013 public LSEncoderEdge(ParametrizedPiercingVertex a,
00014 ParametrizedPiercingVertex b, int maxr) {
00015 super(a, b, maxr);
00016 initParams();
00017 }
00018
00019 public LSEncoderEdge(ParametrizedPiercingVertex a, ParametrizedPiercingVertex b,Image image, int [][] lijn,int maxr) {
00020 super(a, b,image, lijn,maxr);
00021 initParams();
00022 }
00023
00024 private void initParams(){
00025 begin=getLoc(0);
00026 float Sum_X=0;
00027 float Sum_Y=0;
00028 float Sum_XY=0;
00029 float Sum_XX=0;
00030
00031 float X=0;
00032 float Y=0;
00033 for (Loc loc : this.getLocs()) {
00034 if((!loc.isOn(begin) && !loc.isOn(eind) && this.getLengte()!=2)){
00035 X=loc.distance(begin);
00036 Y=Image.getInstance().getPuntOpEnty(loc).getZ();
00037 Sum_X+=X;
00038 Sum_Y+=Y;
00039 Sum_XY+=(X*Y);
00040 Sum_XX+=(X*X);
00041
00042 }
00043 }
00044 float n=this.getLocs().size();
00045 if(this.getLengte()!=2){
00046 n-=2;
00047 }
00048 float S_XY=Sum_XY-(Sum_X*Sum_Y)/n;
00049 float S_XX=Sum_XX-(Sum_X*Sum_X)/n;
00050
00051 a=S_XY/S_XX;
00052 b=Sum_Y/n-a*Sum_X/n;
00053 if(this.getLengte()==2){
00054 a=0;
00055 b=(this.getBegin().getZ()+this.getEind().getZ())/2;
00056 }
00057 }
00058
00059 protected float getFunctiewaardeOn(int index) {
00060 return this.getLoc(index).distance(begin)*a+b;
00061
00062 }
00063
00064
00065 }