00001 package testbench;
00002
00003 import java.io.File;
00004 import java.io.FileNotFoundException;
00005 import java.io.PrintStream;
00006 import java.io.PrintWriter;
00007
00008 import commandline.CodingUtils.ByteConvertor;
00009 import commandline.CodingUtils.CommitDataStructure;
00010 import commandline.Decoder.NormalMeshDecoder;
00011 import commandline.Distributions.VerticalDistribution;
00012 import commandline.Encoder.EncoderEdge;
00013 import commandline.Encoder.EncoderTypeSelector;
00014 import commandline.Encoder.NormalMeshEncoder;
00015 import commandline.Encoder.Iterators.MeshIteratorSelector;
00016 import commandline.ImageStuff.GeometricObjects.GenericEdge;
00017 import commandline.ImageStuff.GeometricObjects.factories.GenericEdgeConstructorTriangleMakerFactory;
00018 import commandline.TxTPackage.DirectoryAndFileClass;
00019 import commandline.binToFilePackage.BinaryFeed;
00020 import commandline.debuggingCode.Debug;
00021 import commandline.flatFileToBinaryPackage.HuffMan.Huffman;
00022
00023
00030 public class NormalIndexAndVerticalOffsetTestBench{
00031 private PrintStream outputStream;
00032 private PrintWriter printWriter;
00033 protected String path_to_out_dir;
00034 protected String pre;
00035 protected File file;
00036
00037 public NormalIndexAndVerticalOffsetTestBench(File file,String[] args,String path_to_out_dir) {
00038 this.file=file;
00039 this.path_to_out_dir=path_to_out_dir;
00040 this.pre="nv_";
00041 try{
00042 outputStream=new PrintStream(file);
00043 }catch(FileNotFoundException exception){
00044 exception.printStackTrace();
00045 }
00046 printWriter=new PrintWriter(outputStream);
00047 printWriter.println("%H L lengte normal_index vertikaloffset oppervlakte state");
00048 try {
00049 perform(args);
00050 } catch (FileNotFoundException e) {
00051
00052 e.printStackTrace();
00053 }
00054 }
00055
00056 public void perform(String args[]) throws FileNotFoundException{
00057
00058 NormalMeshEncoder encoder=NormalMeshEncoder.commandline(args);
00059
00060 update(encoder);
00061 }
00062
00063 public void update(NormalMeshEncoder encoder){
00064
00065 CommitDataStructure dataStructure= encoder.getTriangleStorage().getDataStructure();
00066 EncoderEdge encoderEdge=null;
00067 float H,lengte,L;
00068 float normal_index,vertical_index,oppervlakte,genormaliseerde_verticale_offset;
00069 printWriter.println("prob_table=[");
00070 for(GenericEdge edge: dataStructure.getEdgeList()){
00071 try{
00072 encoderEdge=(EncoderEdge) edge;
00073 if(encoderEdge.hasChildren()){
00074 H=Math.abs(encoderEdge.getBegin().getZ()-encoderEdge.getEind().getZ());
00075 L=encoderEdge.getLengte();
00076 lengte=encoderEdge.getEuclidischeLengte();
00077 normal_index=encoderEdge.getNormalOffset();
00078 vertical_index=encoderEdge.getVerticalOffset();
00079 genormaliseerde_verticale_offset=vertical_index*encoderEdge.getNormalisationFactor();
00080 oppervlakte=encoderEdge.getNormalisationFactor();
00081 String state=encoderEdge.getState().getStateString();
00082 int state_int=0;
00083 if(state.equals("A")){state_int=0;}
00084 if(state.equals("B")){state_int=1;}
00085 if(state.equals("C")){state_int=2;}
00086 printWriter.println("["+ H + " "+ L +" "+ lengte+" "+normal_index +" " +vertical_index+ " "+ oppervlakte+ " " + state_int+" " +genormaliseerde_verticale_offset+"]");
00087 }
00088 }catch(ClassCastException castException){
00089
00090 }
00091
00092 }
00093 printWriter.println("];");
00094 printWriter.flush();
00095
00096
00097
00098
00099
00100
00101 NormalMeshDecoder decoder;
00102
00106 printWriter.println("PMF_dist= [");
00107 try {
00108 String nob_file=encoder.getConfiguration().getOutputDir()+File.separator+
00109 encoder.getConfiguration().getOutputName()+".nob";
00110
00111 decoder = new NormalMeshDecoder( nob_file,new GenericEdgeConstructorTriangleMakerFactory());
00112 BinaryFeed binaryFeed=decoder.getBinaryFeed();
00113 VerticalDistribution distribution= binaryFeed.getVerticalOffsetIterator().getVerticalDistribution();
00114 double[] PMF=distribution.getPMF(-ByteConvertor.MAX_COLOR_VALUE,ByteConvertor.MAX_COLOR_VALUE, 0);
00115 for (int i = 0; i < PMF.length; i++) {
00116 printWriter.println(""+PMF[i]);
00117 }
00118
00119 } catch (FileNotFoundException e) {
00120 e.printStackTrace();
00121 }catch (NullPointerException nullPointerException) {
00122 System.out.println("you used a GENERIC COMPRESSION -> no PMF attached");
00123 }
00124 printWriter.flush();
00125 printWriter.println("];");
00126
00127
00128
00132 printWriter.println("vertical_PMF= strvcat(...");
00133 try {
00134 String nob_file=encoder.getConfiguration().getOutputDir()+File.separator+
00135 encoder.getConfiguration().getOutputName()+".nob";
00136
00137 decoder = new NormalMeshDecoder(nob_file,new GenericEdgeConstructorTriangleMakerFactory());
00138 BinaryFeed binaryFeed=decoder.getBinaryFeed();
00139 VerticalDistribution distribution= binaryFeed.getVerticalOffsetIterator().getVerticalDistribution();
00140 double[] PMF=distribution.getPMF(-ByteConvertor.MAX_COLOR_VALUE,ByteConvertor.MAX_COLOR_VALUE, 0);
00141 Huffman huffman=new Huffman(PMF);
00142 for (int i = -ByteConvertor.MAX_COLOR_VALUE; i <=ByteConvertor.MAX_COLOR_VALUE; i++) {
00143 printWriter.println("'"+huffman.charCode(i+ByteConvertor.MAX_COLOR_VALUE)+"',...");
00144 }
00145 } catch (FileNotFoundException e) {
00146 e.printStackTrace();
00147 }catch (NullPointerException nullPointerException) {
00148 System.out.println("you used a GENERIC COMPRESSION -> no PMF attached");
00149 }
00150 printWriter.flush();
00151 printWriter.println("'2');");
00152
00153
00158 printWriter.close();
00159 Debug.print("file printed to: "+ file.getAbsolutePath());
00160
00161 }
00162
00163
00164
00165 public static void processImage(String extra_name,String path_output_dir,String args[]){
00166 String s=File.separator;
00167 Debug.print("path_output_dir= "+path_output_dir);
00168 new NormalIndexAndVerticalOffsetTestBench(new File(path_output_dir+s+ "table_"+extra_name+".m"),args,path_output_dir);
00169 Debug.print("written to " + path_output_dir);
00170
00171 }
00172
00173 public static void main(String args_2[]){
00174
00175
00176
00177
00178
00179 String s=File.separator;
00180 String name= "hor_1_little";
00181 String path_output_dir=Paths.pathToRateDistortionOutput+s+"prob_"+name;
00182 DirectoryAndFileClass.makeDir(path_output_dir);
00183
00184 for (int stop=100;stop <=1000;stop+=100){
00185 String[] args=new String[]{
00186 "-i", ""+Paths.getPathToImageDB()+s+name+".bmp",
00187 "-o" ,""+ path_output_dir,
00188 "-n", name+"_"+stop,
00189 "-IT",""+MeshIteratorSelector.UNTIL_NUMBER_OF_TRIANGLES_REACHED,
00190 "-stop",""+ stop,
00191 "-compressiontype", EncoderTypeSelector.getNameForCompressionType(EncoderTypeSelector.HUFFMAN_POWER_LAW),
00192 "-maxr",""+12
00193 };
00194 NormalIndexAndVerticalOffsetTestBench.processImage("_"+stop,path_output_dir,args);
00195 }
00196 }
00197
00198 }