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

vul2vul.cpp

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

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