00001 package commandline.ImageStuff.GeometricObjects.Impl; 00002 00003 import java.util.Iterator; 00004 00005 import commandline.ImageStuff.Image; 00006 import commandline.ImageStuff.Loc; 00007 import commandline.ImageStuff.GeometricObjects.Triangle; 00008 import commandline.ImageStuff.GeometricObjects.factories.EdgeConstructorTriangleMakerFactory; 00009 import commandline.ImageStuff.Topology.AbstractTesselation; 00010 import commandline.ImageStuff.Topology.ConnectieCriterium; 00011 import commandline.ImageStuff.Topology.TriangleTesselationSet; 00012 import commandline.Norm.NormenMaker; 00013 import commandline.NormalMeshAlgorithm.Configuration; 00014 import commandline.NormalMeshAlgorithm.SnijPixelStrategy; 00015 import commandline.debuggingCode.Debug; 00016 00022 public abstract class TriangleImpl { 00023 00024 protected Triangle triangle; 00025 private NormenMaker normenMaker; 00026 00027 float Sobolev; 00028 00034 public TriangleImpl(Triangle triangle){ 00035 this.triangle=triangle; 00036 } 00037 00042 public abstract TriangleImplType getTriangleImplementationType(); 00043 public abstract float getFunctiewaardeOn(Loc loc); 00044 public abstract float fundamentenwaardeOn(Loc loc); 00045 public abstract AbstractTesselation getBestEncoderTesselation( 00046 SnijPixelStrategy snijPixelStrategy, 00047 ConnectieCriterium connectieCriterium,EdgeConstructorTriangleMakerFactory edgeConstructorTriangleMakerFactory 00048 ,Configuration configuration); 00049 00055 public NormenMaker getError(Image image){ 00056 if(this.normenMaker!=null){return normenMaker;} 00057 Iterator<Loc> iter = triangle.getLocs().iterator(); 00058 Loc loc; 00059 NormenMaker normenmaker=new NormenMaker(triangle.getLocs().size()); 00060 while(iter.hasNext()){ 00061 loc=(Loc)iter.next(); 00062 00063 if(image.getPuntOpEnty(loc).getZ()-triangle.getFunctiewaardeOn(loc)==Float.NaN){ 00064 Debug.print("functiewaarde = NAN"); 00065 Debug.print("image.functiewaarde ="+ image.getPuntOpEnty(loc).getZ()); 00066 Debug.print("this.functiewaarde = "+ triangle.getFunctiewaardeOn(loc)); 00067 00068 } 00069 normenmaker.add(image.getPuntOpEnty(loc).getZ()-this.getFunctiewaardeOn(loc)); 00070 } 00071 00072 // @TODO zorg dat er slechts 1 norm wordt berekend, nl. Diegene die nodig is 00073 normenmaker.addSobelev(this.getSobolevError(image)); 00074 this.normenMaker=normenmaker; 00075 return this.normenMaker; 00076 } 00077 00078 00084 protected float getSobolevError(Image image){ 00085 00086 if(Sobolev!=-1){return Sobolev;} 00087 Sobolev=0; 00088 Iterator<Loc> iter = triangle.getLocs().iterator(); 00089 Loc loc; 00090 while(iter.hasNext()){ 00091 loc=(Loc)iter.next(); 00092 Sobolev+=Math.abs(getSobel(loc,image)-image.getSobel(loc)); 00093 } 00094 return Sobolev; 00095 } 00096 00097 00102 protected float getSobel(Loc loc,Image image){ 00103 // System.out.println("GeometricImage Sobel"); 00104 // DIfferential operator 00115 float a= 1f/4f; 00116 float c= -1f/4f; 00117 00118 float g= -1f/4f; 00119 float i= 1f/4f; 00120 00121 int aantal=0; 00122 float waarde_a=0; 00123 float waarde_c=0; 00124 float waarde_g=0; 00125 float waarde_i=0; 00126 00127 Loc l=new Loc(loc.getX()-1,loc.getY()); 00128 // links 00129 if(image.contains(l)){ 00130 aantal++; 00131 // waarde_a=getFunctiewaardeOn(l); 00132 } 00133 00134 00135 00136 l.setX(loc.getX()-1); 00137 l.setY(loc.getY()+1); 00138 // linksboven 00139 if(image.contains(l)){ 00140 waarde_a=getFunctiewaardeOn(l); 00141 }else{ a=0; i=0; g=1/2;i=-1/2; } 00142 // rechtsboven 00143 l.setX(loc.getX()+1); 00144 l.setY(loc.getY()+1); 00145 if(image.contains(l)){ 00146 waarde_c=getFunctiewaardeOn(l); 00147 } 00148 // linksonder 00149 l.setX(loc.getX()-1); 00150 l.setY(loc.getY()-1); 00151 if(image.contains(l)){ 00152 waarde_g=getFunctiewaardeOn(l); 00153 } 00154 // rechtsonder 00155 l.setX(loc.getX()+1); 00156 l.setY(loc.getY()-1); 00157 if(image.contains(l)){ 00158 waarde_i=getFunctiewaardeOn(l); 00159 } 00160 return a*waarde_a+c*waarde_c+g*waarde_g+i*waarde_i; 00161 } 00162 }
1.5.5