00001 package commandline.ImageStuff.Topology;
00002 import java.util.ArrayList;
00003 import java.util.HashSet;
00004 import java.util.Iterator;
00005
00006 import commandline.ImageStuff.Image;
00007 import commandline.ImageStuff.Loc;
00008 import commandline.ImageStuff.GeometricObjects.GeometricObject;
00009 import commandline.ImageStuff.GeometricObjects.Triangle;
00010 import commandline.debuggingCode.Debug;
00011
00012
00017 public class ImageDependent_ConnectionCriterium extends ConnectieCriterium{
00018
00019 protected int NORM;
00020 protected static ImageDependent_ConnectionCriterium theInstance=null;
00021 protected ImageDependent_ConnectionCriterium(int NORM){
00022 this.NORM=NORM;
00023 }
00024
00025 static ConnectieCriterium getInstance(int NORM){
00026 if(theInstance!=null && NORM==theInstance.getNORM()){return theInstance;}
00027
00028 return new ImageDependent_ConnectionCriterium(NORM);
00029 }
00030
00031 public String getInformation(){
00032 return " smallest L_p norm";
00033 }
00034
00035
00036 public int getType(){
00037 return ConnectionCriteriumSelector.IMAGE_DEPENDENT_CONNECTION_CRITERIUM;
00038 }
00039
00040
00041
00042
00043
00044
00045
00046
00047 public GenericTriangleTesselation besteConnectie(TriangleTesselationSet t){
00048
00049 DistanceBasket basket_best=getErrorBasket(t.getTesselation(TriangleTesselationSet.ENUM[0]));
00050 DistanceBasket tempbasket;
00051 float error=basket_best.getTotalTesselationError(NORM);
00052 float error_temp=0;
00053 int selectie=TriangleTesselationSet.ENUM[0];
00054
00055 for (int k=1;k!=TriangleTesselationSet.ENUM.length;k++){
00056 GenericTriangleTesselation tes=t.getTesselation(TriangleTesselationSet.ENUM[k]);
00057 tempbasket=getErrorBasket(tes);
00058 error_temp=tempbasket.getTotalTesselationError(NORM);
00059 if(error_temp<error){
00060 error=error_temp;
00061 selectie=TriangleTesselationSet.ENUM[k];
00062 basket_best=tempbasket;
00063 }
00064 }
00065
00066
00067 return t.getTesselation(selectie);
00068 }
00069
00076 public DistanceBasket getErrorBasket(GenericTriangleTesselation tesselation){
00077 ArrayList <GeometricObject> d=tesselation.getParts();
00078 int[] size_locs=new int[d.size()];
00079 for(int i =0; i!=d.size();i++){
00080 size_locs[i]=d.get(i).getLocs().size();
00081 }
00082
00083 DistanceBasket basket= new DistanceBasket(d.size(),size_locs);
00084
00085 for(int i =0;i!=d.size();i++){
00086 HashSet<Loc> locs=(HashSet<Loc>)d.get(i).getLocs().clone();
00087 for(int j=0;j<i;j++){
00088 locs.removeAll(d.get(j).getLocs());
00089 }
00090 Iterator<Loc> I =locs.iterator();
00091 float verschil=0; float verschil_stelling=0;
00092
00093 Loc temp;
00094 while(I.hasNext()){
00095 temp=(Loc)(I.next());
00096 verschil=d.get(i).getFunctiewaardeOn(temp)-Image.getInstance().getPuntOpEnty(temp).getZ();
00097 verschil_stelling=d.get(i).fundamentenwaardeOn(temp)-Image.getInstance().getPuntOpEnty(temp).getZ();
00098 basket.add_diff_func(i,verschil);
00099 basket.add_diff_stelling(i, verschil_stelling);
00100 }
00101
00102 }
00103
00104 return basket;
00105 }
00106
00107
00108
00109
00110
00111
00112
00113 private static void test(Triangle[] d, Triangle parent,int TOPOLOGIE){
00114 HashSet<Loc> h=(HashSet<Loc>)parent.getLocs().clone();
00115 for(int i =0;i!=d.length;i++){
00116 h.removeAll(d[i].getLocs());
00117 }
00118
00119 HashSet<Loc> grote=(HashSet<Loc>)parent.getLocs().clone();
00120 HashSet<Loc> alle_kleine=new HashSet<Loc>();
00121 for(int i =0;i!=d.length;i++){
00122 alle_kleine.addAll(d[i].getLocs());
00123 }
00124 alle_kleine.removeAll(grote);
00125
00126 HashSet<Loc> parent_edges=new HashSet<Loc>();
00127 parent_edges.addAll(parent.getEdge(0).getLocs());
00128 parent_edges.addAll(parent.getEdge(1).getLocs());
00129 parent_edges.addAll(parent.getEdge(2).getLocs());
00130
00131
00132 HashSet<Loc> children_edges=new HashSet<Loc>();
00133 for(int i =0;i!=d.length;i++){
00134 children_edges.addAll(d[i].getEdge(0).getLocs());
00135 children_edges.addAll(d[i].getEdge(1).getLocs());
00136 children_edges.addAll(d[i].getEdge(2).getLocs());
00137 }
00138 HashSet<Loc> dif_1=new HashSet<Loc>(parent_edges);
00139 dif_1.removeAll(children_edges);
00140
00141
00142
00143 if(h.size()!=0 || alle_kleine.size() != 0 || dif_1.size()!=0){
00144 Debug.print("Topologie:= "+ TOPOLOGIE);
00145 Debug.print("grootte van disjuctie (parent \\ children):= "+h.size()+ " (zou nul moeten zijn!)");
00146 Debug.print("grootte van disjuctie (children \\ parent ):= "+alle_kleine.size()+ " (zou nul moeten zijn!)");
00147 Debug.print("grootte van disjuctie (parent edges \\ children edges):= "+dif_1.size()+ " (zou nul moeten zijn!)");
00148
00149 parent.printInfo();
00150 d[0].printInfo();
00151 d[1].printInfo();
00152 d[2].printInfo();
00153 d[3].printInfo();
00154 Debug.print("ontbrekende locs");
00155 Iterator<Loc> I=alle_kleine.iterator();
00156 while(I.hasNext()){
00157 ((Loc)(I.next())).print();
00158 }
00159 }
00160 }
00161
00162 public int getNORM() {
00163 return NORM;
00164 }
00165
00166 }