00001 package commandline.ImageStuff.GeometricObjects; 00002 00003 import java.util.ArrayList; 00004 import java.util.HashSet; 00005 import java.util.Iterator; 00006 00007 import commandline.ImageStuff.HierachicalInterFace; 00008 import commandline.ImageStuff.Image; 00009 import commandline.ImageStuff.Loc; 00010 import commandline.ImageStuff.GeometricObjects.Impl.TriangleImplType; 00011 import commandline.ImageStuff.GeometricObjects.factories.EdgeConstructorTriangleMakerFactory; 00012 import commandline.ImageStuff.Properties.DefaultGeometricProperty; 00013 import commandline.ImageStuff.Properties.GeometricProperty; 00014 import commandline.ImageStuff.Topology.AbstractTesselation; 00015 import commandline.ImageStuff.Topology.ConnectieCriterium; 00016 import commandline.Norm.NormenMaker; 00017 import commandline.NormalMeshAlgorithm.Configuration; 00018 import commandline.NormalMeshAlgorithm.SnijPixelStrategy; 00019 import commandline.debuggingCode.Debug; 00020 00028 public abstract class GeometricObject implements HierachicalInterFace<GeometricObject>{ 00029 00030 public final static GeometricObject DEFAULT_GEOM=new Triangle(TriangleImplType.INTERPOLOLATING); // ipv null!! 00031 00032 private GeometricProperty geometricProperty; 00033 protected HashSet<Loc> locs; 00034 private NormenMaker normenMaker; 00035 float Sobolev; 00036 00037 00038 00039 public GeometricObject() { 00040 locs=new HashSet<Loc>(); 00041 this.geometricProperty=DefaultGeometricProperty.getInstance(); 00042 Sobolev=-1; 00043 } 00044 00045 00046 public abstract float getArea(); 00047 public abstract int getAantalPunten(); 00048 public abstract float fundamentenwaardeOn(Loc loc); 00049 public abstract float getHoekInDomain(int index); 00050 public abstract GenericEdge getEdge(int i); 00051 public abstract boolean isATriangle(); 00052 public abstract boolean isAnEdge(); 00053 public abstract int getNbrOfEdges(); 00054 public abstract boolean hasChildren(); 00055 00056 00062 public abstract AbstractTesselation getBestEncoderTesselation(SnijPixelStrategy snijPixelStrategy,ConnectieCriterium connectieCriterium,EdgeConstructorTriangleMakerFactory edgeConstructorTriangleMakerFactory,Configuration configuration); 00063 //public abstract AbstractTesselation getTesselation(SnijPixelStrategy snijPixelStrategy,String choise); 00064 00065 00070 public HashSet<Loc> getLocs(){ 00071 return this.locs; 00072 } 00073 00074 00079 public abstract void disposeLocationSet(); 00080 00081 public boolean contains(Loc loc){ 00082 Iterator<Loc> I=this.locs.iterator(); 00083 while(I.hasNext()){ 00084 Loc l=(Loc)(I.next()); 00085 if(l.isOn(loc)) return true; 00086 } 00087 return false; 00088 } 00089 00090 //protected abstract void VulOp(); 00091 public abstract void setChildren(ArrayList<GeometricObject> children); 00092 public abstract ArrayList<GeometricObject> getChildren(); 00093 00094 00095 public abstract float getFunctiewaardeOn(Loc l); 00096 00097 public abstract boolean hasToBeConsidered(); 00098 00104 public NormenMaker getError(Image image){ 00105 if(this.normenMaker!=null){return normenMaker;} 00106 Iterator<Loc> iter = this.getLocs().iterator(); 00107 Loc loc; 00108 NormenMaker normenmaker=new NormenMaker(this.getLocs().size()); 00109 while(iter.hasNext()){ 00110 loc=(Loc)iter.next(); 00111 00112 if(image.getPuntOpEnty(loc).getZ()-this.getFunctiewaardeOn(loc)==Float.NaN){ 00113 Debug.print("functiewaarde = NAN"); 00114 Debug.print("image.functiewaarde ="+ image.getPuntOpEnty(loc).getZ()); 00115 Debug.print("this.functiewaarde = "+ this.getFunctiewaardeOn(loc)); 00116 00117 } 00118 normenmaker.add(image.getPuntOpEnty(loc).getZ()-this.getFunctiewaardeOn(loc)); 00119 } 00120 00121 // @TODO zorg dat er slechts 1 norm wordt berekend, nl. Diegene die nodig is 00122 normenmaker.addSobelev(this.getSobolevError(image)); 00123 this.normenMaker=normenmaker; 00124 return this.normenMaker; 00125 } 00126 00132 protected float getSobolevError(Image image){ 00133 00134 if(Sobolev!=-1){return Sobolev;} 00135 Sobolev=0; 00136 Iterator<Loc> iter = this.getLocs().iterator(); 00137 Loc loc; 00138 while(iter.hasNext()){ 00139 loc=(Loc)iter.next(); 00140 Sobolev+=Math.abs(getSobel(loc,image)-image.getSobel(loc)); 00141 } 00142 return Sobolev; 00143 } 00144 00145 00150 protected float getSobel(Loc loc,Image image){ 00151 // System.out.println("GeometricImage Sobel"); 00152 // DIfferential operator 00163 float a= 1f/4f; 00164 float c= -1f/4f; 00165 00166 float g= -1f/4f; 00167 float i= 1f/4f; 00168 00169 int aantal=0; 00170 float waarde_a=0; 00171 float waarde_c=0; 00172 float waarde_g=0; 00173 float waarde_i=0; 00174 00175 Loc l=new Loc(loc.getX()-1,loc.getY()); 00176 // links 00177 if(image.contains(l)){ 00178 aantal++; 00179 // waarde_a=getFunctiewaardeOn(l); 00180 } 00181 00182 00183 00184 l.setX(loc.getX()-1); 00185 l.setY(loc.getY()+1); 00186 // linksboven 00187 if(image.contains(l)){ 00188 waarde_a=getFunctiewaardeOn(l); 00189 }else{ a=0; i=0; g=1/2;i=-1/2; } 00190 // rechtsboven 00191 l.setX(loc.getX()+1); 00192 l.setY(loc.getY()+1); 00193 if(image.contains(l)){ 00194 waarde_c=getFunctiewaardeOn(l); 00195 } 00196 // linksonder 00197 l.setX(loc.getX()-1); 00198 l.setY(loc.getY()-1); 00199 if(image.contains(l)){ 00200 waarde_g=getFunctiewaardeOn(l); 00201 } 00202 // rechtsonder 00203 l.setX(loc.getX()+1); 00204 l.setY(loc.getY()-1); 00205 if(image.contains(l)){ 00206 waarde_i=getFunctiewaardeOn(l); 00207 } 00208 return a*waarde_a+c*waarde_c+g*waarde_g+i*waarde_i; 00209 } 00210 00211 00212 public abstract ParametrizedPiercingVertex getVertex(int i); 00213 00214 public abstract ArrayList<ParametrizedPiercingVertex> getOrderedVertices(); 00215 00220 public void setGeometricProperty(GeometricProperty gp){ 00221 this.geometricProperty=gp; 00222 } 00223 00228 public GeometricProperty getGeometricProperty(){ 00229 return geometricProperty; 00230 } 00231 00232 00233 00234 00235 00236 00242 public boolean hasPartiallyEdgeInCommon(GeometricObject geometricObject){ 00243 // assume this.level <= geometricObject.level 00244 for (int i = 0; i < this.getNbrOfEdges(); i++) { 00245 for (int j = 0; j < geometricObject.getNbrOfEdges(); j++) { 00246 if(this.getEdge(i)==geometricObject.getEdge(j)){ 00247 return true; 00248 } 00249 } 00250 } 00251 // none of the edges where in common 00252 00253 // check whether the child edges of this object's edges have 00254 for (int i = 0; i < this.getNbrOfEdges(); i++) { 00255 for(GeometricObject geometricObject2:this.getEdge(i).getChildren()){ // loop over all children of the edge 00256 hasPartiallyEdgeInCommon(geometricObject); // check if it has an edge in common 00257 } 00258 } 00259 00260 // do the same but the other way around (above depents whether this is at a coarser level 00261 // assume this.level >= geometricObject.level 00262 geometricObject.hasPartiallyEdgeInCommon(this); 00263 return false; 00264 } 00265 00266 00267 }
1.5.5