00001 package Encoder; 00002 00003 import java.util.ArrayList; 00004 import java.util.PriorityQueue; 00005 import debuggingCode.Debug; 00006 import CodingUtils.DataStructure; 00007 import CodingUtils.GeometricObjectComparator; 00008 import ImageStuff.GenericEdge; 00009 import ImageStuff.GeometricObject; 00010 import ImageStuff.Image; 00011 import ImageStuff.Triangle; 00012 import ImageStuff.Topology.AbstractTesselation; 00013 import ImageStuff.Topology.ConnectieCriterium; 00014 import ImageStuff.Topology.GenericTriangleTesselation; 00015 import ImageStuff.Topology.ImageDependent_ConnectionCriterium; 00016 import ImageStuff.Topology.TriangleTesselationSet; 00017 import Norm.NormPakket; 00018 import NormalMeshAlgorithm.Configuration; 00019 import NormalMeshAlgorithm.SnijPixelStrategy; 00020 00021 00022 public class GreatestErrorFirstMeshIterator { 00023 00024 private EncoderMesh m; 00025 protected DataStructure dataStructure; 00026 protected PriorityQueue<GeometricObject> sortedGeomQueue; 00027 protected SnijPixelStrategy snijPixelStrategy; 00028 protected ConnectieCriterium connectieCriterium; 00029 protected Configuration configuration; 00030 public GreatestErrorFirstMeshIterator(EncoderMesh m, 00031 DataStructure dataStructure,SnijPixelStrategy snijPixelStrategy,ConnectieCriterium connectieCriterium,Configuration configuration) { 00032 this.configuration=configuration; 00033 this.m=m; 00034 this.dataStructure=dataStructure; 00035 this.snijPixelStrategy=snijPixelStrategy; 00036 this.connectieCriterium=connectieCriterium; 00037 m.commit(dataStructure); 00038 // constructie en initialisatie van een gesorteerde set 00039 sortedGeomQueue=new PriorityQueue<GeometricObject>(dataStructure.getTriangles().size(),new GeometricObjectComparator(this.configuration)); 00040 sortedGeomQueue.addAll(dataStructure.getTriangles()); // alle driehoeken er al insteken 00041 perform(); 00042 setOutputName(); 00043 } 00044 00045 protected void setOutputName(){ 00046 // configuration.setOutputName(configuration.getOutputName()+"_"+(int)(configuration.getError()*1000)); 00047 00048 } 00049 00050 private void perform(){ 00051 GeometricObject nextGeomObj; 00052 // Queue 00053 float error; 00054 // GenericEdge edge; 00055 00056 while(!sortedGeomQueue.isEmpty()){ 00057 nextGeomObj=sortedGeomQueue.poll(); // take the next GeometricObject from the sortedQueue 00058 error=nextGeomObj.getError(Image.getInstance()).getNorm(configuration.getWhichNormToUseForRefinement()); // calculate the error 00059 if(Debug.DEBUG && Debug.DEBUG_ENCODERSTUFF) Debug.print("error " + error + " Edge: " + nextGeomObj.isAnEdge()); 00060 if(stop(error)){ 00061 break; // exit loop 00062 }else{ 00063 if(nextGeomObj.isATriangle()){// Type: Triangle 00064 if(nextGeomObj.hasToBeConsidered()){// hasToBeConsidered 00065 this.tesselateCommitAndAddToQueue(nextGeomObj); // tess & add all children to queue 00066 } 00067 else{ // not has to be considered 00068 // break Triangle in pieces 00069 //parts=new ArrayList(3); // new references to parts 00070 ArrayList<GeometricObject> parts=Splitter.split((Triangle)nextGeomObj,true); 00071 00072 nextGeomObj.setChildren(parts); // setting parts as children to the Triangle 00073 sortedGeomQueue.addAll(parts); // adding parts to be refined in a next step 00074 } 00075 }// end Type: Triangle 00076 if(nextGeomObj.isAnEdge()){ // Type: Edge 00077 if(nextGeomObj.getEdge(0).getLengte()<=2){ // otherwise ChildMaker.BuiltChildren gives back a child refering to the parent edge 00078 //nop the edge collapsed in a point 00079 }else{ 00080 this.tesselateCommitAndAddToQueue(nextGeomObj); // tess & add all children to queue 00081 } 00082 } 00083 00084 00085 00086 00087 00088 }// end else 00089 00090 }// end while 00091 } 00092 00093 protected boolean stop(float status){ 00094 return status<configuration.getError(); 00095 } 00096 00097 private void tesselateCommitAndAddToQueue(GeometricObject nextGeomObj){ 00098 // adds all parts of the best possible tesselation in the queue 00099 AbstractTesselation tesselation=nextGeomObj.getBestEncoderTesselation(snijPixelStrategy,connectieCriterium); 00100 tesselation.commit(dataStructure); 00101 for(GeometricObject t: nextGeomObj.getChildren()){ 00102 sortedGeomQueue.add(t);} 00103 } 00104 00105 00106 00107 00108 00109 00110 00111 }
1.5.5