00001 package commandline.Decoder;
00002
00003 import java.io.File;
00004 import java.io.FileInputStream;
00005 import java.io.FileNotFoundException;
00006 import java.io.PrintStream;
00007
00008 import commandline.Program;
00009 import commandline.CodingUtils.CommitDataStructure;
00010 import commandline.Encoder.Mesh_Save_Type_Enumeration;
00011 import commandline.Encoder.Events.RecodingEvent;
00012 import commandline.ImageStuff.GeometricObjects.factories.EdgeConstructorTriangleMakerFactory;
00013 import commandline.ImageStuff.GeometricObjects.factories.GenericEdgeConstructorTriangleMakerFactory;
00014 import commandline.NormalMeshAlgorithm.CommandLineConfiguration;
00015 import commandline.NormalMeshAlgorithm.Configuration;
00016 import commandline.NormalMeshAlgorithm.ConfigurationReader;
00017 import commandline.binToFilePackage.BinaryFeed;
00018 import commandline.binToFilePackage.MyDataInPutStream;
00019 import commandline.binToFilePackage.MyTestDataInputStream;
00020 import commandline.dataToImage.MeshToImageDataFilter;
00021 import commandline.debuggingCode.Debug;
00029 public class NormalMeshDecoder extends Program {
00030
00031
00032 private CommitDataStructure finalCommitDataStructure;
00033 private BreathFirstDecoder breathFirstDecoder;
00034 private Configuration configuration;
00035 BinaryFeed binaryFeed;
00036 MeshToImageDataFilter triangleStorage;
00037 protected EdgeConstructorTriangleMakerFactory edgeConstructorTriangleMakerFactory;
00043 public NormalMeshDecoder(String path,EdgeConstructorTriangleMakerFactory edgeConstructorTriangleMakerFactory) throws FileNotFoundException {
00044 this.edgeConstructorTriangleMakerFactory=edgeConstructorTriangleMakerFactory;
00045 if(!new File(path).exists()) {throw new FileNotFoundException();}
00046 if(!path.endsWith(".nob")) {
00047 System.err.println("path didn't end on .nob"+ " " + this.getClass().getSimpleName());
00048 }
00049
00050
00051
00052
00053
00054
00055 finalCommitDataStructure=new CommitDataStructure();
00056
00057 MyDataInPutStream codedFileDataInputStream=null;
00058 try{
00059 if(Debug.DEBUG & Debug.DEBUG_DECODER){
00060 codedFileDataInputStream=new MyTestDataInputStream(new FileInputStream(path),
00061 new PrintStream(path+"DECREAD"));
00062 }
00063 else{
00064 codedFileDataInputStream=new MyDataInPutStream(new FileInputStream(path));
00065 }
00066 }catch(FileNotFoundException fileNotFoundException){
00067 fileNotFoundException.printStackTrace(System.out);
00068 }
00069
00070
00071 ConfigurationReader configurationReader =new ConfigurationReader(codedFileDataInputStream);
00072 configurationReader.read();
00073 if(Debug.VERBOSE) Debug.print("reading in the configuration");
00074 this.configuration=configurationReader.makeConfiguration();
00075
00076
00077
00078 binaryFeed=new BinaryFeed(edgeConstructorTriangleMakerFactory,codedFileDataInputStream,configuration);
00079 binaryFeed.read();
00080 configuration.setImageDimensions(binaryFeed.getDecoderMesh().getDimension());
00081 }
00082
00083 public void perform(){
00084 breathFirstDecoder=new BreathFirstDecoder(edgeConstructorTriangleMakerFactory,this.binaryFeed,this.binaryFeed.getDecoderMesh() ,this.finalCommitDataStructure,configuration);
00085 breathFirstDecoder.decode();
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 triangleStorage=new MeshToImageDataFilter(configuration.getImageDimension());
00096 triangleStorage.setInput(finalCommitDataStructure);
00097 updateRecodingListeners();
00098 }
00099
00100
00101
00102
00103
00104 private void updateRecodingListeners(){
00105 if(recodingListener!=null){
00106 RecodingEvent event=new RecodingEvent(null,triangleStorage,triangleStorage);
00107 recodingListener.update(event);
00108 }
00109 }
00110
00111
00112 public Program getNewProgram(Configuration configuration) throws FileNotFoundException{
00113 return new NormalMeshDecoder(configuration.getPath(),edgeConstructorTriangleMakerFactory);
00114 }
00115
00116
00117 public void save(Mesh_Save_Type_Enumeration INSTRUCTION, File f){
00118 Debug.print("yet to be inmplemented");
00119 }
00120
00121 public Mesh_Save_Type_Enumeration[] getSaveEnumeration(){
00122 Debug.print("yet to be inmplemented");
00123 return null;
00124 }
00125
00126 public static void main(String args[]) throws FileNotFoundException {
00127 Configuration configuration=new CommandLineConfiguration(args);
00128 NormalMeshDecoder decoder = new NormalMeshDecoder(configuration.getPath(),new GenericEdgeConstructorTriangleMakerFactory());
00129 decoder.perform();
00130 }
00131
00132 public MeshToImageDataFilter getTriangleStorage() {
00133 return triangleStorage;
00134 }
00135
00136 public BinaryFeed getBinaryFeed() {
00137 return binaryFeed;
00138 }
00139
00140 }