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

vud2vuf.cpp

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include "Volume/Regular/Unimodal/3d/1B/Intensity/SimpleFVR/vuSimpleFVR.h"
00003 #include "vuMisc/vuCommandLineTool.h"
00004 #include "vuTFunc/vuTFDesign.h"
00005 
00006 /* 
00007    Usage: vud2vuf OPTIONS input.vud output.vuf
00008 
00009    OPTIONS:
00010 */
00011 
00012 
00013 vuString    g_ErrorMsg;
00014 vuString    g_OutputFile;
00015 vuString    g_InputFile;
00016 vuTFDesign *g_TFunc   = NULL;
00017 float       g_MultPad = M_SQRT2;
00018 float       g_AddPad  = 0.0;
00019 float       g_Scale   = 1.0f;
00020 
00021 void doIt(void) {
00022   cout << "multPad = " << g_MultPad << endl;
00023   cout << "addPad  = " << g_AddPad  << endl;
00024   cout << "scale   = " << g_Scale   << endl;
00025   vu1112119::convertVUD2VUF(g_InputFile, g_OutputFile,
00026                             g_MultPad, g_AddPad, g_Scale, g_TFunc);
00027 }
00028 
00029 bool loadTFuncFromFile(vuString fileName)
00030 {
00031   if (fileName.isEmpty()) return true;
00032 
00033   cerr << "........ load transfer function" << endl;
00034   try {
00035     g_TFunc = new vuTFDesign();
00036     if (g_TFunc->loadTF(fileName)) {
00037       g_TFunc->generateFunction();
00038     }
00039     else
00040       return false;
00041   }
00042   catch (const char *msg) {
00043     cerr << msg << endl;
00044     CHECKNDELETE(g_TFunc);
00045     return false;
00046   }
00047   return true;
00048 }
00049 
00050 vuString _helpString(vuCommandLineTool &tool)
00051 {
00052   vuString str;
00053 
00054 
00055   str += "Creates frequency data volumes of type '*.vuf'.\n\n";
00056   str += "Usage: ";
00057   str += tool.toolName();
00058   str += " [additional_options] inputFile outputFile\n";
00059   str += "\nadditional_options:\n";
00060   str += "  --tfunc=fff    transfer function file,       e.g.";
00061   str += " --tfunc=engine.tf\n";  
00062   str += "  --multPad=fff  padding factor (sqrt(2)),     e.g. --multPad=1.0\n";
00063   str += "  --addPad=fff   padding delta  (0.0),         e.g. --addPad=128\n";
00064   str += "  --scale=fff    image scaling  (1.0),         e.g. --scale=25.5\n";
00065   str += "  --help         prints this help text\n";
00066   str += "\ninputFile:\n";
00067   str += "  a regular 3D vuVolume data file,             e.g. engine.vud\n";
00068   str += "\noutputFile:\n";
00069   str += "  a fourier volume rendering file,             e.g. engine_3F.vuf\n";
00070   
00071   return str;
00072 }
00073 
00074 bool _parseParameters(int argc, const char **argv)
00075 {
00076   bool isOk = true;
00077   vuCommandLineTool tool(argc, argv);
00078 
00079   if (tool.hasParameter("--help")) {
00080     g_ErrorMsg += _helpString(tool);
00081     return false;
00082   }
00083 
00084   if (tool.hasParameter("--multPad"))
00085       g_MultPad = tool.floatForParameter("--multPad");
00086   if (tool.hasParameter("--addPad"))
00087       g_AddPad = tool.floatForParameter ("--addPad");
00088   if (tool.hasParameter("--scale"))
00089       g_Scale = tool.floatForParameter  ("--scale");
00090 
00091   g_ErrorMsg += "Following error(s) occured:\n";
00092 
00093   if (tool.hasParameter("--tfunc")) {
00094     vuString fileName = tool.stringForParameter("--tfunc");
00095     if (!loadTFuncFromFile(fileName)) {
00096       g_ErrorMsg += "  - Could not load transfer function from '";
00097       g_ErrorMsg += fileName + "'.\n";
00098       isOk = false;
00099     }
00100   }
00101 
00102   if (g_MultPad < 1.0f) {
00103     g_ErrorMsg += "  - MultPad must be larger than or equal to 1.0\n";
00104     isOk = false;
00105   }
00106 
00107   if (g_AddPad < 0.0f) {
00108     g_ErrorMsg += "  - AddPad must be larger than or equal to 0.0\n";
00109     isOk = false;
00110   }
00111 
00112   bool isValid;
00113   word fileCount = tool.numberOfNonParameters(isValid);
00114 
00115   if (fileCount == 0) {
00116     g_ErrorMsg += "  - Neither an input nor an output file is specified.\n";
00117     isOk = false;
00118   }
00119   else if (fileCount == 1)  {
00120     g_ErrorMsg += "  - No output file specified.\n";
00121     isOk = false;
00122   }
00123   else if (fileCount == 2 && isValid)  {
00124     g_InputFile  = tool.getArgument(argc-2);
00125     g_OutputFile = tool.getArgument(argc-1);
00126     if (!tool.fileExists(g_InputFile)) {
00127       g_ErrorMsg += "  - InputFile does not exist ('";
00128       g_ErrorMsg += g_InputFile + "').\n";
00129       isOk = false;
00130     }
00131     if (g_OutputFile.isEmpty()) {
00132       g_ErrorMsg += "  - No output file specified.\n";
00133       isOk = false;
00134     }
00135   }
00136   else if (fileCount > 2)  {
00137     g_ErrorMsg += "  - More than one input and one output file specified.\n";
00138     isOk = false;
00139   }
00140   else {
00141     g_ErrorMsg += "  - The input and output file are expected to be at the ";
00142     g_ErrorMsg += " end of the line.\n";
00143     isOk = false;
00144   }
00145 
00146   g_ErrorMsg += "\nType '" + tool.toolName() + " --help' for more information!\n";
00147 
00148   if (isOk) g_ErrorMsg = "";
00149 
00150   return isOk;
00151 }
00152 
00153 int main(int argc, const char **argv)
00154 {
00155   if (!_parseParameters(argc, argv)) {
00156     cerr << g_ErrorMsg << endl;
00157     exit(0);
00158   }
00159 
00160   doIt();
00161 
00162   return 0;
00163 }

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