Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

vul2fourier.cpp

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include "vuMisc/vuCommandLineTool.h"
00003 #include "vuLightfield/Converter/vuSphericLightfieldFourier.h"
00004 #include "vuFile/vuFileHelper.h"
00005 
00006 /* 
00007    Usage: vul2fourier --type=3B input.vul output.vul
00008 
00009 */
00010 
00011 vuString g_ErrorMsg;
00012 bool     g_IsVerbose = true;
00013 vuString g_Type;
00014 vuString g_OutputFile;
00015 vuString g_InputFile;
00016 
00017 vuBasicLightfieldConverter *g_Converter = NULL;
00018 
00019 bool _isConverterAvailable(vuString &file)
00020 {
00021   vuString type = vuFileHelper::getFileType(file);
00022   if (!type.hasPrefix("1611") || (type.getLength() < 5)) {
00023     g_ErrorMsg += "  - Input file is not a spherical lightfield file.\n";
00024     return false;
00025   }
00026 
00027   const char chr = type.operator[](4);
00028   switch (chr) {
00029     case '1': type = "1B"; break;
00030     case '2': type = "2B"; break;
00031     case '3': type = "3B"; break;
00032             
00033     case 'A': type = "1F"; break;
00034     case 'B': type = "2F"; break;
00035     case 'C': type = "3F"; break;
00036     default: {
00037       g_ErrorMsg += "  - Don't know type '";
00038       g_ErrorMsg += type;
00039       g_ErrorMsg += "'.";
00040       return false;
00041     }
00042   }
00043 
00044   type += g_Type;
00045 
00046   g_Converter = vuSphericLightfieldFourierFactory::getConverter(type);
00047   if (g_Converter == NULL) {
00048     g_ErrorMsg += "  - Could not find converter for type '";
00049     g_ErrorMsg += type;
00050     g_ErrorMsg += "'\n";
00051     return false;
00052   }
00053   return true;
00054 }
00055 
00056 void destroy()
00057 {
00058   CHECKNDELETE(g_Converter);
00059 }
00060 
00061 void convert()
00062 {  
00063   g_Converter->convert(g_InputFile, g_OutputFile, g_IsVerbose);
00064 }
00065 
00066 /* ------------------------------------------------------------------------ */
00067 /* --- private parameter parsing functions -------------------------------- */
00068 /* ------------------------------------------------------------------------ */
00069 
00070 
00071 vuString _helpString(vuCommandLineTool &tool)
00072 {
00073   vuString str;
00074 
00075 
00076   str += "Converting spherical lightfields to different types,";
00077   str += " e.g. 3 byte -> 2 float\n\n";
00078 
00079   str += "Usage: ";
00080   str += tool.toolName();
00081   str += " --type=tt inputFile outputFile\n\n";
00082   str += "  --type=tt    result type (1B,2B,3B,1F,2F or 3F),   e.g.";
00083   str += " --type=1B\n";
00084   str += "  inputFile    a vuVolume spherical lightfield file, e.g.";
00085   str += " engine_3B.vul\n";
00086   str += "  outputFile   a vuVolume spherical lightfield file, e.g.";
00087   str += " engine_1F.vul\n";
00088  
00089   return str;
00090 }
00091 
00092 bool _parseParameters(int argc, const char **argv)
00093 {
00094   bool isOk = true;
00095   vuCommandLineTool tool(argc, argv);
00096 
00097   g_Type = tool.stringForParameter("--type");
00098   g_Type = "2F";
00099 
00100   if (tool.hasParameter("--help")) {
00101     g_ErrorMsg += _helpString(tool);
00102     return false;
00103   }
00104 
00105   g_ErrorMsg += "Following error(s) occured:\n";
00106 
00107 #if 0
00108   if (!tool.hasParameter("--type")) {
00109     g_ErrorMsg += "  - Result type not set (use '--type=3B').\n";
00110     isOk = false;
00111   }
00112   else  if (g_Type != "1B" && g_Type != "2B" && g_Type != "3B" &&
00113             g_Type != "1F" && g_Type != "2F" && g_Type != "3F") {
00114     g_ErrorMsg += "  - Result type is not properly set. ";
00115     g_ErrorMsg += "(Chose from 1B, 2B, 3B, 1F, 2F or 3F)\n";
00116     isOk = false;
00117   }
00118 #endif
00119 
00120   bool isValid;
00121   word fileCount = tool.numberOfNonParameters(isValid);
00122 
00123   if (fileCount == 0) {
00124     g_ErrorMsg += "  - Neither an input nor an output file is specified.\n";
00125     isOk = false;
00126   }
00127   else if (fileCount == 1)  {
00128     g_ErrorMsg += "  - No output file specified.\n";
00129     isOk = false;
00130   }
00131   else if (fileCount == 2 && isValid)  {
00132     g_InputFile  = tool.getArgument(argc-2);
00133     g_OutputFile = tool.getArgument(argc-1);
00134     if (!tool.fileExists(g_InputFile)) {
00135       g_ErrorMsg += "  - InputFile does not exist ('";
00136       g_ErrorMsg += g_InputFile + "').\n";
00137       isOk = false;
00138     }
00139     else if (!_isConverterAvailable(g_InputFile)) {
00140       // g_ErrorMsg set by _isConverterAvailable()
00141       isOk = false;
00142     }
00143     if (g_OutputFile.isEmpty()) {
00144       g_ErrorMsg += "  - No output file specified.\n";
00145       isOk = false;
00146     }
00147   }
00148   else if (fileCount > 2)  {
00149     g_ErrorMsg += "  - More than one input and one output file specified.\n";
00150     isOk = false;
00151   }
00152   else {
00153     g_ErrorMsg += "  - The input and output file are expected to be at the ";
00154     g_ErrorMsg += " end of the line.\n";
00155     isOk = false;
00156   }
00157 
00158   g_ErrorMsg += "\nType '" + tool.toolName() + " --help' for more information!\n";
00159 
00160   if (isOk) g_ErrorMsg = "";
00161 
00162   return isOk;
00163 }
00164 
00165 /* ------------------------------------------------------------------------ */
00166 /* --- main function ------------------------------------------------------ */
00167 /* ------------------------------------------------------------------------ */
00168 
00169 int main(int argc, const char **argv)
00170 {
00171   if (!_parseParameters(argc, argv)) {
00172     cerr << g_ErrorMsg << endl;
00173     exit(0);
00174   }
00175 
00176   convert();
00177 
00178   destroy();
00179 
00180   return 0;
00181 }

Generated on Wed Dec 15 21:20:35 2004 for vuVolume by  doxygen 1.3.9.1