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

slicer.cpp

Go to the documentation of this file.
00001 #include "FourierSlicer.h"
00002 #include <stdio.h>
00003 #include "vuMisc/vuCommandLineTool.h"
00004 #include "vuFile/vuFileHelper.h"
00005 #include <GL/glut.h>
00006 
00007 /* 
00008    Usage: slicer OPTIONS input.vuf output.vul
00009 
00010    OPTIONS: --views=100 [--show] [--scale=1] [--bias=0] [--filter=d0_c3_2ef]
00011 */
00012 
00013 FourierSlicer_ *g_Slicer     = NULL;
00014 vuString        g_ErrorMsg;
00015 vuString        g_OutputFile;
00016 vuString        g_InputFile;
00017 vuString        g_TimingFileName;
00018 vuString        g_FilterName = "d0_c3_2ef";
00019 float           g_Scale      = 1.0;
00020 float           g_Bias       = 0.0;
00021 int             g_NumOfViews = -1;
00022 int             g_Width      = -1;
00023 int             g_Height     = -1;
00024 bool            g_Visualize  = false;
00025 
00026 void init(void) {
00027   vuString fileType = vuFileHelper::getFileType(g_InputFile.c_str());
00028 
00029   if (fileType == "1712A") {
00030     g_Slicer = new FourierSlicer<1>(g_InputFile.c_str(),
00031                                     g_NumOfViews,
00032                                     g_Scale,
00033                                     g_Bias,
00034                                     g_FilterName,
00035                                     g_TimingFileName);
00036   }
00037   else if (fileType == "1712B") {
00038     g_Slicer = new FourierSlicer<2>(g_InputFile.c_str(),
00039                                     g_NumOfViews,
00040                                     g_Scale,
00041                                     g_Bias,
00042                                     g_FilterName,
00043                                     g_TimingFileName);
00044   }
00045   else if (fileType == "1712C") {
00046     g_Slicer = new FourierSlicer<3>(g_InputFile.c_str(),
00047                                     g_NumOfViews,
00048                                     g_Scale,
00049                                     g_Bias,
00050                                     g_FilterName,
00051                                     g_TimingFileName);
00052   }
00053   else {
00054     cerr << "\nError: fileType '" <<fileType<< "' is not supported!\n" << endl;
00055     exit(0);
00056   }
00057   g_Width  = g_Slicer->getImageWidth();
00058   g_Height = g_Slicer->getImageHeight();
00059 }
00060 
00061 void destroy(void) {
00062   delete g_Slicer;
00063 }
00064 
00065 //*****************************************//
00066 //**** The glut stuff                  ****//
00067 //*****************************************//
00068 
00069 void display(void)
00070 {
00071   g_Slicer->lazyCalculateAndDisplay(g_OutputFile);
00072 }
00073 
00074 void keyboard(unsigned char key, int x, int y)
00075 {
00076   switch(key)
00077     {
00078     case 27:
00079     case 'q':
00080     case 'Q':
00081       destroy();
00082       exit(0);
00083       break;
00084     default:
00085       break;
00086     }
00087   glutPostRedisplay();
00088 }
00089 
00090 void reshape(int width, int height)
00091 {
00092 
00093   glViewport(0, 0, width, height);
00094 
00095   glMatrixMode(GL_PROJECTION);
00096   glLoadIdentity();
00097   gluPerspective(60.0f, 1.0f, 0.1f, 10.0f);
00098   glMatrixMode(GL_MODELVIEW);
00099   glLoadIdentity();
00100   glPixelZoom((float)width/g_Width,(float)height/g_Height);
00101   glTranslated(0.0, 0.0, -2.5);
00102 }
00103 
00104 vuString _helpString(vuCommandLineTool &tool)
00105 {
00106   vuString str;
00107 
00108 
00109   str += "Creating spherical lightfields with arbitrary number of channels"
00110          " using the Fourier Volume Rendering technique.\n\n";
00111   str += "Usage: ";
00112   str += tool.toolName();
00113   str += " mandatory_options [additional_options] inputFile outputFile\n";
00114   str += "\nmandatory_options:\n";
00115   str += "  --views=nnn    number of views,              e.g. --views=100\n";
00116   str += "\nadditional_options:\n";
00117   str += "  --show         shows the views in a window,  e.g. --show\n";
00118   str += "  --scale=fff    sets the image scaling,       e.g. --scale=10.5\n";
00119   str += "  --bias=fff     sets the image bias,          e.g. --bias=128\n";
00120   str += "  --timingFile=f stores timing infos in file f e.g.";
00121   str += " --timingFile=timings.txt\n";
00122   str += "  --filter=name  the interpolation filter,     e.g.";
00123   str += " --filter=d0_c3_2ef\n";
00124   str += "  --help         prints this help text\n";
00125   str += "\ninputFile:\n";
00126   str += "  a unimodal fourier data file (*.vuf),        e.g. engine.vuf\n";
00127   str += "\noutputFile:\n";
00128   str += "  a vuVolume spherical lightfield file,        e.g.";
00129   str += " engine_100_3F.vul\n";
00130   str += "\n\n";
00131   str += "Hint: In case the output is black only, use the --scale option.\n";
00132   
00133   return str;
00134 }
00135 
00136 bool _parseParameters(int argc, const char **argv)
00137 {
00138   bool isOk = true;
00139   vuCommandLineTool tool(argc, argv);
00140 
00141   if (tool.hasParameter("--help")) {
00142     g_ErrorMsg += _helpString(tool);
00143     return false;
00144   }
00145 
00146   g_NumOfViews = tool.intForParameter   ("--views");
00147   g_Visualize  = tool.hasParameter      ("--show");
00148   if (tool.hasParameter("--scale"))
00149     g_Scale = tool.floatForParameter ("--scale");
00150   if (tool.hasParameter("--bias"))
00151     g_Bias = tool.floatForParameter ("--bias");
00152   if (tool.hasParameter("--filter"))
00153     g_FilterName = tool.stringForParameter ("--filter");
00154   if (tool.hasParameter("--timingFile"))
00155     g_TimingFileName = tool.stringForParameter("--timingFile");
00156   
00157   g_ErrorMsg += "Following error(s) occured:\n";
00158 
00159   if (g_Scale <= 0.0f) {
00160     g_ErrorMsg += "  - Scale must be larger than 0\n";
00161     isOk = false;
00162   }
00163 
00164   if (g_FilterName.isEmpty()) {
00165     g_ErrorMsg += "  - filterName is set to empty string";
00166     isOk = false;
00167   }
00168 
00169   if (!tool.hasParameter("--views")) {
00170     g_ErrorMsg += "  - Number of views not set (use '--views=100').\n";
00171     isOk = false;
00172   }
00173   else if (g_NumOfViews < 1 || g_NumOfViews > 10000) {
00174     g_ErrorMsg += "  - Number of views not properly set. ";
00175     g_ErrorMsg += "(Must be between 1 and 10000)\n";
00176     isOk = false;
00177   }
00178 
00179   bool isValid;
00180   word fileCount = tool.numberOfNonParameters(isValid);
00181 
00182   if (fileCount == 0) {
00183     g_ErrorMsg += "  - Neither an input nor an output file is specified.\n";
00184     isOk = false;
00185   }
00186   else if (fileCount == 1)  {
00187     g_ErrorMsg += "  - No output file specified.\n";
00188     isOk = false;
00189   }
00190   else if (fileCount == 2 && isValid)  {
00191     g_InputFile  = tool.getArgument(argc-2);
00192     g_OutputFile = tool.getArgument(argc-1);
00193     if (!tool.fileExists(g_InputFile)) {
00194       g_ErrorMsg += "  - InputFile does not exist ('";
00195       g_ErrorMsg += g_InputFile + "').\n";
00196       isOk = false;
00197     }
00198     if (g_OutputFile.isEmpty()) {
00199       g_ErrorMsg += "  - No output file specified.\n";
00200       isOk = false;
00201     }
00202   }
00203   else if (fileCount > 2)  {
00204     g_ErrorMsg += "  - More than one input and one output file specified.\n";
00205     isOk = false;
00206   }
00207   else {
00208     g_ErrorMsg += "  - The input and output file are expected to be at the ";
00209     g_ErrorMsg += " end of the line.\n";
00210     isOk = false;
00211   }
00212 
00213   g_ErrorMsg += "\nType '" + tool.toolName() + " --help' for more information!\n";
00214 
00215   if (isOk) g_ErrorMsg = "";
00216 
00217   return isOk;
00218 }
00219 
00220 int main(int argc, const char **argv)
00221 {
00222   if (!_parseParameters(argc, argv)) {
00223     cerr << g_ErrorMsg << endl;
00224     exit(0);
00225   }
00226 
00227   init();
00228 
00229   if (g_Visualize) {
00230     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
00231     glutInitWindowSize(g_Width, g_Height);
00232     glutInitWindowPosition(0, 0);
00233 
00234     glutCreateWindow("fourier slicer");
00235 
00236     glutDisplayFunc(display);
00237     glutKeyboardFunc(keyboard);
00238     glutReshapeFunc(reshape);
00239     glutMainLoop();
00240   }
00241   else {
00242     g_Slicer->lazyCalculateAndLog(g_OutputFile);
00243   }
00244 
00245   destroy();
00246   return 0;
00247 }

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