00001 package commandline.NormalMeshAlgorithm;
00002
00003
00004 import java.io.File;
00005
00006 import commandline.Encoder.EncoderTypeSelector;
00007 import commandline.Encoder.Iterators.MeshIteratorSelector;
00008 import commandline.ImageStuff.Topology.ConnectieCriterium;
00009 import commandline.ImageStuff.Topology.ConnectionCriteriumSelector;
00010 import commandline.debuggingCode.Debug;
00011 import commandlineprocessing.OptionSet;
00012 import commandlineprocessing.Options;
00013 import commandlineprocessing.Options.Multiplicity;
00014 import commandlineprocessing.Options.Separator;
00015
00016 public class CommandLineConfiguration extends Configuration {
00017
00018 private Options opt;
00019 public CommandLineConfiguration(String[] options){
00020 configure_commandline(options);
00021 feedArgsToConfiguration();
00022
00023 }
00024
00025
00026 private void configure_commandline(String[] args){
00027
00028 opt = new Options(args,0,1);
00029
00030 opt.addSet("help").addOption("h",Multiplicity.ONCE);
00031
00032 opt.addSet("encode");
00033 OptionSet encode=opt.getSet("encode");
00034
00035 encode.addOption("i",Separator.BLANK,Multiplicity.ONCE_OR_MORE);
00036 encode.addOption("o",Separator.BLANK,Multiplicity.ONCE_OR_MORE);
00037 encode.addOption("n",Separator.BLANK,Multiplicity.ONCE_OR_MORE);
00038 encode.addOption("IT",Separator.BLANK,Multiplicity.ONCE_OR_MORE);
00039 encode.addOption("stop",Separator.BLANK,Multiplicity.ONCE_OR_MORE);
00040
00041 encode.addOption("p",Separator.BLANK,Multiplicity.ZERO_OR_MORE);
00042 encode.addOption("Con",Separator.BLANK,Multiplicity.ZERO_OR_MORE);
00043 encode.addOption("Wnr",Separator.BLANK,Multiplicity.ZERO_OR_MORE);
00044 encode.addOption("Wnt",Separator.BLANK,Multiplicity.ZERO_OR_MORE);
00045 encode.addOption("compressiontype",Separator.BLANK,Multiplicity.ZERO_OR_MORE);
00046 encode.addOption("maxr",Separator.BLANK,Multiplicity.ZERO_OR_MORE);
00047 encode.addOption("snij",Separator.BLANK,Multiplicity.ZERO_OR_MORE);
00048
00049 encode.addOption("mb",Separator.BLANK,Multiplicity.ZERO_OR_MORE);
00050 encode.addOption("perc",Separator.BLANK,Multiplicity.ZERO_OR_MORE);
00051 encode.addOption("k",Separator.BLANK,Multiplicity.ZERO_OR_MORE);
00052 encode.addOption("L",Separator.BLANK,Multiplicity.ZERO_OR_MORE);
00053 encode.addOption("N",Separator.BLANK,Multiplicity.ZERO_OR_MORE);
00054 encode.addOption("D",Separator.BLANK,Multiplicity.ZERO_OR_MORE);
00055 encode.addOption("vtk",Separator.BLANK,Multiplicity.ZERO_OR_MORE);
00056 opt.addSet("decode");
00057 OptionSet decode=opt.getSet("decode");
00058 decode.addOption("i",Separator.BLANK,Multiplicity.ONCE_OR_MORE);
00059 decode.addOption("o",Separator.BLANK,Multiplicity.ONCE_OR_MORE);
00060 decode.addOption("n",Separator.BLANK,Multiplicity.ONCE_OR_MORE);
00061
00062
00063 }
00064
00065
00066
00067
00068
00069
00070 private void printHelp(){
00071
00072 Debug.print("-i <path> -o <dir> -n <string> -IT <int> -stop <float|int> [-p <float>] [-Con <int> -Wnr <int> -Wnt <int>] [-compressiontype <Generic| Huffman | Power_Law>] [-maxr <int>]");
00073 Debug.print("-i " + "path: filepath for the image to compress");
00074 Debug.print("-o "+" path: directory path for the output image" );
00075 Debug.print("-n "+"name of the output file[without extension]" );
00076 Debug.print("-IT" +" MeshIteratorTYPE:");
00077 MeshIteratorSelector.getHelp(System.out);
00078 Debug.print("-stop " + " float to stop meaning depending on the value of -IT");
00079 Debug.print("OPTIONAL: ");
00080 Debug.print("-p"+" pruning and value for lagrangian (typically 0..100) ");
00081 Debug.print("-Con"+" ConnectionCriterium: ");
00082 ConnectionCriteriumSelector.getHelp(System.out);
00083 Debug.print("-Wnr" + " WichNormToUseFoRRefinement: [0,1,2] [infty,L_1,L_2]");
00084 Debug.print("-Wnt" + " WichNormToUseFoRTesselation: [0,1,2] [infty,L_1,L_2]");
00085 Debug.print("-compressiontype"+ " Generic, Huffman ,Power_Law" );
00086 Debug.print("-maxr" +" maximal slope of the normal");
00087 Debug.print("-snij" +" snijpixelstrategie [0,1,2]");
00088
00089
00090
00091
00092
00093 Debug.print("------Basemesh properties------");
00094 Debug.print("-mb" +" if present, makes basemesh");
00095 Debug.print("-perc [0,1] percentage of vertices to keep in basemesh");
00096 Debug.print("-k" +" [int] innerpixel distance for raster");
00097 Debug.print("-L" +" [int]");
00098 Debug.print("-N" +" [int]");
00099 Debug.print("-D" +" DEGREE [int] greatest angle in basemesh");
00100
00101 Debug.print("------Basemesh properties------");
00102 Debug.print("-vtk"+ " true" );
00103
00104 Debug.print(" Examples");
00105 Debug.print("(1) >>java -Xmx825m -cp nodic.jar commandline.Encoder.NormalMeshEncoder");
00106 Debug.print(" -i victoria_crater.bmp -o C:\\output -n victoria -IT 0 -stop 50");
00107
00108 }
00109
00110
00111 private void feedArgsToConfiguration(){
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 OptionSet set = opt.getMatchingSet();
00129
00130
00131
00132 if(set==null){
00133 System.err.println("no matching commandline set found!");
00134 System.err.println(opt.getCheckErrors());
00135 this.printHelp();
00136 System.exit(-1);
00137 }
00138
00139
00140 if(set.getSetName().equals("help")){
00141 if (!opt.check("help")) {
00142 System.err.println(opt.getCheckErrors());
00143
00144 printHelp();
00145 System.exit(1);
00146 }
00147 }
00148
00149 if(set.getSetName().equals("decode") ){
00150 if (!opt.check("decode")) {
00151 System.err.println(opt.getCheckErrors());
00152
00153 printHelp();
00154 System.exit(1);
00155 }
00156
00157 if (set.isSet("i")){
00158 String path=set.getOption("i").getResultValue(0);
00159 super.setPath(path);
00160 int pos = path.lastIndexOf(File.separator);
00161 String naam = path.substring(pos+1,path.length());
00162 super.setImageName(naam);
00163 Debug.print("Image Name=" + naam);
00164 }
00165
00166 if (set.isSet("o")){
00167 String outdir=set.getOption("o").getResultValue(0);
00168 setOutputDir(outdir);
00169 }
00170
00171 if (set.isSet("n")){
00172 String outputname= set.getOption("n").getResultValue(0);
00173 super.setOutputName(outputname);
00174 }
00175 }
00176
00177
00178
00179
00180 if(set.getSetName().equals("encode")
00181
00182 ){
00183 if (!opt.check("encode")) {
00184 System.err.println(opt.getCheckErrors());
00185
00186 printHelp();
00187 System.exit(1);
00188 }
00189
00190 if (set.isSet("i")){
00191 String path=set.getOption("i").getResultValue(0);
00192 super.setPath(path);
00193 int pos = path.lastIndexOf(File.separator);
00194 String naam = path.substring(pos+1,path.length());
00195 super.setImageName(naam);
00196 Debug.print("Image Name=" + naam);
00197 }
00198
00199 if (set.isSet("o")){
00200 String outdir=set.getOption("o").getResultValue(0);
00201 setOutputDir(outdir);
00202 }
00203
00204 if (set.isSet("n")){
00205 String outputname= set.getOption("n").getResultValue(0);
00206 super.setOutputName(outputname);
00207 }
00208
00209 if (set.isSet("IT")){
00210 String iterType=set.getOption("IT").getResultValue(0);
00211 super.setIteratorType(Integer.valueOf(iterType).intValue());
00212 }
00213
00214 if (set.isSet("stop")){
00215 String stop=set.getOption("stop").getResultValue(0);
00216 super.setStopValue(Integer.valueOf(stop).intValue());
00217 }
00218
00219 if (set.isSet("p")){
00220 String prune=set.getOption("p").getResultValue(0);
00221 super.setPrune(true);
00222 super.setLagrangian(Float.valueOf(prune).floatValue());
00223 }
00224
00225 if (set.isSet("compressiontype")){
00226 String comprType=set.getOption("compressiontype").getResultValue(0);
00227 if(comprType.equalsIgnoreCase(EncoderTypeSelector.getNameForCompressionType(EncoderTypeSelector.GENERIC_COMPRESSION))){super.setCompressionType(EncoderTypeSelector.GENERIC_COMPRESSION);}
00228 if(comprType.equalsIgnoreCase(EncoderTypeSelector.getNameForCompressionType(EncoderTypeSelector.HUFFMAN_COMPRESSION))){super.setCompressionType(EncoderTypeSelector.HUFFMAN_COMPRESSION);}
00229 if(comprType.equalsIgnoreCase(EncoderTypeSelector.getNameForCompressionType(EncoderTypeSelector.HUFFMAN_POWER_LAW))){super.setCompressionType(EncoderTypeSelector.HUFFMAN_POWER_LAW);}
00230 }
00231 }
00232
00233 if (set.isSet("Con")){
00234 String connType=set.getOption("Con").getResultValue(0);
00235 super.setConnectionCriterium(ConnectionCriteriumSelector.createCriterium(Integer.valueOf(connType).intValue(),super.getWhichNormToUseForTesselation()));
00236 }
00237
00238 if (set.isSet("Wnr")){
00239 String refNorm= set.getOption("Wnr").getResultValue(0);
00240 super.setWhichNormToUseForNextRefinement(Integer.valueOf(refNorm).intValue());
00241 }
00242
00243 if (set.isSet("Wnt")){
00244 String tesnorm = set.getOption("Wnt").getResultValue(0);
00245 super.setWhichNormToUseForTesselation(Integer.valueOf(tesnorm).intValue());
00246 ConnectieCriterium.setWichNormToUse(getWhichNormToUseForTesselation());
00247 }
00248
00249 if (set.isSet("maxr")){
00250 String max_rico=set.getOption("maxr").getResultValue(0);
00251 super.setMaxRico(Integer.valueOf(max_rico).intValue());
00252 }
00253
00254 if (set.isSet("snij")){
00255 String max_rico=set.getOption("snij").getResultValue(0);
00256 int SNIJPIXLESTRATEGYTYPE=Integer.valueOf(max_rico).intValue();
00257 super.setSnijPixelStrategyTYPE(SNIJPIXLESTRATEGYTYPE);
00258 }
00259
00260
00261
00262 if (set.isSet("mb")){
00263 super.setMakeBaseMesh(true);
00264 }
00265 if (set.isSet("perc")){
00266 String percentage=set.getOption("perc").getResultValue(0);
00267 super.setPercentage(Float.valueOf(percentage).floatValue());
00268 }
00269 if (set.isSet("k")){
00270 String k=set.getOption("k").getResultValue(0);
00271 super.setk(Integer.valueOf(k).intValue());
00272 }
00273 if (set.isSet("L")){
00274 String L=set.getOption("L").getResultValue(0);
00275 super.setL(Integer.valueOf(L).intValue());
00276 }
00277
00278 if (set.isSet("N")){
00279 String N=set.getOption("N").getResultValue(0);
00280 super.setN(Integer.valueOf(N).intValue());
00281 }
00282 if (set.isSet("D")){
00283 String D=set.getOption("D").getResultValue(0);
00284 super.setDEGREE(Integer.valueOf(D).intValue());
00285
00286 }
00287 if (set.isSet("vtk")){
00288 this.setWritevtk_and_matlabfile(true);
00289
00290 }
00291
00292 }
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309 private boolean String2Bool(String bool){
00310
00311 if(bool.equalsIgnoreCase("true")){
00312 return true;}else{
00313 return false;
00314 }
00315 }
00316
00317
00318 }