00001 package commandline.Encoder;
00002
00003 import java.util.ArrayList;
00004 import java.util.LinkedList;
00005 import java.util.Queue;
00006
00007 import junit.framework.Assert;
00008
00009 import commandline.CodingUtils.CodedFile;
00010 import commandline.Encoder.dynamicProg.Node;
00011 import commandline.ImageStuff.GeometricObjects.GeometricObject;
00012
00013
00014
00015
00016
00017
00018 public class BreathFirstTreeStructureEncoder{
00019
00020 CodedFile codedFile,metadata;
00021 Queue<Node> queue;
00022 public BreathFirstTreeStructureEncoder(ArrayList<Node> rootNodes,CodedFile codedFile, CodedFile metadata) {
00023 queue=new LinkedList<Node>();
00024 queue.addAll(rootNodes);
00025 this.codedFile=codedFile;
00026 this.metadata=metadata;
00027 encode();
00028 }
00029
00030
00031 public void encode(){
00032 GeometricObject nextGeometricObject;
00033 Node node;
00034 while(!queue.isEmpty()){
00035 node=queue.poll();
00036 nextGeometricObject=node.getGeometricObject();
00037
00038
00039
00040 if(nextGeometricObject.isATriangle() && !nextGeometricObject.hasToBeConsidered()){
00041
00042
00043 if(node.hasChildren()){
00044 codedFile.addString("1", "hasChildren");
00045 ArrayList<GeometricObject> children= nextGeometricObject.getChildren();
00046 ArrayList<Node> parts=new ArrayList<Node>();
00047 for(int i=0;i!=nextGeometricObject.getNbrOfEdges();i++){
00048 GeometricObject geomPart=nextGeometricObject.getEdge(i);
00049 if(children.contains(geomPart)){
00050 codedFile.addString("1","furtherexists");
00051
00052 Assert.assertNotNull(node.getChildCoupledtoGeomObj(geomPart));
00053 parts.add(node.getChildCoupledtoGeomObj(geomPart));
00054 Assert.assertTrue(node.getChildCoupledtoGeomObj(geomPart).getGeometricObject()==geomPart);
00055 }
00056 else{
00057 codedFile.addString("0","doesnotexistanylonger");
00058 }
00059 }
00060
00061 queue.addAll(parts);
00062 }else{
00063 codedFile.addString("0","hasNoChildren");
00064 }
00065 }
00066 else{
00067
00068 if(nextGeometricObject.isAnEdge() && nextGeometricObject.getEdge(0).getLengte()<=2){
00069
00070 }else{
00071 if( !node.hasChildren()){
00072 codedFile.addString("0","hasNoChildren");
00073
00074 }
00075 else{
00076 codedFile.addString("1","hasChildren");
00077 queue.addAll(node.getChildren());
00078 }
00079 }
00080 }
00081 }
00082 metadata.addString(""+codedFile.getCodeWoorden().size(),"lengte_binaire_enc");
00083
00084 }
00085
00086
00087
00088
00089 }