00001 package flatFileToBinaryPackage;
00002
00003 import java.io.IOException;
00004 import java.util.ArrayList;
00005
00006 import CodingUtils.ByteConvertor;
00007 import CodingUtils.CodedFile;
00008 import CodingUtils.DataStructure;
00009 import Encoder.EncoderEdge;
00010 import HuffMan.Huffman;
00011 import ImageStuff.GenericEdge;
00012
00013 public class LogDecayNormalIndexFlatToBin extends Flat2Bin {
00014
00015 public static final float PROB_SCALE_FACTOR=1000;
00016 public LogDecayNormalIndexFlatToBin(DataStructure dataStructure,
00017 CodedFile treeStucture, MyDataOutPutStream dos) {
00018 super(dataStructure, treeStucture, dos);
00019
00020 }
00021
00022 protected void writeTesselations(){
00023
00024 float[] count=new float[4];
00025 for(String s: breathFirstDatastructure.getTesselationFile().getCodeWoorden()){
00026 if(s.equals("00")){count[0]++;}
00027 if(s.equals("01")){count[1]++;}
00028 if(s.equals("10")){count[2]++;}
00029 if(s.equals("11")){count[3]++;}
00030 }
00031 float totalcount=count[0]+count[1]+count[2]+count[3];
00032
00033
00034 count[0]=(int)Math.round(count[0]/totalcount*PROB_SCALE_FACTOR);
00035 count[1]=(int)Math.round(count[1]/totalcount*PROB_SCALE_FACTOR);
00036 count[2]=(int)Math.round(count[2]/totalcount*PROB_SCALE_FACTOR);
00037 count[3]=(int)Math.round(count[3]/totalcount*PROB_SCALE_FACTOR);
00038 Debug.print("* writing the percentage of occurence of symbol 00 = "+ (int)count[0]);
00039 super.writeShort((int)count[0]);
00040 Debug.print("* writing the percentage of occurence of symbol 01 = "+ (int)count[1]);
00041 super.writeShort((int)count[1]);
00042 Debug.print("* writing the percentage of occurence of symbol 10 = "+ (int)count[2]);
00043 super.writeShort((int)count[2]);
00044 Debug.print("* writing the percentage of occurence of symbol 11 = "+ (int)count[3]);
00045 super.writeShort((int)count[3]);
00046
00047 count[0]=count[0]/PROB_SCALE_FACTOR;
00048 count[1]=count[1]/PROB_SCALE_FACTOR;
00049 count[2]=count[2]/PROB_SCALE_FACTOR;
00050 count[3]=count[3]/PROB_SCALE_FACTOR;
00051 Huffman h =new Huffman(count);
00052 h.compress();
00053 String code;
00054
00055 for (int i =0;i!=count.length;i++){
00056 code =h.charCode(i);
00057 if(!Debug.DISTIBUTION) Debug.print("de code van de het " +i+"-de woord met kans "+ h._count[i]+ " ="+ code);
00058 }
00059
00060 ArrayList<String> string_code_00=ByteConvertor.StringToStringArrayOfBits(h.charCode(0));
00061 ArrayList<String> string_code_01=ByteConvertor.StringToStringArrayOfBits(h.charCode(1));
00062 ArrayList<String> string_code_10=ByteConvertor.StringToStringArrayOfBits(h.charCode(2));
00063 ArrayList<String> string_code_11=ByteConvertor.StringToStringArrayOfBits(h.charCode(3));
00064
00065 ArrayList<String> tesselationbits=new ArrayList<String>();
00066 for(String s: breathFirstDatastructure.getTesselationFile().getCodeWoorden()){
00067 if(s.equals("00")){tesselationbits.addAll(string_code_00);}
00068 if(s.equals("01")){tesselationbits.addAll(string_code_01);}
00069 if(s.equals("10")){tesselationbits.addAll(string_code_10);}
00070 if(s.equals("11")){tesselationbits.addAll(string_code_11);}
00071 }
00072
00073 int bitwinst=2*breathFirstDatastructure.getTesselationFile().getCodeWoorden().size()
00074 -tesselationbits.size();
00075 Debug.print("winst gehaald uit het Huffmanencoderen van de Tesselatie= " + bitwinst +" byte of " + (int)(bitwinst/8000) + "kB");
00076
00077 try{
00078 int number_of_tesselationcodewords=breathFirstDatastructure.getTesselationFile().getCodeWoorden().size();
00079 Debug.print("* writing the number of tesselation codewords " + number_of_tesselationcodewords);
00080 writeShort(number_of_tesselationcodewords);
00081 Debug.print("* writing series of tesselation bits");
00082 super.writeArrayListOfBitStringsToBytes(tesselationbits);}
00083 catch(IOException exception){
00084 exception.printStackTrace(System.out);
00085 }
00086
00087
00088 }
00089 protected void writeOffsets(){
00090 this.writeVerticalOffsets();
00091 this.writeNormalOffsets();
00092 }
00093
00094
00095
00096
00097 protected void writeVerticalOffsets(){
00098 ArrayList<String> verticaloffsetbits=new ArrayList<String>();
00099
00100
00101 int lengte=ByteConvertor.BITS_PER_VERTICAL_OFFSET;
00102 int winstopVerticalOffsets=0;
00103 for(GenericEdge e: super.breathFirstDatastructure.getParentCommitOrderedList()){
00104
00105 String[] verticalindex=ByteConvertor.getStringArrayOfBitsFor(ByteConvertor.MAX_COLOR_VALUE+(int)e.getVerticalOffset(),lengte);
00106 winstopVerticalOffsets+=16-lengte;
00107 for(String s: verticalindex){
00108 verticaloffsetbits.add(s);
00109 }
00110 }
00111
00112 Debug.print("BITWINST OP DE Verticale OFFSETS DOOR LOG_2 = " + winstopVerticalOffsets +" of "+(int)(winstopVerticalOffsets/8000) +"kB");
00113 try{
00114 int number_of_vertical_offsets=verticaloffsetbits.size()/ByteConvertor.BITS_PER_VERTICAL_OFFSET;
00115 if(!Debug.DISTIBUTION) Debug.print("* writing number of verticaloffset 9-tuple bitarrays = " + number_of_vertical_offsets);
00116 super.writeShort(number_of_vertical_offsets);
00117 if(!Debug.DISTIBUTION) Debug.print("* writing series of verticaloffset bits");
00118 super.writeArrayListOfBitStringsToBytes(verticaloffsetbits);}
00119 catch(IOException exception){
00120 exception.printStackTrace(System.out);
00121 }
00122
00123 }
00124
00125 protected void writeNormalOffsets(){
00126 ArrayList<String> normaloffsetbits=new ArrayList<String>();
00127 int lengte;
00128 int winstopNormalOffsets=0;
00129 int number_of_normal_offsets=0;
00130 for(GenericEdge e: super.breathFirstDatastructure.getParentCommitOrderedList()){
00131
00132 number_of_normal_offsets++;
00133 lengte=ByteConvertor.nbrBitsForNbrCodeWords(e.getLengte());
00134 String[] normalindex=ByteConvertor.getStringArrayOfBitsFor(e.getNormalOffset(),lengte);
00135 winstopNormalOffsets+=16-lengte;
00136 for(String s: normalindex){
00137 normaloffsetbits.add(s);
00138 }
00139 }
00140
00141 Debug.print("BITWINST OP DE NORMALE OFFSETS DOOR LOG_2 = " + winstopNormalOffsets +" of "+(int)(winstopNormalOffsets/8000) +"kB");
00142
00143 try{
00144 Debug.print("* writing number of normaloffsets = " + number_of_normal_offsets);
00145 super.writeShort(number_of_normal_offsets);
00146 Debug.print("* writing series of normaloffset bits");
00147 super.writeArrayListOfBitStringsToBytes(normaloffsetbits);}
00148 catch(IOException exception){
00149 exception.printStackTrace(System.out);
00150 }
00151 }
00152
00153
00154
00155
00156
00157 }